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