Clean questions

@param SessionConfigurationInterface $configuration

@return $this
161602
public function cleanQuestions(SessionConfigurationInterface $configuration)
    {
        $categoriesId = array();
        $questionsLevel = $configuration->getQuestionsLevel();

        foreach ($configuration->getCategories() as $category) {
            $categoriesId[] = $category->getId();
        }

        foreach ($configuration->getQuestions() as $question) {
            if (!in_array($question->getCategory()->getId(), $categoriesId)) {
                $configuration->removeQuestion($question);
            } else if (!empty($questionsLevel) && !in_array($question->getLevel(), $questionsLevel)) {
                $configuration->removeQuestion($question);
            }
        }

        if ($configuration->getMaxQuestions() < $configuration->getQuestions()->count()) {
            $questions = $configuration->getQuestions()->toArray();
            shuffle($questions);

            $questions = array_slice($questions, 0, $configuration->getQuestions()->count() - $configuration->getMaxQuestions());

            foreach ($questions as $question) {
                $configuration->removeQuestion($question);
            }
        }

        return $this;
    }
1277438
public function clear(): SessionInterface
    {
        $values = $this->getAll();

        if (count($values) > 0) {
            $this->delete(...array_keys($values));
        }

        return $this;
    }
858592
private function flushConfiguration(ConfigurationInterface $configuration)
    {
        $this
            ->configurationObjectManager
            ->persist($configuration);

        $this
            ->configurationObjectManager
            ->flush($configuration);

        return $this;
    }
1286283
static function cleanup()
    {
        $http = eZHTTPTool::instance();

        $http->removeSessionVariable( 'CanInstantiateClassList' );
        $http->removeSessionVariable( 'ClassesCachedForUser' );

        // Note: This must be done more generic with an internal
        //       callback system.
        eZPreferences::sessionCleanup();
    }
142603
public function clean()
    {
        foreach ($this->data as $key => $data) {
            if (empty($data)) {
                unset($this->data[$key]);
            }
        }

        return $this;
    }
269005
public function addQuestion(QuestionInterface $question)
    {
        if (!$this->hasQuestion($question)) {
            $this->questions->add($question);
        }

        return $this;
    }
661514
public function cleanup()
    {
        // check if history cleanup is needed
        $lastCleanup = Mage::app()->loadCache(Mage_Cron_Model_Observer::CACHE_KEY_LAST_HISTORY_CLEANUP_AT);
        if ($lastCleanup > time() - Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_CLEANUP_EVERY) * 60) {
            return $this;
        }

        $startTime = microtime(true);

        $history = Mage::getModel('cron/schedule')->getCollection()
            ->addFieldToFilter('status', array('nin' => array(
                Aoe_Scheduler_Model_Schedule::STATUS_PENDING,
                Aoe_Scheduler_Model_Schedule::STATUS_RUNNING
            )))
            ->load();

        $historyLifetimes = array(
            Aoe_Scheduler_Model_Schedule::STATUS_KILLED =>          Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_DISAPPEARED =>     Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS =>         Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_REPEAT =>          Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_MISSED =>          Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_SKIP_PILINGUP =>   Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_ERROR =>           Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_DIED =>            Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60,
            Aoe_Scheduler_Model_Schedule::STATUS_SKIP_OTHERJOBRUNNING => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60,
        );

        $now = time();
        foreach ($history->getIterator() as $record) { /* @var $record Aoe_Scheduler_Model_Schedule */
            if (isset($historyLifetimes[$record->getStatus()])) {
                if (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()]) {
                    $record->delete();
                }
            }
        }

        // save time history cleanup was ran with no expiration
        Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, array('crontab'), null);


        // delete successful tasks (beyond the configured max number of tasks to keep)
        $maxNo = Mage::getStoreConfig(self::XML_PATH_HISTORY_MAXNO);
        if ($maxNo) {
            $history = Mage::getModel('cron/schedule')->getCollection()
                ->addFieldToFilter(
                    array('status'),
                    array(
                        array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS),
                        array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_REPEAT)
                    )
                )
                ->setOrder('finished_at', 'desc')
                ->load();
            $counter = array();
            foreach ($history->getIterator() as $record) { /* @var $record Aoe_Scheduler_Model_Schedule */
                $jobCode = $record->getJobCode();
                if (!isset($counter[$jobCode])) {
                    $counter[$jobCode] = 0;
                }
                $counter[$jobCode]++;
                if ($counter[$jobCode] > $maxNo) {
                    $record->delete();
                }
            }
        }

        if ($logFile = Mage::getStoreConfig('system/cron/logFile')) {
            $duration = microtime(true) - $startTime;
            Mage::log('History cleanup (Duration: ' . round($duration, 2) . ' sec)', null, $logFile);
        }

        return $this;
    }
859899
public function removeQuestion(QuestionInterface $question)
    {
        if ($this->hasQuestion($question)) {
            $this->questions->removeElement($question);
            $question->setCategory(null);
        }

        return $this;
    }
