/** * 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; }