예제 #1
0
 /**
  * Executes view action : displays the user profile
  */
 public function executeView()
 {
     $id = $this->getRequestParameter('id');
     parent::executeView();
     $hasPublicProfile = UserPrivateData::hasPublicProfile($id);
     if (!$this->getUser()->isConnected() && !$hasPublicProfile) {
         // page owner has not allowed anonymous users to access his personal page
         $this->setTemplate('login');
     } else {
         if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
             if ($hasPublicProfile) {
                 $this->getResponse()->addMeta('robots', 'index, follow');
             } else {
                 $this->getResponse()->addMeta('robots', 'noindex, nofollow');
             }
             // get associated outings
             $associated_outings = array();
             $nb_outings = count(Association::countAllLinked(array($id), 'uo'));
             $nb_outings_limit = 0;
             if ($nb_outings > 0) {
                 $outing_params = array('users' => $id);
                 $nb_outings_limit = sfConfig::get('app_users_outings_limit');
                 $associated_outings = Outing::listLatest($nb_outings_limit, array(), array(), array(), $outing_params, false, false);
                 $associated_outings = Language::getTheBest($associated_outings, 'Outing');
             }
             $this->nb_outings = $nb_outings;
             $this->nb_outings_limit = $nb_outings_limit;
             $this->associated_outings = $associated_outings;
             $forum_nickname = Punbb::getNickname($id);
             $this->forum_nickname = $forum_nickname[0]['username'];
             // check if user is forum and / or topoguide moderator
             $this->forum_moderator = UserPrivateData::isForumModerator($id);
             $user_permissions = Doctrine_Query::create()->from('User.groups.permissions, User.permissions')->where('User.id = ?', $id)->execute(array(), Doctrine::FETCH_ARRAY);
             $topoguide_moderator = false;
             $moderator_credential = sfConfig::get('app_credentials_moderator');
             foreach ($user_permissions[0]['groups'] as $group) {
                 foreach ($group['permissions'] as $permission) {
                     if ($permission['name'] == $moderator_credential) {
                         $topoguide_moderator = true;
                         break 2;
                     }
                 }
             }
             foreach ($user_permissions[0]['permissions'] as $permission) {
                 if ($permission['name'] == $moderator_credential) {
                     $topoguide_moderator = true;
                     break;
                 }
             }
             $this->topoguide_moderator = $topoguide_moderator;
         } else {
             // only moderators and user itself should see archive versions of user docs
             $this->filterAuthorizedPeople($id);
         }
     }
 }
예제 #2
0
 public function executeView()
 {
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         // get last geo-associated outings
         $current_doc_id = $this->getRequestParameter('id');
         $latest_outings = array();
         $nb_outings = 0;
         $outing_params = array('areas' => $current_doc_id);
         $nb_outings = sfConfig::get('app_nb_linked_outings_areas');
         $latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
         $latest_outings = Language::getTheBest($latest_outings, 'Outing');
         $this->latest_outings = $latest_outings;
         $this->nb_outings = $nb_outings;
         $related_portals = array();
         $id = $this->getRequestParameter('id');
         $areas = array(array('id' => $id));
         Portal::getLocalPortals($related_portals, $areas);
         $this->related_portals = $related_portals;
         $area_types_list = sfConfig::get('mod_areas_area_types_list');
         $title = $this->document->get('name') . ' :: ' . $this->__($area_types_list[$this->document->get('area_type')]);
         $this->setPageTitle($title);
     }
 }
예제 #3
0
 public static function buildPagerConditions(&$q, $criteria)
 {
     $conditions = $criteria[0];
     $values = $criteria[1];
     $joins = $criteria[2];
     self::buildAreaIdPagerConditions($q, $joins);
     // join with site / book / article tables only if needed
     if (isset($joins['join_site'])) {
         Site::buildSitePagerConditions($q, $joins, true);
     }
     // join with summit tables only if needed
     if (isset($joins['join_summit'])) {
         Summit::buildSummitPagerConditions($q, $joins, false, false, 'm.associations', 'st');
     }
     // join with hut tables only if needed
     if (isset($joins['join_hut'])) {
         Hut::buildHutPagerConditions($q, $joins, false, false, 'm.associations', 'ht');
     }
     // join with parking tables only if needed
     if (isset($joins['join_parking'])) {
         Parking::buildParkingPagerConditions($q, $joins, false, false, 'm.associations', 'pt');
     }
     // join with outing tables only if needed
     if (isset($joins['join_user'])) {
         $joins['join_outing'] = true;
         $joins['post_outing'] = true;
     }
     if (isset($joins['join_outing'])) {
         Outing::buildOutingPagerConditions($q, $joins, false, true, 'm.LinkedAssociation', 'to');
         if (isset($joins['join_user'])) {
             User::buildUserPagerConditions($q, $joins, false, false, 'lo.MainMainAssociation', 'uo');
         }
     }
     // join with image tables only if needed
     if (isset($joins['join_image_id']) || isset($joins['join_image']) || isset($joins['join_image_i18n']) || isset($joins['join_itag_id'])) {
         Image::buildImagePagerConditions($q, $joins, false, 'pi');
     }
     if (!empty($conditions)) {
         $q->addWhere(implode(' AND ', $conditions), $values);
     }
 }
예제 #4
0
 public static function buildPagerConditions(&$q, $criteria)
 {
     $conditions = $criteria[0];
     $values = $criteria[1];
     $joins = $criteria[2];
     $route_join = 'm.associations';
     $route_ltype = 'ri';
     $summit_join = 'm.associations';
     $summit_ltype = 'si';
     $hut_join = 'm.associations';
     $hut_ltype = 'hi';
     $parking_join = 'm.associations';
     $parking_ltype = 'pi';
     $site_join = 'm.associations';
     $site_ltype = 'ti';
     self::joinOnLinkedDocMultiRegions($q, $joins);
     if (isset($joins['doc']) || isset($joins['dtag'])) {
         $q->leftJoin('m.associations lid');
         if (isset($joins['dtag'])) {
             $q->leftJoin('lid.LinkedLinkedAssociation ldc');
         }
     }
     // join with image tables only if needed
     if (isset($joins['join_image'])) {
         Image::buildImagePagerConditions($q, $joins, true);
     }
     // join with outing tables only if needed
     if (isset($joins['join_outing'])) {
         Outing::buildOutingPagerConditions($q, $joins, false, false, 'm.associations', 'oi');
         $route_join = 'lo.MainAssociation';
         $route_ltype = 'ro';
         $summit_join = 'lr.MainAssociation';
         $summit_ltype = 'sr';
         $hut_join = 'lr.MainAssociation';
         $hut_ltype = 'hr';
         $parking_join = 'lr.MainAssociation';
         $parking_ltype = 'pr';
         $site_join = 'lo.MainAssociation';
         $site_ltype = 'to';
         if (isset($joins['ouser_id'])) {
             $q->leftJoin($route_join . ' lou');
         }
         if (isset($joins['join_summit']) || isset($joins['join_hut']) || isset($joins['join_parking'])) {
             $joins['join_route'] = true;
             $joins['post_route'] = true;
         }
     }
     // join with route tables only if needed
     if (isset($joins['join_route'])) {
         Route::buildRoutePagerConditions($q, $joins, false, false, $route_join, $route_ltype);
         $summit_join = 'lr.MainAssociation';
         $summit_ltype = 'sr';
         $hut_join = 'lr.MainAssociation';
         $hut_ltype = 'hr';
         $parking_join = 'lr.MainAssociation';
         $parking_ltype = 'pr';
     }
     // join with summit tables only if needed
     if (isset($joins['join_summit'])) {
         Summit::buildSummitPagerConditions($q, $joins, false, false, $summit_join, $summit_ltype);
     }
     // join with hut tables only if needed
     if (isset($joins['join_hut'])) {
         Hut::buildHutPagerConditions($q, $joins, false, false, $hut_join, $hut_ltype);
     }
     // join with parking tables only if needed
     if (isset($joins['join_parking'])) {
         Parking::buildParkingPagerConditions($q, $joins, false, false, $parking_join, $parking_ltype);
     }
     // join with site tables only if needed
     if (isset($joins['join_site'])) {
         Site::buildSitePagerConditions($q, $joins, false, false, $site_join, $site_ltype);
     }
     // join with user tables only if needed
     if (isset($joins['user_id'])) {
         $q->leftJoin('m.versions v')->leftJoin('v.history_metadata hm')->addWhere('v.version = 1');
     }
     if (!empty($conditions)) {
         $q->addWhere(implode(' AND ', $conditions), $values);
     }
 }
예제 #5
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     parent::executeView();
     $mobile_version = c2cTools::mobileVersion();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         sfLoader::loadHelpers(array('Pagination'));
         $user = $this->getUser();
         $prefered_cultures = $user->getCulturesForDocuments();
         $document = $this->document;
         $id = $this->document->get('id');
         $topo_filter = $this->document->get('topo_filter');
         $url_params = array();
         $main_params = unpackUrlParameters($topo_filter, $main_url_params);
         // map filter
         $has_map = $this->document->get('has_map');
         $has_map = !$mobile_version && !empty($has_map);
         $this->has_map = $has_map;
         if ($has_map) {
             $map_filter_temp = $this->document->get('map_filter');
             $map_filter_temp = str_replace(' ', '', $map_filter_temp);
             $map_filter_temp = explode('|', $map_filter_temp);
             $map_filter = array();
             foreach ($map_filter_temp as $filter) {
                 $filter = explode(':', $filter);
                 if (isset($filter[1])) {
                     $map_filter[$filter[0]] = $filter[1];
                 }
             }
             if (empty($map_filter['objects'])) {
                 $map_filter['objects'] = null;
             }
             if (!empty($map_filter['lon']) || !empty($map_filter['lat']) || !empty($map_filter['zoom'])) {
                 if (empty($map_filter['lon'])) {
                     $lon = $this->document->get('lon');
                     if (is_null($lon)) {
                         $lon = 7;
                     }
                 } else {
                     $lon = $map_filter['lon'];
                 }
                 if (empty($map_filter['lat'])) {
                     $lat = $this->document->get('lat');
                     if (is_null($lat)) {
                         $lat = 45.5;
                     }
                 } else {
                     $lat = $map_filter['lat'];
                 }
                 if (empty($map_filter['zoom'])) {
                     $zoom = 6;
                 } else {
                     $zoom = $map_filter['zoom'];
                 }
                 $map_filter['center'] = array($lon, $lat, $zoom);
             } else {
                 $map_filter['center'] = null;
             }
             if (empty($map_filter['height'])) {
                 $map_filter['height'] = null;
             }
             $this->map_filter = $map_filter;
             $this->has_geom = false;
         }
         // user filters:
         $perso = c2cPersonalization::getInstance();
         $langs = $ranges = $activities = array();
         if ($perso->isMainFilterSwitchOn()) {
             $langs = $perso->getLanguagesFilter();
             $names = array_keys($main_params);
             if (!array_intersect($names, array('areas', 'summits', 'sites', 'huts', 'parkings', 'routes', 'books'))) {
                 $ranges = $perso->getPlacesFilter();
             }
             if (!in_array('act', $names)) {
                 $activities = $perso->getActivitiesFilter();
             }
         }
         // latest outings
         $nb_outings = $this->document->get('nb_outings');
         $has_outings = !empty($nb_outings);
         $this->has_outings = $has_outings;
         if ($has_outings) {
             $outing_url_params = array();
             $outing_params = $this->document->get('outing_filter');
             $outing_params = unpackUrlParameters($outing_params, $outing_url_params);
             $outing_langs = $langs;
             $outing_ranges = $ranges;
             $outing_activities = $activities;
             if (isset($outing_params['perso'])) {
                 $perso_params = explode('-', $outing_params['perso']);
                 if (array_intersect(array('areas', 'act', 'cult', 'no'), $perso_params)) {
                     if (!in_array('cult', $perso_params)) {
                         $outing_langs = array();
                     }
                     if (!in_array('areas', $perso_params)) {
                         $outing_ranges = array();
                     }
                     if (!in_array('act', $perso_params)) {
                         $outing_activities = array();
                     }
                 }
             }
             $latest_outings = Outing::listLatest($nb_outings, $outing_langs, $outing_ranges, $outing_activities, $outing_params);
             // choose best language for outings and regions names
             $latest_outings = Language::getTheBest($latest_outings, 'Outing');
             $this->latest_outings = Language::getTheBestForAssociatedAreas($latest_outings);
             $this->outing_url_params = $outing_url_params;
         }
         // latest articles
         $nb_articles = $this->document->get('nb_articles');
         $has_articles = !empty($nb_articles);
         $this->has_articles = $has_articles;
         if ($has_articles) {
             $article_url_params = array();
             $article_params = $this->document->get('article_filter');
             $article_params = unpackUrlParameters($article_params, $article_url_params);
             $this->latest_articles = Article::listLatest($nb_articles, $langs, $activities, $article_params);
             $this->article_url_params = $article_url_params;
         }
         // latest images
         if ($mobile_version) {
             $nb_images = sfConfig::get('app_recent_documents_images_mobile_limit');
         } else {
             $nb_images = $this->document->get('nb_images');
         }
         $has_images = !empty($nb_images);
         $this->has_images = $has_images;
         if ($has_images) {
             $image_url_params = array();
             $image_params = $this->document->get('image_filter');
             $image_params = unpackUrlParameters($image_params, $image_url_params);
             $latest_images = Image::listLatest($nb_images, $langs, $ranges, $activities, $image_params);
             $this->latest_images = Language::getTheBest($latest_images, 'Image');
             $this->image_url_params = $image_url_params;
         }
         // latest videos
         $nb_videos = $this->document->get('nb_videos');
         $has_videos = !$mobile_version && !empty($nb_videos);
         if ($has_videos) {
             $video_url_params = array();
             $video_params = $this->document->get('video_filter');
             $video_params = explode('|', $video_params, 3);
             if (count($video_params) == 3) {
                 $video_item = array('url' => trim($video_params[0]), 'thumbnail' => trim($video_params[1]), 'title' => trim($video_params[2]));
                 $latest_videos = array($video_item);
                 $this->latest_videos = $latest_videos;
             } else {
                 $has_videos = false;
             }
         }
         $this->has_videos = $has_videos;
         // forum 'mountain news' latest active threads
         $nb_news = $this->document->get('nb_news');
         $has_news = !empty($nb_news);
         $this->has_news = $has_news;
         $news_filter_ids = array();
         if ($has_news) {
             $news_filter_temp = $this->document->get('news_filter');
             $news_filter_temp = explode('|', $news_filter_temp);
             $news_filter = array();
             foreach ($news_filter_temp as $filter) {
                 $filter = explode(':', $filter);
                 if (isset($filter[1])) {
                     $news_filter[$filter[0]] = explode(',', $filter[1]);
                 }
             }
             $news_filter_ids = PunbbTopics::getForumIds('app_forum_mountain_news', $langs, $activities, $news_filter);
             $this->latest_mountain_news = PunbbTopics::listLatestById($nb_news, $news_filter_ids);
             $this->news_filter_ids = implode('-', $news_filter_ids);
         }
         // forum latest active threads
         $nb_topics = $this->document->get('nb_topics');
         $has_topics = !empty($nb_topics);
         $this->has_topics = $has_topics;
         if ($has_topics) {
             $forum_filter_temp = $this->document->get('forum_filter');
             $forum_filter_temp = explode('|', $forum_filter_temp);
             $forum_filter = array();
             foreach ($forum_filter_temp as $filter) {
                 $filter = explode(':', $filter);
                 if (isset($filter[1])) {
                     $forum_filter[$filter[0]] = explode(',', $filter[1]);
                 }
             }
             $forum_filter_ids = PunbbTopics::getForumIds('app_forum_public_ids', $langs, $activities, $forum_filter);
             $this->latest_threads = PunbbTopics::listLatestById($nb_topics, $forum_filter_ids);
             $this->forum_filter_ids = implode('-', array_merge($news_filter_ids, $forum_filter_ids));
         }
         $cda_config = sfConfig::get('app_portals_cda');
         if ($id == $cda_config['id']) {
             $description = $this->document->get('description');
             $has_description = !empty($description);
             $this->has_description = $has_description;
             $this->setTemplate('changerdapproche');
         }
         sfLoader::loadHelpers(array('sfBBCode', 'SmartFormat'));
         $abstract = strip_tags(parse_links(parse_bbcode_abstract($this->document->get('abstract'))));
         $this->getResponse()->addMeta('description', $abstract);
     }
 }
예제 #6
0
 /**
  * Executes list action, adding ratings from routes linked to outings
  */
 public function executeList()
 {
     // redirect to user outings list if connected and if myoutings criteria is set
     if ($this->getUser()->isConnected() && $this->getRequestParameter('myoutings')) {
         sfLoader::loadHelpers(array('Pagination'));
         $user_id = $this->getUser()->getId();
         $this->redirect(_addUrlParameters(_getBaseUri(), array('myoutings'), array('users' => $user_id)));
     }
     // TODO something to do if outings where filtered on route ratings?
     parent::executeList();
     $format = $this->format;
     if (in_array('cond', $format) && !in_array('json', $format)) {
         $this->setTemplate('conditions');
         if (in_array('full', $format)) {
             $this->setPageTitle($this->__('conditions and comments'));
         } else {
             $this->setPageTitle($this->__('recent conditions'));
         }
     }
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $show_images = $this->show_images;
     $timer = new sfTimer();
     $outings = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     $outings = Outing::getAssociatedCreatorData($outings);
     // retrieve outing creator names
     c2cActions::statsdTiming('outing.getAssociatedCreatorData', $timer->getElapsedTime());
     $timer = new sfTimer();
     $outings = Outing::getAssociatedRoutesData($outings);
     // retrieve associated route ratings
     c2cActions::statsdTiming('outing.getAssociatedRoutesData', $timer->getElapsedTime());
     if (!in_array('list', $format)) {
         $timer = new sfTimer();
         $outings = Language::getTheBestForAssociatedAreas($outings);
         c2cActions::statsdTiming('language.getTheBestForAssociatedAreas', $timer->getElapsedTime());
     }
     // add images infos
     if ($show_images) {
         $timer = new sfTimer();
         Image::addAssociatedImages($outings, 'oi');
         c2cActions::statsdTiming('image.addAssociatedImages', $timer->getElapsedTime());
     }
     Area::sortAssociatedAreas($outings);
     $this->items = Language::parseListItems($outings, 'Outing', !$show_images);
 }
예제 #7
0
 public static function buildPagerConditions(&$q, $criteria)
 {
     $conditions = $criteria[0];
     $values = $criteria[1];
     $joins = $criteria[2];
     $route_join = 'm.MainGeoassociations';
     $route_ltype = '';
     $summit_join = 'm.MainGeoassociations';
     $summit_ltype = '';
     $hut_join = 'm.MainGeoassociations';
     $hut_ltype = '';
     $parking_join = 'm.MainGeoassociations';
     $parking_ltype = '';
     $site_join = 'm.MainGeoassociations';
     $site_ltype = '';
     $user_join = 'm.MainGeoassociations';
     $user_ltype = '';
     // join with area tables only if needed
     if (isset($joins['join_area'])) {
         Area::buildAreaPagerConditions($q, $joins, true);
     }
     // join with outing tables only if needed
     if (isset($joins['join_outing'])) {
         Outing::buildOutingPagerConditions($q, $joins, false, false, 'm.MainGeoassociations', '');
         $route_join = 'lo.MainAssociation';
         $route_ltype = 'ro';
         $summit_join = 'lr.MainAssociation';
         $summit_ltype = 'sr';
         $hut_join = 'lr.MainAssociation';
         $hut_ltype = 'hr';
         $parking_join = 'lr.MainAssociation';
         $parking_ltype = 'pr';
         $site_join = 'lo.MainAssociation';
         $site_ltype = 'to';
         $user_join = 'lu.MainAssociations';
         $user_ltype = 'uo';
     }
     // join with route tables only if needed
     if (isset($joins['join_route'])) {
         Route::buildRoutePagerConditions($q, $joins, false, false, $route_join, $route_ltype);
         $summit_join = 'lr.MainAssociation';
         $summit_ltype = 'sr';
         $hut_join = 'lr.MainAssociation';
         $hut_ltype = 'hr';
         $parking_join = 'lr.MainAssociation';
         $parking_ltype = 'pr';
     }
     // join with summit tables only if needed
     if (isset($joins['join_summit'])) {
         Summit::buildSummitPagerConditions($q, $joins, false, false, $summit_join, $summit_ltype);
     }
     // join with hut tables only if needed
     if (isset($joins['join_hut'])) {
         Hut::buildHutPagerConditions($q, $joins, false, false, $hut_join, $hut_ltype);
     }
     // join with parking tables only if needed
     if (isset($joins['join_parking'])) {
         Parking::buildParkingPagerConditions($q, $joins, false, false, $parking_join, $parking_ltype);
     }
     // join with site tables only if needed
     if (isset($joins['join_site'])) {
         Site::buildSitePagerConditions($q, $joins, false, false, $site_join, $site_ltype);
     }
     // join with product tables only if needed
     if (isset($joins['join_product'])) {
         Product::buildProductPagerConditions($q, $joins, false, false, 'm.MainGeoassociations', '');
     }
     // join with user tables only if needed
     if (isset($joins['join_user'])) {
         User::buildUserPagerConditions($q, $joins, false, false, $user_join, $user_ltype);
     }
     // join with image tables only if needed
     if (isset($joins['join_image'])) {
         Image::buildImagePagerConditions($q, $joins, false, '');
     }
     if (!empty($conditions)) {
         $q->addWhere(implode(' AND ', $conditions), $values);
     }
 }
예제 #8
0
// we have to do this, else we get a PHP Fatal error:
// Call to a member function formatExists() on a non-object in /usr/share/php/symfony/i18n/sfI18N.class.php on line 132
// cf. http://www.symfony-project.com/forum/index.php/m/32891/
$dir = sfConfig::get('sf_app_i18n_dir');
$i18n = $context->getI18N();
$i18n->setMessageSourceDir($dir, 'fr');
$n = 0;
$meta_url = sfConfig::get('app_meta_engine_base_url');
$user_id = sfConfig::get('app_meta_engine_c2c_id');
// camptocamp.org metaengine id
$user_key = sfConfig::get('app_meta_engine_c2c_key');
// camptocamp.org key for push
$meta_activities = sfConfig::get('app_meta_engine_activities');
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><outings xmlns="http://meta.camptocamp.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://meta.camptocamp.org/metaengineschema.xsd"></outings>');
// get (id, lang) of outings created in the last hour:
$latest_outings = Outing::listRecentInTime(900);
// fetch info for those (id, lang) :
foreach ($latest_outings as $outing) {
    $id = $outing['document_id'];
    $lang = $outing['culture'];
    //echo "Fetching data and building XML for outing ($id, $lang) ... \n";
    $object = Document::find('Outing', $id);
    if (!$object) {
        continue;
    }
    $n++;
    $item = $xml->addChild('outing');
    $object->setCulture($lang);
    $item->addChild('name', htmlspecialchars($object->get('name')));
    if (($lon = $object->get('lon')) && ($lat = $object->get('lat')) && ($ele = $object->get('elevation'))) {
        // this is the case when a GPX has been uploaded on the outing.
예제 #9
0
 public static function buildPagerConditions(&$q, $criteria)
 {
     $conditions = $criteria[0];
     $values = $criteria[1];
     $joins = $criteria[2];
     $route_join = 'm.associations';
     $route_ltype = 'rc';
     $summit_join = 'm.associations';
     $summit_ltype = 'sc';
     $hut_join = 'm.associations';
     $hut_ltype = 'hc';
     $parking_join = 'm.associations';
     $parking_ltype = 'pc';
     $site_join = 'm.associations';
     $site_ltype = 'tc';
     self::joinOnLinkedDocMultiRegions($q, $joins);
     self::joinOnMulti($q, $joins, 'user_id', 'm.associations u', 4);
     if (isset($joins['cdoc'])) {
         $q->leftJoin('m.associations lcd');
     }
     // join with article tables only if needed
     if (isset($joins['join_article'])) {
         Article::buildArticlePagerConditions($q, $joins, true);
     }
     // join with book tables only if needed
     if (isset($joins['join_cbook'])) {
         Book::buildBookPagerConditions($q, $joins, false, 'c', false, $main_join, 'bc');
     }
     // join with outing tables only if needed
     if (isset($joins['join_outing'])) {
         Outing::buildOutingPagerConditions($q, $joins, false, false, 'm.associations', 'oc');
         $route_join = 'lo.MainAssociation';
         $route_ltype = 'ro';
         $summit_join = 'lr.MainAssociation';
         $summit_ltype = 'sr';
         $hut_join = 'lr.MainAssociation';
         $hut_ltype = 'hr';
         $parking_join = 'lr.MainAssociation';
         $parking_ltype = 'pr';
         $site_join = 'lo.MainAssociation';
         $site_ltype = 'to';
         if (isset($joins['join_summit']) || isset($joins['join_hut']) || isset($joins['join_parking'])) {
             $joins['join_route'] = true;
             $joins['post_route'] = true;
         }
     }
     // join with route tables only if needed
     if (isset($joins['join_route'])) {
         Route::buildRoutePagerConditions($q, $joins, false, false, $route_join, $route_ltype);
         $summit_join = 'lr.MainAssociation';
         $summit_ltype = 'sr';
         $hut_join = 'lr.MainAssociation';
         $hut_ltype = 'hr';
         $parking_join = 'lr.MainAssociation';
         $parking_ltype = 'pr';
     }
     // join with summit tables only if needed
     if (isset($joins['join_summit'])) {
         Summit::buildSummitPagerConditions($q, $joins, false, false, $summit_join, $summit_ltype);
     }
     // join with hut tables only if needed
     if (isset($joins['join_hut'])) {
         Hut::buildHutPagerConditions($q, $joins, false, false, $hut_join, $hut_ltype);
     }
     // join with parking tables only if needed
     if (isset($joins['join_parking'])) {
         Parking::buildParkingPagerConditions($q, $joins, false, false, $parking_join, $parking_ltype);
     }
     // join with site tables only if needed
     if (isset($joins['join_site'])) {
         Site::buildSitePagerConditions($q, $joins, false, false, $site_join, $site_ltype);
     }
     // join with image tables only if needed
     if (isset($joins['join_image'])) {
         Image::buildImagePagerConditions($q, $joins, false, 'ci');
     }
     if (!empty($conditions)) {
         $q->addWhere(implode(' AND ', $conditions), $values);
     }
 }
예제 #10
0
 public static function buildPagerConditions(&$q, $criteria)
 {
     $conditions = $criteria[0];
     $values = $criteria[1];
     $joins = $criteria[2];
     self::buildAreaIdPagerConditions($q, $joins);
     // join with users tables only if needed
     if (isset($joins['join_user'])) {
         User::buildUserPagerConditions($q, $joins, true);
     }
     // join with image tables only if needed
     if (isset($joins['join_image'])) {
         Image::buildImagePagerConditions($q, $joins, false, 'ui', true);
     }
     // join with outings tables only if needed
     if (isset($joins['join_route']) || isset($joins['join_summit'])) {
         $joins['join_outing'] = true;
         $joins['post_outing'] = true;
     }
     if (isset($joins['join_outing'])) {
         Outing::buildOutingPagerConditions($q, $joins, false, true, 'm.LinkedAssociation', 'uo');
         if (isset($joins['join_summit'])) {
             $joins['join_route'] = true;
             $joins['post_route'] = true;
         }
         if (isset($joins['join_route'])) {
             Route::buildRoutePagerConditions($q, $joins, false, false, 'lo.MainMainAssociation', 'ro');
             if (isset($joins['join_summit'])) {
                 Summit::buildSummitPagerConditions($q, $joins, false, false, 'lr.MainAssociation', 'sr');
             }
         }
         // join with geo-associations linked to outings
         self::joinOnLinkedDocMultiRegions($q, $joins, array(), false, 'oarea', null, 'lo', 'go');
     }
     if (!empty($conditions)) {
         $q->addWhere(implode(' AND ', $conditions), $values);
     }
 }
예제 #11
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         $user = $this->getUser();
         $prefered_cultures = $user->getCulturesForDocuments();
         $current_doc_id = $this->getRequestParameter('id');
         $parent_ids = $sub_site_ids = $site_docs_ids = $child_types = array();
         // if we have sub-(sub)-sites, we also want to display the outings and images linked to these sites
         $main_associated_sites = $this->associated_sites;
         if (count($main_associated_sites)) {
             $associated_sites = Association::createHierarchyWithBestName($main_associated_sites, $prefered_cultures, array('type' => 'tt', 'current_doc_id' => $current_doc_id, 'keep_current_doc' => true));
             $i = reset($associated_sites);
             while (!isset($i['is_doc'])) {
                 $i = next($associated_sites);
             }
             $doc_level = $i['level'];
             $i = next($associated_sites);
             while ($i !== false && $i['level'] > $doc_level) {
                 $sub_site_ids[] = $i['id'];
                 $i = next($associated_sites);
             }
             // we want to display on the page the images and outings of the subsites
             if (count($sub_site_ids)) {
                 $site_docs = array_filter($this->associated_docs, array('c2cTools', 'is_image'));
                 foreach ($site_docs as $doc) {
                     $site_docs_ids[] = $doc['id'];
                 }
                 $child_types[] = 'ti';
                 $child_types[] = 'to';
             }
         } else {
             $associated_sites = $main_associated_sites;
         }
         $associated_summits = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_summit')), 'elevation');
         // we display sub-sub-sites one the page, but also the others sites linked to the same summits
         if (count($associated_summits)) {
             foreach ($associated_summits as $summit) {
                 $summit_ids[] = $summit['id'];
             }
             $sites_ids = array();
             foreach ($associated_sites as $site) {
                 $sites_ids[] = $site['id'];
             }
             $summit_docs_ids = array_merge($sites_ids, array($current_doc_id));
             $associated_summits_sites = Association::findLinkedDocsWithBestName($summit_ids, $prefered_cultures, 'st', true, true, $summit_docs_ids);
             $associated_sites = array_merge($associated_sites, $associated_summits_sites);
         }
         // associated parkings 2-hop hierarchy
         $associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
         if (count($associated_parkings)) {
             foreach ($associated_parkings as $parking) {
                 $parent_ids[] = $parking['id'];
             }
             $child_types[] = 'pp';
         }
         $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
         // all outings (directly or indirectly linked)
         $parent_ids = array_merge($parent_ids, $sub_site_ids);
         if (count($parent_ids)) {
             $associated_childs = Association::findLinkedDocsWithBestName($parent_ids, $prefered_cultures, $child_types, true, true, $site_docs_ids);
             $this->associated_docs = array_merge($this->associated_docs, $associated_childs);
             if (count($associated_parkings)) {
                 $associated_parkings = Association::createHierarchy($associated_parkings, array_filter($associated_childs, array('c2cTools', 'is_parking')), array('type' => 'pp', 'show_sub_docs' => false));
             }
             if (count($sub_site_ids)) {
                 $associated_site_outings = array_filter($associated_childs, array('c2cTools', 'is_outing'));
                 if (count($associated_site_outings)) {
                     if (count($associated_outings)) {
                         $outing_ids = array();
                         foreach ($associated_outings as $outing) {
                             $outing_ids[] = $outing['id'];
                         }
                         foreach ($associated_site_outings as $outing) {
                             if (!in_array($outing['id'], $outing_ids)) {
                                 $associated_outings[] = $outing;
                             }
                         }
                     } else {
                         $associated_outings = $associated_site_outings;
                     }
                 }
             }
         }
         $this->associated_sites = $associated_sites;
         array_unshift($sub_site_ids, $current_doc_id);
         $this->ids = implode('-', $sub_site_ids);
         $this->associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
         $this->associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' ');
         $this->associated_huts = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_hut')), 'elevation');
         $this->associated_summits = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_summit')), 'elevation');
         // also get author of books
         $associated_books = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_book')), 'name');
         if (count($associated_books)) {
             $associated_books = Book::getAssociatedBooksData($associated_books);
         }
         $this->associated_books = $associated_books;
         if (!isset($associated_outings)) {
             $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
         }
         $associated_outings = Outing::fetchAdditionalFields($associated_outings, true, true);
         // sort outings array by antichronological order.
         usort($associated_outings, array('c2cTools', 'cmpDate'));
         $this->nb_outings = count($associated_outings);
         // group them by blocks
         $outings_limit = sfConfig::get('app_documents_outings_limit');
         $a = array();
         $i = 0;
         while (count($associated_outings) - $i * $outings_limit > $outings_limit) {
             $a[] = array_slice($associated_outings, $i * $outings_limit, $outings_limit);
             $i++;
         }
         $a[] = array_slice($associated_outings, $i * $outings_limit);
         $this->associated_outings = $a;
         $this->associated_images = Document::fetchAdditionalFieldsFor(array_filter($this->associated_docs, array('c2cTools', 'is_image')), 'Image', array('filename', 'image_type', 'date_time', 'width', 'height'));
         $site_types = $this->document->get('site_types');
         if (!is_array($site_types)) {
             $site_types = Document::convertStringToArray($site_types);
         }
         $site_types_list = sfConfig::get('app_sites_site_types');
         foreach ($site_types as &$type) {
             $type = $this->__($site_types_list[$type]);
         }
         $site_types = implode(', ', $site_types);
         if (!empty($site_types)) {
             $site_types = ' (' . $site_types . ')';
         }
         $site_types = $this->__('site') . $site_types;
         $doc_name = $this->document->get('name');
         $title = $doc_name;
         if ($this->document->isArchive()) {
             $version = $this->getRequestParameter('version');
             $title .= ' :: ' . $this->__('revision') . ' ' . $version;
         }
         $title .= ' :: ' . $site_types;
         $this->setPageTitle($title);
         $description = array($site_types . ' :: ' . $doc_name, $this->getAreasList());
         $this->getResponse()->addMeta('description', implode(' - ', $description));
     }
 }
예제 #12
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         $user = $this->getUser();
         $prefered_cultures = $user->getCulturesForDocuments();
         $current_doc_id = $this->getRequestParameter('id');
         $is_gite_camping = $this->document->get('shelter_type') == 5 || $this->document->get('shelter_type') == 6;
         // retrieve 2-hops parkings
         $associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
         if (count($associated_parkings)) {
             $associated_parkings = Association::createHierarchyWithBestName($associated_parkings, $prefered_cultures, array('type' => 'pp'));
             $associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
         }
         $this->associated_parkings = $associated_parkings;
         $associated_routes = array_filter($this->associated_docs, array('c2cTools', 'is_route'));
         // associated summits
         $associated_summits = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_summit')), 'name');
         $this->associated_summits = $associated_summits;
         $summit_ids = $summit_routes_tmp = $summit_routes_ids = array();
         if (count($associated_summits)) {
             foreach ($associated_summits as $summit) {
                 $summit_ids[] = $summit['id'];
             }
             $summit_routes_tmp = Association::countAllLinked($summit_ids, 'sr');
             foreach ($summit_routes_tmp as $route) {
                 $summit_routes_ids[] = $route['linked_id'];
             }
         }
         // for a gite, routes  and sites are not directly linked. We retrieve the routes linked to the linked parkings
         if ($is_gite_camping) {
             $parking_ids = array();
             foreach ($associated_parkings as $parking) {
                 $parking_ids[] = $parking['id'];
             }
             $associated_parking_docs = Association::findLinkedDocsWithBestName($parking_ids, $prefered_cultures, array('pr', 'pt'), false, true);
             $associated_routes = array_filter($associated_parking_docs, array('c2cTools', 'is_route'));
             $associated_parking_sites = c2cTools::sortArrayByName(array_filter($associated_parking_docs, array('c2cTools', 'is_site')));
             $this->associated_sites = array_merge($this->associated_sites, $associated_parking_sites);
             // associated sites should be empty!! Else it violates moderation rules
             $this->ids = implode('-', $parking_ids);
         } else {
             $associated_routes = array_filter($this->associated_docs, array('c2cTools', 'is_route'));
             $this->associated_sites = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_site')));
             $this->ids = $current_doc_id;
         }
         // get additional data for routes
         $associated_routes = Route::getAssociatedRoutesData($associated_routes, $this->__(' :') . ' ', reset($summit_ids));
         // these are the routes where the hut act as a summit
         // they are displayed in a specific section
         $summit_ids = $summit_routes_tmp = $summit_routes_ids = $associated_summit_routes = array();
         if (count($associated_summits)) {
             foreach ($associated_summits as $summit) {
                 $summit_ids[] = $summit['id'];
             }
             $summit_routes_tmp = Association::countAllLinked($summit_ids, 'sr');
             foreach ($summit_routes_tmp as $route) {
                 $summit_routes_ids[] = $route['linked_id'];
             }
         }
         if (count($summit_routes_ids)) {
             foreach ($associated_routes as $key => $route) {
                 if (in_array($route['id'], $summit_routes_ids)) {
                     $associated_summit_routes[$key] = $route;
                     unset($associated_routes[$key]);
                 }
             }
         }
         $this->associated_routes = $associated_routes;
         $this->associated_summit_routes = $associated_summit_routes;
         // We retrieve both the books directly linked
         $associated_books = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_book')));
         // AND the books linked to linked routes
         // FIXME we should probably also do this with linked sites
         $route_ids = array();
         $associated_routes_books = array();
         if (count($associated_routes)) {
             foreach ($associated_routes as $route) {
                 if ($route['duration'] instanceof Doctrine_Null || $route['duration'] <= 4) {
                     $route_ids[] = $route['id'];
                 }
             }
             if (count($route_ids)) {
                 $book_ids = array();
                 foreach ($associated_books as $book) {
                     $book_ids[] = $book['id'];
                 }
                 $associated_route_docs = Association::findLinkedDocsWithBestName($route_ids, $prefered_cultures, array('br'), false, false, $book_ids);
                 if (count($associated_route_docs)) {
                     $associated_route_docs = c2cTools::sortArray($associated_route_docs, 'name');
                     $associated_routes_books = array_filter($associated_route_docs, array('c2cTools', 'is_book'));
                     foreach ($associated_routes_books as $key => $book) {
                         $associated_routes_books[$key]['parent_id'] = true;
                     }
                 }
             }
         }
         $associated_books = array_merge($associated_books, $associated_routes_books);
         if (count($associated_books)) {
             $associated_books = Book::getAssociatedBooksData($associated_books);
         }
         $this->associated_books = $associated_books;
         // get associated outings
         $latest_outings = array();
         $nb_outings = 0;
         if (!$is_gite_camping && count($associated_routes) || $is_gite_camping && count($parking_ids)) {
             if (!$is_gite_camping) {
                 $outing_params = array('huts' => $current_doc_id);
             } else {
                 $outing_params = array('parkings' => $this->ids);
             }
             $nb_outings = sfConfig::get('app_nb_linked_outings_docs');
             $latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
             $latest_outings = Language::getTheBest($latest_outings, 'Outing');
         }
         $this->latest_outings = $latest_outings;
         $this->nb_outings = $nb_outings;
         // possibly related portals
         $related_portals = array();
         Portal::getRelatedPortals($related_portals, $this->associated_areas, $associated_routes);
         $this->related_portals = $related_portals;
         $cab = count($associated_books);
         $this->section_list = array('books' => $cab != 0, 'map' => (bool) $this->document->get('geom_wkt'));
         $hut_type_list = sfConfig::get('mod_huts_shelter_types_list');
         $hut_type_index = $this->document->get('shelter_type');
         $hut_type = $this->__($hut_type_list[$hut_type_index]);
         $doc_name = $this->document->get('name');
         $title = $doc_name;
         if ($this->document->isArchive()) {
             $version = $this->getRequestParameter('version');
             $title .= ' :: ' . $this->__('revision') . ' ' . $version;
         }
         $title .= ' :: ' . $hut_type;
         $this->setPageTitle($title);
         $description = array($hut_type . ' :: ' . $doc_name, $this->getActivitiesList(), $this->getAreasList());
         $this->getResponse()->addMeta('description', implode(' - ', $description));
     }
 }
예제 #13
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         $user = $this->getUser();
         $prefered_cultures = $user->getCulturesForDocuments();
         $current_doc_id = $this->getRequestParameter('id');
         $main_associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
         // Idea here is to retrieve not only the routes linked directly to the parking, but also the ones
         // associated to the sub(-sub)-parkings
         // We also do this for products and huts
         $parking_ids = array();
         if (count($main_associated_parkings)) {
             $associated_parkings = Association::createHierarchyWithBestName($main_associated_parkings, $prefered_cultures, array('type' => 'pp', 'current_doc_id' => $current_doc_id, 'keep_current_doc' => true));
             $associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
             // simply go through the list and get the next items that have a bigger level
             $i = reset($associated_parkings);
             while (!isset($i['is_doc'])) {
                 $i = next($associated_parkings);
             }
             $doc_level = $i['level'];
             $i = next($associated_parkings);
             while ($i !== false && $i['level'] > $doc_level) {
                 $parking_ids[] = $i['id'];
                 $i = next($associated_parkings);
             }
             if (count($parking_ids)) {
                 $this->associated_docs = array_merge($this->associated_docs, Association::findLinkedDocsWithBestName($parking_ids, $prefered_cultures, array('pr', 'ph', 'pf')));
             }
         } else {
             $associated_parkings = $main_associated_parkings;
         }
         $this->associated_parkings = $associated_parkings;
         array_unshift($parking_ids, $current_doc_id);
         $this->ids = implode('-', $parking_ids);
         $associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' ');
         $this->associated_routes = $associated_routes;
         // related books (associated to the above mentioned routes)
         $route_ids = array();
         $associated_routes_books = array();
         if (count($associated_routes)) {
             foreach ($associated_routes as $route) {
                 if ($route['duration'] instanceof Doctrine_Null || $route['duration'] <= 4) {
                     $route_ids[] = $route['id'];
                 }
             }
             if (count($route_ids)) {
                 $associated_route_docs = Association::findLinkedDocsWithBestName($route_ids, $prefered_cultures, array('br'), false, false);
                 if (count($associated_route_docs)) {
                     $associated_route_docs = c2cTools::sortArray($associated_route_docs, 'name');
                     $associated_routes_books = array_filter($associated_route_docs, array('c2cTools', 'is_book'));
                     foreach ($associated_routes_books as $key => $book) {
                         $associated_routes_books[$key]['parent_id'] = true;
                     }
                 }
             }
         }
         $cab = 0;
         if (count($associated_routes_books)) {
             $associated_books = Book::getAssociatedBooksData($associated_routes_books);
             $this->associated_books = $associated_books;
             $cab = count($associated_books);
         }
         // get associated outings (to the above mentionned routes)
         $latest_outings = array();
         $nb_outings = 0;
         if (count($associated_routes)) {
             $outing_params = array('parkings' => $this->ids);
             $nb_outings = sfConfig::get('app_nb_linked_outings_docs');
             $latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
             $latest_outings = Language::getTheBest($latest_outings, 'Outing');
         }
         $this->latest_outings = $latest_outings;
         $this->nb_outings = $nb_outings;
         // associated huts
         $this->associated_huts = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_hut')), 'elevation');
         // asscoiated products
         $this->associated_products = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_product')), 'name');
         // related portals
         $related_portals = array();
         $public_transportation_rating = $this->document->get('public_transportation_rating');
         if (in_array($public_transportation_rating, array(1, 2, 4, 5))) {
             $related_portals[] = 'cda';
         }
         Portal::getRelatedPortals($related_portals, $this->associated_areas, $associated_routes);
         $this->related_portals = $related_portals;
         $this->section_list = array('books' => $cab != 0, 'map' => (bool) $this->document->get('geom_wkt'));
         $description = array($this->__('parking') . ' :: ' . $this->document->get('name'), $this->getAreasList());
         $this->getResponse()->addMeta('description', implode(' - ', $description));
     }
 }
예제 #14
0
 public static function buildPagerConditions(&$q, $criteria)
 {
     $conditions = $criteria[0];
     $values = $criteria[1];
     $joins = $criteria[2];
     self::buildAreaIdPagerConditions($q, $joins);
     // join with parking / book / article tables only if needed
     if (isset($joins['join_parking'])) {
         Parking::buildParkingPagerConditions($q, $joins, true);
     }
     // join with huts tables only if needed
     if (isset($joins['join_hut'])) {
         Hut::buildHutPagerConditions($q, $joins, false, true, 'm.LinkedAssociation', 'ph');
     }
     // join with routes tables only if needed
     if (isset($joins['join_summit']) || isset($joins['join_outing'])) {
         $joins['join_route'] = true;
         $joins['post_route'] = true;
     }
     if (isset($joins['join_route'])) {
         Route::buildRoutePagerConditions($q, $joins, false, true, 'm.LinkedAssociation', 'pr');
         if (isset($joins['join_summit'])) {
             Summit::buildSummitPagerConditions($q, $joins, false, false, 'lr.MainAssociation', 'sr');
         }
         if (isset($joins['join_outing'])) {
             Outing::buildOutingPagerConditions($q, $joins, false, true, 'lr.LinkedAssociation', 'ro');
         }
     }
     // join with site tables only if needed
     if (isset($joins['join_site'])) {
         Site::buildSitePagerConditions($q, $joins, false, true, 'm.LinkedAssociation', 'pt');
     }
     // join with image tables only if needed
     if (isset($joins['join_image'])) {
         Image::buildImagePagerConditions($q, $joins, false, 'pi');
     }
     if (!empty($conditions)) {
         $q->addWhere(implode(' AND ', $conditions), $values);
     }
 }
예제 #15
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     sfLoader::loadHelpers(array('General'));
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         // Add the summit name to route
         $associated_routes = array_filter($this->associated_docs, array('c2cTools', 'is_route'));
         $associated_routes = Route::addBestSummitName($associated_routes, $this->__(' :') . ' ');
         // Include outings additional data
         $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
         $associated_outings = Outing::fetchAdditionalFields($associated_outings);
         // group all linked docs except images in a single list
         $associated_docs = array_filter($this->associated_docs, array('c2cTools', 'is_not_route'));
         $associated_docs = array_filter($associated_docs, array('c2cTools', 'is_not_outing'));
         $associated_docs = array_filter($associated_docs, array('c2cTools', 'is_not_image'));
         $associated_docs = array_merge($associated_docs, $associated_routes, $associated_outings);
         // sort by document type, name
         if (count($associated_docs)) {
             foreach ($associated_docs as $key => $row) {
                 $module[$key] = $row['module'];
                 $name[$key] = remove_accents($row['name']);
             }
             array_multisort($module, SORT_STRING, $name, SORT_STRING, $associated_docs);
         }
         $this->associated_users = array_filter($associated_docs, array('c2cTools', 'is_user'));
         $this->associated_documents = $associated_docs;
         // Retrieve linked docs areas (except users)
         $parent_ids = array();
         $associated_areas = array();
         foreach ($this->associated_docs as $doc) {
             if ($doc['module'] != 'users') {
                 $parent_ids[] = $doc['id'];
             }
         }
         if (count($parent_ids)) {
             $prefered_cultures = $this->getUser()->getCulturesForDocuments();
             $associated_areas = GeoAssociation::findAreasWithBestName($parent_ids, $prefered_cultures);
         }
         $this->associated_areas = $associated_areas;
         // retrieve related portals, depending on article category
         // Soft mobility articles => changedapproche
         // ice activity + gear, stories or expeditions => ice portal
         $related_portals = array();
         $activities = $this->document->get('activities');
         $categories = $this->document->get('categories');
         if (in_array(7, $categories)) {
             $related_portals[] = 'cda';
         }
         if (array_intersect(array(2, 3, 8), $categories) && in_array(5, $activities)) {
             $related_portals[] = 'ice';
         }
         Portal::getLocalPortals($related_portals, $associated_areas);
         $this->related_portals = $related_portals;
         sfLoader::loadHelpers(array('sfBBCode', 'SmartFormat'));
         $abstract = strip_tags(parse_links(parse_bbcode_abstract($this->document->get('abstract'))));
         $this->getResponse()->addMeta('description', $abstract);
         if (in_array(100, $categories)) {
             $this->getResponse()->addMeta('robots', 'noindex, follow');
         }
     }
 }
예제 #16
0
 /**
  * RSS version of list page
  */
 public function executeRss()
 {
     // TODO: factorize with list action?
     $timer = new sfTimer('executeRss');
     $module = $this->getModuleName();
     $model = $this->model_class;
     $criteria = $this->getListCriteria($model);
     if ($criteria !== 'no_result' && $module != 'documents') {
         $sort = call_user_func(array('Document', 'getListSortCriteria'), $model);
         $page = $this->getRequestParameter('page', 1);
         $infos = call_user_func(array('Document', 'browse'), $model, $sort, $criteria, array('rss'), $page);
         $nb_results = $infos['nb_results'];
         $this->pager = $infos['pager'];
         $this->query = $infos['query'];
         if ($nb_results > 0) {
             $items = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
             if (isset($items[0]['geoassociations'])) {
                 $items = Language::getTheBestForAssociatedAreas($items);
             }
             // Retrieve creator and creation date.
             $items = Outing::getAssociatedCreatorData($items);
         } else {
             $items = array();
         }
     } else {
         $nb_results = 0;
         $items = array();
     }
     $this->nb_results = $nb_results;
     $this->items = $items;
     $this->setLayout(false);
     $this->setTemplate('../../documents/templates/rss');
     $this->setCacheControl();
     c2cActions::statsdTiming('document.executeRss', $timer->getElapsedTime('executeRss'));
 }
예제 #17
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         $user = $this->getUser();
         $prefered_cultures = $user->getCulturesForDocuments();
         $current_doc_id = $this->getRequestParameter('id');
         $parent_ids = array();
         $main_associated_summits = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_summit')), 'elevation');
         if (count($main_associated_summits)) {
             foreach ($main_associated_summits as $summit) {
                 $parent_ids[] = $summit['id'];
             }
         }
         // extract coord of highest summit
         $highest_summit = c2cTools::extractHighest($main_associated_summits);
         $this->lat = $highest_summit['lat'];
         $this->lon = $highest_summit['lon'];
         $this->elevation = $highest_summit['elevation'];
         // routes associated with this route (eg because they share most of the route)
         $associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' ');
         $this->associated_routes = $associated_routes;
         // We will display the outings linked to associated routes in a separate section
         // but not for the raids
         $route_ids = array();
         if (count($associated_routes)) {
             foreach ($associated_routes as $route) {
                 if ($route['duration'] instanceof Doctrine_Null or $route['duration'] <= 4) {
                     $route_ids[] = $route['id'];
                 }
             }
         }
         // we will also get parkings linked to linked parkings
         $associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
         if (count($associated_parkings)) {
             foreach ($associated_parkings as $parking) {
                 $parent_ids[] = $parking['id'];
             }
         }
         // 2-hops summits, parkings, outings, huts
         $parent_ids = array_merge($parent_ids, $route_ids);
         if (count($parent_ids)) {
             $associated_childs = Association::findLinkedDocsWithBestName($parent_ids, $prefered_cultures, array('ss', 'pp', 'ro', 'sh'), true, true);
         } else {
             $associated_childs = array();
         }
         if (count($main_associated_summits)) {
             $associated_summits = Association::createHierarchy($main_associated_summits, array_filter($associated_childs, array('c2cTools', 'is_summit')), array('type' => 'ss', 'show_sub_docs' => false));
         } else {
             $associated_summits = $main_associated_summits;
         }
         // directly and indirectly linked huts
         $associated_huts = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_hut')), 'elevation');
         $associated_summit_huts = array_filter($associated_childs, array('c2cTools', 'is_hut'));
         // remove the summit if it is linked to a hut
         // because in that case it is a ghost summit of the hut, and
         // shouldn't be displayed
         $summit_huts = array();
         foreach ($associated_summit_huts as $summit_hut) {
             foreach ($associated_huts as $key1 => $hut) {
                 if ($summit_hut['id'] == $hut['id']) {
                     $linked = array_keys($summit_hut['parent_relation']);
                     $hut['ghost_id'] = array_shift($linked);
                     $summit_huts[] = $hut;
                     unset($associated_huts[$key1]);
                     foreach ($associated_summits as $key2 => $summit) {
                         if ($summit['id'] == $hut['ghost_id']) {
                             unset($associated_summits[$key2]);
                             break;
                         }
                     }
                     break;
                 }
             }
         }
         $this->associated_huts = Document::fetchAdditionalFieldsFor(array_merge($summit_huts, $associated_huts), 'Hut', array('shelter_type'));
         $this->associated_summits = Document::fetchAdditionalFieldsFor($associated_summits, 'Summit', array('summit_type'));
         // get all the outings from route and associated routes
         $outing_ids = $associated_routes_outings = array();
         if (count($route_ids)) {
             $associated_routes_outings = array_filter($associated_childs, array('c2cTools', 'is_outing'));
             if (count($associated_routes_outings)) {
                 $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
                 if (count($associated_outings)) {
                     foreach ($associated_outings as $outing) {
                         $outing_ids[] = $outing['id'];
                     }
                     foreach ($associated_routes_outings as $outing) {
                         if (!in_array($outing['id'], $outing_ids)) {
                             $associated_outings[] = $outing;
                         }
                     }
                 } else {
                     $associated_outings = $associated_routes_outings;
                 }
             }
         }
         array_unshift($route_ids, $current_doc_id);
         $this->ids = implode('-', $route_ids);
         if (count($associated_parkings)) {
             $associated_parkings = Association::createHierarchy($associated_parkings, array_filter($associated_childs, array('c2cTools', 'is_parking')), array('type' => 'pp', 'show_sub_docs' => false));
             $associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
         }
         $this->associated_parkings = $associated_parkings;
         // also get author of books
         $associated_books = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_book')), 'name');
         if (count($associated_books)) {
             $associated_books = Book::getAssociatedBooksData($associated_books);
         }
         $this->associated_books = $associated_books;
         // TODO request will become more and more inefficient as number of linked outings will grow...
         if (!isset($associated_outings)) {
             $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
         }
         $associated_outings = Outing::fetchAdditionalFields($associated_outings, true, true);
         // sort outings
         usort($associated_outings, array('c2cTools', 'cmpDate'));
         if (count($associated_routes_outings)) {
             $main_outings = $routes_outings = array();
             foreach ($associated_outings as $outing) {
                 if (in_array($outing['id'], $outing_ids)) {
                     $main_outings[] = $outing;
                 } else {
                     $routes_outings[] = $outing;
                 }
             }
         } else {
             $main_outings = $associated_outings;
             $routes_outings = array();
         }
         $nb_outings = count($associated_outings);
         $this->nb_outings = count($associated_outings);
         $this->nb_main_outings = count($main_outings);
         $this->nb_routes_outings = count($routes_outings);
         // group main_outings  by blocks
         $outings_limit = sfConfig::get('app_users_outings_limit');
         $a = array();
         $i = 0;
         while ($i < 9 && count($main_outings) - $i * $outings_limit > $outings_limit) {
             $a[] = array_slice($main_outings, $i * $outings_limit, $outings_limit);
             $i++;
         }
         $a[] = array_slice($main_outings, $i * $outings_limit, $outings_limit);
         $this->associated_outings = $a;
         // group routes_outings  by blocks
         $a = array();
         $i = 0;
         while ($i < 0 && count($routes_outings) - $i * $outings_limit > $outings_limit) {
             $a[] = array_slice($routes_outings, $i * $outings_limit, $outings_limit);
             $i++;
         }
         $a[] = array_slice($routes_outings, $i * $outings_limit, $outings_limit);
         $this->routes_outings = $a;
         // Get related portals
         $related_portals = array();
         $route_data = array();
         $route_data['activities'] = $this->document->get('activities');
         $route_data['ice_rating'] = $this->document->get('ice_rating');
         $route_data['toponeige_technical_rating'] = $this->document->get('toponeige_technical_rating');
         $route_data['global_rating'] = $this->document->get('global_rating');
         $route_data['equipment_rating'] = $this->document->get('equipment_rating');
         $route_data['engagement_rating'] = $this->document->get('engagement_rating');
         $route_data['difficulties_height'] = $this->document->get('difficulties_height');
         $route_data['duration'] = $this->document->get('duration');
         $route_data = array($route_data);
         Portal::getRelatedPortals($related_portals, $this->associated_areas, $route_data);
         $this->related_portals = $related_portals;
         // extract highest associated summit, and prepend its name to display this route's name.
         $this->highest_summit_name = $highest_summit['name'];
         // redefine page title: prepend summit name
         $doc_name = $this->highest_summit_name . $this->__(' :') . ' ' . $this->document->get('name');
         $title = $doc_name;
         if ($this->document->isArchive()) {
             $version = $this->getRequestParameter('version');
             $title .= ' :: ' . $this->__('revision') . ' ' . $version;
         }
         $doc_type = $this->__('route') . ' / topo';
         $title .= ' :: ' . $doc_type;
         $this->setPageTitle($title);
         $description = array($doc_type . ' :: ' . $doc_name, $this->getActivitiesList(), $this->getAreasList());
         $this->getResponse()->addMeta('description', implode(' - ', $description));
     }
 }
예제 #18
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         $user = $this->getUser();
         $prefered_cultures = $user->getCulturesForDocuments();
         $current_doc_id = $this->getRequestParameter('id');
         // ghost summits, used for adding routes to huts
         // if summit is associated directly to a hut, redirect to hut unless ?redirect=no is appended (after a slug!)
         $associated_huts = array_filter($this->associated_docs, array('c2cTools', 'is_hut'));
         if (count($associated_huts) > 0 && $this->getRequestParameter('redirect') != 'no') {
             $associated_hut = reset($associated_huts);
             // array has been filtered
             $hut_id = $associated_hut['id'];
             $lang = $this->getRequestParameter('lang');
             $this->redirect("@document_by_id_lang?module=huts&id={$hut_id}&lang={$lang}");
         }
         // main associated summits are summits directly linked to this one
         $main_associated_summits = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_summit')), 'elevation');
         $associated_sites = $this->associated_sites;
         // idea here is to display some docs (routes, images, sites), not only if they are directly linked to the summit,
         // but also if they are linked to a sub(-sub)-summit
         $sub_summit_ids = array();
         $sub_summit_names = array();
         $summit_name = $this->document->get('name');
         $over_summit_name = '';
         if (count($main_associated_summits)) {
             $associated_summits = Association::createHierarchyWithBestName($main_associated_summits, $prefered_cultures, array('type' => 'ss', 'current_doc_id' => $current_doc_id, 'keep_current_doc' => true));
             // simply go through the list and get the next items that have a bigger level
             $i = reset($associated_summits);
             while (!isset($i['is_doc'])) {
                 $i = next($associated_summits);
             }
             $doc_level = $i['level'];
             $i = next($associated_summits);
             while ($i !== false && $i['level'] > $doc_level) {
                 $sub_summit_ids[] = $i['id'];
                 $sub_summit_names[] = $i['name'];
                 $i = next($associated_summits);
             }
             if (count($sub_summit_ids)) {
                 $summit_docs = array_filter($this->associated_docs, array('c2cTools', 'is_site_route_image'));
                 $summit_docs_ids = array();
                 foreach ($summit_docs as $doc) {
                     $summit_docs_ids[] = $doc['id'];
                 }
                 $associated_summit_docs = Association::findLinkedDocsWithBestName($sub_summit_ids, $prefered_cultures, array('st', 'sr', 'si'), false, true, $summit_docs_ids);
                 $this->associated_docs = array_merge($this->associated_docs, $associated_summit_docs);
                 $associated_summit_sites = c2cTools::sortArrayByName(array_filter($associated_summit_docs, array('c2cTools', 'is_site')));
                 foreach ($associated_summit_sites as $key => $site) {
                     $associated_summit_sites[$key]['parent_id'] = true;
                 }
                 $associated_sites = array_merge($associated_sites, $associated_summit_sites);
                 $this->associated_sites = $associated_sites;
                 // Find part of summit name which is used into sub-summit names
                 foreach ($sub_summit_names as $sub_summit_name) {
                     $sub_summit_name_prefix = explode(' - ', $sub_summit_name, -1);
                     if (count($sub_summit_name_prefix) && strpos($summit_name, $sub_summit_name_prefix[0]) !== false) {
                         $over_summit_name = $sub_summit_name_prefix[0];
                         break;
                     }
                 }
                 $over_summit_name_2 = false;
                 $over_summit_name_3 = false;
                 foreach ($sub_summit_names as $sub_summit_name) {
                     if (!$over_summit_name_3 && strpos($sub_summit_name, $summit_name) === 0) {
                         $over_summit_name_2 = true;
                     } else {
                         if (!empty($over_summit_name) && strpos($sub_summit_name, $over_summit_name) !== false) {
                             $over_summit_name_3 = true;
                         }
                     }
                 }
                 if ($over_summit_name_2) {
                     $over_summit_name = $summit_name;
                 }
             }
         } else {
             $associated_summits = $main_associated_summits;
         }
         $this->associated_summits = $associated_summits;
         array_unshift($sub_summit_ids, $current_doc_id);
         $this->ids = implode('-', $sub_summit_ids);
         // second param will not display the summit name before the route when the summit is the one of the document
         $associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' ', $this->document->get('id'), $over_summit_name);
         $this->associated_routes = $associated_routes;
         $associated_books = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_book')));
         $doc_ids = array();
         $associated_huts = array();
         $associated_parkings = array();
         $associated_routes_books = array();
         if (count($associated_routes) || count($associated_sites)) {
             foreach ($associated_routes as $route) {
                 if ($route['duration'] instanceof Doctrine_Null || $route['duration'] <= 4) {
                     $doc_ids[] = $route['id'];
                 }
             }
             foreach ($associated_sites as $site) {
                 $doc_ids[] = $site['id'];
             }
             if (count($doc_ids)) {
                 $book_ids = array();
                 foreach ($associated_books as $book) {
                     $book_ids[] = $book['id'];
                 }
                 $associated_route_docs = Association::findLinkedDocsWithBestName($doc_ids, $prefered_cultures, array('hr', 'ht', 'pr', 'pt', 'br'), false, false, $book_ids);
                 if (count($associated_route_docs)) {
                     $associated_route_docs = c2cTools::sortArray($associated_route_docs, 'elevation');
                     $associated_huts = array_filter($associated_route_docs, array('c2cTools', 'is_hut'));
                     $associated_parkings = Parking::getAssociatedParkingsData(array_filter($associated_route_docs, array('c2cTools', 'is_parking')));
                     $associated_routes_books = c2cTools::sortArray(array_filter($associated_route_docs, array('c2cTools', 'is_book')), 'name');
                     foreach ($associated_routes_books as $key => $book) {
                         $associated_routes_books[$key]['parent_id'] = true;
                     }
                 }
             }
         }
         $this->associated_huts = $associated_huts;
         $this->associated_parkings = $associated_parkings;
         $associated_books = array_merge($associated_books, $associated_routes_books);
         if (count($associated_books)) {
             $associated_books = Book::getAssociatedBooksData($associated_books);
         }
         $this->associated_books = $associated_books;
         // get associated outings
         $latest_outings = array();
         $nb_outings = 0;
         if (count($associated_routes)) {
             $outing_params = array('summits' => $this->ids);
             $nb_outings = sfConfig::get('app_nb_linked_outings_docs');
             $latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
             $latest_outings = Language::getTheBest($latest_outings, 'Outing');
         }
         $this->latest_outings = $latest_outings;
         $this->nb_outings = $nb_outings;
         $this->associated_images = Document::fetchAdditionalFieldsFor(array_filter($this->associated_docs, array('c2cTools', 'is_image')), 'Image', array('filename', 'image_type', 'date_time', 'width', 'height'));
         $cab = count($associated_books);
         $this->section_list = array('books' => $cab != 0, 'map' => (bool) $this->document->get('geom_wkt'));
         $related_portals = array();
         Portal::getRelatedPortals($related_portals, $this->associated_areas, $associated_routes);
         $summit_type_index = $this->document->get('summit_type');
         if ($summit_type_index == 5 && !in_array('raid', $related_portals)) {
             $related_portals[] = 'raid';
         }
         $this->related_portals = $related_portals;
         $summit_type_list = sfConfig::get('app_summits_summit_types');
         $summit_type_list[1] = 'summit';
         $summit_type = $this->__($summit_type_list[$summit_type_index]);
         $doc_name = $summit_name;
         $title = $doc_name;
         if ($this->document->isArchive()) {
             $version = $this->getRequestParameter('version');
             $title .= ' :: ' . $this->__('revision') . ' ' . $version;
         }
         $title .= ' :: ' . $summit_type;
         $this->setPageTitle($title);
         $description = array($summit_type . ' :: ' . $doc_name, $this->document->get('elevation') . $this->__('meters'), $this->getAreasList());
         $this->getResponse()->addMeta('description', implode(' - ', $description));
     }
 }