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