/** * DOCUMENT ME */ public static function retrieveCategoriesWithCounts() { $categorizables = aCategoryTable::getCategorizables(); $q = aCategoryTable::getInstance()->createQuery(); foreach ($categorizables as $key => $info) { $q->leftJoin($info['relation'] . ' ' . $key); $q->addSelect(sprintf('COUNT(%s.id)')); } }
/** * DOCUMENT ME * @return mixed */ protected function getTaggedItems() { $value = $this->slot->getArrayValue(); $this->items = array(); $this->itemIds = array(); // Not set yet if (!count($value)) { return; } if (isset($value['form'])) { // Tolerate what my early alphas did to save our devs some grief, but don't // respect it return; } // We have getBrowseQuery, so reuse it! $params = array(); if (isset($value['categories_list'])) { $params['allowed_categories'] = aCategoryTable::getInstance()->createQuery('c')->whereIn('c.id', $value['categories_list'])->execute(); } if (isset($value['tags_list'])) { $params['allowed_tags'] = $value['tags_list']; } if (isset($this->options['constraints'])) { foreach ($this->options['constraints'] as $k => $v) { $params[$k] = $v; } } $params['type'] = 'image'; $q = aMediaItemTable::getBrowseQuery($params); $q->andWhere('(aMediaItem.view_is_secure IS NULL OR aMediaItem.view_is_secure IS FALSE)'); $q->limit($value['count']); $q->orderBy('aMediaItem.created_at DESC'); $this->items = $q->execute(); // shuffle likes real arrays better $a = array(); foreach ($this->items as $item) { $a[] = $item; } $this->items = $a; $this->itemIds = aArray::getIds($this->items); }
/** * Returns categories that were added to this object by someone else which this user * is not eligible to remove * @return mixed */ public function getAdminCategories() { $reserved = array(); $existing = Doctrine::getTable('aCategory')->createQuery('c')->select('c.*')->innerJoin('c.MediaItems mi WITH mi.id = ?', $this->id)->execute(); $categoriesForUser = aCategoryTable::getInstance()->addCategoriesForUser(sfContext::getInstance()->getUser()->getGuardUser(), $this->isAdmin())->execute(); $ours = array_flip(aArray::getIds($categoriesForUser)); foreach ($existing as $category) { if (!isset($ours[$category->id])) { $reserved[] = $category; } } return $reserved; }