xref: /plugin/bez/mdl/Thread_comment.php (revision 16c7b168a60daa2c9b9ddcfa51e05d123a2a17dc)
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        ));
48
49		//new object
50		if ($this->id === NULL) {
51
52            $this->author = $this->model->user_nick;
53            $this->create_date = date('c');
54            $this->last_modification_date = $this->create_date;
55
56
57            if (!isset($defaults['thread'])) {
58                throw new \Exception('$defaults[thread] not set');
59            }
60            $this->thread = $defaults['thread'];
61			$this->thread_id = $this->thread->id;
62            $this->coordinator = $this->thread->coordinator;
63		} else {
64            if (isset($defaults['thread']) && $this->thread_id == $defaults['thread']->id) {
65                $this->thread = $defaults['thread'];
66            }
67        }
68
69
70		//set validation
71        if ($this->thread->user_is_coordinator()) {
72            $this->validator->set_rules(
73                array(
74                    'type' => array(
75                        array('select', array('comment', 'cause_real', 'cause_potential', 'closing_comment')),
76                        'NOT NULL')
77                )
78            );
79        }
80	}
81
82    public function set_data($post) {
83        parent::set_data($post);
84        $this->content_html = p_render('xhtml',p_get_instructions($this->content), $ignore);
85    }
86
87    public function mail_notify_add() {
88
89        $rep = array(
90            'content' => $this->content,
91            'content_html' => $this->content_html,
92            'who' => $this->author,
93            'when' => $this->create_date
94        );
95
96        if ($this->type > 0) {
97            $rep['action'] = $this->model->action->getLang('mail_cause_added');
98            $rep['action_color'] = '#ffeedc';
99            $rep['action_border_color'] = '#ddb68d';
100        } else {
101            $rep['action'] = $this->model->action->getLang('mail_comment_added');
102            $rep['action_color'] = 'transparent';
103            $rep['action_border_color'] = '#E5E5E5';
104        }
105
106        $this->thread->mail_notify($rep);
107    }
108}
109