/**
  * Return the number of result rows.
  * @return integer
  */
 public function countResults()
 {
     $params = $this->getTemplate()->getSectionParams('datasource');
     if ($params->getParameter('countmode', null) === 'none') {
         $this->api_count = null;
         $this->result_count = 0;
     } elseif ($params->getParameter('countmode', null) !== 'simple') {
         if ($this->api_count !== null) {
             $this->api_count->setSearchType(IcingaApiConstants::SEARCH_TYPE_COUNT);
             if (is_array($fields = $params->getParameter('countfields')) && count($fields)) {
                 /**
                  * We need to reset the columns here. Count columns differs
                  * from result set columns
                  */
                 $this->api_count->setResultColumns($fields, true);
                 $this->api_count->setResultType(IcingaApiConstants::RESULT_ARRAY);
                 $result = $this->api_count->fetch();
                 // Try to determine the fields
                 $row = $result->getRow();
                 if ($row !== false) {
                     $fields = array_keys($row);
                     $field = array_shift($fields);
                     $this->result_count = (int) $row[$field];
                 }
             }
         }
     }
     return $this->result_count;
 }
 public function setColumns(IcingaApiSearchIdo $search, AgaviRequestDataHolder $rd)
 {
     if ($search->getSearchType() == IcingaApiSearch::SEARCH_TYPE_COUNT) {
         $search->setResultColumns($rd->getParameter("countColumn"));
         return true;
     }
     $columns = $rd->getParameter("columns", null);
     if (!is_null($columns)) {
         $search->setResultColumns($columns);
     } else {
         $search->setResultColumns(self::$defaultColumns[$rd->getParameter("target")]);
     }
 }