xref: /plugin/bez/mdl/Task_comment.php (revision f4ba43dc4c2ffd4a56d5db3392811439ede14cfb)
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->content_html = p_render('xhtml',p_get_instructions($this->content), $ignore);
73    }
74
75    public function mail_notify_add() {
76        $rep = array(
77            'content' => $this->content,
78            'content_html' => $this->content_html,
79            'who' => $this->author,
80            'when' => $this->create_date
81        );
82
83        $rep['action'] = $this->model->action->getLang('mail_comment_added');
84        $rep['action_color'] = 'transparent';
85        $rep['action_border_color'] = '#E5E5E5';
86
87        //$this->thread->mail_notify($rep);
88    }
89}
90