49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Clients\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
use App\Models\Traits\TenantScopedModel;
|
|
|
|
class ClientModel extends Model
|
|
{
|
|
use TenantScopedModel;
|
|
|
|
protected $table = 'organizations_clients';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = true;
|
|
protected $allowedFields = ['organization_id', 'name', 'email', 'phone', 'notes'];
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
/**
|
|
* Получить клиентов организации
|
|
*/
|
|
public function forOrganization(int $organizationId)
|
|
{
|
|
return $this->where('organization_id', $organizationId);
|
|
}
|
|
|
|
/**
|
|
* Поиск по имени или email
|
|
*/
|
|
public function search(int $organizationId, string $query = '')
|
|
{
|
|
$builder = $this->forOrganization($organizationId);
|
|
|
|
if (!empty($query)) {
|
|
$builder->groupStart()
|
|
->like('name', $query)
|
|
->orLike('email', $query)
|
|
->orLike('phone', $query)
|
|
->groupEnd();
|
|
}
|
|
|
|
return $builder;
|
|
}
|
|
}
|