38 lines
1.4 KiB
PHP
38 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class OrganizationModel extends Model
|
|
{
|
|
protected $table = 'organizations';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = true; // Включаем мягкое удаление (deleted_at)
|
|
protected $allowedFields = ['owner_id', 'name', 'type', 'logo', 'requisites', 'trial_ends_at', 'settings'];
|
|
|
|
protected $useTimestamps = true;
|
|
protected $dateFormat = 'datetime';
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
// Получить организации конкретного пользователя
|
|
public function getUserOrganizations(int $userId): array
|
|
{
|
|
$db = $this->db();
|
|
$builder = $db->newQuery();
|
|
|
|
return $builder->select('o.*, ou.role, ou.status as membership_status, ou.joined_at')
|
|
->from('organizations o')
|
|
->join('organization_users ou', 'ou.organization_id = o.id', 'inner')
|
|
->where('ou.user_id', $userId)
|
|
->where('ou.status', 'active')
|
|
->where('o.deleted_at', null)
|
|
->orderBy('ou.joined_at', 'ASC')
|
|
->get()
|
|
->getResultArray();
|
|
}
|
|
} |