Esempio n. 1
0
 public function executeTooltipTest()
 {
     $bbox = $this->getRequestParameter('bbox');
     $layers = $this->getRequestParameter('layers');
     // TODO check params
     $this->nb_items = 0;
     foreach (explode(',', $layers) as $layer) {
         list($module, $model, $type_where) = self::_getTooltipParamFromLayer($layer);
         $where = gisQuery::getQueryByBbox($bbox, 'geom', $module);
         $q = Doctrine_Query::create()->from("{$model} m")->where('m.redirects_to IS NULL')->addWhere($where['where_string']);
         if ($type_where) {
             $q->addWhere($type_where);
         }
         //$this->nb_items += $q->count(); TODO is it quickier to use directly count?
         $results = $q->execute();
         $this->nb_items += count($results);
         // save information that can be useful in next steps
         if ($results->getFirst()) {
             $sav_model = $model;
             $sav_id = $results->getFirst()->getId();
         }
     }
     // if only one result, directly display its name
     if ($this->nb_items == 1) {
         // specific behaviour for users: we don't want to display user name if profile
         // is private and user is not connected
         if ($sav_model == 'User' && !$this->getUser()->isConnected() && !UserPrivateData::hasPublicProfile($sav_id)) {
             $this->name = $this->__('not available');
         } else {
             $langs = sfContext::getInstance()->getUser()->getPreferedLanguageList();
             $i18n = Doctrine_Query::create()->select('m.culture, m.name')->from("{$sav_model}I18n m")->where('m.id = ?', array($sav_id))->execute();
             $old_lang = 200;
             foreach ($i18n as $name) {
                 $lang_pos = array_search($name->get('culture'), $langs);
                 if ($lang_pos === false) {
                     $lang_pos = 10;
                 }
                 // test if language is prefered over the older
                 if ($lang_pos < $old_lang) {
                     $old_lang = $lang_pos;
                     $uname = $name->get('name');
                 }
             }
             $this->name = $uname;
         }
     }
     $this->setJsonResponse();
 }
 public static function buildBboxCondition(&$conditions, &$values, $field, $param)
 {
     /*
     $bbox_array = explode(',', $param);
     $reformatted_bbox = "$bbox_array[0] $bbox_array[1], $bbox_array[2] $bbox_array[3]";
     $reformatted_field = str_replace('.', '_', $field);
     $conditions[] = "get_bbox('$reformatted_field', '$reformatted_bbox')";
     */
     $param = str_replace(array('-', '~'), array(',', ','), $param);
     $where = gisQuery::getQueryByBbox($param, $field);
     $conditions[] = $where['where_string'];
 }