1192685
protected function prepareServiceManager(Configuration $configuration)
    {
        $container      = $this->config->get('services', []);
        $serviceManager = new LeagueAdapter();

        foreach ($container as $className) {

            /** @var ServiceProvider $provider */
            $provider = new $className();

            if ( $provider instanceof ServiceProvider ) {
                throw new \InvalidArgumentException(
                    sprintf('Provider %s must be ServiceProvider', $className)
                );
            }

            $aliases = $provider->alias();
            if ( !is_array($aliases) ) {
                $aliases = [$aliases];
            }

            foreach ($aliases as $alias) {
                if ( $provider->share() ) {
                    $serviceManager->share($alias);
                }

                if ( $provider instanceof ServiceManager\SetterInjectorProvider ) {
                    $serviceManager
                        ->inflector($provider->inflector())
                        ->invokeMethod($provider->method(), [$alias]);
                }

                $provides = $provider->provide();

                if ( !is_callable($provides) ) {
                    $serviceManager->alias($alias, $provides);
                    continue;
                }

                $serviceManager->add(
                    $alias,
                    function () use ($provides, $serviceManager) {
                        return $serviceManager->call($provides);
                    }
                );
            }

        }

        // Add the ServiceManager and the Configuration
        $serviceManager->add(LeagueAdapter::class, $serviceManager);
        $serviceManager->add(ConfigurationContainer::class, $this->config);

        return $serviceManager;
    }
739225
public function clean($markup, $config = null)
    {
        if (empty($config) && !empty($this->_config['config'])) {
            $config = $this->config('config');
        }
        return Purifier::clean($markup, $config);
    }
990401
protected function sanitize(array $configuration)
    {
        foreach ($configuration as $key => $config) {
            if (null === $config['name']) {
                $configuration[$key]['name'] = $this->defaultRouteName($key);
            }
            if (null === $config['path']) {
                $configuration[$key]['path'] = $this->defaultRoutePath($key);
            }
            if (null === $config['api_name']) {
                $configuration[$key]['api_name'] = $this->defaultApiRouteName($key);
            }
            if (null === $config['api_path']) {
                $configuration[$key]['api_path'] = $this->defaultApiRoutePath($key);
            }
        }

        return $configuration;
    }
232480
public function flush() : ContainerInterface
    {
        $this->collection = [];
        $this->dependencies = [];
        $this->resolving = [];
        $this->resolved = [];

        return $this;
    }
1210684
public function clearSessionCookies()
    {
        $this->_data = array_filter(
            $this->_data,
            function ($cookie) {
                return !$cookie->discard() && $cookie->expires();
            }
        );
        return $this;
    }
888955
public function updateSessionConfiguration()
    {
        $configuration = clone $this->getUserConfiguration();
        $userSession = $this->manager->getRepository('QcmPublicBundle:UserSession')->findOneBy(array(
            'id' => $this->userSession->getId()
        ));

        $userSession->setConfiguration($configuration);
        $this->manager->persist($userSession);
        $this->manager->flush();

        $this->session->set('user_session', $userSession);

        return $this;
    }
1159760
public function clear(): SessionInterface
    {
        # Get all the current session data
        $values = $this->getAll();

        # Replace all the values with nulls
        $values = array_map(function ($value) {
            return null;
        }, $values);

        # Store all the null values (effectively unsetting the keys)
        $this->set($values);

        return $this;
    }
826598
public static function create(SessionInterface $session, Configuration $config = null, EventManager $evm = null)
    {
        return new self($session, $config, $evm);
    }
1147915
public function removePageSessionPluginAction()
    {
        $module = $this->getRequest()->getQuery('module', null);
        $pluginName = $this->getRequest()->getQuery('pluginName', '');
        $pageId = $this->getRequest()->getQuery('pageId', null);
        $pluginId = $this->getRequest()->getQuery('pluginId', null);
        $pluginTag = $this->getRequest()->getQuery('pluginTag', null);
        
        $parameters = array(
            'module' => $module,
            'pluginName' => $pluginName,
            'pageId' => $pageId,
            'pluginId' => $pluginId,
            'pluginTag' => $pluginTag,
        );
        
        $translator = $this->serviceLocator->get('translator');

        if (empty($module) || empty($pluginName) || empty($pageId) || empty($pluginId))
        {

            $result = array(
                'success' => 0,
                'errors' => array(array('empty' => $translator->translate('tr_meliscms_form_common_errors_Empty datas')))
            );
        }
        else
        {

            $this->getEventManager()->trigger('meliscms_page_removesession_plugin_start', null, $parameters);
            
            // removing plugin from session
            $container = new Container('meliscms');
            if (!empty($container['content-pages'][$pageId][$pluginTag][$pluginId]))
                unset($container['content-pages'][$pageId][$pluginTag][$pluginId]);
            
            $this->getEventManager()->trigger('meliscms_page_removesession_plugin_end', null, $parameters);
            
            $result = array(
                'success' => 1,
                'errors' => array()
            );
        }
         
        return new JsonModel($result);
    }