/**
  * Countable: return count of rows
  *
  * @return int
  */
 public function count()
 {
     if ($this->count === null) {
         $this->count = $this->dataSource->count();
     }
     return $this->count;
 }
 public function testCountReturnsCountOfRows()
 {
     $count = rand(3, 75);
     $dataSource = $this->getArrayDataSource($count);
     $this->resultSet->initialize($dataSource);
     $this->assertEquals($count, $this->resultSet->count());
 }
 /**
  * Get joined product
  * 
  * @param int $id product id
  * @return ProductJoinedRow
  * @throws Exception\InvalidArgumentException
  */
 public function getProductJoinedRow($id)
 {
     $id = (int) $id;
     $pt = $this->getJoinedTable('ProductTable')->getTable();
     $pdt = $this->getJoinedTable('ProductDescriptionTable')->getTable();
     $select = $this->sql->select()->from("{$pt}")->columns(array("*"))->join($pdt, "{$pt}.product_id = {$pdt}.product_id", array('description_id', 'description'), Select::JOIN_LEFT)->order("{$pt}.product_id DESC")->where("{$pt}.product_id = {$id}");
     $statement = $this->sql->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new ProductJoinedRow());
     $resultSet->initialize($statement->execute());
     if (!$resultSet->count()) {
         throw new Exception\InvalidArgumentException("Not found joined product: {$id}");
     }
     return $resultSet->current();
 }
 /**
  * Check modules structure pages
  *
  * @param string $module
  * @return boolean
  */
 public function checkModuleStructurePages($module)
 {
     $select = $this->select();
     $select->from(['a' => 'application_module'])->columns([])->join(['b' => 'page_system'], 'a.id = b.module', [])->join(['c' => 'page_structure'], 'b.id = c.system_page', ['id'])->where(['name' => $module])->limit(1);
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     $result = $resultSet->count() ? true : false;
     // load the module's translations
     if (true === $result) {
         $module = $this->getModuleInfo($module);
         if ($module['type'] == self::MODULE_TYPE_CUSTOM && $module['status'] == self::MODULE_STATUS_NOT_ACTIVE) {
             $this->addModuleTranslations($this->getSystemModuleConfig($module['name'], false));
         }
     }
     return $result;
 }
 /**
  * Get all the attributes ids from the group attributes Idx
  * 
  * @param \Zend\Db\ResultSet\ResultSet $records
  * @return array
  */
 public function getAllAttributeIds(\Zend\Db\ResultSet\ResultSet $records)
 {
     $ids = array();
     if ($records->count()) {
         foreach ($records as $record) {
             $ids[] = $record->attribute_id;
         }
     }
     return $ids;
 }
 public function setEntities(ResultSet $oResultSet)
 {
     $aEntities = array();
     if ($oResultSet->count()) {
         foreach ($oResultSet as $oRow) {
             foreach ($oRow as $sKey => $sValue) {
                 $oRow->{$sKey} = $this->getTranslatedValue($sKey, $sValue);
             }
             $oEntity = $this->createNewEntity();
             $oEntity->setOptions($oRow);
             $aEntities[] = $oEntity;
         }
     }
     return $aEntities;
 }
 public function init($params, $table, $whereSql = '')
 {
     $result['draw'] = (int) $params['draw'];
     $columns = $this->_extractColumns($params);
     $sql = new Sql($this->adapterDb);
     $where = new Where();
     $select = $sql->select()->from($table)->columns(array('total' => new Expression('COUNT(*)')));
     if ($whereSql) {
         $where->literal($whereSql);
         $select->where($where);
     }
     $statement = $sql->prepareStatementForSqlObject($select);
     $resultsSql = $statement->execute();
     $result['recordsTotal'] = (int) $resultsSql->current()['total'];
     $select = $sql->select()->from($table)->columns($columns);
     $globalSearch = [];
     if ($search = $params['search']['value']) {
         foreach ($columns as $col) {
             $globalSearch[] = "`{$col}` LIKE '%{$search}%'";
         }
     }
     if (!empty($globalSearch)) {
         $globalSearchSql = implode(' OR ', $globalSearch);
         $where->literal("({$globalSearchSql})");
     }
     $columnSearch = [];
     foreach ($params['columns'] as $index => $column) {
         if ($column['search']['value']) {
             if ($params['search']['regex'] == 'false') {
                 $columnSearch[] = "`{$columns[$index]}` LIKE '%{$column['search']['value']}%'";
             } else {
                 $columnSearch[] = "`{$columns[$index]}` = '{$column['search']['value']}'";
             }
         }
     }
     if (!empty($columnSearch)) {
         $columnSearchSql = implode(' AND ', $columnSearch);
         $where->literal("({$columnSearchSql})");
     }
     if ($whereSql) {
         $where->literal($whereSql);
     }
     $select->where($where);
     if (isset($params['order'])) {
         $arrayOrder = [];
         foreach ($params['order'] as $order) {
             $arrayOrder[$columns[$order['column']]] = $order['dir'];
         }
         $select->order($arrayOrder);
     }
     //        die($select->getSqlString());
     $statement = $sql->prepareStatementForSqlObject($select);
     $resultsSql = $statement->execute();
     $resultSet = new ResultSet();
     $resultSet->initialize($resultsSql);
     $result['recordsFiltered'] = (int) $resultSet->count();
     $dbSelect = new DbSelect($select, $this->adapterDb);
     $paginator = new Paginator($dbSelect);
     $paginator->setItemCountPerPage($params['length']);
     $paginator->setCurrentPageNumber($params['start'] / $params['length'] + 1);
     $array = [];
     foreach ($paginator as $index => $data) {
         foreach ($data as $value) {
             $array[$index][] = $value;
         }
     }
     $result['data'] = $array;
     $this->data = $result;
     return $this;
 }
