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