/** * Executes view action. */ public function executeView() { parent::executeView(); if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) { $user = $this->getUser(); $prefered_cultures = $user->getCulturesForDocuments(); $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; $related_portals = array(); Portal::getLocalPortals($related_portals, $this->associated_areas); $this->related_portals = $related_portals; $product_type_list = sfConfig::get('mod_products_types_list'); $product_type_index_list = $this->document->get('product_type'); $product_type_name_list = array(); foreach ($product_type_index_list as $product_type_index) { $product_type_name_list[] = $this->__($product_type_list[$product_type_index]); } $product_types = implode(', ', $product_type_name_list); $doc_name = $this->document->get('name'); $title = $doc_name; if ($this->document->isArchive()) { $version = $this->getRequestParameter('version'); $title .= ' :: ' . $this->__('revision') . ' ' . $version; } $title .= ' :: ' . $product_types; $this->setPageTitle($title); $description = array($product_types . ' :: ' . $doc_name, $this->getAreasList()); $this->getResponse()->addMeta('description', implode(' - ', $description)); } }
/** * 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() { parent::executeView(); // redefine page title: prepend date sfLoader::loadHelpers(array('Date')); $title = $this->document->get('name') . ', ' . format_date($this->document->get('date'), 'D') . ' :: ' . $this->__('outing'); $this->setPageTitle($title); if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) { $user = $this->getUser(); $prefered_cultures = $user->getCulturesForDocuments(); $associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' '); // determines outing max elevation using routes max elevations if it is not set $max_elevation = $this->document->getMaxElevation(); if ($max_elevation == NULL || $max_elevation == 0) { $outing_max_elevation = 0; foreach ($associated_routes as $route) { $route_max_elevation = $route['max_elevation'] instanceof Doctrine_Null ? 0 : $route['max_elevation']; if ($route_max_elevation > $outing_max_elevation) { $outing_max_elevation = $route_max_elevation; } } if ($outing_max_elevation > 0) { $this->document->setMaxElevation($outing_max_elevation); } } // the routes/sites linked to the outing will be used to retrieve 2-hops docs like summits, // huts, parkings.... // However, we need some special handling with raid routes (more than 2 days) $parent_ids = $other_ids = $other_routes = $default_ids = array(); $associated_summits = array(); $associated_huts = array(); $associated_parkings = array(); if (count($associated_routes)) { $associated_routes = c2cTools::sortArray($associated_routes, 'duration'); foreach ($associated_routes as $route) { // pour les docs de 2?me niveau, on retient uniquement les itin?raires de 1 ou 2 jours if (!$route['duration'] instanceof Doctrine_Null) { if ($route['duration'] <= 4) { $parent_ids[] = $route['id']; } else { $other_routes[$route['id']] = $route['duration']; } } else { $default_ids[] = $route['id']; } } // s'il n'y a pas d'itin?raire de 1 ou 2 jours, on utilise les itin?raires qui ont la plus petite dur?e // s'il n'y en a pas non plus, on utilise les itin?raire dont la dur?e est non renseign?e if (!count($parent_ids)) { if (count($other_routes) > 1) { asort($other_routes); $min_duration = $other_routes . reset(); foreach ($other_routes as $id => $duration) { if ($duration == $min_duration) { $other_ids[] = $id; } } } elseif (count($other_routes)) { $other_ids[] = key($other_routes); } else { $other_ids = $default_ids; } $parent_ids = $other_ids; } } if (count($this->associated_sites)) { $associated_sites = $this->associated_sites; foreach ($associated_sites as $site) { $parent_ids[] = $site['id']; } } // now retrieve the associated docs (summits, huts, parkings) if (count($parent_ids)) { $associated_route_docs = Association::findLinkedDocsWithBestName($parent_ids, $prefered_cultures, array('sr', 'hr', 'pr', 'pt'), false, false); if (count($associated_route_docs)) { $associated_route_docs = c2cTools::sortArray($associated_route_docs, 'elevation'); $associated_summits = array_filter($associated_route_docs, array('c2cTools', 'is_summit')); $associated_huts = array_filter($associated_route_docs, array('c2cTools', 'is_hut')); $associated_parkings = Parking::getAssociatedParkingsData(array_filter($associated_route_docs, array('c2cTools', 'is_parking'))); if (count($associated_summits) && count($associated_huts)) { $summit_ids = $summit_hut_tmp = $summit_hut_ids = array(); foreach ($associated_summits as $summit) { $summit_ids[] = $summit['id']; } $summit_hut_tmp = Association::countAllLinked($summit_ids, 'sh'); if (count($summit_hut_tmp)) { foreach ($summit_hut_tmp as $hut) { $summit_hut_ids[] = $hut['main_id']; } foreach ($associated_summits as $key => $summit) { if (in_array($summit['id'], $summit_hut_ids)) { unset($associated_summits[$key]); } } } } } } $this->associated_summits = $associated_summits; $this->associated_huts = $associated_huts; $this->associated_parkings = $associated_parkings; $this->associated_routes = $associated_routes; // associated users $associated_users = array_filter($this->associated_docs, array('c2cTools', 'is_user')); if (count($associated_users) >= 2) { // Set outing creator at first in the users list, and sort other users by name $creator_id = $this->document->getCreatorId(); $creator = array(); $associated_users_2 = array(); foreach ($associated_users as $key => $user) { if ($user['id'] == $creator_id) { $creator[$key] = $user; } else { $associated_users_2[$key] = $user; } } if (count($associated_users_2) >= 2) { $associated_users_2 = c2cTools::sortArrayByName($associated_users_2); } $associated_users = array_merge($creator, $associated_users_2); } $this->associated_users = $associated_users; // related portals $related_portals = array(); $activities = $this->document->get('activities'); $outing_with_public_transportation = $this->document->get('outing_with_public_transportation'); if (!$outing_with_public_transportation instanceof Doctrine_Null && $outing_with_public_transportation) { $related_portals[] = 'cda'; } Portal::getRelatedPortals($related_portals, $this->associated_areas, $associated_routes, $activities); $this->related_portals = $related_portals; $description = array($title, $this->getActivitiesList(), $this->getAreasList()); $this->getResponse()->addMeta('description', implode(' - ', $description)); } else { // only moderators and associated users should see archive versions of outings $this->filterAuthorizedPeople($this->getRequestParameter('id')); } }
public static function createHierarchy($docs, $linked_docs, $options = array()) { $type = _option($options, 'type'); $sort_field = _option($options, 'sort_field'); $show_sub_docs = _option($options, 'show_sub_docs', true); $current_doc_id = _option($options, 'current_doc_id', 0); if (!count($docs)) { return $docs; } // internal order between docs of same level $order = null; if (empty($sort_field)) { switch ($type) { case 'ss': $sort_field = 'elevation'; $order = SORT_DESC; break; case 'pp': $sort_field = 'elevation'; $order = SORT_ASC; break; default: $sort_field = 'name'; } } // add relation information to 1-hop docs foreach ($docs as $id => $doc) { $doc['parent_relation'] = array(); foreach ($linked_docs as $doc2) { if (isset($doc2['parent_relation'][$doc['id']])) { $docs[$id]['parent_relation'][$doc2['id']] = $doc2['parent_relation'][$doc['id']] == 'parent' ? 'child' : 'parent'; } } } $all_docs = array_merge($docs, $linked_docs); // Mark original document foreach ($all_docs as $key => $doc) { if ($doc['id'] == $current_doc_id) { $all_docs[$key]['is_doc'] = true; break; } } // if documents from different hierarchical levels are linked, we might have duplicates at that point // we should remove them $ids = $keys = array(); foreach ($all_docs as $key => $doc) { $pos = array_search($doc['id'], $ids); if ($pos !== false) { $all_docs[$keys[$pos]]['parent_relation'] = isset($all_docs[$keys[$pos]]['parent_relation']) ? $all_docs[$keys[$pos]]['parent_relation'] + $doc['parent_relation'] : $doc['parent_relation']; unset($all_docs[$key]); } else { $ids[] = $doc['id']; $keys[] = $key; } } // get all docs that don't have parents and put them in the output list with level 1 foreach ($all_docs as $id => $doc) { if (!isset($doc['parent_relation']) || array_search('parent', $doc['parent_relation']) === false) { $doc['level'] = 1; $output[] = $doc; unset($all_docs[$id]); } } $output = c2cTools::sortArray($output, $sort_field, null, $order); // for each level 1 doc, get corresponding children and insert them into the list // repeat the same process for level 2 docs for ($level = 2; $level <= 3; $level++) { $offset = 1; foreach ($output as $pos => $sorted_doc) { // only go through level 2 docs on second run if ($level == 3 && $sorted_doc['level'] !== 2) { continue; } $sub_docs = array(); foreach ($all_docs as $id => $doc) { if (array_key_exists($sorted_doc['id'], $doc['parent_relation'])) { $doc['level'] = $level; $sub_docs[] = $doc; unset($all_docs[$id]); } } if (count($sub_docs)) { $sub_docs = c2cTools::sortArray($sub_docs, $sort_field, null, $order); array_splice($output, $pos + $offset, 0, $sub_docs); $offset = $offset + count($sub_docs); } } } if (!$show_sub_docs) { // we don't want to display extra docs that are not parent from directly linked docs // as this would be useless information in some cases (for example, if I have a route linked to zermatt // I don't want to have the sub-parkings of zermatt listed in the route document) // we simply go from deepest level and remove leaves which are not dorectly linked for ($level = 3; $level > 0; $level--) { $temp = null; foreach (array_reverse($output, true) as $key => $doc) { if ($doc['level'] === $level && !isset($doc['directly_linked']) && (!isset($temp) || $temp['level'] <= $level)) { unset($output[$key]); } $temp = $doc; } } } return $output; }
/** * 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)); } }
/** * 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)); } }
/** * 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)); } }
/** * 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)); } }