示例#1
0
 public static function getAssociatedMapsData($maps)
 {
     if (!count($maps)) {
         return array();
     }
     $editor_list = sfConfig::get('app_maps_editors');
     foreach ($maps as $key => $map) {
         $name = $editor_list[$map['editor']] . ' ' . $map['code'] . ' ' . $map['name'];
         $maps[$key]['name'] = $name;
     }
     return c2cTools::sortArrayByName($maps);
 }
示例#2
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     $timer = new sfTimer('executeView');
     $this->timer = $timer;
     sfLoader::loadHelpers(array('General', 'MetaLink'));
     $id = $this->getRequestParameter('id');
     $lang = $this->getRequestParameter('lang');
     $version = $this->getRequestParameter('version');
     $slug = $this->getRequestParameter('slug');
     // and if not, redirect to true module...
     if ($this->model_class == 'Document') {
         $doc = Document::find('Document', $id, array('module'));
         $module = $doc->get('module');
     }
     $user = $this->getUser();
     $prefered_cultures = $user->getCulturesForDocuments();
     $module = isset($module) ? $module : $this->getModuleName();
     // we check here if document id requested corresponds to $module model
     if (empty($lang)) {
         // if lang isn't set, we use the prefered language session and redirect to the good URL
         // (for caching reasons, this cannot be silent)
         if (!($lang = DocumentI18n::findBestCulture($id, $prefered_cultures, $this->model_class))) {
             c2cActions::statsdTiming('document.executeView.redirect', $timer->getElapsedTime('executeView'));
             $this->setNotFoundAndRedirect();
         } else {
             $document = $this->getDocument($id, $lang, $version);
             c2cActions::statsdTiming('document.executeView.redirect', $timer->getElapsedTime('executeView'));
             $this->redirectIfSlugMissing($document, $id, $lang, $module);
         }
     }
     $document = $this->getDocument($id, $lang, $version);
     // no need to test whether document has been found :
     // already done in getDocument method.
     if (empty($version) && $module != 'users' && (empty($slug) || $module != 'routes' && $slug != get_slug($document))) {
         c2cActions::statsdTiming('document.executeView.redirect', $timer->getElapsedTime('executeView'));
         $this->redirectIfSlugMissing($document, $id, $lang, $module);
     }
     // case where module = documents, and lang, version or slug already given
     if ($this->model_class == 'Document') {
         $this->redirect("@document_by_id_lang_slug?module={$module}&id={$id}&lang={$lang}&slug={$slug}", 301);
     }
     if ($to_id = $document->get('redirects_to')) {
         $this->setWarning('Current document has been merged into document %1%', array('%1%' => $to_id), false);
     }
     $title = $document->get('name');
     if ($document->isArchive()) {
         $this->getResponse()->addMeta('robots', 'noindex, nofollow');
         $this->metadata = $document->getMetadatas();
         $this->created_at = $this->metadata->get('written_at');
         $this->current_version = $version;
         $title .= ' :: ' . $this->__('revision') . ' ' . $version;
         $this->associated_docs = array();
         // we need associated images for displaying them
         $prefered_cultures = $this->getUser()->getCulturesForDocuments();
         $association_type = c2cTools::Module2Letter($module) . 'i';
         $this->associated_images = Document::fetchAdditionalFieldsFor(Association::findAllWithBestName($id, $prefered_cultures, $association_type), 'Image', array('filename', 'image_type', 'date_time'));
     } else {
         if (isset($to_id)) {
             $this->getResponse()->addMeta('robots', 'noindex, follow');
         } else {
             $this->getResponse()->addMeta('robots', 'index, follow');
         }
         $this->metadata = NULL;
         if ($module != 'portals') {
             $version_infos = Document::getCurrentVersionInfosFromIdAndCulture($id, $lang);
             $this->current_version = $version_infos['version'];
             $this->created_at = $version_infos['created_at'];
         }
         // retrieve associated docs
         // some additional docs can be retrieved in module/executeView, like two hops summits
         // contains all documents directly linked
         $association_type = $module == 'users' ? array('ui') : null;
         $associated_docs = Association::findAllWithBestName($id, $prefered_cultures, $association_type);
         // mark them (useful information)
         foreach ($associated_docs as &$doc) {
             $doc['directly_linked'] = true;
         }
         $this->associated_docs = $associated_docs;
         // all the linked articles
         $this->associated_articles = array_filter($this->associated_docs, array('c2cTools', 'is_article'));
         // linked sites
         $this->associated_sites = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_site')));
         // linked books. For summits and huts, the displayed books are the one linked to the linked routes
         if (!in_array($module, array('summits', 'huts'))) {
             $this->associated_books = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_book')));
         }
         // linked images
         // For sites and summits, we will dislay images linked to the summit/site AND its subsummits/subsites
         if (!in_array($module, array('summits', 'sites'))) {
             $this->associated_images = Document::fetchAdditionalFieldsFor(array_filter($this->associated_docs, array('c2cTools', 'is_image')), 'Image', array('filename', 'image_type', 'date_time', 'width', 'height'));
         }
         // Geo associated docs
         if (!in_array($module, array('articles', 'books'))) {
             $associated_areas = GeoAssociation::findAreasWithBestName($id, $prefered_cultures);
             $this->associated_areas = $associated_areas;
         }
         if (!in_array($module, array('outings', 'articles', 'books', 'portals'))) {
             $associated_maps = GeoAssociation::findMapsWithBestName($id, $prefered_cultures);
             $this->associated_maps = Map::getAssociatedMapsData($associated_maps);
         }
     }
     // nb comments
     $this->nb_comments = PunbbComm::retrieveNbComments($id . '_' . $lang);
     // js translation code if needed
     $this->needs_translation = $lang == $user->getCulture() ? false : $lang;
     $response = $this->getResponse();
     if ($this->needs_translation && !c2cTools::mobileVersion()) {
         $response->addJavascript('/static/js/translation.js', 'last');
     }
     if (!in_array($module, array('summits', 'routes', 'sites', 'huts', 'products'))) {
         $title .= ' :: ' . $this->__(substr($module, 0, -1));
         $this->setPageTitle($title);
     }
     $response->addMeta('description', $title);
     /* image_src fixes the image proposed eg by facebook
           - for an image, force it to be the image miniature
           - for a doc with attached images, leave facebook decide
           - for a book without attached image, force the c2c logo
        */
     if ($module != 'images' && !count($this->associated_images)) {
         addMetaLink('image_src', sfConfig::get('app_images_default_meta'));
     }
     /* small js code to append QR code when printing page */
     if (!$document->isArchive() && !c2cTools::mobileVersion()) {
         $response->addJavascript('/static/js/qrcode.js', 'last');
     }
     $this->document = $document;
     $this->languages = $document->getLanguages();
     c2cActions::statsdTiming('document.executeView', $timer->getElapsedTime('executeView'));
 }
