Exemplo n.º 1
0
 public function executeView()
 {
     sfLoader::loadHelpers(array('General', 'MetaLink'));
     parent::executeView();
     // we get the user (id + name) who first uploaded this picture:
     $this->creator = $this->document->getCreator();
     $this->image_type = $this->document['image_type'];
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         // here, we add the summit name to route names :
         $associated_routes = array_filter($this->associated_docs, array('c2cTools', 'is_route'));
         $associated_routes = Route::addBestSummitName($associated_routes, $this->__(' :') . ' ');
         $associated_docs = array_filter($this->associated_docs, array('c2cTools', 'is_not_route'));
         $associated_docs = array_filter($associated_docs, array('c2cTools', 'is_not_image'));
         $associated_docs = array_merge($associated_docs, $associated_routes);
         // sort by document type, name
         if (!empty($associated_docs)) {
             foreach ($associated_docs as $key => $row) {
                 $module[$key] = $row['module'];
                 $name[$key] = remove_accents($row['name']);
             }
             array_multisort($module, SORT_STRING, $name, SORT_STRING, $associated_docs);
         }
         $this->associated_documents = $associated_docs;
         // add linked docs areas (except users and images)
         $parent_ids = array();
         $associated_areas = array();
         foreach ($this->associated_docs as $doc) {
             if (!in_array($doc['module'], array('images', 'users'))) {
                 $parent_ids[] = $doc['id'];
             }
         }
         if (count($parent_ids)) {
             $prefered_cultures = $this->getUser()->getCulturesForDocuments();
             $associated_docs_areas = GeoAssociation::findAreasWithBestName($parent_ids, $prefered_cultures);
             $associated_areas = $this->associated_areas;
             $areas_ids = array();
             foreach ($associated_areas as $area) {
                 $areas_ids[] = $area['id'];
             }
             foreach ($associated_docs_areas as $area) {
                 if (!in_array($area['id'], $areas_ids)) {
                     $associated_areas[] = $area;
                 }
             }
         }
         $this->associated_areas = $associated_areas;
         $related_portals = array();
         $activities = $this->document->get('activities');
         if (in_array(5, $activities)) {
             $related_portals[] = 'ice';
         }
         Portal::getLocalPortals($related_portals, $associated_areas);
         $this->related_portals = $related_portals;
         // link for facebook
         list($image_name, $image_ext) = Images::getFileNameParts($this->document['filename']);
         $image_url = DIRECTORY_SEPARATOR . sfConfig::get('app_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_images_directory_name') . DIRECTORY_SEPARATOR . $image_name . 'SI' . $image_ext;
         addMetaLink('image_src', $image_url);
     }
 }
function makeAssociations($id_min, $id_max, $is_map = false)
{
    $id = $id_min;
    while ($id <= $id_max) {
        echo "Computing associations for document {$id} ... \n";
        // if associations with areas for current doc already existed, delete them
        //$deleted = Association::deleteAllFor($id, array('dr', 'dc', 'dd', 'dm'));
        //if ($deleted) echo "Deleted $deleted already existing associations. \n";
        // compute new associations
        $areas = gisQuery::getAreasContaining($id);
        $maps = gisQuery::getMapsContaining($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;
            }
            $a = new GeoAssociation();
            echo "[type={$type}] found area : " . $area['id'] . "\n";
            $a->doSaveWithValues($id, $area['id'], $type);
            // main, linked, type
            unset($a);
        }
        // perform association with these maps if current document is not a map.
        if (!$is_map) {
            foreach ($maps as $map) {
                $a = new GeoAssociation();
                echo "[type=dm] found map : " . $map['id'] . "\n";
                $a->doSaveWithValues($id, $map['id'], 'dm');
                // main, linked, type
                unset($a);
            }
        }
        $id++;
    }
}
Exemplo n.º 3
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));
     }
 }
