1<?php 2/** @var action_plugin_bez $this */ 3 4use \dokuwiki\plugin\bez; 5 6if ($this->model->get_level() < BEZ_AUTH_USER) { 7 throw new bez\meta\PermissionDeniedException(); 8} 9 10class Timeline { 11 protected $timeline = array(); 12 13 protected function datetime($iso8601) { 14 $timestamp = strtotime($iso8601); 15 $date = date('Y-m-d', $timestamp); 16 $time = date('H:i', $timestamp); 17 18 return array($date, $time); 19 } 20 21 public function push($datetime, $type, $author, $entity) { 22 list($date, $time) = $this->datetime($datetime); 23 24 if (!isset($this->timeline[$date])) $timeline[$date] = array(); 25 $this->timeline[$date][] = array('time' => $time, 26 'type' => $type, 27 'author' => $author, 28 'entity' => $entity); 29 } 30 31 public function get_assoc() { 32 //sort dates, iso8601 can be compared as strings 33 krsort($this->timeline); 34 35 //sort times 36 foreach ($this->timeline as &$elm) { 37 usort($elm, function ($a, $b) { 38 return -1 * strcmp($a['time'], $b['time']); 39 }); 40 } 41 return $this->timeline; 42 } 43} 44 45$month_earlier = date('c', strtotime('-1 month')); 46$filter = array(); 47$filter['create_date'] = array('>=', $month_earlier, array('date')); 48$threads = $this->model->threadFactory->get_all($filter, 'create_date DESC'); 49$thread_comments = $this->model->thread_commentFactory->get_all($filter, 'create_date DESC'); 50$tasks = $this->model->taskFactory->get_all($filter, 'create_date DESC'); 51$task_comments = $this->model->task_commentFactory->get_all($filter, 'create_date DESC'); 52 53$timeline = new Timeline(); 54foreach ($threads as $thread) { 55 if ($thread->acl_of('id') < BEZ_PERMISSION_VIEW) continue; 56 57 $project = ''; 58 if ($thread->type == 'project') { 59 $project = '_project'; 60 } 61 62 if ($thread->state == 'proposal') { 63 $timeline->push($thread->create_date, 'thread_proposal' . $project, $thread->original_poster, $thread); 64 } else { 65 $timeline->push($thread->create_date, 'thread_opened' . $project, $thread->coordinator, $thread); 66 } 67 68 if ($thread->state == 'done') { 69 $timeline->push($thread->last_activity_date, 'thread_done' . $project, $thread->coordinator, $thread); 70 } elseif ($thread->state == 'closed') { 71 $timeline->push($thread->last_activity_date, 'thread_closed' . $project, $thread->coordinator, $thread); 72 } elseif ($thread->state == 'rejected') { 73 $timeline->push($thread->last_activity_date, 'thread_rejected' . $project, $thread->coordinator, $thread); 74 } 75} 76 77foreach ($thread_comments as $thread_comment) { 78 if ($thread_comment->thread->acl_of('id') < BEZ_PERMISSION_VIEW) continue; 79 80 if ($thread_comment->type == 'comment') { 81 $timeline->push($thread_comment->create_date, 'thread_comment_added', $thread_comment->author, $thread_comment); 82 } else { 83 $timeline->push($thread_comment->create_date, 'thread_comment_cause_added', $thread_comment->author, $thread_comment); 84 } 85} 86 87foreach ($tasks as $task) { 88 if ($task->acl_of('id') < BEZ_PERMISSION_VIEW) continue; 89 90 $timeline->push($task->create_date, 'task_opened', $task->assignee, $task); 91 92 if ($task->state == 'done') { 93 $timeline->push($task->last_activity_date, 'task_done', $task->assignee, $task); 94 } 95} 96 97foreach ($task_comments as $task_comment) { 98 if ($task_comment->task->acl_of('id') < BEZ_PERMISSION_VIEW) continue; 99 100 $timeline->push($task_comment->create_date, 'task_comment_added', $task_comment->author, $task_comment); 101} 102 103$this->tpl->set('timeline', $timeline->get_assoc()); 104 105$orderby = array('sort', 'priority DESC', 'create_date DESC'); 106$filter = array('state' => 'proposal'); 107$proposals = $this->model->threadFactory->get_all($filter, $orderby); 108$this->tpl->set('proposals', $proposals); 109$this->tpl->set('proposals_count', $this->model->threadFactory->count($filter)); 110 111$orderby = array('sort', 'priority DESC', 'create_date DESC'); 112$filter = array('state' => 'opened', 'coordinator' => $this->model->user_nick); 113$my_threads = $this->model->threadFactory->get_all($filter, $orderby); 114$this->tpl->set('my_threads', $my_threads); 115$this->tpl->set('my_threads_count', $this->model->threadFactory->count($filter)); 116 117$orderby = array('priority DESC', 'plan_date'); 118$filter = array('state' => 'opened', 'assignee' => $this->model->user_nick); 119$my_tasks = $this->model->taskFactory->get_all($filter, $orderby); 120$this->tpl->set('my_tasks', $my_tasks); 121$this->tpl->set('my_tasks_count', $this->model->taskFactory->count($filter)); 122 123$orderby = array('sort', 'priority DESC', 'create_date DESC'); 124$filter = array('state' => 'opened', 'original_poster' => $this->model->user_nick); 125$reported_threads = $this->model->threadFactory->get_all($filter, $orderby); 126$this->tpl->set('reported_threads', $reported_threads); 127$this->tpl->set('reported_threads_count', $this->model->threadFactory->count($filter)); 128 129$orderby = array('priority DESC', 'plan_date'); 130$filter = array('state' => 'opened', 'original_poster' => $this->model->user_nick); 131$reported_tasks = $this->model->taskFactory->get_all($filter, $orderby); 132$this->tpl->set('reported_tasks', $reported_tasks); 133$this->tpl->set('reported_tasks_count', $this->model->taskFactory->count($filter)); 134 135