public function executeNormalView() { $this->setup(); $this->options['constraints'] = $this->getOption('constraints', array()); // Behave well if it's not set yet! if (strlen($this->slot->value)) { $items = $this->slot->MediaItems; $data = $this->slot->getArrayValue(); $order = $data['order']; $itemsById = aArray::listToHashById($items); $this->items = array(); foreach ($order as $id) { if (isset($itemsById[$id])) { $this->items[] = $itemsById[$id]; } } $this->itemIds = aArray::getIds($this->items); foreach ($this->items as $item) { $this->itemIds[] = $item->id; } if ($this->getOption('random', false)) { shuffle($this->items); } } else { $this->items = array(); $this->itemIds = array(); } }
/** * DOCUMENT ME * @return mixed */ public function getOrderedMediaItems() { $order = $this->getMediaItemOrder(); $items = $this->getMediaItems(); if ($order) { $itemsById = aArray::listToHashById($items); $ordered = array(); foreach ($order as $id) { if (isset($itemsById[$id])) { $ordered[] = $itemsById[$id]; } } return $ordered; } return $items; }
/** * Fetch an array of information about categories related to this page. If the page is restricted by * category then only those categories are candidates for inclusion, otherwise any category might be * included in the results. The results are further filtered by whether any objects (or any objects * of the specified model class, if not null) are actually associated with those categories. An * a.get_count_by_category event is posted to determine the overall item counts by model class * for each category in an extensible way. The result is an associative array by model class, * the values of which are associative arrays with a single "counts" key, the value of * which is an associative array by category id of category information including name and * count keys * @param mixed $class * @return array */ public function getCategoriesInfo($class = null) { $event = new sfEvent(null, 'a.get_count_by_category'); sfContext::getInstance()->getEventDispatcher()->filter($event, array()); $counts = $event->getReturnValue(); $fcounts = array(); $categories = $this->getCategories(); if (!count($categories)) { $categories = Doctrine::getTable('aCategory')->findAll(); } $ids = aArray::listToHashById($categories); foreach ($counts as $cclass => $countsInfo) { $fcountsInfo = $countsInfo; foreach ($countsInfo['counts'] as $id => $info) { if (!isset($ids[$id])) { unset($fcountsInfo['counts'][$id]); } } $fcounts[$cclass] = $fcountsInfo; } if (!is_null($class)) { if (isset($fcounts[$class])) { return $fcounts[$class]; } else { return 0; } } else { return $fcounts; } }
/** * DOCUMENT ME * @param mixed $validator * @param mixed $value * @return mixed */ public function validateViewGroups($validator, $value) { $values = json_decode($value, true); if (!is_array($values)) { throw new sfValidatorError($validator, 'Bad permissions JSON'); } $candidates = Doctrine::getTable('aPage')->getViewCandidateGroups(); $candidates = aArray::listToHashById($candidates); foreach ($values as $info) { if ($info['id'] === 'editors_and_guests') { continue; } if (!isset($candidates[$info['id']])) { throw new sfValidatorError($validator, 'noncandidate'); } } return $value; }
/** * Given an array of blogItems this function will populate its virtual page * areas with the current slot versions. * @param aBlogItem $blogItems */ public static function populatePages($blogItems) { $pageIds = array(); foreach ($blogItems as $aBlogItem) { $pageIds[] = $aBlogItem['page_id']; } $pages = array(); if (count($pageIds)) { $q = aPageTable::queryWithSlots(); $q->whereIn('id', $pageIds); $fast = sfConfig::get('app_a_fasthydrate', false); $pagesInfo = $q->execute(array(), $fast ? Doctrine::HYDRATE_ARRAY : Doctrine::HYDRATE_RECORD); foreach ($pagesInfo as $pageInfo) { $pages[] = aTools::cacheVirtualPage($pageInfo); } } $pagesById = aArray::listToHashById($pages); foreach ($blogItems as $aBlogItem) { if (isset($pagesById[$aBlogItem->page_id])) { $aBlogItem->Page = $pagesById[$aBlogItem->page_id]; } } }
/** * DOCUMENT ME * @param sfWebRequest $request * @return mixed */ public function executeSelected(sfWebRequest $request) { $this->hasPermissionsForSelect(); $this->forward404Unless(aMediaTools::isSelecting()); $selection = aMediaTools::getSelection(); $imageInfo = aMediaTools::getAttribute('imageInfo'); // Get all the items in preparation for possible cropping if (count($selection)) { $items = Doctrine::getTable('aMediaItem')->createQuery('m')->whereIn('m.id', $selection)->execute(); } else { $items = array(); } $items = aArray::listToHashById($items); $newSelection = array(); foreach ($selection as $id) { $nid = $id; // Try not to make gratuitous crops if (isset($imageInfo[$id])) { $item = $items[$id]; $i = $imageInfo[$id]; if ($item->getCroppable() && isset($i['cropLeft']) && ($i['cropLeft'] > 0 || $i['cropTop'] > 0 || $i['cropWidth'] != $item->width || $i['cropHeight'] != $item->height)) { // We need to make a crop $item = $items[$id]; $crop = $item->findOrCreateCrop($imageInfo[$id]); $crop->save(); $nid = $crop->id; } $newSelection[] = $nid; } } // Ooops best to get this before clearing it huh $after = aMediaTools::getAfter(); // addParamsNoDelete never attempts to eliminate a field just because // its value is empty. This is how we distinguish between cancellation // and selecting zero items if (!aMediaTools::isMultiple()) { // Call this too soon and you lose isMultiple aMediaTools::clearSelecting(); if (count($newSelection)) { $after = aUrl::addParams($after, array("aMediaId" => $newSelection[0])); return $this->redirect($after); } else { // Our image UI lets you trash your single selection. Which makes sense. // So implement a way of passing that back. It's up to the // receiving action to actually respect it of course $after = aUrl::addParams($after, array("aMediaUnset" => 1)); return $this->redirect($after); } } else { aMediaTools::clearSelecting(); $url = aUrl::addParamsNoDelete($after, array("aMediaIds" => implode(",", $newSelection))); return $this->redirect($url); } }