Example #1
0
 /**
  * {@inheritdoc}
  */
 public function order($columnOrAlias, $dir = null)
 {
     foreach ($this->subQueries as $sub) {
         $sub->requireColumn($columnOrAlias);
     }
     return parent::order($columnOrAlias, $dir);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getGroup()
 {
     $group = parent::getGroup();
     if (!empty($group) && $this->ds->getDbType() === 'pgsql') {
         foreach ($this->columnMap as $table => $columns) {
             $pk = ($table === 'objects' ? 'cvo.' : 'cvs.') . $this->getPrimaryKeyColumn($table);
             foreach ($columns as $alias => $_) {
                 if (!in_array($pk, $group, true) && in_array($alias, $group, true)) {
                     $group[] = $pk;
                     break;
                 }
             }
         }
     }
     return $group;
 }
Example #3
0
 /**
  * Get the offset if any
  *
  * @return int|null
  */
 public function getOffset()
 {
     return $this->query->getOffset();
 }
 /**
  * {@inheritdoc}
  */
 public function getGroup()
 {
     $group = parent::getGroup() ?: array();
     if (!is_array($group)) {
         $group = array($group);
     }
     if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) {
         $group[] = 's.service_id';
         $group[] = 'so.object_id';
         if ($this->hasJoinedVirtualTable('hosts')) {
             $group[] = 'h.host_id';
         }
         if ($this->hasJoinedVirtualTable('hoststatus')) {
             $group[] = 'hs.hoststatus_id';
         }
         if ($this->hasJoinedVirtualTable('servicestatus')) {
             $group[] = 'ss.servicestatus_id';
         }
         if ($this->hasJoinedVirtualTable('hostgroups')) {
             $selected = false;
             foreach ($this->columns as $alias => $column) {
                 if ($column instanceof Zend_Db_Expr) {
                     continue;
                 }
                 $table = $this->aliasToTableName($this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias));
                 if ($table === 'hostgroups') {
                     $selected = true;
                     break;
                 }
             }
             if ($selected) {
                 $group[] = 'hg.hostgroup_id';
                 $group[] = 'hgo.object_id';
             }
         }
         if ($this->hasJoinedVirtualTable('servicegroups')) {
             $selected = false;
             foreach ($this->columns as $alias => $column) {
                 if ($column instanceof Zend_Db_Expr) {
                     continue;
                 }
                 $table = $this->aliasToTableName($this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias));
                 if ($table === 'servicegroups') {
                     $selected = true;
                     break;
                 }
             }
             if ($selected) {
                 $group[] = 'sg.servicegroup_id';
                 $group[] = 'sgo.object_id';
             }
         }
     }
     return $group;
 }
 /**
  * {@inheritdoc}
  */
 public function getGroup()
 {
     $group = parent::getGroup() ?: array();
     if (!is_array($group)) {
         $group = array($group);
     }
     $groupedTables = array();
     if ($this->hasJoinedVirtualTable('servicegroups')) {
         $group[] = 'ho.object_id';
         $group[] = 'h.host_id';
         $groupedTables['hosts'] = true;
         $serviceGroupColumns = array_keys($this->columnMap['servicegroups']);
         $selectedServiceGroupColumns = array_intersect($serviceGroupColumns, array_keys($this->columns));
         if (!empty($selectedServiceGroupColumns)) {
             $group[] = 'sgo.object_id';
             $group[] = 'sg.servicegroup_id';
             $groupedTables['servicegroups'] = true;
         }
     }
     if ($this->hasJoinedVirtualTable('hostgroups')) {
         if (!isset($groupedTables['hosts'])) {
             $group[] = 'ho.object_id';
             $group[] = 'h.host_id';
             $groupedTables['hosts'] = true;
         }
         $hostGroupColumns = array_keys($this->columnMap['hostgroups']);
         $selectedHostGroupColumns = array_intersect($hostGroupColumns, array_keys($this->columns));
         if (!empty($selectedHostGroupColumns)) {
             $group[] = 'hgo.object_id';
             $group[] = 'hg.hostgroup_id';
             $groupedTables['hostgroups'] = true;
         }
     }
     if (!empty($groupedTables)) {
         foreach ($this->columns as $alias => $column) {
             if ($column instanceof Zend_Db_Expr || $column === '(NULL)') {
                 continue;
             }
             $tableName = $this->aliasToTableName($this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias));
             if (isset($groupedTables[$tableName])) {
                 continue;
             }
             switch ($tableName) {
                 case 'hoststatus':
                     $group[] = 'hs.hoststatus_id';
                     break;
                 case 'serviceproblemsummary':
                     $group[] = 'sps.unhandled_services_count';
                     break;
                 case 'services':
                     $group[] = 'so.object_id';
                     $group[] = 's.service_id';
                     break;
                 case 'instances':
                     $group[] = 'i.instance_id';
                     break;
                 default:
                     continue 2;
             }
             $groupedTables[$tableName] = true;
         }
     }
     return $group;
 }
Example #6
0
 public function requireColumn($alias)
 {
     $this->contacts->addColumn($alias);
     $this->contactgroups->addColumn($alias);
     return parent::requireColumn($alias);
 }
Example #7
0
 public function whereToSql($col, $sign, $expression)
 {
     switch ($col) {
         case 'CASE WHEN ss.current_state = 0 THEN 0 ELSE 1 END':
             if ($sign !== '=') {
                 break;
             }
             if ($expression) {
                 return 'ss.current_state > 0';
             } else {
                 return 'ss.current_state = 0';
             }
             break;
         case 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END':
             if ($sign !== '=') {
                 break;
             }
             if ($expression) {
                 return 'hs.current_state > 0';
             } else {
                 return 'hs.current_state = 0';
             }
             break;
         case 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END':
             if ($sign !== '=') {
                 break;
             }
             if ($expression == 99) {
                 return 'ss.has_been_checked = 0 OR ss.has_been_checked IS NULL';
             }
             if (in_array($expression, array(0, 1, 2, 3))) {
                 return sprintf('((ss.state_type = 1 AND ss.current_state = %d) OR (ss.state_type = 0 AND ss.last_hard_state = %d))', $expression, $expression);
             }
             break;
     }
     return parent::whereToSql($col, $sign, $expression);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function columns(array $columns)
 {
     parent::columns($columns);
     $this->requireVirtualTable('hosts');
     $this->requireVirtualTable('services');
 }