コード例 #1
0
 public static function buildPersoCriteria(&$conditions, &$values, &$joins, &$params_list, $module, $activity_param = 'act', $na_activities = array())
 {
     $has_merged = self::buildConditionItem($conditions, $values, $joins, $params_list, 'ItemNull', 'm.redirects_to', 'merged', 'merged');
     if ($has_merged) {
         $joins['merged'] = $has_merged;
     } else {
         $conditions[] = 'm.redirects_to IS NULL';
     }
     self::buildConditionItem($conditions, $values, $joins, $params_list, 'Config', '', 'all', 'all');
     if (isset($joins['all'])) {
         if ($joins['all']) {
             return;
         } else {
             unset($joins['all']);
         }
     }
     $perso = c2cTools::getArrayElement($params_list, 'perso');
     if (!empty($perso)) {
         $perso = explode('-', $perso);
     } else {
         $perso = array();
     }
     $filters_active_and_on = c2cPersonalization::getInstance()->areFiltersActiveAndOn($module);
     if (!$has_merged) {
         if ($filters_active_and_on && (empty($params_list) || count($perso) == 1 && in_array('ifon', $perso))) {
             list($langs_enable, $areas_enable, $activities_enable) = c2cPersonalization::getDefaultFilters($module);
             if ($langs_enable) {
                 $perso[] = 'cult';
             }
             if ($areas_enable) {
                 $perso[] = 'areas';
             }
             if ($activities_enable) {
                 $perso[] = 'act';
             }
         } elseif (!$filters_active_and_on && in_array('ifon', $perso)) {
             $perso = array();
         }
     } else {
         $perso = array();
     }
     if (!empty($perso)) {
         $params = array_keys($params_list);
         if (!array_intersect(array('areas', 'bbox', 'around'), $params) && array_intersect(array('areas', 'yes', 'all'), $perso)) {
             $areas = c2cPersonalization::getInstance()->getPlacesFilter();
             if (count($areas)) {
                 $params_list['areas'] = implode('-', $areas);
             }
         }
         if (!in_array($activity_param, $params) && array_intersect(array('act', 'yes', 'all'), $perso)) {
             $activities = c2cPersonalization::getInstance()->getActivitiesFilter();
             $activities = array_udiff($activities, $na_activities, 'strcmp');
             if (count($activities)) {
                 $params_list[$activity_param] = implode('-', $activities);
             }
         }
         $culture_param = c2cTools::Module2Letter($module) . 'cult';
         if (!in_array($culture_param, $params) && array_intersect(array('cult', 'yes', 'all'), $perso)) {
             $cultures = c2cPersonalization::getInstance()->getLanguagesFilter();
             if (count($cultures)) {
                 $params_list[$culture_param] = implode('-', $cultures);
             }
         }
         if (isset($params_list['perso'])) {
             unset($params_list['perso']);
         }
         if (empty($params_list)) {
             $joins['all'] = true;
         }
     }
     if (isset($params_list[$activity_param])) {
         $joins['act'] = $params_list[$activity_param];
     } else {
         $joins['act'] = '';
     }
 }
コード例 #2
0
 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;
 }