xref: /plugin/bez/ctl/task.php (revision ff14b1073c2dab2f863cab3b8baf8b1a01f7993a)
1<?php
2/** @var action_plugin_bez_default $this */
3
4use \dokuwiki\plugin\bez;
5
6if ($this->get_param('tid') == '') {
7    header('Location: ' . $this->url('tasks'));
8}
9
10/** @var bez\mdl\Task $task */
11$task = $this->model->taskFactory->get_one($this->get_param('tid'));
12$this->tpl->set('task', $task);
13$this->tpl->set('task_comments', $this->model->task_commentFactory->get_from_task($task));
14$this->tpl->set('task_programs',  $this->model->task_programFactory->get_all());
15
16if ($this->get_param('action') == 'comment_add') {
17
18    /** @var bez\mdl\Thread_comment $thread_comment */
19    $task_comment = $this->model->task_commentFactory->create_object(array('task' => $task));
20    $this->model->task_commentFactory->initial_save($task_comment, $_POST);
21
22    $anchor = 'k'.$task_comment->id;
23    $redirect = true;
24
25} elseif ($this->get_param('action') == 'subscribe') {
26
27    $task->set_participant_flags($this->model->user_nick, array('subscribent'));
28    $redirect = true;
29
30} elseif ($this->get_param('action') == 'unsubscribe') {
31
32    $task->remove_participant_flags($this->model->user_nick, array('subscribent'));
33
34    $this->add_notification($this->getLang('unsubscribed_com'));
35    $redirect = true;
36
37} elseif ($this->get_param('action') == 'invite') {
38     $client = $_POST['client'];
39
40    $task->invite($client);
41    $this->add_notification($this->model->userFactory->get_user_email($client), $this->getLang('invitation_has_been_send'));
42
43    $redirect = true;
44} elseif ($this->get_param('action') == 'comment_delete') {
45    /** @var bez\mdl\Task_comment $task_comment */
46    $task_comment = $this->model->task_commentFactory->get_one($this->get_param('zkid'), array('task' => $task));
47    $this->model->task_commentFactory->delete($task_comment);
48
49    $redirect = true;
50} elseif ($this->get_param('action') == 'comment_edit') {
51    /** @var bez\mdl\Task_comment $task_comment */
52    $task_comment = $this->model->task_commentFactory->get_one($this->get_param('zkid'), array('thread' => $thread));
53
54    if(count($_POST) === 0) {
55        $this->tpl->set_values($task_comment->get_assoc());
56    } else {
57        $this->model->task_commentFactory->update_save($task_comment, $_POST);
58
59        $anchor   = 'zk' . $task_comment->id;
60        $redirect = true;
61    }
62} elseif ($this->get_param('action') == 'task_edit') {
63    //save
64    if (count($_POST) === 0) {
65        $this->tpl->set_values($task->get_assoc());
66    } else {
67        $this->model->taskFactory->update_save($task, $_POST);
68        $redirect = true;
69    }
70}
71
72if (isset($redirect) && $redirect == true) {
73    if (isset($anchor)) {
74        $anchor = '#'.$anchor;
75    } else {
76        $anchor = '';
77    }
78    header("Location: " . $this->url('task', 'tid', $task->id) . $anchor);
79}
80
81//$template['tid'] = $nparams['tid'];
82//$template['action'] = isset($nparams['action']) ? $nparams['action'] : '-default';
83//$template['state'] = isset($nparams['state']) ? $nparams['state'] : '-1';
84//try {
85//    $task = $this->model->tasks->get_one($template['tid']);
86//    $template['task'] = $task;
87//
88//    if ($task->issue == '') {
89//        //remove userts that are subscribents already
90//        $template['users_to_invite'] = array_diff_key($this->model->users->get_all(), $task->get_subscribents());
91//    }
92//
93//
94//    if ($task->cause !== NULL && $task->cause !== '') {
95//        $template['commcause'] = $this->model->commcauses->get_one($task->cause);
96//    }
97//
98//    if ($task->issue !== NULL && $task->issue !== '') {
99//        $template['issue'] = $this->model->issues->get_one($task->issue);
100//    }
101//
102//
103//    if ($template['action'] === 'task_change_state') {
104//        if (count($_POST) > 0) {
105//            if (isset($_POST['no_evaluation'])) {
106//                $_POST['reason'] = '';
107//            }
108//
109//            $task->set_state(array(
110//                        'state' => $nparams['state'],
111//                        'reason' => $_POST['reason'])
112//                    );
113//            $this->model->tasks->save($task);
114//
115//            if (isset($template['issue'])) {
116//                $template['issue']->update_last_activity();
117//                $this->model->issues->save($template['issue']);
118//            }
119//
120//            $task->mail_notify_subscribents($template['issue'],
121//                        array('action' => $bezlang['mail_task_change_state']));
122//
123//            $redirect = true;
124//        } else {
125//            $value = $task->get_assoc();
126//        }
127//    } elseif ($template['action'] === 'task_reopen') {
128//        $task->set_state(array('state' => '0'));
129//        $this->model->tasks->save($task);
130//
131//        if (isset($template['issue'])) {
132//            $template['issue']->update_last_activity();
133//            $this->model->issues->save($template['issue']);
134//        }
135//
136//        $task->mail_notify_subscribents($template['issue'],
137//                        array('action' => $bezlang['mail_task_reopened']));
138//
139//
140//        $redirect = true;
141//    } elseif($template['action'] === 'task_edit') {
142//
143//        $template['users'] = $this->model->users->get_all();
144//        $template['tasktypes'] = $this->model->tasktypes->get_all();
145//
146//        if (isset($template['issue'])) {
147//            $template['causes'] = $this->model->commcauses->get_all(array(
148//                'issue' => $template['issue']->id,
149//                'type' => array('!=', '0'),
150//            ));
151//        }
152//
153//        if (count($_POST) > 0) {
154//            //checkboxes
155//            if (!isset($_POST['all_day_event'])) {
156//                $_POST['all_day_event'] = '0';
157//            }
158//            $task->set_data($_POST);
159//            //for reason
160//            //$task->set_state($_POST);
161//
162//            $this->model->tasks->save($task);
163//
164//            $redirect = true;
165//        } else {
166//            $value = $task->get_assoc();
167//        }
168//
169//    } elseif ($template['action'] === 'subscribe') {
170//			$task->add_subscribent($INFO['client']);
171//			$this->model->tasks->save($task);
172//
173//            header("Location: ?id=bez:task:tid:".$task->id);
174//
175//    } elseif ($template['action'] === 'unsubscribe') {
176//			$task->remove_subscribent($INFO['client']);
177//			$this->model->tasks->save($task);
178//
179//            $this->add_notification($bezlang['unsubscribed_task_com']);
180//
181//            $redirect = true;
182//
183//    } elseif ($template['action'] === 'invite') {
184//            $client = $_POST['client'];
185//
186//			$state = $task->add_subscribent($client);
187//            //user wasn't subscribent
188//            if ($state === true) {
189//                $this->model->tasks->save($task);
190//                $task->mail_notify_invite($client);
191//
192//                $this->add_notification($this->model->users->get_user_email($client), $bezlang['invitation_has_been_send']);
193//
194//                $redirect = true;
195//            }
196//
197//    } elseif($template['action'] === 'task_edit_metadata') {
198//        $template['users'] = $this->model->users->get_all();
199//
200//        if (count($_POST) > 0) {
201//            $task->set_meta($_POST);
202//            $this->model->tasks->save($task);
203//
204//            $redirect = true;
205//        } else {
206//            $value = $task->get_assoc();
207//            $value['date'] = date('Y-m-d', (int)$value['date']);
208//            $value['close_date'] = date('Y-m-d', (int)$value['close_date']);
209//        }
210//    }
211//
212//    if ($redirect) {
213//        header("Location: ?id=bez:task:tid:".$template['tid']);
214//    }
215//} catch (ValidationException $e) {
216//	$errors = $e->get_errors();
217//	$value = $_POST;
218//} catch (DBException $e) {
219//    echo nl2br($e);
220//}
221
222