1<?php 2 3/** @var action_plugin_bez $this */ 4 5define('BEZ_THREAD_FILTERS_COOKIE_NAME', 'bez_task_filters'); 6 7if (count($_POST) > 0) { 8 $raw_filters = $_POST; 9} elseif (empty($this->params) && isset($_COOKIE[BEZ_THREAD_FILTERS_COOKIE_NAME])) { 10 $raw_filters = $_COOKIE[BEZ_THREAD_FILTERS_COOKIE_NAME]; 11} 12 13if (isset($raw_filters)) { 14 //save filters 15 foreach ($raw_filters as $k => $v) { 16 setcookie(BEZ_THREAD_FILTERS_COOKIE_NAME."[$k]", $v); 17 } 18 19 $filters = array_filter($raw_filters, function($v) { 20 return $v !== '-all' && $v !== ''; 21 }); 22 23 if (empty($filters)) { 24 $filters['year'] = '-all'; 25 } 26 27 header('Location: '.$this->url('tasks', $filters)); 28} else { 29 $filters = $this->params; 30} 31 32$this->tpl->set_values($filters); 33 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('thread_id', 'state', 'type', 'task_program_id')); 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 ''; 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['assignee']) && 59 substr($filters['assignee'], 0, 1) === '@') { 60 $group = substr($filters['assignee'], 1); 61 $db_filters['assignee'] = array('OR', $this->model->userFactory->users_of_group($group)); 62} 63 64if (isset($filters['content'])) { 65 $content = preg_replace('/\s/', '%', $filters['content']); 66 $db_filters['content'] = array('LIKE', "%$content%"); 67} 68 69$orderby = 'last_activity_date'; 70 71$tasks = $this->model->taskFactory->get_all($db_filters, $orderby); 72 73$this->tpl->set('task_programs', $this->model->task_programFactory->get_all()); 74$this->tpl->set('tasks', $tasks); 75$this->tpl->set('months', array(1 => 'jan', 76 2 => 'feb', 77 3 => 'mar', 78 4 => 'apr', 79 5 => 'may', 80 6 => 'june', 81 7 => 'july', 82 8 => 'aug', 83 9 => 'sept', 84 10 => 'oct', 85 11 => 'nov', 86 12 => 'dec')); 87$this->tpl->set('years', $years); 88