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