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 89 90//include_once DOKU_PLUGIN."bez/models/tasks.php"; 91//include_once DOKU_PLUGIN."bez/models/taskactions.php"; 92//include_once DOKU_PLUGIN."bez/models/taskstates.php"; 93//include_once DOKU_PLUGIN."bez/models/tasktypes.php"; 94//include_once DOKU_PLUGIN."bez/models/users.php"; 95//include_once DOKU_PLUGIN."bez/models/issues.php"; 96// 97//if (!$helper->user_viewer()) { 98// throw new PermissionDeniedException(); 99//} 100// 101//$tasko = new Tasks(); 102//$taskao = new Taskactions(); 103//$taskso = new Taskstates(); 104//$tasktypeso = new Tasktypes(); 105//$usro = new Users(); 106//$isso = new Issues(); 107// 108//if (count($_POST) > 0) 109// $raw_filters = $_POST; 110//elseif (count($nparams) === 1 && isset($_COOKIE['bez_tasks_filters'])) 111// $raw_filters = $_COOKIE['bez_tasks_filters']; 112// 113//if (isset($raw_filters)) { 114// $filters = $tasko->validate_filters($raw_filters); 115// $query_uri = ''; 116// foreach ($filters as $k => $v) 117// if ($v != '-all' && $v != '') 118// $query_uri .= ':'.urlencode($k).':'.urlencode($v); 119// 120// if ($query_uri == "") 121// $query_uri = ":year:-all"; 122// 123// header('Location: ?id='.$this->id('tasks').$query_uri); 124//} 125// 126///*rekordy parzyste to nagłówki, nieparzyste to ich wartości.*/ 127///*np. status:1:type:2:podmiot:PCA*/ 128//$value = array('issue' => '-all', 'action' => '-all', 'taskstate' => '-all', 129// 'executor' => '-all', 'year' => '-all', 'tasktype' => '-all', 130// 'month' => '-all', 'task' => '', 'reason' => '', 'date_type' => 'plan'); 131//for ($i = 0; $i < count($params); $i += 2) 132// $value[urldecode($params[$i])] = urldecode($params[$i+1]); 133// 134////save filters 135//foreach ($value as $k => $v) 136// setcookie("bez_tasks_filters[$k]", $v); 137// 138//$ical_link = '?id=bez:tasks_ical'; 139//foreach ($value as $k => $v) 140// if ($v != '-all' && $v != '') 141// $ical_link .= ':'.urlencode($k).':'.urlencode($v); 142// 143//$template['ical_link'] = $ical_link; 144// 145//$template['uri'] = $uri; 146// 147//$template['issues'] = $isso->get_ids(); 148// 149//$template['actions'] = $taskao->get(); 150// 151//$template['states'] = $taskso->get(); 152// 153//$template['executors'] = $usro->get(); 154//$template['groups'] = $usro->groups(); 155// 156// 157//$template['years'] = $tasko->get_years(); 158// 159//$tasks = $tasko->get_filtered($value); 160// 161// 162//$template['tasks_stats']['total'] = count($tasks); 163// 164//$tcost = 0; 165//$thours = 0; 166//foreach ($tasks as &$task) { 167// $tcost += (int)$task['cost']; 168// if ($task['start_time'] != '') { 169// $start_time = strtotime($task['start_time']); 170// $finish_time = strtotime($task['finish_time']); 171// $secs = $finish_time - $start_time; 172// $hours = $secs / 3600; 173// $hours_s = sprintf("%.1f", $hours); 174// $task['hours'] = $hours_s; 175// $thours += $hours; 176// } else 177// $task['hours'] = ''; 178//} 179//$template['tasks'] = $tasks; 180// 181//$template['tasks_stats']['totalcost'] = $tcost; 182//$template['tasks_stats']['totalhours'] = sprintf("%.1f", $thours); 183// 184//$tasktypes = $tasktypeso->get(); 185//$template['tasktypes'] = $tasktypes; 186// 187// 188//if ($nparams['taskstate'] == '0') 189// $template['view'] = 'plan'; 190//else 191// $template['view'] = 'realization'; 192// 193//$template['months'] = array(1 => 'jan', 194// 2 => 'feb', 195// 3 => 'mar', 196// 4 => 'apr', 197// 5 => 'may', 198// 6 => 'june', 199// 7 => 'july', 200// 8 => 'aug', 201// 9 => 'sept', 202// 10 => 'oct', 203// 11 => 'nov', 204// 12 => 'dec'); 205