protected function isInGroup($group_name) { $nb = Doctrine_Query::create()->select('COUNT(ug.group_id) nb')->from('UserGroup ug')->where('ug.group_id = (SELECT g.id FROM Group g WHERE g.name = ?) AND ug.user_id = ?')->limit(1)->execute(array($group_name, $this->getId()))->getFirst()->nb; c2cTools::log('{user->isInGroup()} group name : ' . $group_name . 'user id : ' . $this->getId() . 'result : ' . $nb); return $nb > 0 ? true : false; }
/** * Move given image and its resized versions. */ public static function moveAll($file, $pathFrom, $pathTo) { c2cTools::log("moving {$file} from {$pathFrom} to {$pathTo}"); $types = sfConfig::get('app_images_types', array()); list($file_name, $file_ext) = self::getFileNameParts($file); // move original $success = rename($pathFrom . DIRECTORY_SEPARATOR . $file, $pathTo . DIRECTORY_SEPARATOR . $file); // move thumbs foreach ($types as $type) { $success = $success && rename($pathFrom . DIRECTORY_SEPARATOR . $file_name . $type['suffix'] . $file_ext, $pathTo . DIRECTORY_SEPARATOR . $file_name . $type['suffix'] . $file_ext); } // move svg if any if (file_exists($pathFrom . DIRECTORY_SEPARATOR . $file_name . '.svg')) { $success = $success && rename($pathFrom . DIRECTORY_SEPARATOR . $file_name . '.svg', $pathTo . DIRECTORY_SEPARATOR . $file_name . '.svg'); } return $success; }
/** * Adds given address to given mailing list. * @param string listname * @param string email * @return boolean status (true=success, false=failure) */ public static function subscribe($listname, $email) { $conn = sfDoctrine::Connection(); try { $conn->beginTransaction(); $sympa = new Sympa(); $sympa->list_subscriber = $listname; $sympa->user_subscriber = $email; $sympa->save(); $conn->commit(); return true; } catch (Exception $e) { // Subscription failed! For instance because email address was already registered. $conn->rollback(); c2cTools::log("Failed adding address {$email} to list {$listname}: " . $e->getMessage()); return false; } }
public function execute($filterChain) { $context = $this->getContext(); $session_user = $context->getUser(); $cookie_name = sfConfig::get('app_remember_key_cookie_name', 'c2corg_remember'); $cookie_value = $context->getRequest()->getCookie($cookie_name); if ($this->isFirstCall() && !$session_user->isConnected() && !is_null($cookie_value)) { c2cTools::log('{rememberFilter} user has a cookie, trying to auto login'); $remember_key = RememberKey::getKey($cookie_value); if ($remember_key) { c2cTools::log('{rememberFilter} user found from his cookie'); $user = $remember_key->getUser(); if ($user->exists()) { $session_user->signIn($user->get('private_data')->getLoginName(), $user->get('private_data')->getPassword(), true, true); } // User has signed in, and is now correctly in symfony session. However, forums // and several personnalization functions rely on cookies, that will be sent with the request, // but are not yet 'available' from javascript if the value expired from previous sessions (they will be on next page) // easiest solution is to force the browser to reload the current page // we only do this for GET requests $request = $this->getContext()->getRequest(); if ($request->getMethod() == sfRequest::GET) { // symfony 1.0 getUriPrefix is not working well with https on haproxy // it then tries to redirect to https://site.org:80, which is wrong $proto = $request->isSecure() ? 'https' : 'http'; $request_uri = $proto . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $this->getContext()->getController()->redirect($request_uri); exit; } } else { // delete cookie value in client so that no more requests are made to the db sfContext::getInstance()->getResponse()->setCookie($cookie_name, ''); // log this c2cTools::log('{rememberFilter} user has unknown remember key!'); c2cActions::statsdIncrement('bad_remember_cookie', 'symfony.' . sfConfig::get('sf_environment') . '.users.'); } } $filterChain->execute(); }
protected static function filterOnRegions($q, $areas = null, $alias = 'g2') { if (is_null($areas)) { $areas = c2cPersonalization::getInstance()->getPlacesFilter(); } if (!empty($areas)) { $q->leftJoin('m.associations l')->leftJoin('l.MainGeoassociations ' . $alias)->addWhere(self::getAreasQueryString($areas, $alias), $areas); c2cTools::log('filtering on regions'); } }
public function executeFilterredirect() { if ($this->getRequestParameter('cond') || $this->getRequestParameter('format')) { $action = 'conditions'; } else { $action = 'list'; } $route = '/' . $this->getModuleName() . '/' . $action; if ($this->getRequest()->getMethod() == sfRequest::POST) { $criteria = array_merge($this->filterSearchParameters(), $this->filterSortParameters()); if ($criteria) { $route .= '?' . implode('&', $criteria); } } c2cTools::log("redirecting to {$route}"); $this->redirect($route); }
public function doSaveWithValues($main_id, $linked_id, $type, $user_id) { $conn = sfDoctrine::Connection(); try { $conn->beginTransaction(); // we create the association: $this->main_id = $main_id; $this->linked_id = $linked_id; $this->type = $type; $this->save(); // and we log this: $al = new AssociationLog(); $al->main_id = $main_id; $al->linked_id = $linked_id; $al->type = $type; $al->user_id = $user_id; $al->is_creation = true; $al->save(); $conn->commit(); // send an email to moderators if a picture is associated to a book if ($type == 'bi') { try { // retrieve moderators email $moderator_id = sfConfig::get('app_moderator_user_id'); // currently send to topo-fr only $conn->beginTransaction(); $rows = $conn->standaloneQuery('SELECT email FROM app_users_private_data d WHERE id = ' . $moderator_id)->fetchAll(); $conn->commit(); $email_recipient = $rows[0]['email']; $mail = new sfMail(); $mail->setCharset('utf-8'); // definition of the required parameters $mail->setSender(sfConfig::get('app_outgoing_emails_sender')); $mail->setFrom(sfConfig::get('app_outgoing_emails_from')); $mail->addReplyTo(sfConfig::get('app_outgoing_emails_reply_to')); $mail->addAddress($email_recipient); $mail->setSubject('New image associated to book'); $mail->setContentType('text/html'); $server = $_SERVER['SERVER_NAME']; $body = "<p>A <a href=\"http://{$server}/images/{$linked_id}\">new image</a> has been associated to <a href=\"http://{$server}/books/{$main_id}\">book {$main_id}</a>.</p>" . "<p>The image may require a copyright license. If so, please ensure that:</p>" . "<ul>" . "<li>the owner is correctly acknowledged in the author field;</li>" . "<li>the image is not too big (max 800px width or height).</li>" . "</ul>"; $mail->setBody($body); // send the email $mail->send(); } catch (exception $e) { $conn->rollback(); c2cTools::log("Association::doSaveWithValues({$main_id}, {$linked_id}, {$type}, {$user_id}) failed sending email for image associated to book"); } } return true; } catch (exception $e) { $conn->rollback(); c2cTools::log("Association::doSaveWithValues({$main_id}, {$linked_id}, {$type}, {$user_id}) failed - rollback"); return false; } }
/** * 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'); } } } } } } }
/** * Clear cache for view / history , diff and list after a new comment has been posted * rq: comment page is not cached */ public static function clearCommentCache($id, $lang = null, $module = '*') { $cache_dir = sfConfig::get('sf_root_cache_dir') . '/frontend/*/template/*/*'; $cache_dir .= sfConfig::get('sf_no_script_name') ? '/' : '/*/'; $items = array("{$module}/history/id/{$id}/", "{$module}/view/id/{$id}/", "{$module}/diff/id/{$id}/"); foreach ($items as $item) { $item .= $lang == null ? '*' : "lang/{$lang}/*"; c2cTools::log('{cache} removing : ' . $cache_dir . $item); sfToolkit::clearGlob($cache_dir . $item); } // Clear cache for list : $item = "{$module}/list/*"; c2cTools::log('{cache} removing : ' . $cache_dir . $item); sfToolkit::clearGlob($cache_dir . $item); }
/** * 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'); } } } }
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 } }
protected function removeGloballyFromCache($items) { $cache_dir = sfConfig::get('sf_root_cache_dir') . '/frontend/*/template/*/*'; $cache_dir .= sfConfig::get('sf_no_script_name') ? '/' : '/*/'; foreach ($items as $item) { c2cTools::log('{cache} removing : ' . $cache_dir . $item); sfToolkit::clearGlob($cache_dir . $item); } }
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); }
public static function buildStringCondition(&$conditions, &$values, $field, $param, $model, $join = array(null, null)) { $has_result = false; $has_id = false; $nb_result = 0; $join_result = null; $param = urldecode($param); if (strlen($param) > 2) { if (sfConfig::get('app_solr_enable') == true) { /* init solr */ $max_row = sfConfig::get('app_solr_maxrow'); $options = array('hostname' => sfConfig::get('app_solr_host'), 'port' => sfConfig::get('app_solr_port'), 'path' => sfConfig::get('app_solr_path'), 'timeout' => sfConfig::get('app_solr_timeout')); $client = new SolrClient($options); try { // 1st search : exact search $query_solr_exact = new SolrQuery(); $query_solr_exact->setQuery('*' . $param . '*'); $query_solr_exact->setRows($max_row); if ($model == 'User' || $model == 'UserPrivateData') { if (!sfContext::getInstance()->getUser()->isConnected()) { $query_solr_exact->addFilterQuery('user_private_public:true'); } } $query_solr_exact->addFilterQuery('module:' . strtolower($model) . 's'); $query_solr_exact->addField('name')->addField('module')->addField('id_doc'); $res_exact = $client->query($query_solr_exact)->getResponse(); if ($res_exact['response']['numFound'] > 0) { for ($i = 0; $i < $res_exact['response']['numFound']; $i++) { $ids_tmp[]['id'] = $res_exact['response']['docs'][$i]['id_doc']; } } else { // No exact serach ... so try fuzzy search $query_solr = new SolrQuery(); // Fuzzy search word > 3 letters $query_words = explode(" ", $param); foreach ($query_words as &$word) { switch (true) { case in_array(strlen($word), range(0, 3)): $word = $word; break; case in_array(strlen($word), range(4, 5)): $word = $word . '~1'; break; case in_array(strlen($word), range(6, 7)): $word = $word . '~2'; break; case in_array(strlen($word), range(8, 9)): $word = $word . '~3'; break; default: $word = $word . '~4'; break; } } $query_search_fuzzy = implode(' ', $query_words); $query_search = "({$param})^20 OR ({$query_search_fuzzy})^5"; c2cTools::log(" solr request : " . $query_search); $query_solr->setQuery($query_search); $query_solr->setRows($max_row); if ($model == 'User' || $model == 'UserPrivateData') { if (!sfContext::getInstance()->getUser()->isConnected()) { $query_solr->addFilterQuery('user_private_public:true'); } } $query_solr->addFilterQuery('module:' . strtolower($model) . 's'); $query_solr->addField('name')->addField('module')->addField('id_doc'); $res = $client->query($query_solr)->getResponse(); for ($i = 0; $i < $res['response']['numFound']; $i++) { $ids_tmp[]['id'] = $res['response']['docs'][$i]['id_doc']; } } } catch (Exception $e) { c2cTools::log(" exception solr : " . $e); $ids_tmp = self::idSearchByName($param, $model); } } else { $ids_tmp = self::idSearchByName($param, $model); } if (count($ids_tmp)) { $ids = array(); foreach ($ids_tmp as $id) { $ids[] = $id['id']; } $conditions[] = $field[0] . ' IN (' . implode(',', $ids) . ')'; $has_result = true; $nb_result = count($ids); $join_result = $join[0]; if (!$join[0]) { $has_id = true; } } } else { $conditions[] = $field[1] . ' LIKE make_search_name(?)||\'%\''; $values[] = $param; $has_result = true; if ($join[1]) { $join_result = $join[1]; } } return array('has_result' => $has_result, 'has_id' => $has_id, 'nb_result' => $nb_result, 'join' => $join_result); }
/** * kml2wkt does what its name implies : * it takes a kml file, parses it for linestrings and returns an equivalent WKT LINESTRING * * The returned WKT can be 2, 3 or 4D. * If does not really handle 4D parsing (beyond scope IMO) => KML import is restricted to routes (outings will only support GPX input) * If $dim = 4, then time field will be zero-padded. */ public static function kml2wkt($path, $dim = 3) { // FIXME: document structure is very user customizable, and thus this function is not very robust ... // a solution would be to extract points linked to a linestring (if these points are present), and to sort them by date to build the linestring. $xml = c2cTools::simplexmlLoadFile($path); // TODO: handle files with Document>NetworkLink>Url>href : wget content... (mymaps generates these ones) // TODO: handle files with one waypoint for point update ? // TODO : handle multilines geometries ? $i = 0; $wkta = array(); if ($pm = $xml->Document->Placemark) { // this is a simple kml // (for instance, one made with google "my maps") // in which these is no folder. c2cTools::log("ParseGeo::kml2wkt({$path}, {$dim}) with xml->Document->Placemark"); return 'LINESTRING(' . self::getKmlCoordinates($pm->LineString->coordinates, $dim) . ')'; } elseif ($geom_folders = $xml->Document->Folder) { // this is a "complex" KML with several folders (typical output of gpsbabel from gpx) $trk_coords = array(); // kml file may contain three geom folders : Waypoints, Tracks and Routes foreach ($geom_folders as $folder) { // we're just looking for tracks : if ($folder->name == 'Tracks') { // there might be subfolders if gps signal has been interrupted // we merge these folders together to build a single track. foreach ($folder->Folder as $track) { $trk_coords[] = self::getKmlCoordinates($track->Placemark->LineString->coordinates, $dim); } } } c2cTools::log("ParseGeo::kml2wkt({$path}, {$dim}) with xml->Document->Folder"); return 'LINESTRING(' . implode(', ', $trk_coords) . ')'; } else { c2cTools::log("kml2wkt : no track found"); return false; } }
public function executeCdaredirect() { if ($this->getRequest()->getMethod() == sfRequest::POST) { $module = $this->getRequestParameter('module'); $join = ''; $criteria = array(); // tc criteria if ($module == 'routes') { $criteria[] = 'tp=1-2-4-5'; } elseif ($module == 'outings') { $criteria[] = 'owtp=1'; } // area criteria $this->addListParam($criteria, 'areas'); // activities criteria $this->addListParam($criteria, 'stags'); // for paragliding activity $activities = $this->getRequestParameter('act'); $group_activities = $activities; if ($key = array_search(8, $group_activities)) { unset($group_activities[$key]); } $nb_grp = count($group_activities); $group_name = ''; if ($nb_grp == 1) { $group_list = sfConfig::get('app_cda_activities_id'); $group_name = $group_list[reset($group_activities)]; } if ($group_name == 'crag') { $key = array_search(400, $activities); if ($module == 'outings') { $activities[$key] = 4; } else { unset($activities[$key]); } } if (count($activities)) { $criteria[] = 'act=' . implode('-', $activities); } // module criteria if ($nb_grp == 1 && in_array($group_name, array('crag', 'climbing'))) { if ($module == 'routes' && $group_name == 'crag') { $module = 'sites'; } if ($module == 'outings') { if ($group_name == 'crag') { $join = 'sites'; } else { $join = 'routes'; } } } // around criteria if ($module == 'routes') { $around = 'parnd'; } elseif ($module == 'sites') { $around = 'tarnd'; } elseif ($module == 'outings') { if ($nb_grp == 1 && $group_name == 'crag') { $around = 'tarnd'; } else { $around = 'sarnd'; } } $has_around = $this->addAroundParam($criteria, 'arnd', $around); if ($has_around) { $join = ''; } // elevation critera if (!($nb_grp == 1 && $group_name == 'crag')) { $elevation = $this->getRequestParameter('elevation'); if ($elevation >= 1 && $elevation <= 3) { $elevation_range = sfConfig::get('app_cda_elevation_range'); $param = $elevation_range[$module . '_param']; $value = $elevation_range[$elevation]; $criteria[] = "{$param}={$value}"; } } // difficulty criteria if (!($nb_grp == 1 && $group_name == 'crag' && $module == 'outings')) { $difficulty = $this->getRequestParameter('difficulty'); if ($nb_grp == 1 && $difficulty >= 1 && $difficulty <= 3) { $group_info = sfConfig::get('app_cda_difficulty_range_' . $group_name); $param = $group_info['param']; $value = $group_info[$difficulty]; $criteria[] = "{$param}={$value}"; $join = ''; } } // join criteria if (!empty($join)) { $criteria[] = "{$join}= "; } $route = '@default?module=' . $module . '&action=list&' . implode('&', $criteria); c2cTools::log("redirecting to {$route}"); $this->redirect($route); } else { $this->setErrorAndRedirect('Invalid request parameters', '@cdasearch'); } }
public function doSaveWithValues($main_id, $linked_id, $type) { try { $this->main_id = $main_id; $this->linked_id = $linked_id; $this->type = $type; $this->save(); return true; } catch (exception $e) { c2cTools::log("GeoAssociation::doSaveWithValues({$main_id}, {$linked_id}, {$type}) failed"); return false; } }
/** * Return an array of culture ordered by preference * @return array document_culture */ public function getPreferedLanguageList() { $prefered_language_list = $this->getAttribute('prefered_languages_list', null); if (is_null($prefered_language_list) && $this->isConnected()) { c2cTools::log('no prefered languages list setted'); // get list from database $prefered_language_list = explode(',', sfDoctrine::getTable('UserPrivateData')->find($this->getId())->get('document_culture')); } if (count($prefered_language_list) <= 1) { // if it is not a list... we get the symfony default language list $prefered_language_list = array_keys(Language::getAll()); } // save in session $this->saveLanguageListInSession($prefered_language_list); return $prefered_language_list; }
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; }