public function findAll(DTO $dto) { if ($dto->getOrderBys() == array()) { $dto->setOrderBy('Name', 'ASC'); } return parent::findAll($dto); }
/** * Returns an array of all active plugins * * @return array */ public function getAllActive() { $dto = new DTO(); $dto->setParameter("Status", "enabled"); $dto->setParameter("Installed", "1"); $dto->setOrderBy("Priority"); $dto = $this->findAll($dto); return $dto->getResults(); }
/** * Returns all elements that have the specified aspect * * @param string $aspectName The name of the desired aspect * * @return array An array of the results */ public function findAllWithAspect($aspectName, $restrictSiteSlug = null) { // if (!$this->AspectService->getBySlug($aspectName)) // throw new Exception('Cannot find Elements with Aspect ['.$aspectName.'], Aspect does not exist'); $dto = new DTO(); $dto->setParameter("IncludesAspect", ltrim($aspectName, '@')); if (!is_null($restrictSiteSlug)) { $dto->setParameter("AnchoredSiteSlug", $restrictSiteSlug); } $dto = $this->findAll($dto); return $dto->getResults(); }
public function items() { $this->checkPermission('plugins-list'); $this->PluginInstallationService->scanInstall(); $dto = new DTO(); //$this->buildSorts($dto); //$this->buildLimitOffset($dto); //$this->buildFilters($dto); $dto->setLimit(null); $data = $this->PluginService->findAll($dto)->getResults(); if (count($data) > 0) { $data[0]['TotalRecords'] = count($data); } return $data; }
/** * Returns the query results as an array * * @return array Query results */ public function getResultsAsArray() { return parent::getResults(); }
/** * Finds matching elements * * @param DTO $dto A DTO that can accept the following params: * <PrimaryKey> * Slug * PluginID * Anchored * DefaultOrder * AnchoredSiteID * StartDate string ModifiedDate is after this * EndDate string ModifiedDate is before this * Search string Matches any part of name, slug, or description * IncludesAllAspects string A list of aspects that results must be related to * IncludesAspects string A list of aspects that results must relate to at least one of * * @return DTO The filled DTO object */ public function findAll(DTO $dto) { if ($dto->hasParameter($this->getModel()->getPrimaryKey()) || $dto->hasParameter('Slug') || $dto->hasParameter('PluginID') || $dto->getLimit() != null || $dto->getOffset() != null || $dto->getOrderBys() != null) { $sd = __CLASS__ . (string) serialize($dto); $slugs = $this->SystemCache->get($sd); if ($slugs === false) { // find slugs $this->loadSource(); $slugs = array(); $sort_array = array(); $dir = 'ASC'; $orderbys = $dto->getOrderBys(); if (!empty($orderbys)) { foreach ($orderbys as $col => $dir) { } } else { $col = 'Slug'; } foreach ($this->objectsBySlug as $slug => $obj) { if (($val = $dto->getParameter('Slug')) != null) { if ($obj->Slug != $val) { continue; } } if (($val = $dto->getParameter('PluginID')) != null) { if ($obj->PluginID != $val) { continue; } } $slugs[] = $slug; $sort_array[] = $obj[$col]; } array_multisort($sort_array, strtolower($dir) == 'asc' ? SORT_ASC : SORT_DESC, SORT_REGULAR, $slugs); $this->SystemCache->put($sd, $slugs, 0); } } else { $this->populateRels(); if (!empty($this->aspectrel)) { foreach ($this->aspectrel as $elementSlug => $element) { if ($dto->hasParameter('IncludesAspect')) { $aspect = strtolower($dto->getParameter('IncludesAspect')); if (!in_array($aspect, (array) $element['Aspects'])) { continue; } } $slugs[] = $elementSlug; } } } $results = array(); if (!empty($slugs)) { // retrieve objects $rows = $this->multiGetBySlug($slugs); foreach ($slugs as $slug) { $results[] = $rows[$slug]; } } $dto->setResults($results); return $dto; }
protected function readDTO(DTO &$dto) { if ($dto->isRetrieveTotalRecords()) { $this->templateVars['TotalRecords'] = $dto->getTotalRecords(); $this->templateVars['TotalPages'] = intval(($dto->getTotalRecords() - 1) / $dto->getLimit()) + 1; } return $dto->getResultsAsArray(); }
/** * Appends a WHERE statement to the {@link $query} if the DTO parameter * specified by {@link $name} exists and has a value. * * @param Database $db The database * @param Query $query The Query * @param DTO $dto The DTO * @param string $name The name of the DTO parameter that if exists, column will be used in the QUERY * @param string $column A string that will be used in the WHERE query * * @return void */ public function buildExistsFilter($db, $query, $dto, $name, $column = null) { if ($dto->getParameter($name) != null && $dto->getParameter($name) != false) { if (empty($column)) { $column = $name; } $query->WHERE($column); } }