1<?php 2 3namespace dokuwiki\plugin\bez\mdl; 4 5//if(!defined('DOKU_INC')) die(); 6 7//require_once 'factory.php'; 8//require_once 'thread.php'; 9 10 11 12class ThreadFactory extends Factory { 13 14// public function __construct($model) { 15// parent::__construct($model); 16 17 /* state_string: 18 0 -> opened 19 1 -> closed 20 2 -> rejected 21 if state = 0 and all tasks are done -> done 22 */ 23// $this->select_query = "SELECT *, 24// (CASE 25// WHEN state = 2 26// THEN '".$this->model->action->getLang('state_rejected')."' 27// WHEN coordinator = '-proposal' 28// THEN '".$this->model->action->getLang('state_proposal')."' 29// WHEN state = 0 AND assigned_tasks_count > 0 30// AND opened_tasks_count = 0 31// THEN '".$this->model->action->getLang('state_done')."' 32// WHEN state = 0 33// THEN '".$this->model->action->getLang('state_opened')."' 34// WHEN state = 1 35// THEN '".$this->model->action->getLang('state_closed')."' 36// END) AS state_string, 37// 38// (CASE 39// WHEN state = 2 40// THEN '2' 41// WHEN coordinator = '-proposal' 42// THEN '-proposal' 43// WHEN state = 0 AND assigned_tasks_count > 0 44// AND opened_tasks_count = 0 45// THEN '-done' 46// WHEN state = 0 47// THEN '0' 48// WHEN state = 1 49// THEN '1' 50// END) AS full_state, 51// 52// (CASE WHEN state = 2 then '3' 53// WHEN task_priority IS NULL THEN 'None' 54// ELSE task_priority 55// END) AS priority 56// 57// FROM (SELECT issues.*, 58// (SELECT COUNT(*) FROM tasks 59// WHERE tasks.issue = issues.id) 60// AS assigned_tasks_count, 61// (SELECT COUNT(*) FROM tasks 62// WHERE tasks.issue = issues.id AND tasks.state = 0) 63// AS opened_tasks_count, 64// (SELECT MIN((CASE WHEN tasks.state > 0 THEN '3' 65// WHEN tasks.plan_date >= date('now', '+1 month') THEN '2' 66// WHEN tasks.plan_date >= date('now') THEN '1' 67// ELSE '0' END)) FROM tasks WHERE tasks.issue = issues.id) 68// AS task_priority, 69// (SELECT SUM(tasks.cost) FROM tasks 70// WHERE tasks.issue = issues.id) 71// AS cost, 72// issuetypes.".$this->model->conf['lang']." AS type_string 73// FROM issues 74// LEFT JOIN issuetypes ON issues.type = issuetypes.id)"; 75// } 76 77 protected function select_query() { 78 return "SELECT thread.*, label.id AS label_id, label.name AS label_name FROM thread 79 LEFT JOIN thread_label ON thread.id = thread_label.thread_id 80 LEFT JOIN label ON label.id = thread_label.label_id"; 81 } 82 83 public function get_years_scope() { 84 $r = $this->model->sqlite->query('SELECT create_date FROM thread ORDER BY id LIMIT 1'); 85 $date = $this->model->sqlite->res2single($r); 86 87 //get only year 88 $first = (int) substr($date, 0, strpos($date, '-')); 89 $last = (int) date('Y'); 90 91 $years = array(); 92 for ($year = $first; $year <= $last; $year++) { 93 $years[] = (string) $year; 94 } 95 return $years; 96 } 97} 98