예제 #1
0
 /**
  * If the current version number is not set, it looks in DB
  * else it takes it from the static property current_version.
  * TODO: compare it with a document_id, because current_version is only independent from same document
  */
 public static function getCurrentVersionNb($id, $lang)
 {
     if (!isset(self::$current_version)) {
         self::$current_version = Document::getCurrentVersionNumberFromIdAndCulture($id, $lang);
     }
     return self::$current_version;
 }
예제 #2
0
 public function executeView()
 {
     parent::executeView();
     // add editor + code for in map title
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         $related_portals = array();
         Portal::getLocalPortals($related_portals, $this->associated_areas);
         $this->related_portals = $related_portals;
         $map_editors_list = sfConfig::get('mod_maps_editors_list');
         $title = $this->__($map_editors_list[$this->document->get('editor')]) . ' ' . $this->document->get('code') . ' ' . $this->document->get('name') . ' :: ' . $this->__(substr($this->getModuleName(), 0, -1));
         $this->setPageTitle($title);
     }
 }
예제 #3
0
 /**
  * Executes list action
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $products = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     Parking::addAssociatedParkings($products, 'pf');
     // add associated parkings infos to $products
     c2cActions::statsdTiming('parking.addAssociatedParkings', $timer->getElapsedTime());
     Area::sortAssociatedAreas($products);
     $this->items = Language::parseListItems($products, 'Product');
 }
예제 #4
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();
         $this->associated_summits = Summit::getAssociatedSummitsData($this->associated_docs);
         $this->associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' ');
         $this->associated_huts = Hut::getAssociatedHutsData($this->associated_docs);
         $this->associated_sites = Site::getAssociatedSitesData($this->associated_docs);
         // add linked docs areas
         $parent_ids = array();
         $associated_areas = array();
         if (count($this->associated_docs)) {
             foreach ($this->associated_docs as $doc) {
                 $parent_ids[] = $doc['id'];
             }
             $associated_areas = GeoAssociation::findAreasWithBestName($parent_ids, $prefered_cultures);
         }
         $this->associated_areas = $associated_areas;
         $cas = count($this->associated_summits);
         $car = count($this->associated_routes);
         $cah = count($this->associated_huts);
         $cab = count($this->associated_sites);
         $this->section_list = array('summits' => $cas != 0, 'routes' => $car != 0, 'huts' => $cah != 0, 'sites' => $cab != 0, 'docs' => $cas + $car + $cah + $cab == 0);
         $related_portals = array();
         $activities = $this->document->get('activities');
         $book_types = $this->document->get('book_types');
         Portal::getRelatedPortals($related_portals, $this->associated_areas, $this->associated_routes, $activities);
         if (array_intersect(array(1, 4, 10, 14, 18), $book_types) && in_array(5, $activities) && !in_array('ice', $related_portals)) {
             $related_portals[] = 'ice';
         }
         $this->related_portals = $related_portals;
         $description = array($this->__('book') . ' :: ' . $this->document->get('name'), $this->getActivitiesList());
         $this->getResponse()->addMeta('description', implode(' - ', $description));
     }
 }
예제 #5
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);
     }
 }
예제 #6
0
 /**
  * Executes list action, adding parkings linked to routes
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $routes = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     // if they are criterias on the summit (snam, srnam, salt, styp)
     // we might have only some of the associated summits and not the 'best one' (ticket #337)
     // so we must add a new request to get the summits, display the best one and add a note to explain that the
     // other summit is associated
     // FIXME would be nice to put all in a single request (before), but I didn't manage to do it
     // TODO not working right now
     //if ($this->hasRequestParameter('snam') || $this->hasRequestParameter('srnam') ||
     //    $this->hasRequestParameter('salt') || $this->hasRequestParameter('styp'))
     //{
     // $routes = Route::addBestSummitName($routes, '');
     //}
     $timer = new sfTimer();
     Parking::addAssociatedParkings($routes, 'pr');
     // add associated parkings infos to $routes
     c2cActions::statsdTiming('parking.addAssociatedParkings', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($routes, 'ro', true);
     // number of associated outings
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($routes);
     $this->items = Language::parseListItems($routes, 'Route');
 }
예제 #7
0
 /**
  * Executes edit action.
  */
 public function executeEdit()
 {
     $id = $this->getRequestParameter('id');
     $user = $this->getUser();
     $is_moderator = $user->hasCredential(sfConfig::get('app_credentials_moderator'));
     //    FIXME : only moderators can edit a portal, waiting for correct edition right management :
     //      - for common portals, the members con edit only text fields, and data fields are editable only by moderators
     //      - for cda portal, the moderators only can edit it
     //    $cda_config = sfConfig::get('app_portals_cda');
     //    if ($is_moderator || $id != $cda_config['id'])
     if ($is_moderator) {
         parent::executeEdit();
     } else {
         return $this->ajax_feedback('You do not have enough credentials to perform this operation');
     }
 }
예제 #8
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);
 }
