xref: /plugin/bez/mdl/Task_commentFactory.php (revision a0cd8c785f18b483f73582b411767428d04a78f6)
1<?php
2
3namespace dokuwiki\plugin\bez\mdl;
4
5class Task_commentFactory extends Factory {
6
7    public function get_from_task(Task $task) {
8        return $this->get_all(array('task_id' => $task->id), $orderby='', $desc=true, array('task' => $task));
9    }
10
11    /**
12     * @param Thread_comment $thread_comment
13     * @param                $data
14     * @throws \Exception
15     */
16    public function initial_save(Entity $task_comment, $data) {
17        try {
18            $this->beginTransaction();
19
20            //if empty content and task_do, do not save the comment
21            if ($data['fn'] == 'comment_add' || $data['content'] != '') {
22                parent::initial_save($task_comment, $data);
23                $task_comment->task->set_participant_flags($task_comment->author, array('subscribent', 'commentator'));
24            }
25
26            if ($data['fn'] == 'task_do') {
27                $task_comment->task->set_state('done');
28            } elseif ($data['fn'] == 'task_reopen') {
29                $task_comment->task->set_state('opened');
30            }
31
32            if ($task_comment->task->thread_id != '') {
33                $task_comment->task->thread->update_last_activity();
34            }
35
36            $this->commitTransaction();
37        } catch(Exception $exception) {
38            $this->rollbackTransaction();
39        }
40
41        $task_comment->mail_notify_add();
42    }
43
44    public function update_save(Entity $task_comment, $data) {
45        try {
46            $this->beginTransaction();
47            parent::update_save($task_comment, $data);
48
49            $task_comment->task->update_last_activity();
50
51            $this->commitTransaction();
52        } catch(Exception $exception) {
53            $this->rollbackTransaction();
54        }
55    }
56
57    public function delete(Entity $obj) {
58        try {
59            $this->beginTransaction();
60
61            parent::delete($obj);
62            $obj->task->update_last_activity();
63
64            $this->commitTransaction();
65        } catch(Exception $exception) {
66            $this->rollbackTransaction();
67        }
68    }
69}