xref: /plugin/bez/mdl/Thread_comment.php (revision fe5d6d1ebd253c129098b67fff8cf438a54d8650)
1<?php
2//
3//if(!defined('DOKU_INC')) die();
4//
5//require_once 'entity.php';
6//
7//
8//class BEZ_mdl_Dummy_Commcause extends BEZ_mdl_Entity  {
9//
10//    protected $coordinator;
11//
12//    function __construct($model, $defaults=array()) {
13//        parent::__construct($model);
14//
15//        if (!isset($defaults['issue'])) {
16//            throw new Exception('every dummy entity must have issue in $defaults');
17//        }
18//
19//        $issue = $this->model->issues->get_one($defaults['issue']);
20//        $this->coordinator = $issue->coordinator;
21//    }
22//
23//    public function __get($property) {
24//		if ($property === 'coordinator') {
25//            return $this->coordinator;
26//        }
27//        parent::__get($property);
28//	}
29//}
30//
31
32namespace dokuwiki\plugin\bez\mdl;
33
34use dokuwiki\plugin\bez\meta\PermissionDeniedException;
35use dokuwiki\plugin\bez\meta\ValidationException;
36
37class Thread_comment extends Entity {
38
39	//real
40	protected $id, $issue, $datetime, $reporter, $type, $content, $content_cache;
41
42	//virtual
43	//protected $coordinator, $tasks_count;
44
45    //protected $parse_int = array('tasks_count');
46	public static function get_columns() {
47		return array('id', 'thread_id', 'type', 'author', 'create_date', 'content', 'content_cache');
48	}
49
50//	public function get_virtual_columns() {
51//		return array('coordinator', 'tasks_count');
52//	}
53//
54//	public function get_table_name() {
55//		return 'commcauses';
56//	}
57
58    //defaults: isssue, type
59	public function __construct($model, $defaults=array()) {
60		parent::__construct($model, $defaults);
61
62		$this->validator->set_rules(array(
63			'issue' => array(array('numeric'), 'NOT NULL'),
64			'datetime'	=> array(array('sqlite_datetime'), 'NOT NULL'),
65			'reporter' => array(array('dw_user'), 'NOT NULL'),
66			'type' => array(array('select', array('0', '1', '2')), 'NOT NULL'),
67			'content' => array(array('length', 10000), 'NOT NULL'),
68			'content_cache' => array(array('length', 10000), 'NOT NULL'),
69
70			'coordinator' => array(array('dw_user', array('-proposal')), 'NOT NULL')
71		));
72
73		//new object
74		if ($this->id === NULL) {
75
76            //throws ValidationException
77			$this->issue =
78                $this->validator->validate_field('issue', $defaults['issue']);
79
80            $issue = $this->model->issues->get_one($defaults['issue']);
81
82            $this->coordinator = $issue->coordinator;
83
84            //we are coordinator of newly created object
85            if ($issue->user_is_coordinator()) {
86                //throws ValidationException
87                $this->type =
88                    $this->validator->validate_field('type', $defaults['type']);
89            } else {
90                $this->type = '0';
91            }
92
93			$this->reporter = $this->model->user_nick;
94			$this->datetime = $this->sqlite_date();
95		}
96	}
97
98    public function update_cache() {
99		if ($this->model->acl->get_level() < BEZ_AUTH_ADMIN) {
100			return false;
101		}
102		$this->content_cache = $this->helper->wiki_parse($this->content);
103	}
104
105	public function set_data($data, $filter=NULL) {
106        $input = array('content', 'type');
107        $val_data = $this->validator->validate($data, $input);
108
109		if ($val_data === false) {
110			throw new ValidationException('issues',	$this->validator->get_errors());
111		}
112
113        $this->set_property_array($val_data);
114
115		$this->content_cache = $this->helper->wiki_parse($this->content);
116    }
117
118    public function get_meta_fields() {
119        return array('reporter', 'datetime');
120    }
121
122    public function set_meta($post) {
123        parent::set_data($post, $this->get_meta_fields());
124    }
125
126    public function mail_notify_add($issue_obj) {
127        if ($issue_obj->id !== $this->issue) {
128            throw new Exception('issue object id and commcause->issue does not match');
129        }
130
131        $rep = array(
132            'content' => $this->content,
133            'content_html' => $this->content_cache,
134            'who' => $this->reporter,
135            'when' => $this->datetime
136        );
137
138        if ($this->type > 0) {
139            $rep['action'] = $this->model->action->getLang('mail_cause_added');
140            $rep['action_color'] = '#ffeedc';
141            $rep['action_border_color'] = '#ddb68d';
142        } else {
143            $rep['action'] = $this->model->action->getLang('mail_comment_added');
144            $rep['action_color'] = 'transparent';
145            $rep['action_border_color'] = '#E5E5E5';
146        }
147
148        $issue_obj->mail_notify($rep);
149    }
150}
151