name = 'Tests'; $this->defaultTask = 'listing'; $this->testClass = new TestClass(); } private function getNumberOfElementsToDisplay() { $selectValue = Security::getVar('int', 'acyc_element_per_page', $this->config->get('listing_element_page', self::DEFAULT_ELEMENTS_PER_PAGE)); $this->config->save(['listing_element_page' => $selectValue]); return $selectValue; } public function listing() { $this->layout = 'listing'; $data = [ 'per_page' => $this->getNumberOfElementsToDisplay(), 'search' => $this->getVarFiltersListing('string', 'search', ''), 'page' => $this->getVarFiltersListing('int', self::PAGINATION_NAME, 1), 'current_status' => $this->getVarFiltersListing('string', 'status', ''), ]; $this->prepareTestsElements($data); $this->preparePagination($data); $this->prepareTexts($data); $this->prepareStatus($data); $this->displayInfoInProgress(); $this->breadcrumb[__('Tests', 'acychecker')] = Url::completeLink('tests'); $this->display($data); } private function prepareTestsElements(&$data) { $data['offset'] = ($data['page'] - 1) * $data['per_page']; $results = $this->testClass->getMatchingElements($data); $data = array_merge($data, $results); } private function preparePagination(&$data) { $data['pagination'] = new PaginationService($data['page'], $data['total'], $data['per_page'], self::PAGINATION_NAME); } private function prepareTexts(&$data) { $data['final_status_texts'] = [ 'not_existing' => __('Not existing', 'acychecker'), 'risky' => __('Risky', 'acychecker'), 'possible' => __('Possible', 'acychecker'), 'valid' => __('Valid', 'acychecker'), ]; } private function prepareStatus(&$data) { $data['status'] = [ 'all' => [ 'text' => __('All', 'acychecker'), 'number' => $this->testClass->getStatusNumber('all', $data), 'value' => 'all', ], 'tested' => [ 'text' => __('Tested', 'acychecker'), 'number' => $this->testClass->getStatusNumber('tested', $data), 'value' => 'tested', ], 'progress' => [ 'text' => __('In progress', 'acychecker'), 'number' => $this->testClass->getStatusNumber('progress', $data), 'value' => 'progress', ], ]; } public function displayInfoInProgress() { $tests = $this->config->get('urls_results_batch'); $tests = json_decode($tests, true); if (!empty($tests)) { $nbBatchs = count($tests); Message::enqueueMessage(sprintf(__('You currently have tests in progress (composed of %s batches). Results will be available soon.', 'acychecker'), $nbBatchs), 'info'); } } public function doexport() { $separator = '","'; $eol = "\r\n"; $before = '"'; $after = '"'; error_reporting(E_ALL); @ini_set('display_errors', 1); $columns = Database::loadResultArray('SHOW COLUMNS FROM #__acyc_test'); $query = 'SELECT * FROM #__acyc_test AS test'; $elements = Database::loadObjectList($query); if (empty($elements)) { // Remove noheader in url $completLink = rtrim(Url::completeLink('tests', false, true), '&noheader=1'); Message::enqueueMessage(__('No data found to export', 'acychecker'), 'warning'); Router::redirect($completLink); } $lines = []; $lines[] = $before.implode($separator, $columns).$after; foreach ($elements as $oneElement) { $line = []; $oneElement->status = $oneElement->status ? __('Completed', 'acychecker') : __('In progress', 'acychecker'); foreach ($oneElement as $col => $item) { if ($col == 'raw_result') { $array = json_decode($item); $suggestions = $array->domain_suggestions; $line[] = htmlspecialchars(implode(',', $suggestions), ENT_QUOTES, 'UTF-8'); } else { $line[] = htmlspecialchars($item, ENT_QUOTES, 'UTF-8'); } } $lines[] = $before.implode($separator, $line).$after; } $final = implode($eol, $lines); @ob_get_clean(); $filename = 'export_acychecker_'.date('Y-m-d'); HttpService::setDownloadHeaders($filename); echo $final; exit; } public function clearTests() { $testClass = new TestClass(); $testClass->deleteAllTests(); $this->listing(); } }