public function executePortalredirect() { $module = $this->getRequestParameter('wtype'); $params = $this->getRequestParameter('params'); $query_string = $this->getRequestParameter('q'); if ($query_string) { list($module, $module_params) = explode('/', $module, 2); if (!empty($module_params)) { $params = $module_params; } if ($module && in_array($module, sfConfig::get('app_modules_list'))) { $model = c2cTools::module2model($module); } else { $model = 'Document'; $module = 'documents'; } $perso = c2cPersonalization::getInstance(); if ($perso->isMainFilterSwitchOn()) { $langs = $perso->getLanguagesFilter(); $ranges = $perso->getPlacesFilter(); $activities = $perso->getActivitiesFilter(); } else { $langs = $ranges = $activities = array(); } sfLoader::loadHelpers(array('Pagination')); $url_params = array(); unpackUrlParameters($params, $url_params); $result_module = $module; $field = 'name'; switch ($module) { case 'documents': $order = 'orderby=module&order=desc'; break; case 'portals': $field = 'wnam'; $order = 'orderby=wnam&order=asc'; break; case 'summits': $result_module = 'routes'; $field = 'snam'; $order = 'orderby=rnam&order=asc'; break; case 'sites': $field = 'tnam'; $order = 'orderby=tnam&order=asc'; break; case 'routes': $field = 'srnam'; $order = 'orderby=rnam&order=asc'; break; case 'parkings': $result_module = 'routes'; $field = 'pnam'; $order = 'orderby=rnam&order=asc'; break; case 'huts': $result_module = 'routes'; $field = 'hnam'; $order = 'orderby=rnam&order=asc'; break; case 'products': $field = 'fnam'; $order = 'orderby=fnam&order=asc'; break; case 'outings': $field = 'onam'; $order = 'orderby=date&order=desc'; break; case 'areas': $result_module = 'routes'; $field = 'anam'; $order = 'orderby=rnam&order=asc'; break; case 'maps': $field = 'mnam'; $order = 'orderby=mnam&order=asc'; break; case 'books': $result_module = 'routes'; $field = 'rbnam'; $order = 'orderby=rnam&order=asc'; break; case 'articles': $field = 'cnam'; $order = 'orderby=cnam&order=asc'; break; case 'images': $field = 'inam'; $order = ''; break; case 'users': $field = 'utfnam'; // utfnam = unam + ufnam $order = 'orderby=unam&order=asc'; break; default: $order = ''; break; } $query_string = trim(str_replace(array(' ', ' ', '.'), array(' ', ' ', '%2E'), $query_string)); $url_params[] = "{$field}={$query_string}"; $url_params[] = $order; $route = '/' . $result_module . '/list?' . implode('&', $url_params); c2cTools::log("redirecting to {$route}"); $this->redirect($route); } else { $this->forward404('need a string'); } }
<?php use_helper('MyForm', 'Language', 'Javascript', 'Ajax', 'Link'); echo customization_nav('customize'); ?> <div id="fake_div"> <div id="customize"> <?php echo c2c_form_remote_tag('users/savefilters'); $perso = c2cPersonalization::getInstance(); ?> <div id="home_left_content"> <?php echo tips_tag('if you select nothing / deselect all, no filter is applied'); ?> <fieldset> <legend><?php echo __('languages_to_display'); ?> </legend> <?php echo checkbox_nokey_list('language_filter', $sf_user->getCulturesForDocuments(), $perso->getLanguagesFilter(), false, false); ?> </fieldset> <fieldset> <legend><?php echo __('activities_to_display'); ?>
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'); } }
function activities_selector($onclick = false, $use_personalization = false, $filtered_activities = array(), $unavailable_activities = array(), $merged_activities = array(), $multiple = true, $show_picto = true, $activity_config = '') { $out = array(); $col = 0; $col_item = 0; if (empty($activity_config)) { $activity_config = 'app_activities_form'; } $activities = sfConfig::get($activity_config); $multiple_activities = array(); if (is_array($multiple)) { if (count($multiple)) { $multiple_activities = $multiple; } $multiple = false; } if (!$multiple) { foreach ($merged_activities as $key => $value) { $activities[$key] = $value; } } foreach ($unavailable_activities as $key => $value) { if (array_key_exists($key, $activities) && (empty($value) || !$multiple)) { $activity = $activities[$key]; unset($activities[$key]); } if (!empty($value) && !$multiple) { $activities[$key] = $activity; } } if ($multiple) { foreach ($merged_activities as $key => $value) { $activities[$key] = $value; } } else { foreach ($multiple_activities as $key) { $activity = $activities[$key]; unset($activities[$key]); $activities[$key] = $activity; } } $item_max = count($activities) - count($multiple_activities) - 1; $col_item_max = ceil(($item_max + 1) / 2) - 1; if (!count($filtered_activities) && $use_personalization) { $perso = c2cPersonalization::getInstance(); if ($perso->isMainFilterSwitchOn()) { $filtered_activities = $perso->getActivitiesFilter(); } } foreach ($activities as $activity_id => $activity) { if (array_key_exists($activity_id, $unavailable_activities)) { $tag = explode('/', $unavailable_activities[$activity_id]); if (count($tag) == 2) { $param = $tag[0]; $value = $tag[1]; $ckeckbox = true; } else { continue; } } else { $param = 'act'; $value = $activity_id; if (in_array($activity_id, $multiple_activities)) { $ckeckbox = true; } else { $ckeckbox = $multiple; } } if ($col_item == 0) { $col_class = $col % 2 ? 'col' : 'col_left'; $out[] = '<div class="' . $col_class . '">'; } $checked = in_array($activity_id, $filtered_activities) ? true : false; $activity_id_list = explode('-', $activity_id); $label_text = ''; if ($show_picto) { foreach ($activity_id_list as $id) { $label_text .= '<span class="picto activity_' . $id . '"></span>'; } } $label_text .= __($activity); if ($ckeckbox) { $input_tag = checkbox_tag($param . '[]', $value, $checked); } else { $input_tag = my_radiobutton_tag($param . '[]', $value, $checked); } $out[] = $input_tag . ' ' . label_for($param . '_' . $value, $label_text); if ($col_item == $col_item_max || $col * $col_item_max + $col_item == $item_max) { $out[] = '</div>'; $col += 1; $col_item = 0; } else { $out[] = '<br />'; $col_item += 1; } } if ($col_item > 0) { $out[] = '</div>'; } return '<div id="actform">' . implode("\n", $out) . '</div>'; }
/** * Executes view action. */ public function executeView() { parent::executeView(); $mobile_version = c2cTools::mobileVersion(); if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) { sfLoader::loadHelpers(array('Pagination')); $user = $this->getUser(); $prefered_cultures = $user->getCulturesForDocuments(); $document = $this->document; $id = $this->document->get('id'); $topo_filter = $this->document->get('topo_filter'); $url_params = array(); $main_params = unpackUrlParameters($topo_filter, $main_url_params); // map filter $has_map = $this->document->get('has_map'); $has_map = !$mobile_version && !empty($has_map); $this->has_map = $has_map; if ($has_map) { $map_filter_temp = $this->document->get('map_filter'); $map_filter_temp = str_replace(' ', '', $map_filter_temp); $map_filter_temp = explode('|', $map_filter_temp); $map_filter = array(); foreach ($map_filter_temp as $filter) { $filter = explode(':', $filter); if (isset($filter[1])) { $map_filter[$filter[0]] = $filter[1]; } } if (empty($map_filter['objects'])) { $map_filter['objects'] = null; } if (!empty($map_filter['lon']) || !empty($map_filter['lat']) || !empty($map_filter['zoom'])) { if (empty($map_filter['lon'])) { $lon = $this->document->get('lon'); if (is_null($lon)) { $lon = 7; } } else { $lon = $map_filter['lon']; } if (empty($map_filter['lat'])) { $lat = $this->document->get('lat'); if (is_null($lat)) { $lat = 45.5; } } else { $lat = $map_filter['lat']; } if (empty($map_filter['zoom'])) { $zoom = 6; } else { $zoom = $map_filter['zoom']; } $map_filter['center'] = array($lon, $lat, $zoom); } else { $map_filter['center'] = null; } if (empty($map_filter['height'])) { $map_filter['height'] = null; } $this->map_filter = $map_filter; $this->has_geom = false; } // user filters: $perso = c2cPersonalization::getInstance(); $langs = $ranges = $activities = array(); if ($perso->isMainFilterSwitchOn()) { $langs = $perso->getLanguagesFilter(); $names = array_keys($main_params); if (!array_intersect($names, array('areas', 'summits', 'sites', 'huts', 'parkings', 'routes', 'books'))) { $ranges = $perso->getPlacesFilter(); } if (!in_array('act', $names)) { $activities = $perso->getActivitiesFilter(); } } // latest outings $nb_outings = $this->document->get('nb_outings'); $has_outings = !empty($nb_outings); $this->has_outings = $has_outings; if ($has_outings) { $outing_url_params = array(); $outing_params = $this->document->get('outing_filter'); $outing_params = unpackUrlParameters($outing_params, $outing_url_params); $outing_langs = $langs; $outing_ranges = $ranges; $outing_activities = $activities; if (isset($outing_params['perso'])) { $perso_params = explode('-', $outing_params['perso']); if (array_intersect(array('areas', 'act', 'cult', 'no'), $perso_params)) { if (!in_array('cult', $perso_params)) { $outing_langs = array(); } if (!in_array('areas', $perso_params)) { $outing_ranges = array(); } if (!in_array('act', $perso_params)) { $outing_activities = array(); } } } $latest_outings = Outing::listLatest($nb_outings, $outing_langs, $outing_ranges, $outing_activities, $outing_params); // choose best language for outings and regions names $latest_outings = Language::getTheBest($latest_outings, 'Outing'); $this->latest_outings = Language::getTheBestForAssociatedAreas($latest_outings); $this->outing_url_params = $outing_url_params; } // latest articles $nb_articles = $this->document->get('nb_articles'); $has_articles = !empty($nb_articles); $this->has_articles = $has_articles; if ($has_articles) { $article_url_params = array(); $article_params = $this->document->get('article_filter'); $article_params = unpackUrlParameters($article_params, $article_url_params); $this->latest_articles = Article::listLatest($nb_articles, $langs, $activities, $article_params); $this->article_url_params = $article_url_params; } // latest images if ($mobile_version) { $nb_images = sfConfig::get('app_recent_documents_images_mobile_limit'); } else { $nb_images = $this->document->get('nb_images'); } $has_images = !empty($nb_images); $this->has_images = $has_images; if ($has_images) { $image_url_params = array(); $image_params = $this->document->get('image_filter'); $image_params = unpackUrlParameters($image_params, $image_url_params); $latest_images = Image::listLatest($nb_images, $langs, $ranges, $activities, $image_params); $this->latest_images = Language::getTheBest($latest_images, 'Image'); $this->image_url_params = $image_url_params; } // latest videos $nb_videos = $this->document->get('nb_videos'); $has_videos = !$mobile_version && !empty($nb_videos); if ($has_videos) { $video_url_params = array(); $video_params = $this->document->get('video_filter'); $video_params = explode('|', $video_params, 3); if (count($video_params) == 3) { $video_item = array('url' => trim($video_params[0]), 'thumbnail' => trim($video_params[1]), 'title' => trim($video_params[2])); $latest_videos = array($video_item); $this->latest_videos = $latest_videos; } else { $has_videos = false; } } $this->has_videos = $has_videos; // forum 'mountain news' latest active threads $nb_news = $this->document->get('nb_news'); $has_news = !empty($nb_news); $this->has_news = $has_news; $news_filter_ids = array(); if ($has_news) { $news_filter_temp = $this->document->get('news_filter'); $news_filter_temp = explode('|', $news_filter_temp); $news_filter = array(); foreach ($news_filter_temp as $filter) { $filter = explode(':', $filter); if (isset($filter[1])) { $news_filter[$filter[0]] = explode(',', $filter[1]); } } $news_filter_ids = PunbbTopics::getForumIds('app_forum_mountain_news', $langs, $activities, $news_filter); $this->latest_mountain_news = PunbbTopics::listLatestById($nb_news, $news_filter_ids); $this->news_filter_ids = implode('-', $news_filter_ids); } // forum latest active threads $nb_topics = $this->document->get('nb_topics'); $has_topics = !empty($nb_topics); $this->has_topics = $has_topics; if ($has_topics) { $forum_filter_temp = $this->document->get('forum_filter'); $forum_filter_temp = explode('|', $forum_filter_temp); $forum_filter = array(); foreach ($forum_filter_temp as $filter) { $filter = explode(':', $filter); if (isset($filter[1])) { $forum_filter[$filter[0]] = explode(',', $filter[1]); } } $forum_filter_ids = PunbbTopics::getForumIds('app_forum_public_ids', $langs, $activities, $forum_filter); $this->latest_threads = PunbbTopics::listLatestById($nb_topics, $forum_filter_ids); $this->forum_filter_ids = implode('-', array_merge($news_filter_ids, $forum_filter_ids)); } $cda_config = sfConfig::get('app_portals_cda'); if ($id == $cda_config['id']) { $description = $this->document->get('description'); $has_description = !empty($description); $this->has_description = $has_description; $this->setTemplate('changerdapproche'); } sfLoader::loadHelpers(array('sfBBCode', 'SmartFormat')); $abstract = strip_tags(parse_links(parse_bbcode_abstract($this->document->get('abstract')))); $this->getResponse()->addMeta('description', $abstract); } }
public static function retrieveConditions($days) { $pager = new sfDoctrinePager('Outing', 10); $q = $pager->getQuery(); $q->select('m.date, m.activities, m.conditions_status, m.up_snow_elevation, m.down_snow_elevation, ' . 'm.access_elevation, mi.name, mi.search_name, mi.conditions, mi.conditions_levels, mi.weather, mi.culture' . 'g0.type, g0.linked_id, ai.name, m.max_elevation')->from('Outing m')->leftJoin('m.OutingI18n mi')->where("m.redirects_to IS NULL AND age(date) < interval '{$days} days'")->orderBy('m.date DESC, m.id DESC'); self::joinOnRegions($q); // applying user filters if (c2cPersonalization::getInstance()->isMainFilterSwitchOn()) { self::filterOnLanguages($q); self::filterOnActivities($q); self::filterOnRegions($q); } return $pager; }
public function getPrevNextId($model, $current_id, $direction = 'next') { $where = 'm.id ' . ($direction == 'next' ? '<' : '>') . ' ?'; $orderBy = 'm.id ' . ($direction == 'next' ? 'DESC' : 'ASC'); $q = Doctrine_Query::create()->select('m.id')->from("{$model} m")->where($where, array($current_id))->addWhere('m.redirects_to IS NULL'); if (c2cPersonalization::getInstance()->isMainFilterSwitchOn()) { $this->addPrevNextIdFilters($q, $model); } $res = $q->orderBy($orderBy)->limit(1)->execute()->getFirst(); return !empty($res) ? $res->getId() : NULL; }
public function executeBeforeExecution() { $context = $this->getContext(); $module = $context->getModuleName(); $action = $context->getActionName(); $request_parameters = $context->getRequest()->getParameterHolder()->getAll(); unset($request_parameters['module']); unset($request_parameters['action']); $count_request_parameters = count($request_parameters); // register our cache configuration $this->cacheManager->registerConfiguration($module); // this previous line removes the dynamic cache configuration we could have been adding in previous filter ! // so that conditionalCacheFilter defined in documentation : // http://www.symfony-project.com/book/1_0/12-Caching#Configuring%20the%20Cache%20Dynamically // does not work ! if ($action == 'home' || $module == 'portals' && $action == 'view') { $module_cache = 'outings'; } else { $module_cache = $module; } $perso = c2cPersonalization::getInstance(); list($langs_enable, $areas_enable, $activities_enable) = c2cPersonalization::getDefaultFilters($module_cache); $are_filters_active = $perso->areFiltersActive(); $is_main_filter_switch_on = $perso->isMainFilterSwitchOn(); $count_activities_filter = count($perso->getActivitiesFilter()); $count_places_filter = count($perso->getPlacesFilter()); $are_default_filters = $perso->areDefaultFilters(); $are_simple_activities_langs_filters = $perso->areSimpleActivitiesFilters(true); $are_simple_activities_filters = $perso->areSimpleActivitiesFilters(false); // portals and home cache // Following condition means that filter is deactivated, or filters are empty, // or there is only one culture in the prefs, which the same as the interface culture // Other cases should not happen often, we don't cache them switch ($action) { case 'home': case 'view': if (!$are_filters_active || !$is_main_filter_switch_on || $are_default_filters || $are_simple_activities_langs_filters) { $this->cacheManager->addCache('documents', 'home', array('lifeTime' => 300, 'vary' => array())); $this->cacheManager->addCache('portals', 'changerdapproche', array('lifeTime' => 600, 'vary' => array())); $this->cacheManager->addCache('portals', 'view', array('lifeTime' => 600, 'vary' => array())); } break; case 'list': if (!isset($request_parameters['page'])) { $request_parameters['page'] = 1; $count_request_parameters++; } if ($request_parameters['page'] <= 2 && ($count_request_parameters == 1 || $module == 'outings' && $count_request_parameters == 3 && isset($request_parameters['orderby']) && $request_parameters['orderby'] == 'date' && isset($request_parameters['order']) && $request_parameters['order'] == 'desc') && (!$are_filters_active || !$is_main_filter_switch_on || $perso->areCacheableFilters($module))) { $this->cacheManager->addCache($module, 'list', array('lifeTime' => 350000, 'vary' => array())); } break; case 'filter': if (!$count_request_parameters && !$count_places_filter && (!$are_filters_active || !$is_main_filter_switch_on || $are_simple_activities_filters)) { if (in_array($module, array('outings', 'images'))) { $lifetime = 86400; } else { $lifetime = 600000; } $this->cacheManager->addCache($module, 'filter', array('lifeTime' => $lifetime, 'vary' => array())); } break; case 'cdasearch': if (!$count_request_parameters || !$count_places_filter) { $this->cacheManager->addCache($module, 'cdasearch', array('lifeTime' => 350000, 'vary' => array())); } break; default: break; } if (!$is_main_filter_switch_on || !$count_activities_filter) { $this->cacheManager->addCache('common', '_menu', array('lifeTime' => 350000, 'vary' => array())); } // get current uri adapted for cache $uri = self::getCurrentCacheUri(); // page cache $this->cache[$uri] = array('page' => false, 'action' => false); $cacheable = $this->cacheManager->isCacheable($uri); if ($cacheable) { if ($this->cacheManager->withLayout($uri)) { $inCache = $this->getPageCache($uri); $this->cache[$uri]['page'] = !$inCache; if ($inCache) { // page is in cache, so no need to run execution filter return false; } } else { $inCache = $this->getActionCache($uri); $this->cache[$uri]['action'] = !$inCache; } } return true; }
public function executeCustomize() { $referer = $this->getRequest()->getReferer(); $alist = sfConfig::get('app_activities_list'); array_shift($alist); // to remove 0 if ($this->hasRequestParameter('activity')) { $activity = $this->getRequestParameter('activity', 0) - 1; // comprised between 0 and 7 /* 1: skitouring 2: snow_ice_mixed 3: mountain_climbing 4: rock_climbing 5: ice_climbing 6: hiking 7: snowshoeing 8: paragliding */ } else { if ($this->hasRequestParameter('activity_name')) { $name = $this->getRequestParameter('activity_name'); foreach ($alist as $a => $a_name) { if ($a_name == $name) { $activity = $a; } } } else { $activity = -1; } } $user = $this->getUser(); if ($user->isConnected()) { $user_id = $user->getId(); } else { $user_id = null; } if (array_key_exists($activity, $alist)) { if (c2cPersonalization::getInstance()->getActivitiesFilter() == array($activity + 1) && $this->hasRequestParameter('activity')) { // we disactivate the previously set quick filter on this activity c2cPersonalization::saveFilter(sfConfig::get('app_personalization_cookie_activities_name'), array(), $user_id); return $this->setNoticeAndRedirect("c2c is no more customized with activies", $referer); } else { // we build a simple activity filter with one activity: c2cPersonalization::saveFilter(sfConfig::get('app_personalization_cookie_activities_name'), array($activity + 1), $user_id); // we need to activate main filter switch: $user->setFiltersSwitch(true); $activity_name = $alist[$activity]; return $this->setNoticeAndRedirect("c2c customized for {$activity_name} !", $referer); } } else { return $this->setNoticeAndRedirect('could not understand your request', $referer); } }
public function executeGetmultipleselect() { $mobile_version = c2cTools::mobileVersion(); $separate_prefs = $this->hasRequestParameter('sep_prefs') ? $this->getRequestParameter('sep_prefs') : 'true'; $separate_prefs = $separate_prefs == 'false' ? false : true; $area_type = $this->getRequestParameter('area_type'); if (!$mobile_version) { $default_width = 'auto'; $default_height = '350px'; } else { $default_width = '216px'; $default_height = '3.8em'; } $height = $this->hasRequestParameter('height') ? $this->getRequestParameter('height') . 'px' : $default_height; $width = $this->hasRequestParameter('width') ? $this->getRequestParameter('width') . 'px' : $default_width; $select_id = $this->hasRequestParameter('select_id') ? $this->getRequestParameter('select_id') : 'places'; $select_name = $this->hasRequestParameter('select_id') ? $this->getRequestParameter('select_name') : 'areas'; $areas = $this->getAreas($area_type, $separate_prefs); sfLoader::loadHelpers(array('Tag', 'Form')); return $this->renderText(select_tag($select_name, options_for_select($areas, $separate_prefs ? null : c2cPersonalization::getInstance()->getPlacesFilter()), array('id' => $select_id, 'multiple' => true, 'style' => 'width:' . $width . '; height:' . $height . ';')) . input_hidden_tag($select_id . '_type', $area_type)); }