1<?php 2/** @var action_plugin_bez $this */ 3 4define('BEZ_THREAD_FILTERS_COOKIE_NAME', 'bez_thread_filters'); 5 6if (count($_POST) > 0) { 7 $raw_filters = $_POST; 8} elseif (empty($this->params) && isset($_COOKIE[BEZ_THREAD_FILTERS_COOKIE_NAME])) { 9 $raw_filters = $_COOKIE[BEZ_THREAD_FILTERS_COOKIE_NAME]; 10} 11 12if (isset($raw_filters)) { 13 //save filters 14 foreach ($raw_filters as $k => $v) { 15 setcookie(BEZ_THREAD_FILTERS_COOKIE_NAME."[$k]", $v); 16 } 17 18 $filters = array_filter($raw_filters, function($v) { 19 return $v !== '-all' && $v !== ''; 20 }); 21 22 if (empty($filters)) { 23 $filters['year'] = '-all'; 24 } 25 26 header('Location: '.$this->url('threads', $filters)); 27} else { 28 $filters = $this->params; 29} 30 31$this->tpl->set_values($filters); 32 33//$issuetypes = $this->model->issuetypes->get_all(); 34$years = $this->model->threadFactory->get_years_scope(); 35 36//some filters are just copied 37$db_filters = array_filter($filters, function ($k) { 38 return in_array($k, array('state', 'label', 'coordinator')); 39}, ARRAY_FILTER_USE_KEY); 40 41//-none filters become empty filters 42$db_filters = array_map(function($v) { 43 if ($v === '-none') { 44 return NULL; 45 } 46 return $v; 47}, $db_filters); 48 49if (isset($filters['year']) && $filters['year'] !== '-all') { 50 $year = $filters['year']; 51 52 $start_day = "$year-01-01"; 53 $end_day = "$year-12-31"; 54 55 $db_filters['create_date'] = array('BETWEEN', array($start_day, $end_day), array('date')); 56} 57 58if (isset($filters['coordinator']) && 59 substr($filters['coordinator'], 0, 1) === '@') { 60 $group = substr($filters['coordinator'], 1); 61 $db_filters['coordinator'] = array('OR', $this->model->userFactory->users_of_group($group)); 62} 63 64if (isset($filters['title'])) { 65 $title = preg_replace('/\s/', '%', $filters['title']); 66 $db_filters['title'] = array('LIKE', "%$title%"); 67} 68 69$threads = $this->model->threadFactory->get_all($db_filters); 70 71//$this->tpl->set('issuetypes', $issuetypes); 72$this->tpl->set('threads', $threads); 73$this->tpl->set('years', $years); 74