예제 #1
0
 /**  
  * 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');
     }
 }
 /**
  * Retrieves a pager of recent changes eventually made by a specific user (documents new versions).
  * @param string model name
  * @return Pager
  */
 public static function listRecentChangesPager($model, $langs = null, $areas = null, $activities = null, $doc_ids = null, $user_id = null, $editedby_id = null, $createdby_id = null, $mode = 'editions', $params = array())
 {
     $m = strtolower(substr($model, 0, 1));
     $mi = $m . 'i';
     if ($model == 'Article') {
         $m .= '5';
     } else {
         $m .= '2';
     }
     $model_i18n = $model . 'I18n';
     $query_params = self::queryRecent($mode, $m, $mi, $langs, $areas, $activities, $doc_ids, $user_id, $editedby_id, $createdby_id, $params);
     $field_list = "dv.document_id, dv.culture, dv.version, dv.nature, dv.created_at, up.id, up.topo_name, {$mi}.name, hm.comment, hm.is_minor";
     if ($model == 'Document') {
         $field_list .= ", {$m}.module";
     }
     $pager = new c2cDoctrinePager($model, sfConfig::get('app_list_maxline_number', 25));
     $q = $pager->getQuery();
     $q->select($field_list)->from('DocumentVersion dv')->leftJoin('dv.history_metadata hm')->leftJoin('hm.user_private_data up')->innerJoin("dv.{$model_i18n} {$mi}");
     if ($model == 'Document' || !empty($activities) || !empty($params['ctyp']) || !empty($params['ityp'])) {
         $q->innerJoin("dv.{$model} {$m}");
     }
     if (!empty($areas)) {
         $q->leftJoin('dv.geoassociations geo');
     }
     if (!empty($editedby_id)) {
         $q->leftJoin('dv.versions dv2')->leftJoin('dv2.history_metadata hm2');
     }
     if (!empty($createdby_id)) {
         $q->leftJoin('dv.versions dv3')->leftJoin('dv3.history_metadata hm3');
     }
     if (!empty($query_params['query'])) {
         $q->where($query_params['query'], $query_params['arguments']);
     } else {
         $pager->simplifyBaseCounter();
     }
     $q->orderBy('dv.created_at DESC');
     return $pager;
 }