nhance/app/Models/ClientRMModel.php
2025-09-09 15:44:09 +05:30

59 lines
1.7 KiB
PHP
Executable File

<?php
namespace App\Models;
use CodeIgniter\Model;
class ClientRMModel extends Model
{
protected $table = 'client_rm';
protected $primaryKey = 'id';
protected $allowedFields = [
"id",
"client_id",
"user_id",
"level",
"created_by",
"updated_by",
"is_active",
];
public function checkExistenceOfClientRelation($id, $user_id, $level)
{
$query = $this->where('client_id', $id)
->where('user_id', $user_id)
->where('level', $level)
->countAllResults();
return ($query > 0) ? true : false;
}
public function getAllClientRM()
{
return $this->db->table('client_rm')
->select('client_rm.client_id, client_rm.level,')
->select('user_profiles.first_name as account_manager')
->join('user_profiles', 'user_profiles.id = client_rm.user_id')
->where('level', 3)
->get()
->getResult();
}
public function findAccountManagerEmail($client_id)
{
$builder = $this->db->table('client_rm');
$builder->select('user_profiles.email');
$builder->join('user_profiles', 'user_profiles.id = client_rm.user_id');
$builder->where('client_rm.client_id', $client_id);
$builder->where('client_rm.level', 3); // Assuming level 3 is for account managers
$result = $builder->get()->getResultArray();
if (count($result) > 0) {
// Extract just the email values into a simple string array
return array_column($result, 'email');
} else {
return null; // or []
}
}
}