// needed for doctrine connection to work
sfContext::getInstance();
// Next Step : retrieve highest summits associated (in fact there should always be only one) with routes, and transfer summit geoassociations to route.
// WARNING: set correct id limits
// WARNING 2: routes must be consecutive.
$id = 44918;
$id_max = 57877;
while ($id <= $id_max) {
    echo "Computing associations for route {$id} ... \n";
    // if associations with areas for current doc already existed, delete them
    //$deleted = GeoAssociation::deleteAllFor($id, array('dr', 'dc', 'dd', 'dm'));
    //if ($deleted) echo "Deleted $deleted already existing geoassociations. \n";
    // get all associated regions (3+maps) with this summit:
    //$summit_id is the id of associated summit with route $id
    $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'), 'sr');
    // summit-route
    foreach ($associated_docs as $doc) {
        if ($doc['module'] == 'summits') {
            $summit_id = $doc['id'];
        }
    }
    $associations = GeoAssociation::findAllAssociations($summit_id, array('dr', 'dc', 'dd', 'dm'));
    // replicate them with route_id instead of summit_id:
    foreach ($associations as $ea) {
        $a = new GeoAssociation();
        $a->doSaveWithValues($id, $ea->get('linked_id'), $ea->get('type'));
        echo "Created association with " . $ea->get('linked_id') . " \n";
        unset($a);
    }
    $id++;
}
Exemplo n.º 5
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.º 6
0
 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}");
 }
Exemplo n.º 7
0
 protected function endEdit()
 {
     //Test if form is submitted or not
     if ($this->success) {
         // if this is the first version of the outing (aka creation)
         // set a flash message to encourage to also enhance the corresponding route
         if (is_null($this->document->getVersion())) {
             $this->setNotice('thanks for new outing');
         }
         // try to perform association with linked_doc (if pertinent)
         $associated_id = $this->getRequestParameter('document_id');
         $user_id = $this->getUser()->getId();
         $id = $this->document->get('id');
         if ($this->new_document && $associated_id || $associated_id && !Association::find($associated_id, $id)) {
             // we must get this document's module (site or route ?)
             $associated_doc = Document::find('Document', $associated_id, array('module'));
             if ($associated_doc) {
                 $associated_module = $associated_doc->get('module');
                 $a = new Association();
                 if ($associated_module == 'routes') {
                     $a->doSaveWithValues($associated_id, $id, 'ro', $user_id);
                     // main, linked, type
                     // clear cache of associated route ...
                     $this->clearCache('routes', $associated_id, false, 'view');
                 } elseif ($associated_module == 'sites') {
                     $a->doSaveWithValues($associated_id, $id, 'to', $user_id);
                     // main, linked, type
                     // clear cache of associated site ...
                     $this->clearCache('sites', $associated_id, false, 'view');
                 }
                 // here if we have created a new document and if $this->document->get('geom_wkt') is null, then use associated doc geom associations:
                 // this allows us to filter on ranges even if no GPX is uploaded
                 if ($this->new_document && $associated_id && !$this->document->get('geom_wkt')) {
                     // get all associated regions (only regions, countries, depts, no maps !) with this summit:
                     $associations = GeoAssociation::findAllAssociations($associated_id, array('dr', 'dc', 'dd', 'dv'));
                     // replicate them with outing_id instead of (route_id or site_id):
                     foreach ($associations as $ea) {
                         $areas_id = $ea->get('linked_id');
                         $a = new GeoAssociation();
                         $a->doSaveWithValues($id, $areas_id, $ea->get('type'));
                         // clear cache of associated areas
                         $this->clearCache('areas', $areas_id, false, 'view');
                     }
                 }
             }
         }
         // create also association with current user.
         if ($this->new_document) {
             $uo = new Association();
             $uo->doSaveWithValues($user_id, $id, 'uo', $user_id);
             // main, linked, type
             // clear cache of current user
             $this->clearCache('users', $user_id, false, 'view');
         }
         // create association with MW contest article, if requested
         if ($this->new_document) {
             $mw_contest_associate = $this->getRequestParameter('mw_contest_associate');
             if ($mw_contest_associate) {
                 $mw_article_id = sfConfig::get('app_mw_contest_id');
                 $oc = new Association();
                 $oc->doSaveWithValues($id, $mw_article_id, 'oc', $user_id);
             }
         }
         parent::endEdit();
         // redirect to document view
     }
 }
