153 lines
4.2 KiB
PHP
Executable File
153 lines
4.2 KiB
PHP
Executable File
<?php
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class UserModel extends Model
|
|
{
|
|
protected $DBGroup = 'default';
|
|
protected $table = 'user_profiles';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $insertID = 0;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDelete = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = [
|
|
"id",
|
|
"emp_code",
|
|
"first_name",
|
|
"last_name",
|
|
"email",
|
|
"mobile",
|
|
"profile",
|
|
"role",
|
|
"created_by",
|
|
"created_at",
|
|
"updated_by",
|
|
"updated_at",
|
|
"is_active",
|
|
];
|
|
|
|
// Dates
|
|
protected $useTimestamps = false;
|
|
protected $dateFormat = 'datetime';
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
// Validation
|
|
protected $validationRules = [];
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
protected $cleanValidationRules = true;
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = ["beforeInsert"];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = [];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = ["removePassword"];
|
|
protected $afterFind = ["removePassword"];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
protected function beforeInsert(array $data)
|
|
{
|
|
$data = $this->passwordHash($data);
|
|
return $data;
|
|
}
|
|
|
|
protected function removePassword(array $data)
|
|
{
|
|
// $data =
|
|
unset($data['data']['password']);
|
|
return $data;
|
|
}
|
|
|
|
protected function passwordHash(array $data)
|
|
{
|
|
if (isset($data['data']['password'])) {
|
|
$data['data']['password'] = password_hash($data['data']['password'], PASSWORD_DEFAULT);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getUserByEmail($email){
|
|
|
|
$userData = $this->where('email', $email)->get();
|
|
if ($userData->getNumRows() > 0) {
|
|
return $userData->getRow();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getUserById($id){
|
|
|
|
$userData = $this->where('id', $id)->get();
|
|
if ($userData->getNumRows() > 0) {
|
|
return $userData->getRow();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getUserList(){
|
|
|
|
return $this->db->table('user_profiles')
|
|
->select('user_profiles.*')
|
|
->select('roles.role as user_role')
|
|
->join('roles', 'roles.id = user_profiles.role')
|
|
->get()
|
|
->getResult();
|
|
}
|
|
|
|
public function getUserTeamsByUserID($user_id){
|
|
|
|
$user_teams = $this->db->table('user_profiles')
|
|
->select('user_teams.team_id')
|
|
->join('user_teams', 'user_profiles.id = user_teams.user_id')
|
|
->where('user_profiles.id', $user_id)
|
|
->where('user_teams.is_active', 1)
|
|
->get()
|
|
->getResultArray();
|
|
|
|
if (!empty($user_teams)) {
|
|
// Extract only the 'team_id' values
|
|
$team_ids = array_column($user_teams, 'team_id');
|
|
return $team_ids; // Return array of team IDs
|
|
} else {
|
|
return []; // Return empty array if no teams found
|
|
}
|
|
}
|
|
|
|
public function getUserListForRFQ(){
|
|
|
|
return $this->db->table('user_profiles')
|
|
->select('user_profiles.*')
|
|
->select('roles.role as user_role')
|
|
->join('roles', 'roles.id = user_profiles.role')
|
|
->get()
|
|
->getResultArray();
|
|
}
|
|
|
|
public function getexclusiveUserListForRFQ(){
|
|
$data = $this->db->table('user_profiles')
|
|
->select('user_profiles.*,user_teams.team_id')
|
|
->select('roles.role as user_role')
|
|
->join('roles', 'roles.id = user_profiles.role')
|
|
->join('user_teams', 'user_teams.user_id = user_profiles.id')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
|
|
// dd($data);
|
|
|
|
return $data;
|
|
}
|
|
|
|
}
|
|
?>
|