xref: /plugin/bez/ctl/thread_report.php (revision de02284c1e90f3c0d8df29c1c019b3ef912eafd9)
1<?php
2
3use \dokuwiki\plugin\bez;
4
5if ($this->model->acl->get_level() < BEZ_AUTH_USER) {
6    throw new bez\meta\PermissionDeniedException();
7}
8
9
10if (isset($nparams['id']) && is_numeric($nparams['id'])) {
11	$thread_id = (int)$nparams['id'];
12	/** @var \dokuwiki\plugin\bez\mdl\Thread $thread */
13	$thread = $this->model->threadFactory->get_one($thread_id);
14
15	$tpl->set('thread', $thread);
16}
17//else {
18	//$template['thread'] = $this->model->issues->create_dummy_object();
19	//$template['priority'] = 'None';
20//}
21
22//$action = '';
23//if (isset($nparams['action'])) {
24//	$action = $nparams['action'];
25//}
26
27try {
28	if ($this->param('action') == 'edit') {
29		if (!isset($thread)) {
30			throw new Exception('there is now row with given id');
31		}
32		//$template['form_action'] = 'update';
33		//$value = $thread->get_assoc();
34        $this->tpl->set_values($thread->get_assoc());
35	} elseif ($this->param('action') == 'update') {
36		//$template['form_action'] = 'update';
37
38        $prev_coordiantor = $thread->coordinator;
39
40		$thread->set_data($_POST);
41
42        $thread->add_participant($thread->coordinator);
43
44        //save to get ID!!!
45        $this->model->threadFactory->save($thread);
46
47        if ($thread->coordinator !== '-proposal' &&
48            $INFO['client'] !== $thread->coordinator &&
49            $thread->coordinator != $prev_coordiantor) {
50            //coordinator becomes subscribent automaticly
51            $thread->add_subscribent($thread->coordinator);
52            $this->model->threadFactory->save($thread);
53
54            $thread->mail_inform_coordinator();
55        }
56
57		header('Location: ?id='.$this->id('thread', 'id', $thread->id));
58	} elseif ($this->param('action') == 'add') {
59		//$template['form_action'] = 'add';
60
61        $defaults = array();
62        if ($this->model->acl->get_level() >= BEZ_AUTH_LEADER) {
63            $defaults['coordinator'] = $_POST['coordinator'];
64        }
65        $thread = $this->model->threadFactory->create_object($defaults);
66
67        $data = array(
68//            'type' => $_POST['type'],
69            'title' => $_POST['title'],
70            'content' => $_POST['content']
71        );
72        $thread->set_data($data);
73
74        try {
75            $this->model->threadFactory->beginTransaction();
76
77            $this->model->threadFactory->save($thread);
78
79            $thread->add_label($_POST['label']);
80
81            $thread->set_participant_flags($thread->original_poster, array('original_poster', 'subscribent'));
82            if($thread->coordinator != null) {
83                $thread->set_participant_flags($thread->coordinator, array('coordinator', 'subscribent'));
84            }
85            $this->model->threadFactory->commitTransaction();
86        } catch(Exception $exception) {
87            $this->model->threadFactory->rollbackTransaction();
88        }
89
90
91//        if ($thread->coordinator !== '-proposal' &&
92//            $INFO['client'] !== $thread->coordinator) {
93//            //coordinator becomes subscribent automaticly
94//            $thread->add_subscribent($issue->coordinator);
95//            $this->model->issues->save($thread);
96//
97//            $thread->mail_inform_coordinator();
98//        }
99
100
101		header('Location: ?id='.$this->id('thread', 'id', $thread->id));
102
103	}
104//	else {
105//		$template['form_action'] = 'add';
106//	}
107
108} catch (bez\meta\ValidationException $e) {
109	$errors = $e->get_errors();
110	$value = $_POST;
111}
112
113//$template['issuetypes'] = $this->model->issuetypes->get_all();
114$this->tpl->set('users', $this->model->userFactory->get_all());
115$this->tpl->set('labels', $this->model->labelFactory->get_all());