xref: /plugin/bez/mdl/Thread_commentFactory.php (revision addc91ee3302cfabdbe6588b98874f0b355a06f3)
1<?php
2
3namespace dokuwiki\plugin\bez\mdl;
4
5class Thread_commentFactory extends Factory {
6
7    public function get_table_view() {
8        return 'thread_comment_view';
9    }
10
11    public function get_from_thread(Thread $thread, $filters=array(), $orderby='', $desc=true, $limit=false) {
12        $filters['thread_id'] = $thread->id;
13        return $this->get_all($filters, $orderby, $desc, array('thread' => $thread), $limit);
14    }
15
16    /**
17     * @param Thread_comment $thread_comment
18     * @param                $data
19     * @throws \Exception
20     */
21    public function initial_save(Entity $thread_comment, $data) {
22        try {
23            $this->beginTransaction();
24
25            if ($data['fn'] == 'comment_add' ||
26                $data['fn'] == 'thread_close' ||
27                $data['content'] != '') {
28                parent::initial_save($thread_comment, $data);
29                $thread_comment->thread->set_participant_flags($thread_comment->author, array('subscribent', 'commentator'));
30            }
31
32            if ($data['fn'] == 'thread_close') {
33                $thread_comment->thread->set_state('closed');
34            } elseif ($data['fn'] == 'thread_reject') {
35                $thread_comment->thread->set_state('rejected');
36            } elseif ($data['fn'] == 'thread_reopen') {
37                $thread_comment->thread->set_state('opened');
38            }
39
40            $thread_comment->thread->update_last_activity();
41
42            $this->commitTransaction();
43        } catch(Exception $exception) {
44            $this->rollbackTransaction();
45        }
46
47        $thread_comment->mail_notify_add();
48    }
49
50    public function update_save(Entity $thread_comment, $data) {
51        try {
52            $this->beginTransaction();
53            parent::update_save($thread_comment, $data);
54
55            $thread_comment->thread->update_last_activity();
56
57            $this->commitTransaction();
58        } catch(Exception $exception) {
59            $this->rollbackTransaction();
60        }
61    }
62
63    public function delete(Entity $obj) {
64        try {
65            $this->beginTransaction();
66
67            parent::delete($obj);
68            $obj->thread->update_last_activity();
69
70            $this->commitTransaction();
71        } catch(Exception $exception) {
72            $this->rollbackTransaction();
73        }
74    }
75}