Implement canView for Groups. Implement Monitors() and Children() functions. Use canView when populating Group dropdown
This commit is contained in:
parent
c7754e5be8
commit
aeb98ec790
|
@ -77,7 +77,7 @@ class Group extends ZM_Object {
|
|||
public static function get_dropdown_options() {
|
||||
$Groups = array();
|
||||
foreach ( Group::find(array(), array('order'=>'lower(Name)')) as $Group ) {
|
||||
$Groups[$Group->Id()] = $Group;
|
||||
if ($Group->canView()) $Groups[$Group->Id()] = $Group;
|
||||
}
|
||||
|
||||
# This array is indexed by parent_id
|
||||
|
@ -173,6 +173,31 @@ public function Parents() {
|
|||
}
|
||||
return $Parents;
|
||||
}
|
||||
public function Children() {
|
||||
if (!property_exists($this, 'Children')) {
|
||||
$this->{'Children'} = Group::find(array('ParentId'=>$this->Id()));
|
||||
}
|
||||
return $this->{'Children'};
|
||||
}
|
||||
public function Monitors() {
|
||||
if (!property_exists($this, 'Monitors') ) {
|
||||
$this->{'Monitors'} = Monitor::find(array('Id'=>$this->MonitorIds()));
|
||||
}
|
||||
return $this->{'Monitors'};
|
||||
}
|
||||
|
||||
public function canView($u=null) {
|
||||
global $user;
|
||||
if (!$u) $u = $user;
|
||||
# Can view if we can view any of the monitors in it.
|
||||
foreach ($this->Monitors() as $monitor) {
|
||||
if ($monitor->canView($u)) return true;
|
||||
}
|
||||
foreach ($this->Children() as $child) {
|
||||
if ($child->canView($u)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} # end class Group
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue