/** * 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)); } }
/** * 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'); } } }
/** * 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)); } }
/** * Retrieves a list of outings ordered by effective outing date (more recent first). */ public static function listLatest($max_items, $langs, $ranges, $activities, $params = array(), $linked_areas = true, $orderby_date = true) { if (count($langs)) { $params['ocult'] = implode('-', $langs); } if (count($ranges)) { $params['areas'] = implode('-', $ranges); } if (count($activities)) { $params['act'] = implode('-', $activities); } if ($orderby_date) { $orderby = array('date'); $order = array('desc'); } else { $orderby = array(); $order = array(); } if (isset($params['orderby'])) { $orderby_tmp = array($params['orderby']); if ($orderby_tmp == 'id') { $orderby_date = false; $orderby = array(); } unset($params['orderby']); } if (isset($params['order'])) { $order = array($params['order']); unset($params['order']); } $criteria = Outing::buildListCriteria($params); $sort = array('orderby_params' => $orderby, 'order_params' => $order, 'npp' => $max_items); $sub_query_result = self::browseId('Outing', $sort, $criteria, array(), 1, $max_items); $nb_results = $sub_query_result['nb_results']; $ids = $sub_query_result['ids']; if (empty($nb_results) || empty($ids)) { return array(); } $where_ids = 'm.id' . $sub_query_result['where']; $fields = 'm.id, n.culture, n.name, m.date, m.activities, m.max_elevation'; if ($linked_areas) { $fields .= ', g0.linked_id, a.area_type, ai.name, ai.culture'; } $q = Doctrine_Query::create(); $q->select($fields)->from('Outing m')->leftJoin('m.OutingI18n n')->addWhere($where_ids, $ids); if ($linked_areas) { $q->leftJoin('m.geoassociations g0')->leftJoin('g0.AreaI18n ai')->leftJoin('ai.Area a'); } if ($orderby_date) { $q->orderBy('m.date DESC, m.id DESC'); } else { $q->orderBy('m.id DESC'); } $outings = $q->execute(array(), Doctrine::FETCH_ARRAY); $outings = Outing::fetchAdditionalFields($outings, false, true); return $outings; }