1<?php 2 3namespace dokuwiki\plugin\bez\mdl; 4 5class Task_comment extends Entity { 6 7 //real 8 protected $id, $task_id, $author, $create_date, $last_modification_date, $content, $content_html; 9 10 /** @var Task */ 11 protected $task; 12 13 public static function get_columns() { 14 return array('id', 'task_id', 'author', 15 'create_date', 'last_modification_date', 'content', 'content_html'); 16 } 17 18 public function __get($property) { 19 if ($property == 'task') { 20 if ($this->task_id == null) { 21 return null; 22 } 23 if ($this->task == null) { 24 $this->task = $this->model->taskFactory->get_one($this->task_id); 25 } 26 return $this->task; 27 } 28 return parent::__get($property); 29 } 30 31 public function __construct($model, $defaults=array()) { 32 parent::__construct($model, $defaults); 33 34 $this->validator->set_rules(array( 35 'content' => array(array('length', 10000), 'NOT NULL') 36 )); 37 38 //new object 39 if ($this->id === NULL) { 40 41 $this->author = $this->model->user_nick; 42 $this->create_date = date('c'); 43 $this->last_modification_date = $this->create_date; 44 45 46 if (!isset($defaults['task'])) { 47 throw new \Exception('$defaults[task] not set'); 48 } 49 $this->task = $defaults['task']; 50 $this->task_id = $this->task->id; 51 52 //we can change our own comments 53 if ($this->author == $this->model->user_nick || $this->model->get_level() >= BEZ_AUTH_LEADER) { 54 $this->acl->grant('content', BEZ_PERMISSION_CHANGE); 55 } 56 57 } else { 58 if (isset($defaults['task']) && $this->task_id == $defaults['task']->id) { 59 $this->task = $defaults['task']; 60 } 61 62 //we can change our own comments 63 if ($this->author == $this->model->user_nick || $this->model->get_level() >= BEZ_AUTH_LEADER) { 64 $this->acl->grant('id', BEZ_PERMISSION_DELETE); 65 $this->acl->grant('content', BEZ_PERMISSION_CHANGE); 66 } 67 } 68 69 } 70 public function set_data($post) { 71 parent::set_data($post); 72 $this->purge(); 73 } 74 75 protected function html_link_url() { 76 $tpl = $this->model->action->get_tpl(); 77 78 return $tpl->url('task', 'tid', $this->task_id) . '#zk' . $this->id; 79 } 80 81 protected function html_link_content() { 82 return '#zk' . $this->id; 83 } 84 85 public function mail_notify_add() { 86 $tpl = $this->model->action->get_tpl(); 87 88 $info = array(); 89 $html = p_render('bez_xhtmlmail', p_get_instructions($this->content), $info); 90 $tpl->set('content', $html); 91 $tpl->set('who', $this->author); 92 $tpl->set('when', $this->create_date); 93 $tpl->set('action', 'mail_task_comment_added'); 94 $content = $this->model->action->bez_tpl_include('mail/task_comment', true); 95 96 $this->task->mail_notify($content, false, $info['img']); 97 } 98} 99