1<?php 2 3namespace dokuwiki\plugin\bez\mdl; 4 5use dokuwiki\plugin\bez\meta\PermissionDeniedException; 6use dokuwiki\plugin\bez\meta\ValidationException; 7 8class Thread_comment extends Entity { 9 10 //real 11 protected $id, $thread_id, $type, $author, $create_date, $last_modification_date, $content, $content_html, $task_count; 12 13 //virtual 14 protected $coordinator; 15 16 /** @var Thread */ 17 protected $thread; 18 19 //protected $parse_int = array('tasks_count'); 20 public static function get_columns() { 21 return array('id', 'thread_id', 'type', 'author', 22 'create_date', 'last_modification_date', 'content', 'content_html', 'task_count'); 23 } 24 25 public function __get($property) { 26 if ($property == 'thread') { 27 if ($this->thread_id == null) { 28 return null; 29 } 30 if ($this->thread == null) { 31 $this->thread = $this->model->threadFactory->get_one($this->thread_id); 32 } 33 return $this->thread; 34 35 } elseif ($property == 'coordinator') { 36 return $this->$property; 37 } 38 return parent::__get($property); 39 } 40 41 //defaults: isssue, type 42 public function __construct($model, $defaults=array()) { 43 parent::__construct($model, $defaults); 44 45 $this->validator->set_rules(array( 46 'content' => array(array('length', 10000), 'NOT NULL'), 47 'type' => array( 48 array('select', array('comment', 'cause_real', 'cause_potential')), 49 'NOT NULL') 50 )); 51 52 //new object 53 if ($this->id === NULL) { 54 55 $this->author = $this->model->user_nick; 56 $this->create_date = date('c'); 57 $this->last_modification_date = $this->create_date; 58 59 60 if (!isset($defaults['thread'])) { 61 throw new \Exception('$defaults[thread] not set'); 62 } 63 $this->thread = $defaults['thread']; 64 $this->thread_id = $this->thread->id; 65 $this->coordinator = $this->thread->coordinator; 66 } else { 67 if (isset($defaults['thread']) && $this->thread_id == $defaults['thread']->id) { 68 $this->thread = $defaults['thread']; 69 } 70 } 71 } 72 73 public function set_data($post) { 74 //no all can change type 75 if ($this->acl_of('type') < BEZ_PERMISSION_CHANGE) { 76 unset($post['type']); 77 } 78 parent::set_data($post); 79 $this->content_html = p_render('xhtml',p_get_instructions($this->content), $ignore); 80 } 81 82 public function mail_notify_add() { 83 84 $rep = array( 85 'content' => $this->content, 86 'content_html' => $this->content_html, 87 'who' => $this->author, 88 'when' => $this->create_date 89 ); 90 91 if ($this->type > 0) { 92 $rep['action'] = $this->model->action->getLang('mail_cause_added'); 93 $rep['action_color'] = '#ffeedc'; 94 $rep['action_border_color'] = '#ddb68d'; 95 } else { 96 $rep['action'] = $this->model->action->getLang('mail_comment_added'); 97 $rep['action_color'] = 'transparent'; 98 $rep['action_border_color'] = '#E5E5E5'; 99 } 100 101 $this->thread->mail_notify($rep); 102 } 103} 104