Files
fmgapp/app/models/admin/User.php

250 lines
4.9 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php declare(strict_types=1); namespace IR\App\Models\Admin; if (!defined('IR_START')) exit('<pre>No direct script access allowed</pre>');
/**
* @framework Wevads Framework
* @version 1.0
* @author Amine Idrissi <contact@iresponse.tech>
* @date 2019
* @name User.php
*/
# core
use IR\Core\Application as Application;
# orm
use IR\Orm\ActiveRecord as ActiveRecord;
# helpers
use IR\App\Helpers\AuditLog as AuditLog;
use IR\App\Helpers\Authentication as Authentication;
# utilities
use IR\Utils\Types\Objects as Objects;
/**
* @name User
* @description User Model
*/
class User extends ActiveRecord
{
/**
* @database
* @readwrite
*/
protected $_databaseKey = 'system';
/**
* @schema
* @readwrite
*/
protected $_schema = 'admin';
/**
* @table
* @readwrite
*/
protected $_table = 'users';
# columns
/**
* @column
* @readwrite
* @primary
* @indexed
* @autoincrement
* @type integer
* @nullable false
* @length
*/
protected $_id;
/**
* @column
* @readwrite
* @indexed
* @type integer
* @nullable false
* @length
*/
protected $_production_id;
/**
* @column
* @readwrite
* @type text
* @nullable false
* @length 20
*/
protected $_master_access;
/**
* @column
* @readwrite
* @indexed
* @type text
* @nullable false
* @length 20
*/
protected $_status;
/**
* @column
* @readwrite
* @type text
* @nullable false
* @length 200
*/
protected $_first_name;
/**
* @column
* @readwrite
* @type text
* @nullable true
* @length 200
*/
protected $_last_name;
/**
* @column
* @readwrite
* @type text
* @nullable false
* @length 200
*/
protected $_email;
/**
* @column
* @readwrite
* @type text
* @nullable false
* @length 200
*/
protected $_password;
/**
* @column
* @readwrite
* @type text
* @nullable true
* @length 100
*/
protected $_avatar_name;
/**
* @column
* @readwrite
* @type text
* @nullable false
* @length 200
*/
protected $_created_by;
/**
* @column
* @readwrite
* @type text
* @nullable true
* @length 200
*/
protected $_last_updated_by;
/**
* @column
* @readwrite
* @type date
* @nullable false
* @length
*/
protected $_created_date;
/**
* @column
* @readwrite
* @type date
* @nullable true
* @length
*/
protected $_last_updated_date;
/**
* @var
* @readwrite
*/
protected $_is_tracking_user = false;
/**
* @var
* @permissions
* @readwrite
*/
protected $_permissions = [];
/**
* @var
* @permissions
* @readwrite
*/
protected $_roles = [];
/**
* @name insert
* @description creates a record base on the primary key
* @access public
* @return integer
* @throws DatabaseException
*/
public function insert() : int
{
$this->_id = parent::insert();
# register audit log
AuditLog::registerLog($this->_id,$this->_first_name . ' ' . $this->_last_name,Objects::getInstance()->getName($this),'Insert');
return $this->_id;
}
/**
* @name insert
* @description creates a record base on the primary key
* @access public
* @return integer
* @throws DatabaseException
*/
public function update() : int
{
# register audit log
AuditLog::registerLog($this->_id,$this->_first_name . ' ' . $this->_last_name,Objects::getInstance()->getName($this),'Update');
return parent::update();
}
/**
* @name delete
* @description creates a query object, only if the primary key property value is not empty, and executes the querys delete() method.
* @access public
* @return integer
*/
public function delete() : int
{
# register audit log
AuditLog::registerLog($this->_id,$this->_first_name . ' ' . $this->_last_name,Objects::getInstance()->getName($this),'Delete');
# kill this user's session
$users = Authentication::getAllAuthenticatedUsers();
foreach ($users as $key => $user)
{
if($user->getId() == $this->_id)
{
if(Application::getCurrent()->utils->fileSystem->fileExists(SESSIONS_PATH . DS . $key))
{
Application::getCurrent()->utils->fileSystem->deleteFile(SESSIONS_PATH . DS . $key);
}
}
}
return parent::delete();
}
}