xref: /plugin/bez/mdl/TaskFactory.php (revision e8827d732aaeeee6f7b703c5654f86ca97056383)
1<?php
2/**
3 * Created by PhpStorm.
4 * User: ghi
5 * Date: 12.12.17
6 * Time: 11:58
7 */
8
9namespace dokuwiki\plugin\bez\mdl;
10
11class TaskFactory extends Factory {
12    protected function select_query() {
13        return "SELECT task.*, task_program.name AS task_program_name
14                  FROM task LEFT JOIN task_program ON task.task_program_id = task_program.id";
15    }
16
17    public function get_from_thread(Thread $thread) {
18        $tasks = $this->model->taskFactory->get_all(array('thread_id' => $thread->id),
19                                            'thread_comment_id', false, array('thread' => $thread));
20        $by_thread_comment = array('corrections' => array());
21        foreach ($tasks as $task) {
22            if ($task->thread_comment_id == null) {
23                $by_thread_comment['corrections'][$task->id] = $task;
24                continue;
25            }
26            if (!isset($by_thread_comment[$task->thread_comment_id])) {
27                $by_thread_comment[$task->thread_comment_id] = array();
28            }
29            $by_thread_comment[$task->thread_comment_id][$task->id] = $task;
30        }
31        return $by_thread_comment;
32    }
33
34    public function get_by_type($thread) {
35        $tasks = $this->model->taskFactory->get_all(array('thread_id' => $thread->id),
36                                            'thread_comment_id', false, array('thread' => $thread));
37
38        $by_type = array('correction' => array(), 'corrective' => array(), 'preventive' => array());
39        foreach ($tasks as $task) {
40            $by_type[$task->type][$task->id] = $task;
41        }
42
43        return $by_type;
44    }
45
46    public function initial_save(Entity $task, $data) {
47        parent::initial_save($task, $data);
48
49        $task->set_data($data);
50        try {
51            $this->beginTransaction();
52            $this->save($task);
53
54            if ($task->thread) {
55                $task->thread->set_participant_flags($task->assignee, array('subscribent', 'task_assignee'));
56                $task->thread->update_last_activity();
57            }
58
59            $this->commitTransaction();
60        } catch(Exception $exception) {
61            $this->rollbackTransaction();
62        }
63
64        //$task->mail_notify_add();
65    }
66
67    public function update_save(Entity $task, $data) {
68        parent::update_save($task, $data);
69
70        $task->set_data($data);
71        try {
72            $this->beginTransaction();
73            $this->save($task);
74
75            if ($task->thread) {
76            }
77
78            $this->commitTransaction();
79        } catch(Exception $exception) {
80            $this->rollbackTransaction();
81        }
82    }
83}