2020-06-17 16:50:22 +00:00
|
|
|
<?php
|
|
|
|
namespace ZM;
|
|
|
|
require_once('database.php');
|
|
|
|
require_once('Object.php');
|
2022-10-19 21:49:40 +00:00
|
|
|
require_once('Group_Permission.php');
|
|
|
|
require_once('Monitor_Permission.php');
|
2023-03-20 17:15:23 +00:00
|
|
|
require_once('User_Preference.php');
|
2020-06-17 16:50:22 +00:00
|
|
|
|
|
|
|
class User extends ZM_Object {
|
|
|
|
protected static $table = 'Users';
|
|
|
|
|
|
|
|
protected $defaults = array(
|
2020-10-07 15:16:02 +00:00
|
|
|
'Id' => null,
|
2022-06-01 15:20:16 +00:00
|
|
|
'Username' => array('type'=>'text','filter_regexp'=>'/[^\w\.@ ]/', 'default'=>''),
|
2023-04-03 16:45:09 +00:00
|
|
|
'Name' => '',
|
|
|
|
'Email' => '',
|
|
|
|
'Phone' => '',
|
2020-10-07 15:16:02 +00:00
|
|
|
'Password' => '',
|
|
|
|
'Language' => '',
|
|
|
|
'Enabled' => 1,
|
|
|
|
'Stream' => 'None',
|
|
|
|
'Events' => 'None',
|
|
|
|
'Control' => 'None',
|
|
|
|
'Monitors' => 'None',
|
|
|
|
'Groups' => 'None',
|
|
|
|
'Devices' => 'None',
|
2021-04-12 17:43:29 +00:00
|
|
|
'Snapshots' => 'None',
|
2020-10-07 15:16:02 +00:00
|
|
|
'System' => 'None',
|
|
|
|
'MaxBandwidth' => '',
|
|
|
|
'MonitorIds' => '',
|
2020-06-17 16:50:22 +00:00
|
|
|
'TokenMinExpiry' => 0,
|
2020-10-07 15:16:02 +00:00
|
|
|
'APIEnabled' => 1,
|
2022-03-10 19:09:41 +00:00
|
|
|
'HomeView' => '',
|
2020-06-17 16:50:22 +00:00
|
|
|
);
|
|
|
|
|
2022-10-19 21:49:40 +00:00
|
|
|
private $Group_Permissions; # array of GP objects indexed by id
|
|
|
|
private $Monitor_Permissions;
|
2023-03-20 17:15:23 +00:00
|
|
|
private $Preferences;
|
2022-10-19 21:49:40 +00:00
|
|
|
|
2020-06-17 16:50:22 +00:00
|
|
|
public static function find( $parameters = array(), $options = array() ) {
|
|
|
|
return ZM_Object::_find(get_class(), $parameters, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function find_one( $parameters = array(), $options = array() ) {
|
|
|
|
return ZM_Object::_find_one(get_class(), $parameters, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Name( ) {
|
|
|
|
return $this->{'Username'};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function Indexed_By_Id() {
|
|
|
|
$results = array();
|
|
|
|
foreach ( ZM_Object::_find('ZM\User', null, array('order'=>'lower(Username)')) as $Object ) {
|
|
|
|
$results[$Object->Id()] = $Object;
|
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
2022-10-19 21:49:40 +00:00
|
|
|
public function Group_Permissions() {
|
2022-11-02 19:53:13 +00:00
|
|
|
if (!$this->Group_Permissions) {
|
|
|
|
$this->Group_Permissions = array_to_hash_by_key('GroupId', Group_Permission::find(['UserId'=>$this->Id()]));
|
2022-10-19 21:49:40 +00:00
|
|
|
}
|
2022-11-02 19:53:13 +00:00
|
|
|
return array_values($this->Group_Permissions);
|
2022-10-19 21:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function Group_Permission($group_id) {
|
|
|
|
if (!$this->Group_Permissions) $this->Group_Permissions();
|
|
|
|
|
|
|
|
if (!isset($this->Group_Permissions[$group_id])) {
|
|
|
|
$gp = $this->Group_Permissions[$group_id] = new Group_Permission();
|
|
|
|
$gp->UserId($this->Id());
|
|
|
|
$gp->GroupId($this->Id());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->Group_Permissions[$group_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Monitor_Permissions($new=-1) {
|
2022-11-02 21:44:42 +00:00
|
|
|
if ($new != -1) $this->Monitor_Permissions = $new;
|
2022-10-19 21:49:40 +00:00
|
|
|
if (!$this->Monitor_Permissions) {
|
|
|
|
$this->Monitor_Permissions = array_to_hash_by_key('MonitorId', Monitor_Permission::find(['UserId'=>$this->Id()]));
|
|
|
|
}
|
|
|
|
return array_values($this->Monitor_Permissions);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Monitor_Permission($monitor_id) {
|
|
|
|
if (!$this->Monitor_Permissions) $this->Monitor_Permissions();
|
|
|
|
|
|
|
|
if (!isset($this->Monitor_Permissions[$monitor_id])) {
|
|
|
|
$mp = $this->Monitor_Permissions[$monitor_id] = new Monitor_Permission();
|
|
|
|
$mp->UserId($this->Id());
|
|
|
|
$mp->MonitorId($monitor_id);
|
|
|
|
}
|
|
|
|
return $this->Monitor_Permissions[$monitor_id];
|
|
|
|
}
|
2023-03-20 17:15:23 +00:00
|
|
|
|
|
|
|
public function Preferences($new=-1) {
|
|
|
|
if ($new != -1) $this->Preferences = $new;
|
|
|
|
if (!$this->Preferences) {
|
|
|
|
$this->Preferences = array_to_hash_by_key('Name', User_Preference::find(['UserId'=>$this->Id()]));
|
|
|
|
}
|
|
|
|
return array_values($this->Preferences);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Preference($name) {
|
|
|
|
if (!$this->Preferences) $this->Preferences();
|
|
|
|
|
|
|
|
if (!isset($this->Preferences[$name])) {
|
|
|
|
$mp = $this->Preferences[$name] = new User_Preference();
|
|
|
|
$mp->UserId($this->Id());
|
|
|
|
$mp->Name($name);
|
|
|
|
}
|
|
|
|
return $this->Preferences[$name];
|
|
|
|
}
|
2020-06-17 16:50:22 +00:00
|
|
|
} # end class User
|
|
|
|
?>
|