xref: /plugin/bez/mdl/Thread_comment.php (revision 8a6381983135ed7de69b33e64aa0c1b16dbf69b0)
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, $thread_id, $type, $author, $create_date, $last_modification_date, $content, $content_html, $task_count;
41
42	//virtual
43	protected $coordinator;
44
45	/** @var Thread */
46	protected  $thread;
47
48    //protected $parse_int = array('tasks_count');
49	public static function get_columns() {
50		return array('id', 'thread_id', 'type', 'author',
51                     'create_date', 'last_modification_date', 'content', 'content_html', 'task_count');
52	}
53
54    public function __get($property) {
55	    if ($property == 'coordinator' || $property == 'thread') {
56	        return $this->$property;
57        }
58        return parent::__get($property);
59    }
60
61//	public function get_virtual_columns() {
62//		return array('coordinator', 'tasks_count');
63//	}
64//
65//	public function get_table_name() {
66//		return 'commcauses';
67//	}
68
69    //defaults: isssue, type
70	public function __construct($model, $defaults=array()) {
71		parent::__construct($model, $defaults);
72
73//		$this->validator->set_rules(array(
74//			'issue' => array(array('numeric'), 'NOT NULL'),
75//			'datetime'	=> array(array('sqlite_datetime'), 'NOT NULL'),
76//			'reporter' => array(array('dw_user'), 'NOT NULL'),
77//			'type' => array(array('select', array('0', '1', '2')), 'NOT NULL'),
78//			'content' => array(array('length', 10000), 'NOT NULL'),
79//			'content_cache' => array(array('length', 10000), 'NOT NULL'),
80//
81//			'coordinator' => array(array('dw_user', array('-proposal')), 'NOT NULL')
82//		));
83
84        if (!isset($defaults['thread'])) {
85            throw new \Exception('$defaults[thread] not set');
86        }
87        $this->thread = $defaults['thread'];
88
89        $this->validator->set_rules(array(
90            //'type' => array(array('select', array('0', '1', '2')), 'NOT NULL'),
91            'content' => array(array('length', 10000), 'NOT NULL')
92        ));
93
94		//new object
95		if ($this->id === NULL) {
96
97            $this->author = $this->model->user_nick;
98            $this->create_date = date('c');
99            $this->last_modification_date = $this->create_date;
100
101
102
103			$this->thread_id = $this->thread->id;
104            $this->coordinator = $this->thread->coordinator;
105
106//            //we are coordinator of newly created object
107//            if ($issue->user_is_coordinator()) {
108//                //throws ValidationException
109//                $this->type =
110//                    $this->validator->validate_field('type', $defaults['type']);
111//            } else {
112//                $this->type = '0';
113//            }
114
115//			$this->reporter = $this->model->user_nick;
116//			$this->datetime = $this->sqlite_date();
117		}
118
119		//set validation
120        if ($this->thread->user_is_coordinator()) {
121            $this->validator->set_rules(
122                array(
123                    'type' => array(
124                        array('select', array('comment', 'cause_real', 'cause_potential', 'closing_comment')),
125                        'NOT NULL')
126                )
127            );
128        }
129	}
130
131//    public function update_cache() {
132//		if ($this->model->acl->get_level() < BEZ_AUTH_ADMIN) {
133//			return false;
134//		}
135//		$this->content_cache = $this->helper->wiki_parse($this->content);
136//	}
137//
138//	public function set_data($data, $filter=NULL) {
139//        $input = array('content', 'type');
140//        $val_data = $this->validator->validate($data, $input);
141//
142//		if ($val_data === false) {
143//			throw new ValidationException('issues',	$this->validator->get_errors());
144//		}
145//
146//        $this->set_property_array($val_data);
147
148//		$this->content_cache = $this->helper->wiki_parse($this->content);
149//    }
150
151    public function set_data($post) {
152        parent::set_data($post);
153        $this->content_html = p_render('xhtml',p_get_instructions($this->content), $ignore);
154    }
155
156//    public function get_meta_fields() {
157//        return array('reporter', 'datetime');
158//    }
159//
160//    public function set_meta($post) {
161//        parent::set_data($post, $this->get_meta_fields());
162//    }
163
164    public function mail_notify_add() {
165//        if ($thread->id !== $this->thread_id) {
166//            throw new Exception('issue object id and commcause->issue does not match');
167//        }
168
169        $rep = array(
170            'content' => $this->content,
171            'content_html' => $this->content_html,
172            'who' => $this->author,
173            'when' => $this->create_date
174        );
175
176        if ($this->type > 0) {
177            $rep['action'] = $this->model->action->getLang('mail_cause_added');
178            $rep['action_color'] = '#ffeedc';
179            $rep['action_border_color'] = '#ddb68d';
180        } else {
181            $rep['action'] = $this->model->action->getLang('mail_comment_added');
182            $rep['action_color'] = 'transparent';
183            $rep['action_border_color'] = '#E5E5E5';
184        }
185
186        $this->thread->mail_notify($rep);
187    }
188}
189