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 10if ($this->get_param('id') == '') { 11 header('Location: ' . $this->url('threads')); 12} 13 14/** @var bez\mdl\Thread $thread */ 15$thread = $this->model->threadFactory->get_one($this->get_param('id')); 16 17if ($thread->acl_of('id') < BEZ_PERMISSION_VIEW) { 18 throw new bez\meta\PermissionDeniedException(); 19} 20 21$this->tpl->set('thread', $thread); 22if ($thread->type == 'project') { 23 $this->tpl->set('lang_suffix', '_project'); 24} 25 26$thread_comments = iterator_to_array($this->model->thread_commentFactory->get_from_thread($thread)); 27$tasks = $this->model->taskFactory->get_from_thread($thread); 28 29$timeline = array_merge($thread_comments, $tasks['corrections']); 30usort($timeline, function($a, $b) { 31 if ($a->create_date == $b->create_date) { 32 return 0; 33 } 34 return ($a->create_date < $b->create_date) ? -1 : 1; 35}); 36 37$this->tpl->set('timeline', $timeline); 38$this->tpl->set('tasks', $tasks); 39$this->tpl->set('task_programs', $this->model->task_programFactory->get_all()); 40 41/** @var bez\mdl\Thread_comment $thread_comment */ 42$thread_comment = $this->model->thread_commentFactory->create_object(array('thread' => $thread)); 43$this->tpl->set('thread_comment', $thread_comment); 44 45if ($this->get_param('action') == 'commcause_add') { 46 47 $this->model->thread_commentFactory->initial_save($thread_comment, $_POST); 48 49 $anchor = 'k'.$thread_comment->id; 50 $redirect = true; 51 52} elseif ($this->get_param('action') == 'subscribe') { 53 54 $thread->set_participant_flags($this->model->user_nick, array('subscribent')); 55 $redirect = true; 56 57} elseif ($this->get_param('action') == 'unsubscribe') { 58 59 $thread->remove_participant_flags($this->model->user_nick, array('subscribent')); 60 $this->add_notification($this->getLang('unsubscribed_com')); 61 $redirect = true; 62 63} elseif ($this->get_param('action') == 'invite') { 64 $client = $_POST['client']; 65 66 $thread->invite($client); 67 68 $this->add_notification($this->model->userFactory->get_user_email($client), $this->getLang('invitation_has_been_send')); 69 70 $redirect = true; 71} elseif ($this->get_param('action') == 'commcause_delete') { 72 /** @var bez\mdl\Thread_comment $thread_comment */ 73 $thread_comment = $this->model->thread_commentFactory->get_one($this->get_param('kid'), array('thread' => $thread)); 74 $this->model->thread_commentFactory->delete($thread_comment); 75 76 $redirect = true; 77} elseif ($this->get_param('action') == 'commcause_edit') { 78 /** @var bez\mdl\Thread_comment $thread_comment */ 79 $thread_comment = $this->model->thread_commentFactory->get_one($this->get_param('kid'), array('thread' => $thread)); 80 81 if(count($_POST) === 0) { 82 $this->tpl->set_values($thread_comment->get_assoc()); 83 } else { 84 $this->model->thread_commentFactory->update_save($thread_comment, $_POST); 85 86 $anchor = 'k' . $thread_comment->id; 87 $redirect = true; 88 } 89} elseif ($this->get_param('action') == 'task_add') { 90 91 $defaults = array('thread' => $thread); 92 93 if ($this->get_param('kid') != '') { 94 $thread_comment = $this->model->thread_commentFactory->get_one($this->get_param('kid'), array('thread' => $thread)); 95 $defaults['thread_comment'] = $thread_comment; 96 } 97 /** @var bez\mdl\Task $task */ 98 $task = $this->model->taskFactory->create_object($defaults); 99 $this->tpl->set('task', $task); 100 101 //save 102 if (count($_POST) > 0) { 103 $this->model->taskFactory->initial_save($task, $_POST); 104 105 $anchor = 'z' . $task->id; 106 $redirect = true; 107 } 108} elseif ($this->get_param('action') == 'task_edit') { 109 /** @var bez\mdl\Task $task */ 110 $task = $this->model->taskFactory->get_one($this->get_param('tid'), array('thread' => $thread)); 111 $this->tpl->set('task', $task); 112 113 //save 114 if (count($_POST) === 0) { 115 $this->tpl->set_values($task->get_assoc()); 116 } else { 117 $this->model->taskFactory->update_save($task, $_POST); 118 119 $anchor = 'z' . $task->id; 120 $redirect = true; 121 } 122} 123 124if (isset($redirect) && $redirect == true) { 125 if (isset($anchor)) { 126 $anchor = '#'.$anchor; 127 } else { 128 $anchor = ''; 129 } 130 header('Location: ' . $this->url('thread', 'id', $thread->id) . $anchor); 131} 132