0) { $raw_filters = $_POST; } elseif (empty($this->params) && isset($_COOKIE[BEZ_THREAD_FILTERS_COOKIE_NAME])) { $raw_filters = $_COOKIE[BEZ_THREAD_FILTERS_COOKIE_NAME]; } if (isset($raw_filters)) { //save filters foreach ($raw_filters as $k => $v) { setcookie(BEZ_THREAD_FILTERS_COOKIE_NAME."[$k]", $v); } $filters = array_filter($raw_filters, function($v) { return $v !== '-all' && $v !== ''; }); if (empty($filters)) { $filters['year'] = '-all'; } header('Location: '.$this->url('tasks', $filters)); } else { $filters = $this->params; } $this->tpl->set_values($filters); $years = $this->model->threadFactory->get_years_scope(); //some filters are just copied $db_filters = array_filter($filters, function ($k) { return in_array($k, array('thread_id', 'state', 'type', 'task_program_id')); }, ARRAY_FILTER_USE_KEY); //-none filters become empty filters $db_filters = array_map(function($v) { if ($v === '-none') { return ''; } return $v; }, $db_filters); if (isset($filters['year']) && $filters['year'] !== '-all') { $year = $filters['year']; $start_day = "$year-01-01"; $end_day = "$year-12-31"; $db_filters['create_date'] = array('BETWEEN', array($start_day, $end_day), array('date')); } if (isset($filters['assignee']) && substr($filters['assignee'], 0, 1) === '@') { $group = substr($filters['assignee'], 1); $db_filters['assignee'] = array('OR', $this->model->userFactory->users_of_group($group)); } if (isset($filters['content'])) { $content = preg_replace('/\s/', '%', $filters['content']); $db_filters['content'] = array('LIKE', "%$content%"); } $orderby = 'last_activity_date'; $tasks = $this->model->taskFactory->get_all($db_filters, $orderby); $this->tpl->set('task_programs', $this->model->task_programFactory->get_all()); $this->tpl->set('tasks', $tasks); $this->tpl->set('months', array(1 => 'jan', 2 => 'feb', 3 => 'mar', 4 => 'apr', 5 => 'may', 6 => 'june', 7 => 'july', 8 => 'aug', 9 => 'sept', 10 => 'oct', 11 => 'nov', 12 => 'dec')); $this->tpl->set('years', $years);