public function executeDeletegeom() { $module = $this->getRequestParameter('module'); $id = $this->getRequestParameter('id'); // check user is moderator: done in apps/frontend/config/security.yml if (!$id) { $this->setErrorAndRedirect('Could not understand your request', "@default_index?module={$module}"); } // check document exists (and not protected ? or useless since only moderators can deprotect and delete geom ?) $document = Document::find($this->model_class, $id, array('id', 'is_protected', 'geom_wkt')); // NB: field to set in second time must be hydrated in object, else a second SELECT is triggered. if ($document && !$document->get('is_protected')) { $document->set('geom_wkt', null); // a trigger updates the wkb geom field (and others) in accordance. $document->doSaveWithMetadata($this->getUser()->getId(), false, "Geometry has been deleted"); // also delete geom associations with maps and areas: $nb_deleted = GeoAssociation::deleteAllFor($id, array('dm', 'dr', 'dd', 'dc', 'dv')); c2cTools::log("executeDeletegeom: deleted {$nb_deleted} associated areas and maps with document {$id}"); } else { $this->setErrorAndRedirect('This document is currently write-protected', "@document_by_id?module={$module}&id={$id}"); } // clear cache $this->clearCache($module, $id); $this->setNoticeAndRedirect('Geometry has been deleted', "@document_by_id?module={$module}&id={$id}"); }
public static function createGeoAssociations($id, $delete_old = true, $associate_with_maps = true) { $nb_created = 0; // if associations with areas for current doc already existed, delete them if ($delete_old) { $deleted = GeoAssociation::deleteAllFor($id, array('dr', 'dc', 'dd', 'dv', 'dm')); c2cTools::log("executeEdit: deleted {$deleted} geom associations for document {$id}"); } // compute new associations $areas = self::getAreasContaining($id); // perform association with these areas. foreach ($areas as $area) { switch ($area['type']) { case 1: // range $type = 'dr'; break; case 2: // country $type = 'dc'; break; case 3: // dept $type = 'dd'; break; case 4: // valley $type = 'dv'; break; } $a = new GeoAssociation(); $a->doSaveWithValues($id, $area['id'], $type); // main, linked, type $nb_created++; } if ($associate_with_maps) { // compute new associations $maps = self::getMapsContaining($id); // perform association with these maps. foreach ($maps as $map) { $a = new GeoAssociation(); $a->doSaveWithValues($id, $map['id'], 'dm'); // main, linked, type $nb_created++; } } return $nb_created; }