visa_app/application/models/User_Model.php
venbatechnologies@gmail.com 769edb667b profile
2018-08-09 10:27:59 +05:30

316 lines
10 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model
{
/**
* This function is used to get the User Details
*/
function Get_UserDetails()
{
$this->db->select('*');
$this->db->from('Tab_Register');
$query = $this->db->get();
$UserDetailsData = $query->result();
return $UserDetailsData;
}
/**
* This function is used to get the Profile
*/
function Get_Profile($arg)
{
$this->db->select('reg.*,user.*');
$this->db->from('Tab_Register reg');
$this->db->join('Tab_Users user', 'user.name = reg.Name','left');
$this->db->where('user.userId',$arg);
$query = $this->db->get();
$ProfileData = $query->result();
return $ProfileData;
}
/**
* To Update the values of Country detail on respective CounterCode into 'Tab_Documents' table
* @param arry $CountryMasterDatas : This will have all the edited Country Details
* @param number $Cc : This is Country code
*/
function Update_Register($Registerdata,$RegNo)
{
$this->db->where('RegNo',$RegNo);
$this->db->update('Tab_Register',$Registerdata);
return TRUE;
}
function Update_User($Userdata,$userId){
$this->db->where('userId',$userId);
$this->db->update('Tab_Users',$Userdata);
return TRUE;
}
/**
* This function is used to get the user listing count
* @param string $searchText : This is optional search text
* @return number $count : This is row count
*/
function userListingCount($searchText = '')
{
$this->db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, Role.role');
$this->db->from('Tab_Users as BaseTbl');
$this->db->join('Tab_Roles as Role', 'Role.roleId = BaseTbl.roleId','left');
if(!empty($searchText)) {
$likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%'
OR BaseTbl.name LIKE '%".$searchText."%'
OR BaseTbl.mobile LIKE '%".$searchText."%')";
$this->db->where($likeCriteria);
}
$this->db->where('BaseTbl.isDeleted', 0);
$this->db->where('BaseTbl.roleId !=', 1);
$query = $this->db->get();
return $query->num_rows();
}
/**
* This function is used to get the user listing count
* @param string $searchText : This is optional search text
* @param number $page : This is pagination offset
* @param number $segment : This is pagination limit
* @return array $result : This is result
*/
function userListing($searchText = '', $page, $segment)
{
$this->db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, Role.role');
$this->db->from('Tab_Users as BaseTbl');
$this->db->join('Tab_Roles as Role', 'Role.roleId = BaseTbl.roleId','left');
if(!empty($searchText)) {
$likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%'
OR BaseTbl.name LIKE '%".$searchText."%'
OR BaseTbl.mobile LIKE '%".$searchText."%')";
$this->db->where($likeCriteria);
}
$this->db->where('BaseTbl.isDeleted', 0);
$this->db->where('BaseTbl.roleId !=', 1);
$this->db->limit($page, $segment);
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* This function is used to get the user roles information
* @return array $result : This is result of the query
*/
function getUserRoles()
{
$this->db->select('roleId, role');
$this->db->from('Tab_Roles');
$this->db->where('roleId !=', 1);
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to check whether email id is already exist or not
* @param {string} $email : This is email id
* @param {number} $userId : This is user id
* @return {mixed} $result : This is searched result
*/
function checkEmailExists($email, $userId = 0)
{
$this->db->select("email");
$this->db->from("Tab_Users");
$this->db->where("email", $email);
$this->db->where("isDeleted", 0);
if($userId != 0){
$this->db->where("userId !=", $userId);
}
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to add new user to system
* @return number $insert_id : This is last inserted id
*/
function addNewUser($userInfo)
{
$this->db->trans_start();
$this->db->insert('Tab_Users', $userInfo);
$insert_id = $this->db->insert_id();
$this->db->trans_complete();
return $insert_id;
}
/**
* This function used to get user information by id
* @param number $userId : This is user id
* @return array $result : This is user information
*/
function getUserInfo($userId)
{
$this->db->select('userId, name, email, mobile, roleId');
$this->db->from('Tab_Users');
$this->db->where('isDeleted', 0);
$this->db->where('roleId !=', 1);
$this->db->where('userId', $userId);
$query = $this->db->get();
return $query->result();
}
/**
* This function is used to update the user information
* @param array $userInfo : This is users updated information
* @param number $userId : This is user id
*/
function editUser($userInfo, $userId)
{
$this->db->where('userId', $userId);
$this->db->update('Tab_Users', $userInfo);
return TRUE;
}
/**
* This function is used to delete the user information
* @param number $userId : This is user id
* @return boolean $result : TRUE / FALSE
*/
function deleteUser($userId, $userInfo)
{
$this->db->where('userId', $userId);
$this->db->update('Tab_Users', $userInfo);
return $this->db->affected_rows();
}
/**
* This function is used to match users password for change password
* @param number $userId : This is user id
*/
function matchOldPassword($userId, $oldPassword)
{
$this->db->select('userId, password');
$this->db->where('userId', $userId);
$this->db->where('isDeleted', 0);
$query = $this->db->get('Tab_Users');
$user = $query->result();
if(!empty($user)){
if(verifyHashedPassword($oldPassword, $user[0]->password)){
return $user;
} else {
return array();
}
} else {
return array();
}
}
/**
* This function is used to change users password
* @param number $userId : This is user id
* @param array $userInfo : This is user updation info
*/
function changePassword($userId, $userInfo)
{
$this->db->where('userId', $userId);
$this->db->where('isDeleted', 0);
$this->db->update('Tab_Users', $userInfo);
return $this->db->affected_rows();
}
/**
* This function is used to get user login history
* @param number $userId : This is user id
*/
function loginHistoryCount($userId, $searchText, $fromDate, $toDate)
{
$this->db->select('BaseTbl.userId, BaseTbl.sessionData, BaseTbl.machineIp, BaseTbl.userAgent, BaseTbl.agentString, BaseTbl.platform, BaseTbl.createdDtm');
if(!empty($searchText)) {
$likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%')";
$this->db->where($likeCriteria);
}
if(!empty($fromDate)) {
$likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) >= '".date('Y-m-d', strtotime($fromDate))."'";
$this->db->where($likeCriteria);
}
if(!empty($toDate)) {
$likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) <= '".date('Y-m-d', strtotime($toDate))."'";
$this->db->where($likeCriteria);
}
$this->db->where('BaseTbl.userId', $userId);
$this->db->from('Tab_LastLogin as BaseTbl');
$query = $this->db->get();
return $query->num_rows();
}
/**
* This function is used to get user login history
* @param number $userId : This is user id
* @param number $page : This is pagination offset
* @param number $segment : This is pagination limit
* @return array $result : This is result
*/
function loginHistory($userId, $searchText, $fromDate, $toDate, $page, $segment)
{
$this->db->select('BaseTbl.userId, BaseTbl.sessionData, BaseTbl.machineIp, BaseTbl.userAgent, BaseTbl.agentString, BaseTbl.platform, BaseTbl.createdDtm');
$this->db->from('Tab_LastLogin as BaseTbl');
if(!empty($searchText)) {
$likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%')";
$this->db->where($likeCriteria);
}
if(!empty($fromDate)) {
$likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) >= '".date('Y-m-d', strtotime($fromDate))."'";
$this->db->where($likeCriteria);
}
if(!empty($toDate)) {
$likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) <= '".date('Y-m-d', strtotime($toDate))."'";
$this->db->where($likeCriteria);
}
$this->db->where('BaseTbl.userId', $userId);
$this->db->order_by('BaseTbl.id', 'DESC');
$this->db->limit($page, $segment);
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* This function used to get user information by id
* @param number $userId : This is user id
* @return array $result : This is user information
*/
function getUserInfoById($userId)
{
$this->db->select('userId, name, email, mobile, roleId');
$this->db->from('Tab_Users');
$this->db->where('isDeleted', 0);
$this->db->where('userId', $userId);
$query = $this->db->get();
return $query->row();
}
}