예제 #9
0
 /**
  * Executes delete action
  * Checks if there are some associated routes with only this summit.
  * If not, then call the parent default delete action. 
  * If yes, calls error and redirect
  */
 public function executeDelete()
 {
     $referer = $this->getRequest()->getReferer();
     if ($id = $this->getRequestParameter('id')) {
         // Get all associated documents
         $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'));
         if ($associated_docs) {
             // Initialise the list of routes only associated to this summit
             $single_summit_route_list = array();
             // Check if any associated doc is a route
             foreach ($associated_docs as $doc) {
                 if ($doc['module'] == 'routes') {
                     // if we found an associated route, check if it is associated to several summits
                     $route_associated_docs = Association::findAllAssociatedDocs($doc['id'], array('id', 'module'));
                     if ($route_associated_docs) {
                         // Check if any associated doc to the route is a summit different from the one we want to delete
                         $multiple_summit = False;
                         foreach ($route_associated_docs as $route_associated_doc) {
                             // There's an associated summit which is different from the one we want to delete
                             if ($route_associated_doc['module'] == 'summits' && $route_associated_doc['id'] != $id) {
                                 $multiple_summit = True;
                                 break;
                             }
                         }
                         if (!$multiple_summit) {
                             // this route has only one summit: the one we want to delete
                             $single_summit_route_list[] = $doc['id'];
                         }
                     } else {
                         // shouldn't reach here, as the route we found should at least be associated to the summit that should (or not) be deleted
                         $this->setErrorAndRedirect('Document could not be deleted', $referer);
                     }
                 }
             }
             if (!empty($single_summit_route_list)) {
                 // If we found an associated route which has only one summit, we do not delete the summit
                 $this->setErrorAndRedirect('Document could not be deleted because there would be orphean routes%1%', $referer, array('%1%' => '<li><ul>' . implode('</ul><ul>', $single_summit_route_list) . '</ul></li>'));
             }
         }
         // If we reach here, then either there were no associated docs, or none of them was a route.
         parent::executeDelete();
     } else {
         $this->setErrorAndRedirect('Could not understand your request', $referer);
     }
 }
예제 #10
0
 public function executePopup()
 {
     $id = $this->getRequestParameter('id');
     // if user is not connected, we don't want to display user's popup
     if (!$this->getUser()->isConnected() && !UserPrivateData::hasPublicProfile($id)) {
         $this->raw = $this->getRequestParameter('raw', false);
         if ($this->raw) {
             $this->setLayout(false);
         }
         // deactivate automatic inclusion of js and css files by symfony
         $response = $this->getResponse();
         $response->setParameter('javascripts_included', true, 'symfony/view/asset');
         $response->setParameter('stylesheets_included', true, 'symfony/view/asset');
         $this->setCacheControl();
         // we call users/popupError template
         return sfView::ERROR;
     } else {
         parent::executePopup();
     }
 }
예제 #11
0
 /**
  * Executes list action
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $parkings = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($parkings, 'pr', true);
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($parkings);
     $this->items = Language::parseListItems($parkings, 'Parking');
 }
예제 #12
0
 protected function doMerge($from_id, $document_from, $to_id, $document_to)
 {
     // fetch associated documents before doing the merging as associations will be transferred
     $associations = Association::findAllAssociations($from_id);
     parent::doMerge($from_id, $document_from, $to_id, $document_to);
     // search documents in which from is inserted, and replace the insertion with to
     foreach ($associations as $a) {
         $check_id = $a['main_id'] == $from_id ? $a['linked_id'] : ($check_id = $a['main_id']);
         $check_model = c2cTools::Letter2Model(substr($a['type'], 0, 1));
         $check_module = c2cTools::Model2Module($check_model);
         $check_doc = Document::find($check_model, $check_id);
         $fields = sfConfig::get('mod_images_bbcode_fields_' . $check_module);
         // clear linked doc cache
         $this->clearCache($check_module, $check_id);
         $languages = $check_doc->getLanguages();
         foreach ($languages as $language) {
             $modified = false;
             $conn = sfDoctrine::Connection();
             $conn->beginTransaction();
             $check_doc->setCulture($language);
             foreach ($fields as $field) {
                 $text = $check_doc[$field];
                 $edited = preg_replace('#(\\[img=\\s*)' . $from_id . '([\\w\\s]*\\].*?\\[/img\\])\\n?#is', '${1}' . $to_id . '${2}', $text);
                 $edited = preg_replace('#(\\[img=\\s*)' . $from_id . '([\\w\\s]*\\/\\])\\n?#is', '${1}' . $to_id . '${2}', $edited);
                 if ($edited != $text) {
                     $modified = true;
                     $check_doc->set($field, $edited);
                 }
             }
             if ($modified) {
                 $history_metadata = new HistoryMetadata();
                 $history_metadata->setComment('Updated image tags');
                 $history_metadata->set('is_minor', true);
                 $history_metadata->set('user_id', sfConfig::get('app_moderator_user_id'));
                 $history_metadata->save();
                 c2cTools::log('After merge of image ' . $from_id . ' into ' . $to_id . ': update image tag for ' . strtolower($check_model) . ' ' . $check_id . ' (' . $language . ')');
                 $check_doc->save();
                 $conn->commit();
             } else {
                 $conn->rollback();
             }
         }
     }
     // clear images lists and whatsnew cache
     $this->clearCache('images', 0, true);
 }
예제 #13
0
 protected function endEdit()
 {
     if ($this->success) {
         // create also association with current user (only if this is a personal article)
         if ($this->new_document && $this->document->get('article_type') == 2) {
             $user_id = $this->getUser()->getId();
             $uc = new Association();
             $uc->doSaveWithValues($user_id, $this->document->get('id'), 'uc', $user_id);
             // main, linked, type
         }
         parent::endEdit();
         // redirect to document view
     }
 }