Beispiel #8
0
 /**
  * @param ResultSet|array[] $cities
  * @return array
  */
 private function getCityListAsArray($cities)
 {
     $cityList = ['-- All Cities --'];
     if ($cities->count()) {
         foreach ($cities as $city) {
             $cityList[$city['id']] = $city['name'];
         }
     }
     return $cityList;
 }
 /**
  * Countable: return count of rows
  *
  * @return int
  */
 public function count()
 {
     return $this->zfResultSet->count();
 }
Beispiel #10
0
 /**
  * @param \Zend\Db\ResultSet\ResultSet|MoneyAccount[]|\ArrayObject $pspList
  * @return array
  */
 private function prepareData($pspList)
 {
     $data = [];
     if ($pspList->count()) {
         foreach ($pspList as $psp) {
             $router = $this->getEvent()->getRouter();
             $editUrl = $router->assemble(['controller' => 'psp', 'action' => 'edit', 'id' => $psp->getId()], ['name' => 'finance/psp']);
             $status = $psp->getActive() ? '<span class="label label-success">Active</span>' : '<span class="label label-default">Inactive</span>';
             array_push($data, ['<div class="text-center">' . $status . '</div>', $psp->getShortName(), $psp->getName(), $psp->getMoneyAccountName(), $psp->getBatch(), '<a class="btn btn-xs btn-primary" href="' . $editUrl . '" data-html-content="Edit"></a>']);
         }
     }
     return $data;
 }
 protected function _createSessionFromResult(Db\ResultSet\ResultSet $result)
 {
     if (!$result->count()) {
         return NULL;
     }
     return $this->_arrayToSession((array) $result->current());
 }
 /**
  * Get answer track
  *
  * @param integer $questionId
  * @return array
  */
 public function getAnswerTrack($questionId)
 {
     $processedData = [];
     $select = $this->select();
     $select->from('poll_answer_track')->columns(['answer_id', 'answer_count' => new Expression('count(answer_id)')])->where(['question_id' => $questionId])->group('answer_id');
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     if (!$resultSet->count()) {
         return $processedData;
     }
     // process track data
     foreach ($resultSet as $data) {
         $processedData[$data->answer_id] = $data->answer_count;
     }
     return $processedData;
 }