protected function _actionFetch(KModelContext $context) { $pages = $this->_getPages(); $state = $this->getState(); if ($state->view) { $this->_filterPagesByView($pages, (array) $state->view); } if ($state->id) { $this->_filterPages($pages, 'id', (array) $state->id); } if ($state->alias) { $this->_filterPages($pages, 'alias', (array) $state->alias); } foreach ($pages as &$page) { $page = get_object_vars($page); } unset($page); if ($state->sort && count($pages)) { $page = end($pages); if (isset($page[$state->sort])) { $sort = $state->sort; $direction = $state->direction === 'desc' ? 'desc' : 'asc'; $numeric = is_numeric($page[$state->sort]); usort($pages, function ($a, $b) use($numeric, $sort, $direction) { $result = $numeric ? $a[$sort] - $b[$sort] : strcasecmp($a[$sort], $b[$sort]); return $direction === 'desc' ? -1 * $result : $result; }); } } $options = array('data' => $pages, 'identity_key' => $context->getIdentityKey()); $pages = $this->getObject('com://admin/docman.model.entity.pages', $options); return $pages; }
/** * Fetch a new entity from the data source * * @param KModelContext $context A model context object * @return KModelEntityInterface The entity */ protected function _actionFetch(KModelContext $context) { $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('model', 'entity'); $identifier['name'] = KStringInflector::pluralize($identifier['name']); $options = array('identity_key' => $context->getIdentityKey()); return $this->getObject($identifier, $options); }
/** * Fetch a new entity from the data source * * @param KModelContext $context A model context object * @return KModelEntityInterface The entity */ protected function _actionFetch(KModelContext $context) { $state = $context->state; $table = $this->getTable(); //Entity options $options = array('identity_column' => $context->getIdentityKey()); //Select the rows if (!$state->isEmpty()) { $context->query->columns('tbl.*'); $context->query->table(array('tbl' => $table->getName())); $this->_buildQueryColumns($context->query); $this->_buildQueryJoins($context->query); $this->_buildQueryWhere($context->query); $this->_buildQueryGroup($context->query); $data = $table->select($context->query, KDatabase::FETCH_ROWSET, $options); } else { $data = $table->createRowset($options); } return $data; }
protected function _actionFetch(KModelContext $context) { $pages = $this->_getPages(); $state = $this->getState(); if ($state->view) { $this->_filterPagesByView($pages, (array)$state->view); } if ($state->id) { $this->_filterPages($pages, 'id', (array)$state->id); } if ($state->alias) { $this->_filterPages($pages, 'alias', (array)$state->alias); } foreach ($pages as &$page) { $page = get_object_vars($page); } $options = array( 'data' => $pages, 'identity_key' => $context->getIdentityKey() ); $pages = $this->getObject('com://admin/docman.model.entity.pages', $options); return $pages; }