first commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?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)
|
||||
{
|
||||
// TODO: Здесь мы будем делать JOIN с таблицей organization_users
|
||||
// Пока упрощенная версия для владельца
|
||||
return $this->where('owner_id', $userId)->findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class OrganizationUserModel extends Model
|
||||
{
|
||||
protected $table = 'organization_users';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $allowedFields = ['organization_id', 'user_id', 'role', 'status', 'joined_at'];
|
||||
|
||||
protected $useTimestamps = false; // У нас есть только created_at, можно настроить вручную
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class UserModel extends Model
|
||||
{
|
||||
protected $table = 'users';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
'email',
|
||||
'password',
|
||||
'name',
|
||||
'phone',
|
||||
'avatar',
|
||||
// Поля для верификации email
|
||||
'verification_token',
|
||||
'email_verified',
|
||||
'verified_at'
|
||||
];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
// Хеширование пароля перед вставкой
|
||||
protected $beforeInsert = ['hashPassword'];
|
||||
protected $beforeUpdate = ['hashPassword'];
|
||||
|
||||
protected function hashPassword(array $data)
|
||||
{
|
||||
if (isset($data['data']['password'])) {
|
||||
$data['data']['password'] = password_hash($data['data']['password'], PASSWORD_DEFAULT);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user