Rough in code for User_Preferences

pull/3680/head
Isaac Connor 2023-03-20 13:15:23 -04:00
parent 5d63d4f375
commit 34e3e99c99
2 changed files with 58 additions and 1 deletions

View File

@ -4,7 +4,7 @@ require_once('database.php');
require_once('Object.php');
require_once('Group_Permission.php');
require_once('Monitor_Permission.php');
require_once('User_Preference.php');
class User extends ZM_Object {
protected static $table = 'Users';
@ -32,6 +32,7 @@ class User extends ZM_Object {
private $Group_Permissions; # array of GP objects indexed by id
private $Monitor_Permissions;
private $Preferences;
public static function find( $parameters = array(), $options = array() ) {
return ZM_Object::_find(get_class(), $parameters, $options);
@ -90,5 +91,24 @@ class User extends ZM_Object {
}
return $this->Monitor_Permissions[$monitor_id];
}
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];
}
} # end class User
?>

View File

@ -0,0 +1,37 @@
<?php
namespace ZM;
require_once('database.php');
require_once('User.php');
require_once('Object.php');
class User_Preference extends ZM_Object {
protected static $table = 'User_Preferences';
protected $defaults = array(
'Id' => null,
'UserId' => null,
'Name' => '',
'value' => '',
);
private $User = null;
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 User() {
if (!$this->User) {
if ($this->{'UserId'}) {
$this->User = User::find_one(['Id'=> $this->{'UserId'}]);
}
if (!$this->User) {
$this->User = new User();
}
}
return $this->User;
}
} # end class User_Preference
?>