/**  
  * Executes list action.
  * Overrides documentsActions::executeList()
  */
 public function executeList()
 {
     // params in order to add images of linked summits, parkings, etc...
     $request_array = array();
     if ($this->hasRequestParameter('rsummits') && ($summit_ids = $this->getRequestParameter('rsummits'))) {
         if (!in_array($summit_ids, array('-', ' '))) {
             $request_array = array(explode('-', $summit_ids), 'sr', 'ri', 'si');
         }
     } elseif ($this->hasRequestParameter('rparkings') && ($parking_ids = $this->getRequestParameter('rparkings'))) {
         if (!in_array($parking_ids, array('-', ' '))) {
             $request_array = array(explode('-', $parking_ids), 'pr', 'ri', 'pi');
         }
     } elseif ($this->hasRequestParameter('rhuts') && ($hut_ids = $this->getRequestParameter('rhuts'))) {
         if (!in_array($hut_ids, array('-', ' '))) {
             $request_array = array(explode('-', $hut_ids), 'hr', 'ri', 'hi');
         }
     } elseif ($this->hasRequestParameter('oroutes') && ($route_ids = $this->getRequestParameter('oroutes'))) {
         if (!in_array($route_ids, array('-', ' '))) {
             $request_array = array(explode('-', $route_ids), 'ro', 'oi', 'ri');
         }
     } elseif ($this->hasRequestParameter('osites') && ($site_ids = $this->getRequestParameter('osites'))) {
         if (!in_array($site_ids, array('-', ' '))) {
             $request_array = array(explode('-', $site_ids), 'to', 'oi', 'ti');
         }
     }
     if (!empty($request_array)) {
         $ids = array_shift($request_array);
         $pager = new c2cDoctrinePager('Image', c2cTools::mobileVersion() ? sfConfig::get('app_list_mobile_maxline_number') : sfConfig::get('app_list_maxline_number'));
         $this->pager = $pager;
         $q = $pager->getQuery();
         $q->select('DISTINCT i.id, i.image_type, i.geom_wkt, i.filename, ii.name, ii.culture, ii.search_name')->from('Image i')->leftJoin('i.associations a ON i.id = a.linked_id')->leftJoin('i.ImageI18n ii')->where('(a.main_id IN (SELECT a2.linked_id FROM Association a2 WHERE a2.main_id IN (' . implode(',', $ids) . ') AND a2.type = ?) AND a.type = ?)' . ' OR (a.main_id IN (' . implode(',', $ids) . ') AND a.type = ?)', $request_array);
         $pager->setPage($this->getRequestParameter('page', 1));
         $pager->init();
         $nb_results = $pager->getNbResults();
         $this->nb_results = $nb_results;
         // deal with format
         if (isset($this->format)) {
             $format = $this->format;
         } else {
             $format = $this->getRequestParameter('format', 'list');
             $format = explode('-', $format);
             $this->format = $format;
         }
         if ($nb_results == 0 && !in_array('json', $format)) {
             $params_list = array_keys(c2cTools::getCriteriaRequestParameters());
             if (count($params_list) == 1) {
                 $param = reset($params_list);
                 if (strpos($param, 'nam') !== false) {
                     $this->query_string = $this->getRequestParameter($param);
                     $this->setTemplate('../../documents/templates/simplenoresult');
                 }
             }
         } else {
             $this->items = $pager->getResults('array');
         }
         $this->setPageTitle($this->__($this->getModuleName() . ' list'));
         $this->setTemplate('list');
     } else {
         parent::executeList();
         $nb_results = $this->nb_results;
         if ($nb_results == 0) {
             return;
         }
         $items = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
         $this->items = Language::parseListItems($items, 'Image');
         $this->setTemplate('list');
     }
     if (in_array('json', $this->format)) {
         $this->setJsonResponse();
         $this->setTemplate('../../documents/templates/jsonlist');
     }
 }
 public static function browseId($model = 'Document', $sort, $criteria, $format = array(), $page = 1, $count = 0)
 {
     $conditions = $criteria[0];
     $values = $criteria[1];
     $joins = $criteria[2];
     $joins_order = $criteria[3];
     $joins_pager = $joins + $joins_order;
     $module = c2cTools::model2module($model);
     $mi = c2cTools::Model2Letter($model) . 'i';
     // orderby
     $sort = self::buildSortCriteria($model, $sort['orderby_params'], $sort['order_params'], $sort['npp'], $mi);
     // $npp
     $npp = $sort['npp'];
     // $all
     $all = false;
     if (isset($joins['all'])) {
         $all = $joins['all'];
     }
     // $field_list
     $field_list = call_user_func(array($model, 'buildFieldsList'), false, $mi, $format, $sort);
     // specific $conditions
     if ($module == 'outings' && in_array('cond', $format)) {
         $default_max_age = sfConfig::get('app_outings_recent_conditions_limit', '3W');
         $conditions[] = "age(date) < interval '{$default_max_age}'";
     }
     // $order_by
     $order_by = self::buildOrderby($field_list, $sort);
     // $nb_id
     $nb_id = 0;
     if (isset($joins['nb_id'])) {
         $nb_id = $joins['nb_id'];
     }
     // $pager_count
     if ($nb_id > 0) {
         $count = $nb_id;
     }
     if ($count > $npp) {
         $pager_count = 0;
     } else {
         $pager_count = $count;
     }
     // $independant_count
     $independant_count = !$pager_count && count($joins_pager) > count($joins);
     // create pager
     $pager = new c2cDoctrinePager($model, $npp, $pager_count, $independant_count);
     $pager->setPage($page);
     // independant count
     if ($independant_count) {
         $c = $pager->getCountQuery();
         $c->select('m.id')->from("{$model} m");
         $model::buildPagerConditions($c, $criteria);
     }
     // pager query
     $q = $pager->getQuery();
     $q->select(implode(',', $field_list))->from("{$model} m")->orderBy($order_by);
     if (!$all || !empty($joins_order)) {
         $criteria[2] = $joins_pager;
         $model::buildPagerConditions($q, $criteria);
     } else {
         $pager->simplifyCounter();
     }
     // execute pager query
     $pager->init();
     $count = $pager->getNbResults();
     if ($count == 0) {
         return array('pager' => null, 'nb_results' => 0, 'ids' => null);
     }
     // get ids
     $items = $pager->getResults('array');
     $ids = array();
     $where_ids = array();
     foreach ($items as $item) {
         $ids[] = $item['id'];
         $where_ids[] = '?';
     }
     $where_ids = implode(', ', $where_ids);
     $count_ids = count($ids);
     if ($count_ids == 1) {
         $where = ' = ' . $where_ids;
     } else {
         $where = ' IN ( ' . $where_ids . ' )';
     }
     return array('pager' => $pager, 'nb_results' => $count, 'ids' => $ids, 'where' => $where);
 }