first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Clients\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ClientModel extends Model
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user