xref: /plugin/bez/ctl/8d.php (revision bbd438ce52d241ea42077a932c307ea787417c14)
1f2f5b3feSghi<?php
29fa66638SSzymon Olewniczak/** @var action_plugin_bez $this */
39fa66638SSzymon Olewniczak
49fa66638SSzymon Olewniczakuse \dokuwiki\plugin\bez;
5e8fc7594Sghi
6e8827d73SSzymon Olewniczak//if we don't have a token, generate a new one and redirect
79fa66638SSzymon Olewniczakif (!isset($_GET['t']) && $this->model->authentication_tokenFactory->can_create_token()) {
89fa66638SSzymon Olewniczak    $token = $this->model->authentication_tokenFactory->create_token($this->id());
93be16e0fSSzymon Olewniczak    header('Location: ' .
10b4ea6b2fSSzymon Olewniczak           wl($this->id('8d', 'id', $this->get_param('id')), array('t' => $token), false, '&'));
110a8ec76dSSzymon Olewniczak}
12f2f5b3feSghi
139fa66638SSzymon Olewniczakif ($this->model->get_level() < BEZ_AUTH_VIEWER) {
149fa66638SSzymon Olewniczak    throw new bez\meta\PermissionDeniedException();
159fa66638SSzymon Olewniczak}
169fa66638SSzymon Olewniczak
17e8827d73SSzymon Olewniczak/** @var bez\mdl\Thread $thread */
18e8827d73SSzymon Olewniczak$thread = $this->model->threadFactory->get_one($this->get_param('id'));
19e8827d73SSzymon Olewniczak$this->tpl->set('thread', $thread);
2079fbde34SSzymon Olewniczak$this->tpl->set('causes',
2179fbde34SSzymon Olewniczak        $this->model->thread_commentFactory->
2279fbde34SSzymon Olewniczak        get_from_thread($thread, array('type' => 'cause'))->fetchAll());
2379fbde34SSzymon Olewniczak$this->tpl->set('risks',
2479fbde34SSzymon Olewniczak    $this->model->thread_commentFactory->
2579fbde34SSzymon Olewniczak    get_from_thread($thread, array('type' => 'risk'))->fetchAll());
2679fbde34SSzymon Olewniczak$this->tpl->set('opportunities',
2779fbde34SSzymon Olewniczak                $this->model->thread_commentFactory->
2879fbde34SSzymon Olewniczak                get_from_thread($thread, array('type' => 'opportunity'))->fetchAll());
29e8827d73SSzymon Olewniczak$tasks = $this->model->taskFactory->get_by_type($thread);
30e8827d73SSzymon Olewniczak$this->tpl->set('8d_tasks', $tasks);
3159258bb3SSzymon Olewniczak
3259258bb3SSzymon Olewniczak$all_preventive_done = true;
33*bbd438ceSSzymon Olewniczak$max_preventive_close_date = null;
3459258bb3SSzymon Olewniczakforeach ($tasks['preventive'] as $preventive_action) {
3559258bb3SSzymon Olewniczak    if ($preventive_action->state != 'done') {
3659258bb3SSzymon Olewniczak        $all_preventive_done = false;
3759258bb3SSzymon Olewniczak        break;
3859258bb3SSzymon Olewniczak    }
3959258bb3SSzymon Olewniczak    $max_preventive_close_date = max($max_preventive_close_date, $preventive_action->close_date);
4059258bb3SSzymon Olewniczak}
4159258bb3SSzymon Olewniczak
42*bbd438ceSSzymon Olewniczakif ($all_preventive_done && $max_preventive_close_date != null) {
4359258bb3SSzymon Olewniczak    $this->tpl->set('preventive_close_date', date('Y-m-d', strtotime($max_preventive_close_date)));
4459258bb3SSzymon Olewniczak}