Don't query for Monitors if there are no Monitors in the Group.
parent
54f87aa4cf
commit
4668534bf9
|
@ -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 ) {
|
||||
if ($Group->canView()) $Groups[$Group->Id()] = $Group;
|
||||
if ($Group->canView()) $Groups[$Group->Id()] = $Group;
|
||||
}
|
||||
|
||||
# This array is indexed by parent_id
|
||||
|
@ -138,75 +138,80 @@ class Group extends ZM_Object {
|
|||
} else if ( isset($_COOKIE['zmMonitorId']) ) {
|
||||
$monitor_id = $_COOKIE['zmMonitorId'];
|
||||
}
|
||||
$sql = 'SELECT `Id`,`Name` FROM `Monitors`';
|
||||
if ( $options ) {
|
||||
$sql .= ' WHERE '. implode(' AND ', array(
|
||||
( isset($options['groupSql']) ? $options['groupSql']:'')
|
||||
) ).' ORDER BY `Sequence` ASC';
|
||||
}
|
||||
$monitors_dropdown = array(''=>'All');
|
||||
$sql = 'SELECT `Id`,`Name` FROM `Monitors`';
|
||||
if ( $options ) {
|
||||
$sql .= ' WHERE '. implode(' AND ', array(
|
||||
( isset($options['groupSql']) ? $options['groupSql']:'')
|
||||
) ).' ORDER BY `Sequence` ASC';
|
||||
}
|
||||
$monitors_dropdown = array(''=>'All');
|
||||
|
||||
foreach ( dbFetchAll($sql) as $monitor ) {
|
||||
if ( !visibleMonitor($monitor['Id']) ) {
|
||||
continue;
|
||||
}
|
||||
$monitors_dropdown[$monitor['Id']] = $monitor['Name'];
|
||||
}
|
||||
foreach ( dbFetchAll($sql) as $monitor ) {
|
||||
if ( !visibleMonitor($monitor['Id']) ) {
|
||||
continue;
|
||||
}
|
||||
$monitors_dropdown[$monitor['Id']] = $monitor['Name'];
|
||||
}
|
||||
|
||||
echo htmlSelect('monitor_id', $monitors_dropdown, $monitor_id, array('data-on-change-this'=>'changeMonitor'));
|
||||
return $monitor_id;
|
||||
}
|
||||
echo htmlSelect('monitor_id', $monitors_dropdown, $monitor_id, array('data-on-change-this'=>'changeMonitor'));
|
||||
return $monitor_id;
|
||||
}
|
||||
|
||||
public function Parent( ) {
|
||||
if ( $this->{'ParentId'} ) {
|
||||
return Group::find_one(array('Id'=>$this->{'ParentId'}));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function Parent( ) {
|
||||
if ( $this->{'ParentId'} ) {
|
||||
return Group::find_one(array('Id'=>$this->{'ParentId'}));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function Parents() {
|
||||
$Parents = array();
|
||||
$Parent = $this->Parent();
|
||||
public function Parents() {
|
||||
$Parents = array();
|
||||
$Parent = $this->Parent();
|
||||
$seen_parents = array();
|
||||
while ($Parent) {
|
||||
while ($Parent) {
|
||||
$seen_parents[$Parent->Id()] = $Parent;
|
||||
array_unshift($Parents, $Parent);
|
||||
$Parent = $Parent->Parent();
|
||||
array_unshift($Parents, $Parent);
|
||||
$Parent = $Parent->Parent();
|
||||
if ($Parent and isset($seen_parents[$Parent->Id()])) {
|
||||
Warning("Detected hierarchy loop in group {$Parent->Name()}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $Parents;
|
||||
}
|
||||
public function Children() {
|
||||
if (!property_exists($this, 'Children')) {
|
||||
$this->{'Children'} = Group::find(array('ParentId'=>$this->Id()));
|
||||
}
|
||||
return $this->{'Children'};
|
||||
}
|
||||
public function Monitors() {
|
||||
}
|
||||
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'};
|
||||
}
|
||||
$monitor_ids = $this->MonitorIds();
|
||||
if (count($monitor_ids)) {
|
||||
$this->{'Monitors'} = Monitor::find(array('Id'=>$monitor_ids));
|
||||
} else {
|
||||
$this->{'Monitors'} = array();
|
||||
}
|
||||
}
|
||||
return $this->{'Monitors'};
|
||||
}
|
||||
|
||||
public function canView($u=null) {
|
||||
global $user;
|
||||
if (!$u) $u = $user;
|
||||
public function canView($u=null) {
|
||||
global $user;
|
||||
if (!$u) $u = $user;
|
||||
if (!count($this->Monitors()) and !count($this->Children())) {
|
||||
return true;
|
||||
}
|
||||
# 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;
|
||||
}
|
||||
# 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} # end class Group
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue