/**
  * 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;
 }
 protected function checkTaggingField($fields, $tagging_field)
 {
     $im = new sfImagePoolImage();
     $k = array_search($tagging_field, $fields);
     if ($k !== false && !$im->option('tagging')) {
         unset($fields[$k]);
     }
     return $fields;
 }
 public function setup()
 {
     parent::setup();
     $image = new sfImagePoolImage();
     if ($image->option('tagging')) {
         $query = Doctrine_Core::getTable('Tag')->createQuery('t')->where('id IN(SELECT tag_id FROM tagging WHERE taggable_model = "sfImagePoolImage")');
         $this->widgetSchema['tag'] = new sfWidgetFormDoctrineChoice(array('model' => 'tag', 'multiple' => true, 'expanded' => true, 'query' => $query));
         $this->validatorSchema['tag'] = new sfValidatorDoctrineChoice(array('model' => 'tag', 'multiple' => true, 'required' => false));
     }
     $image->free(true);
 }