<commit_before><?php

namespace SimplyTestable\WebClientBundle\Controller;

use Symfony\Component\HttpFoundation\Response;

class TestHistoryController extends TestViewController
{ 
    const RESULTS_PREPARATION_THRESHOLD = 10;
    const DEFAULT_PAGE_NUMBER = 1;
    
    public function indexAction($page_number) {        
        if ($this->isUsingOldIE()) {
            return $this->forward('SimplyTestableWebClientBundle:App:outdatedBrowser');
        }
        
        $this->getUserService()->setUser($this->getUser());
        
        if (!$this->isUserValid()) {            
            return $this->redirect($this->generateUrl('sign_out_submit', array(), true));
        }
        
        if ($this->isPageNumberBelowRange($page_number)) {
            return $this->redirect($this->generateUrl('view_test_history_index_index'));
        }
        
        $testList = $this->getFinishedTests(10, ($page_number - 1) * 10, $this->get('request')->get('filter'));        
        if ($page_number > $testList->getPageCount() && $testList->getPageCount() > 0) {            
            $redirectParameters = array(
                'page_number' => $testList->getPageCount(),                
            );
            
            if (!is_null($this->get('request')->get('filter'))) {
                $redirectParameters['filter'] = $this->get('request')->get('filter');
            }
            
            return $this->redirect($this->generateUrl('app_history', $redirectParameters));            
        }
        
        $templateName = 'SimplyTestableWebClientBundle:TestHistory:index.html.twig';
        
        $cacheValidatorIdentifier = $this->getCacheValidatorIdentifier(array(
            'template_last_modified_date' => $this->getTemplateLastModifiedDate($templateName)->format('Y-m-d H:i:s'),
            'test_list_hash' => $testList->getHash(),
            'test_list' => md5(json_encode($testList)),
            'filter' => $this->get('request')->get('filter'),
        ));
        
        $cacheValidatorHeaders = $this->getCacheValidatorHeadersService()->get($cacheValidatorIdentifier);        
        $response = $this->getCachableResponse(new Response(), $cacheValidatorHeaders);            
        if ($response->isNotModified($this->getRequest())) {
            return $response;
        }
        
        $cacheValidatorHeaders->setLastModifiedDate(new \DateTime());
        $this->getCacheValidatorHeadersService()->store($cacheValidatorHeaders);;        
        
        return $this->getCachableResponse($this->render($templateName, array(            
            'public_site' => $this->container->getParameter('public_site'),
            'user' => $this->getUser(),
            'is_logged_in' => !$this->getUserService()->isPublicUser($this->getUser()),         
            'test_list' => $testList,
            'pagination_page_numbers' => $testList->getPageNumbers(),
            'filter' => $this->get('request')->get('filter'),
            'websites_source' => $this->generateUrl('app_history_websites', array(), true)
        )), $cacheValidatorHeaders);                
    }
    
    
    public function websitesAction() {
        $this->getUserService()->setUser($this->getUser());
        
        $list = ($this->isUserValid()) ? $this->getTestService()->getRemoteTestService()->getFinishedWebsites() : array();
        return $this->getUncacheableResponse(new Response($this->getSerializer()->serialize($list, 'json')));     
    }
    
    
    /**
     * 
     * @param mixed $pageNumber
     * @return boolean
     */
    private function isPageNumberBelowRange($pageNumber) {
        return (int)$pageNumber < self::DEFAULT_PAGE_NUMBER;
    }
    
    
    
    /**
     * 
     * @return array
     */
    private function getFinishedTests($limit, $offset, $filter = null) {
        $testList = $this->getTestService()->getRemoteTestService()->getFinished($limit, $offset, $filter);
        
        foreach ($testList->get() as $testObject) {
            /* @var $remoteTest RemoteTest */
            $remoteTest = $testObject['remote_test'];
            
            $this->getTestService()->getRemoteTestService()->set($remoteTest);
            $test = $this->getTestService()->get($remoteTest->getWebsite(), $remoteTest->getId(), $remoteTest);
            
            $testList->addTest($test);
            
            if ($testList->requiresResults($test)) {
                if ($remoteTest->isSingleUrl()) {
                    $this->getTaskService()->getCollection($test);
                } else {
                    
//                    
//                    if (($remoteTest->getTaskCount() - self::RESULTS_PREPARATION_THRESHOLD) - $test->getTaskCount()) {
//                        $this->getTaskService()->getCollection($test);
//                    }                   
                }
            }
        }
        
        return $testList;
    }
    
    
    /**
     *
     * @return \SimplyTestable\WebClientBundle\Services\TaskService 
     */
    private function getTaskService() {
        return $this->container->get('simplytestable.services.taskservice');
    }    

}<commit_msg>Remove obsolete methods from old test history controller<commit_after><?php

namespace SimplyTestable\WebClientBundle\Controller;

use Symfony\Component\HttpFoundation\Response;

class TestHistoryController extends TestViewController
{ 
    const RESULTS_PREPARATION_THRESHOLD = 10;
    const DEFAULT_PAGE_NUMBER = 1;
    
    public function websitesAction() {
        $this->getUserService()->setUser($this->getUser());
        
        $list = ($this->isUserValid()) ? $this->getTestService()->getRemoteTestService()->getFinishedWebsites() : array();
        return $this->getUncacheableResponse(new Response($this->getSerializer()->serialize($list, 'json')));     
    }

}
{'fraction_non_alphanumeric': 0.14680778422669855, 'fraction_numerical': 0.002219187435984978, 'mean_word_length': 2.3139140271493215, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2145048', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1536, 'n_words': 205}