示例#3
0
 public static function getAssociatedSitesData($associated_docs)
 {
     $sites = Document::fetchAdditionalFieldsFor(array_filter($associated_docs, array('c2cTools', 'is_site')), 'Site', array('site_types'));
     return c2cTools::sortArrayByName($sites);
 }
示例#4
0
 /**
  * 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'));
     }
 }
示例#5
0
 public static function getAssociatedAreasData($associated_areas)
 {
     $areas = Document::fetchAdditionalFieldsFor($associated_areas, 'Area', array('area_type'));
     return c2cTools::sortArrayByName($areas);
 }
示例#6
0
 /**
  * returns a list of associated routes
  */
 public function executeGetroutes()
 {
     $id = $this->getRequestParameter('summit_id');
     $div_name = $this->getRequestParameter('div_name');
     $div_prefix = $this->getRequestParameter('div_prefix', '');
     $div_id = $div_prefix . $div_name;
     $user = $this->getUser();
     $user_id = $user->getId();
     // if id = 0 or no provided
     if (!$id) {
         return $this->ajax_feedback('Missing id parameter');
     }
     // if session is time-over
     if (!$user_id) {
         return $this->ajax_feedback('Your session is over. Please login again.');
     }
     $summit = Document::find('Summit', $id, array('id', 'elevation'));
     if (!$summit) {
         return $this->ajax_feedback('Summit not found');
     }
     $sub_summits = Summit::getSubSummits($id);
     $ids = array($id);
     foreach ($sub_summits as $sub) {
         $ids[] = $sub['id'];
     }
     $routes = Association::findLinkedDocsWithBestName($ids, $this->getUser()->getCulturesForDocuments(), 'sr');
     $routes = Route::addBestSummitName($routes, $this->__('&nbsp;:') . ' ');
     $routes = c2cTools::sortArrayByName($routes);
     if (count($routes) == 0) {
         return $this->ajax_feedback($this->__('No associated route found'));
     }
     if (!$div_id) {
         return $this->ajax_feedback('Please chose a "select" container ID in "remote_function"');
     }
     $output = $this->__('Route:') . ' <select id="' . $div_id . '" name="' . $div_name . '" onchange="C2C.getWizardRouteRatings(\'' . $div_id . '\');">';
     foreach ($routes as $route) {
         $output .= '<option value="' . $route['id'] . '">' . $route['name'] . '</option>';
     }
     $output .= '</select>';
     $output .= '<p id="wizard_' . $div_id . '_descr" class="short_descr" style="display: none">' . '<span id="' . $div_id . '_descr">' . $this->__('Short description: ') . $this->__('not available') . '</span></p>';
     return $this->renderText($output);
 }
 public static function findMapsWithBestName($id, $user_prefered_langs)
 {
     $query = 'SELECT mi.id, mi.culture, mi.name, m.code, m.editor ' . 'FROM maps_i18n mi LEFT JOIN maps m ON mi.id = m.id ' . 'WHERE mi.id IN ' . '(SELECT a.linked_id FROM app_geo_associations a WHERE a.main_id = ? AND type = ?) ' . 'ORDER BY mi.id ASC';
     $results = sfDoctrine::connection()->standaloneQuery($query, array($id, 'dm'))->fetchAll();
     $out = self::setBestName($results, $user_prefered_langs);
     $out = c2cTools::sortArrayByName($out);
     return $out;
 }
示例#8
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));
     }
 }
示例#9
0
 public static function getAssociatedHutsData($associated_docs)
 {
     $huts = Document::fetchAdditionalFieldsFor(array_filter($associated_docs, array('c2cTools', 'is_hut')), 'Hut', array('elevation'));
     return c2cTools::sortArrayByName($huts);
 }