/** * Fetch images from pool according to any default tag(s) option specified * in the global schema.yml. * Override added to specify per tag in MooEditable * * @return sfDoctrinePager */ public function getPager($per_page = 12, $page = 1, $tagged_object = null, $tag = null) { $pager = new sfDoctrinePager($this->getClassnameToReturn(), $per_page); $im = new sfImagePoolImage(); if (!$im->option('tagging')) { $tagged_object = $tag = null; } $im->free(true); if (isset($tagged_object) && ($tag = $tagged_object->getTagRestriction())) { $query = TagTable::getObjectTaggedWithQuery($this->getClassnameToReturn(), $tag, $pager->getQuery(), array('nb_common_tags' => 1)); $pager->setQuery($query); } else { if (!empty($tag)) { // If only tags we have no taggable object // So get images tagged with this query and do a whereIn on the ids $tags = explode(',', $tag); $images = TagTable::getObjectTaggedWith($tags, array('model' => 'sfImagePoolImage', 'nb_common_tags' => 1)); $image_ids = array(); foreach ($images as $image) { $image_ids[] = $image->id; } if (!empty($image_ids)) { $pager->getQuery()->whereIn('sfImagePoolImage.id', $image_ids); } else { $pager->getQuery()->where('false'); } // we have no images tagged } } $pager->getQuery()->orderBy('updated_at DESC'); $pager->setPage($page); $pager->init(); return $pager; }
public function executeShow(sfWebRequest $request) { $this->talk = Doctrine::getTable('Talk')->createQuery("t")->leftJoin('t.VoteTalk')->leftJoin('t.CreatedBy p')->leftJoin('t.TalkSection')->leftJoin('p.User')->where('t.id = ?', $request->getParameter('id'))->execute()->getFirst(); $this->forward404Unless($this->talk); $this->comments = Comment::getFor($this->talk); $this->form = new CommentTalkForm(); $this->form->setCommented($this->talk); $this->related = TagTable::getObjectTaggedWith(array_keys($this->talk->getTags()), array('nb_common_tags' => 2, 'leftJoin' => 't.CreatedBy p,p.User')); }