Exemplo n.º 1
0
 /**
  * Overriddes the one in parent class 
  * this is because we sometimes have to do things when centroid coordinates have moved.
  * TODO hutsActions::endEdit() should be factorized with this..
  */
 protected function refreshGeoAssociations($id)
 {
     // don't refresh associated doc if summit type is "raid"
     if ($this->document->get('summit_type') == 5) {
         return;
     }
     c2cTools::log("Entering refreshGeoAssociations for routes linked with summit {$id}");
     $associated_routes = Association::findAllAssociatedDocs($id, array('id', 'geom_wkt'), 'sr');
     if (count($associated_routes)) {
         $geoassociations = GeoAssociation::findAllAssociations($id, null, 'main');
         // we create new associations :
         //  (and delete old associations before creating the new ones)
         //  (and do not create outings-maps associations)
         foreach ($associated_routes as $route) {
             $i = $route['id'];
             if (!$route['geom_wkt']) {
                 // replicate geoassoces from doc $id to outing $i and delete previous ones
                 // (because there might be geoassociations created by this same process)
                 $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations, $i, true, true);
                 c2cTools::log("created {$nb_created} geo associations for route N° {$i}");
                 $this->clearCache('routes', $i, false, 'view');
                 $associated_outings = Association::findAllAssociatedDocs($i, array('id', 'geom_wkt'), 'ro');
                 if (count($associated_outings)) {
                     $geoassociations2 = GeoAssociation::findAllAssociations($i, null, 'main');
                     // we create new associations :
                     //  (and delete old associations before creating the new ones)
                     //  (and do not create outings-maps associations)
                     foreach ($associated_outings as $outing) {
                         $j = $outing['id'];
                         if (!$outing['geom_wkt']) {
                             // replicate geoassoces from doc $id to outing $i and delete previous ones
                             // (because there might be geoassociations created by this same process)
                             $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations2, $j, true, false);
                             c2cTools::log("created {$nb_created} geo associations for outing N° {$j}");
                             $this->clearCache('outings', $j, false, 'view');
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Overriddes the one in parent class 
  * this is because we sometimes have to do things when centroid coordinates have moved.
  */
 protected function refreshGeoAssociations($id)
 {
     c2cTools::log("Entering refreshGeoAssociations for outings linked with route {$id}");
     $associated_outings = Association::findAllAssociatedDocs($id, array('id', 'geom_wkt'), 'ro');
     if (count($associated_outings)) {
         $geoassociations = GeoAssociation::findAllAssociations($id, null, 'main');
         // we create new associations :
         //  (and delete old associations before creating the new ones)
         //  (and do not create outings-maps associations)
         foreach ($associated_outings as $outing) {
             $i = $outing['id'];
             if (!$outing['geom_wkt']) {
                 // replicate geoassoces from doc $id to outing $i and delete previous ones
                 // (because there might be geoassociations created by this same process)
                 // and we do not replicate map associations to outings
                 $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations, $i, true, false);
                 c2cTools::log("created {$nb_created} geo associations for outing N° {$i}");
                 $this->clearCache('outings', $i, false, 'view');
             }
         }
     }
 }
Exemplo n.º 3
0
 protected function endEdit()
 {
     if ($this->success) {
         // before redirecting view, we check if either the name, elevation or geolocalization of the hut
         // has changed and pass on those changes to the 'ghost summit'
         $hut_doc = $this->document;
         $summit_doc = $hut_doc->getGhostSummit();
         // check wether elevation, name or geometry of the hut has changed, and
         // change accordingly the ghost summit if that's the case
         if ($summit_doc != false) {
             $geom_changed = $hut_doc->get('lat') !== $summit_doc->get('lat') || $hut_doc->get('lon') !== $summit_doc->get('lon');
             if ($hut_doc->get('elevation') !== $summit_doc->get('elevation') || $hut_doc->get('name') !== $summit_doc->get('name') || $geom_changed) {
                 c2cTools::log('Updating ghost summit of hut');
                 $id = $summit_doc->get('id');
                 $conn = sfDoctrine::Connection();
                 try {
                     $conn->beginTransaction();
                     $history_metadata = new HistoryMetadata();
                     $history_metadata->set('is_minor', false);
                     $history_metadata->set('user_id', $this->getUser()->getId());
                     $history_metadata->setComment('Synchronize summit to associated hut');
                     $history_metadata->save();
                     $summit_doc->set('name', $hut_doc->get('name'));
                     $summit_doc->set('lon', $hut_doc->get('lon'));
                     $summit_doc->set('lat', $hut_doc->get('lat'));
                     $summit_doc->set('elevation', $hut_doc->get('elevation'));
                     $summit_doc->save();
                     $conn->commit();
                     if ($geom_changed) {
                         // TODO idea here is to call the refreshGeoAssociations
                         // from summitsActions but we can't call it. In order not to
                         // change the whole mechanism for refreshAssociations, we kinda copy paste
                         // the function here, but this should be improved / factorized
                         // refer to it to understand what is done here
                         $associated_routes = Association::findAllAssociatedDocs($id, array('id', 'geom_wkt'), 'sr');
                         if (count($associated_routes)) {
                             $geoassociations = GeoAssociation::findAllAssociations($id, null, 'main');
                             foreach ($associated_routes as $route) {
                                 $i = $route['id'];
                                 if (!$route['geom_wkt']) {
                                     $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations, $i, true, true);
                                     $this->clearCache('routes', $i, false, 'view');
                                     $associated_outings = Association::findAllAssociatedDocs($i, array('id', 'geom_wkt'), 'ro');
                                     if (count($associated_outings)) {
                                         $geoassociations2 = GeoAssociation::findAllAssociations($i, null, 'main');
                                         foreach ($associated_outings as $outing) {
                                             $j = $outing['id'];
                                             if (!$outing['geom_wkt']) {
                                                 $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations2, $j, true, false);
                                                 c2cTools::log("created {$nb_created} geo associations for outing N° {$j}");
                                                 $this->clearCache('outings', $j, false, 'view');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 } catch (Exception $e) {
                     $conn->rollback();
                     // TODO It is ok to signal the failure, but anyway, the hut doc has been updated
                     // so there is much room for improvement here :)
                     return $this->setErrorAndRedirect("Failed to synchronize summit", '@document_edit?module=huts&id=' . $hut_doc->getId() . '&lang=' . $hut_doc->getCulture());
                 }
             }
         }
         parent::endEdit();
         // redirect to document view
     }
 }