Exemplo n.º 8
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.º 9
0
function import_new_geometry()
{
    global $conn, $comment, $is_map, $is_new_document, $culture, $name, $map_editor, $map_scale, $map_code, $keepassociations, $region_type, $newgeomtext, $no_oldgeom, $document_id, $a_type, $fullwipe, $oldgeom, $newgeom, $prgmsg;
    info("Importing the new geometry...\n");
    try {
        $conn->beginTransaction();
        $history_metadata = new HistoryMetadata();
        $history_metadata->setComment(isset($comment) ? $comment : ($is_new_document ? 'Imported new ' . ($is_map ? 'map' : 'area') : 'Updated geometry'));
        $history_metadata->set('is_minor', false);
        $history_metadata->set('user_id', 2);
        // C2C user
        $history_metadata->save();
        if ($is_new_document) {
            $doc = $is_map ? new Map() : new Area();
            $doc->setCulture($culture);
            $doc->set('name', $name);
            if ($is_map) {
                $doc->set('editor', $map_editor);
                $doc->set('scale', $map_scale);
                $doc->set('code', $map_code);
            } else {
                $doc->set('area_type', $region_type);
            }
        } else {
            $doc = Document::find($is_map ? 'Map' : 'Area', $document_id);
            $name = $doc->get('name');
            if (!$is_map) {
                $region_type = $doc->get('area_type');
            }
        }
        $doc->set('geom_wkt', $newgeomtext);
        $doc->save();
        info("Geometry uploaded.\n");
        if ($keepassociations) {
            exit;
        }
        if ($is_new_document) {
            $document_id = $doc->get('id');
        }
        // $conn->commit();
        // $conn->beginTransaction();
        if ($is_map) {
            $a_type = 'dm';
        } else {
            switch ($region_type) {
                case 1:
                    // range
                    $a_type = 'dr';
                    break;
                case 2:
                    // country
                    $a_type = 'dc';
                    break;
                case 3:
                    // dept
                    $a_type = 'dd';
                    break;
            }
        }
        // Some explanation for the following queries:
        // - && operator is used to limit docs to the one whose bouding boxes overlap (it uses spatial index)
        // - ST_Within and ST_Intersects are used to work on the actual geometries
        // - ST_Within apears to be faster, so we use it for 'points' (like summits, huts etc), but we have
        //   to use ST_Intersects for 'geometries' (like outings, maps etc)
        // - we only use a buffer of 200m for areas (because of boundaries imprecision), but not for maps
        // - areas are not linked together
        // - maps are not linked to outings, users, and other maps
        // if it is a new document, we create geoassociations for the whole geometry
        // but if its an updated one, we only create geoassociations for the part of the
        // new geometry that does not intersect with the old one
        if ($is_new_document || $no_oldgeom || $fullwipe) {
            // retrieve geom from the database
            $geomquery = '(SELECT geom FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
            $geomqueryb = '(SELECT buffer(geom, 200) FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
            $queryparam = array($document_id, $document_id);
        } else {
            $queryparam = array();
            $creategeom = $conn->standaloneQuery("SELECT ST_Difference('{$newgeom}', '{$oldgeom}')")->fetchAll();
            $creategeomb = $conn->standaloneQuery("SELECT ST_Difference(buffer('{$newgeom}', 200), buffer('{$oldgeom}', 200))")->fetchAll();
            $creategeom = $creategeom[0]['st_difference'];
            $creategeomb = $creategeomb[0]['st_difference'];
            $geomquery = "'{$creategeom}'";
            $geomqueryb = "'{$creategeomb}'";
        }
        // for maps, we don't use buffer at all
        if ($is_map) {
            $geomqueryb = $geomquery;
        }
        $queries = array();
        // point geometry
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomqueryb} " . "AND ST_Within(geom, {$geomqueryb}) " . "AND module IN('summits', 'huts', 'sites', 'parkings', 'products', 'portals', 'images'" . ($is_map ? '' : ", 'users'") . ')', $queryparam);
        // multipoint geometry
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomqueryb} " . "AND ST_Intersects(geom, {$geomqueryb}) AND module" . ($is_map ? "='routes'" : " IN('routes', 'outings')"), $queryparam);
        // for maps areas associations, we always compute 'full wipe', without buffer
        $geomquery = '(SELECT geom FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomquery} " . "AND ST_Intersects(geom, {$geomquery}) AND module='" . ($is_map ? 'areas' : 'maps') . "'", array($document_id, $document_id));
        $results_a = array();
        foreach ($queries as $query) {
            $results_a[] = $conn->standaloneQuery($query[0], $query[1])->fetchAll();
        }
        $results = array();
        foreach ($results_a as $results_set) {
            foreach ($results_set as $d) {
                $results[] = $d;
            }
        }
        $prgmsg = "Create new associations...";
        info($prgmsg);
        $tot = count($results);
        foreach ($results as $i => $d) {
            progression($i, $tot);
            // Apparently in some cases, we ar trying to create associations that
            // already exist, so we check first
            if (!GeoAssociation::find($document_id, $d['id'], null, false)) {
                $a = new GeoAssociation();
                $created[$d['module']] = isset($created[$d['module']]) ? $created[$d['module']] + 1 : 1;
                // for map - area geoassociations, links must not be dm but dr, dc, dd...
                if ($is_map && $d['module'] === 'areas') {
                    $area = Document::find('Area', $d['id']);
                    switch ($area->get('area_type')) {
                        case 1:
                            // range
                            $t_a_type = 'dr';
                            break;
                        case 2:
                            // country
                            $t_a_type = 'dc';
                            break;
                        case 3:
                            // dept
                            $t_a_type = 'dd';
                            break;
                    }
                    $a->doSaveWithValues($document_id, $d['id'], $t_a_type);
                } else {
                    $a->doSaveWithValues($d['id'], $document_id, $a_type);
                }
            }
            // inherited docs: we add geoassociations for the 'inherited docs' from sites, routes and summits
            // but not if they already have a geometry (gps track)
            switch ($d['module']) {
                case 'sites':
                case 'routes':
                    if ($is_map) {
                        break;
                    }
                    // we do not link maps to outings
                    $associated_outings = Association::findAllAssociatedDocs($d['id'], array('id', 'geom_wkt'), $d['module'] === 'routes' ? 'ro' : 'to');
                    if (count($associated_outings)) {
                        foreach ($associated_outings as $outing) {
                            if (!$outing['geom_wkt'] && GeoAssociation::find($outing['id'], $document_id, $a_type) === false) {
                                // we create geoassociation (if it already existed, it has been deleted before in the script)
                                $a = new GeoAssociation();
                                $a->doSaveWithValues($outing['id'], $document_id, $a_type);
                                $created['outings'] = isset($created['outings']) ? $created['outings'] + 1 : 1;
                            }
                        }
                    }
                    break;
                case 'summits':
                    // if summit is of type raid, we should not try to update its routes and outings summit_type=5
                    $summit = Document::find('Summit', $d['id']);
                    if ($summit->get('summit_type') == 5) {
                        break;
                    }
                    $associated_routes = Association::findAllAssociatedDocs($d['id'], array('id', 'geom_wkt'), 'sr');
                    if (count($associated_routes)) {
                        foreach ($associated_routes as $route) {
                            $i = $route['id'];
                            if (!$route['geom_wkt'] && GeoAssociation::find($i, $document_id, $a_type) === false) {
                                $a = new GeoAssociation();
                                $a->doSaveWithValues($i, $document_id, $a_type);
                                $created['routes'] = isset($created['routes']) ? $created['routes'] + 1 : 1;
                                if (!$is_map) {
                                    $associated_outings = Association::findAllAssociatedDocs($i, array('id', 'geom_wkt'), 'ro');
                                    if (count($associated_outings)) {
                                        foreach ($associated_outings as $outing) {
                                            $j = $outing['id'];
                                            if (!$outing['geom_wkt'] && GeoAssociation::find($j, $document_id, $a_type) === false) {
                                                $a = new GeoAssociation();
                                                $a->doSaveWithValues($j, $document_id, $a_type);
                                                $created['outings'] = isset($created['outings']) ? $created['outings'] + 1 : 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }
        info("\n");
        $conn->commit();
        if (isset($created)) {
            associations_result($created);
        }
        if ($is_new_document) {
            info('Added new ' . ($is_map ? 'map' : 'area') . " {$name} ({$document_id})\n");
        } else {
            info('Updated ' . ($is_map ? 'map' : 'area') . " ({$document_id})\n");
        }
    } catch (Exception $e) {
        $conn->rollback();
        throw $e;
    }
}
 public static function replicateGeoAssociations($geoassociations, $id, $delete_old = true, $replicate_maps_associations = true)
 {
     $nb_created = 0;
     if ($delete_old) {
         self::deleteAllFor($id, array('dr', 'dc', 'dm', 'dd'));
     }
     foreach ($geoassociations as $ea) {
         if (!($ea->get('type') == 'dm' && !$replicate_maps_associations)) {
             $a = new GeoAssociation();
             if ($a->doSaveWithValues($id, $ea->get('linked_id'), $ea->get('type'))) {
                 $nb_created++;
             }
         }
     }
     return $nb_created;
 }
Exemplo n.º 11
0
 public function executeAddroute()
 {
     $id = $this->getRequestParameter('document_id');
     // check if a summit is already associated to hut. if not, create it
     $create_summit = Association::countMains($id, 'sh') == 0;
     if ($create_summit) {
         $document = Document::find('Hut', $id, array('elevation', 'geom_wkt'));
         $conn = sfDoctrine::Connection();
         try {
             $conn->beginTransaction();
             // create first version of document, with culture and geometry of hut document
             $hut_elevation = $document['elevation'];
             $hut_lat = $document['lat'];
             $hut_lon = $document['lon'];
             $hut_culture = $document->getCulture();
             $hut_name = $document['name'];
             $history_metadata = new HistoryMetadata();
             $history_metadata->setComment($this->__('Created summit synchronized with hut for access'));
             $history_metadata->set('is_minor', false);
             $history_metadata->set('user_id', 2);
             // C2C user
             $history_metadata->save();
             $summit = new Summit();
             $summit->setCulture($hut_culture);
             $summit->set('name', $hut_name);
             $summit->set('elevation', $hut_elevation);
             $summit->set('summit_type', 100);
             // set summit type to ' hut'
             $summit->set('lat', $hut_lat);
             $summit->set('lon', $hut_lon);
             $summit->save();
             $conn->commit();
             // add others culture versions
             foreach ($document->get('HutI18n') as $i18n) {
                 $culture = $i18n->getCulture();
                 if ($culture != $hut_culture) {
                     $conn->beginTransaction();
                     $hut_name = $i18n->getName();
                     $history_metadata = new HistoryMetadata();
                     $history_metadata->setComment($this->__('Created summit synchronized with hut for access'));
                     $history_metadata->set('is_minor', false);
                     $history_metadata->set('user_id', 2);
                     // C2C user
                     $history_metadata->save();
                     $summit->setCulture($culture);
                     $summit->set('name', $hut_name);
                     $summit->save();
                     $conn->commit();
                 }
             }
         } catch (Exception $e) {
             $conn->rollback();
             return $this->setErrorAndRedirect($this->__('Failed to create synchronized summit'), "routes/edit?link={$summit_id}");
         }
         $summit_id = $summit->get('id');
         // get all associated regions (3+maps) with this hut:
         $associations = GeoAssociation::findAllAssociations($id, array('dr', 'dc', 'dd', 'dv', 'dm'));
         // replicate them with summit_id instead of id:
         foreach ($associations as $ea) {
             $a = new GeoAssociation();
             $a->doSaveWithValues($summit_id, $ea->get('linked_id'), $ea->get('type'));
         }
         // associate hut to summit
         $asso = new Association();
         $asso->doSaveWithValues($summit_id, $id, 'sh', 2);
         // C2C user
     } else {
         $associations = Association::findAllAssociations($id, 'sh');
         $summit_id = $associations[0]->get('main_id');
     }
     $this->clearCache('huts', $id);
     return $this->redirect("routes/edit?link={$summit_id}");
 }
<?php

/**
 * Updates geo associations of documents contained in parameter areas.
 */
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'frontend');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', true);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
// needed for doctrine connection to work
sfContext::getInstance();
// ids of areas containing objects of whom geoassociations must be updated:
$areas_ids = array(369, 379);
$i = 0;
foreach ($areas_ids as $id) {
    // find all doc associated to current area
    $associated_docs = GeoAssociation::findAllAssociations($id, null, 'linked');
    foreach ($associated_docs as $doc) {
        $doc_id = $doc->get('main_id');
        if (!($document = Document::find('Document', $doc_id, array('module')))) {
            continue;
        }
        // no maps are linked to outings, users and other maps
        $linkToMaps = !in_array($document->get('module'), array('outings', 'users', 'maps'));
        gisQuery::createGeoAssociations($doc_id, true, $linkToMaps);
        // TODO: handle "inherited" geo associations such as those of routes and outings
        $i++;
    }
}
echo "{$i} documents updated\n";
Exemplo n.º 13
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     sfLoader::loadHelpers(array('General'));
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         // Add the summit name to route
         $associated_routes = array_filter($this->associated_docs, array('c2cTools', 'is_route'));
         $associated_routes = Route::addBestSummitName($associated_routes, $this->__(' :') . ' ');
         // Include outings additional data
         $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
         $associated_outings = Outing::fetchAdditionalFields($associated_outings);
         // group all linked docs except images in a single list
         $associated_docs = array_filter($this->associated_docs, array('c2cTools', 'is_not_route'));
         $associated_docs = array_filter($associated_docs, array('c2cTools', 'is_not_outing'));
         $associated_docs = array_filter($associated_docs, array('c2cTools', 'is_not_image'));
         $associated_docs = array_merge($associated_docs, $associated_routes, $associated_outings);
         // sort by document type, name
         if (count($associated_docs)) {
             foreach ($associated_docs as $key => $row) {
                 $module[$key] = $row['module'];
                 $name[$key] = remove_accents($row['name']);
             }
             array_multisort($module, SORT_STRING, $name, SORT_STRING, $associated_docs);
         }
         $this->associated_users = array_filter($associated_docs, array('c2cTools', 'is_user'));
         $this->associated_documents = $associated_docs;
         // Retrieve linked docs areas (except users)
         $parent_ids = array();
         $associated_areas = array();
         foreach ($this->associated_docs as $doc) {
             if ($doc['module'] != 'users') {
                 $parent_ids[] = $doc['id'];
             }
         }
         if (count($parent_ids)) {
             $prefered_cultures = $this->getUser()->getCulturesForDocuments();
             $associated_areas = GeoAssociation::findAreasWithBestName($parent_ids, $prefered_cultures);
         }
         $this->associated_areas = $associated_areas;
         // retrieve related portals, depending on article category
         // Soft mobility articles => changedapproche
         // ice activity + gear, stories or expeditions => ice portal
         $related_portals = array();
         $activities = $this->document->get('activities');
         $categories = $this->document->get('categories');
         if (in_array(7, $categories)) {
             $related_portals[] = 'cda';
         }
         if (array_intersect(array(2, 3, 8), $categories) && in_array(5, $activities)) {
             $related_portals[] = 'ice';
         }
         Portal::getLocalPortals($related_portals, $associated_areas);
         $this->related_portals = $related_portals;
         sfLoader::loadHelpers(array('sfBBCode', 'SmartFormat'));
         $abstract = strip_tags(parse_links(parse_bbcode_abstract($this->document->get('abstract'))));
         $this->getResponse()->addMeta('description', $abstract);
         if (in_array(100, $categories)) {
             $this->getResponse()->addMeta('robots', 'noindex, follow');
         }
     }
 }
Exemplo n.º 14
0
    // Remove private data
    Doctrine_Query::create()->delete()->from('UserPrivateData')->addWhere("id = '{$userid_to_wipe}'")->execute();
    $conn->commit();
} catch (Exception $e) {
    $conn->rollback();
    echo "A problem occured during merging\n";
    throw $e;
}
// Clear cache - We cannot use function from c2cActions since it is protected
$cache_dir = sfConfig::get('sf_root_cache_dir') . '/frontend/*/template/*/all';
$cache_dir .= sfConfig::get('sf_no_script_name') ? '/' : '/*/';
//c2cActions::clearCache('users', $userid_to_wipe, false);
$toRemove[] = "users/*/id/{$userid_to_wipe}/*";
//c2cActions::clearCache('users', $userid_to_remain, false);
$toRemove[] = "users/*/id/{$userid_to_remain}/*";
// find all docs associated to user_id_to_remain and clear the cache
$associated_docs = Association::findAllAssociatedDocs($userid_to_remain, array('id', 'module'));
foreach ($associated_docs as $doc) {
    //c2cActions::clearCache($doc['module'], $doc['id'], false, 'view');
    $toRemove[] = "{$doc['module']}/view/id/{$doc['id']}/*";
}
// find all geo associated docs
$associated_docs = GeoAssociation::findAllAssociatedDocs($userid_to_remain, array('id', 'module'));
foreach ($associated_docs as $doc) {
    //c2cActions::clearCache($doc['module'], $doc['id'], false, 'view');
    $toRemove[] = "{$doc['module']}/view/id/{$doc['id']}/*";
}
foreach ($toRemove as $item) {
    sfToolkit::clearGlob($cache_dir . $item);
}
echo "Users successfully merged\n";
Exemplo n.º 15
0
 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;
 }