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