Passed
Push — master ( 9004ba...946be3 )
by Andreas
18:51
created

org_openpsa_projects_status::get_current_status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package org.openpsa.projects
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
/**
10
 * @package org.openpsa.projects
11
 */
12
class org_openpsa_projects_status extends org_openpsa_widgets_status
13
{
14
    /**
15
     * @var org_openpsa_projects_task_dba
16
     */
17
    private $task;
18
19
    /**
20
     * @var midcom_services_i18n_l10n
21
     */
22
    private $l10n;
23
24 1
    public function __construct(org_openpsa_projects_task_dba $task)
25
    {
26 1
        $this->l10n = midcom::get()->i18n->get_l10n('org.openpsa.projects');
27 1
        $this->task = $task;
28 1
    }
29
30 1
    public function get_current_status() : string
31
    {
32 1
        return $this->l10n->get($this->get_status_class());
33
    }
34
35 1
    public function get_status_class() : string
36
    {
37 1
        return $this->task->status_type;
0 ignored issues
show
Bug Best Practice introduced by
The property status_type does not exist on org_openpsa_projects_task_dba. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
    }
39
40 1
    public function get_button() : string
41
    {
42 1
        return '';
43
    }
44
45 1
    public function get_history() : array
46
    {
47 1
        $entries = [];
48 1
        $qb = org_openpsa_projects_task_status_dba::new_query_builder();
49 1
        $qb->add_constraint('task', '=', $this->task->id);
50 1
        $qb->add_order('id', 'DESC');
51
52 1
        $fallback_creator = midcom_db_person::get_cached(1);
53 1
        foreach ($qb->execute() as $status_change) {
54
            $status_changer_label = $this->l10n->get('system');
55
            $target_person_label = $this->l10n->get('system');
56
57
            if (    $status_change->metadata->creator
58
                 && $status_change->metadata->creator != $fallback_creator->guid) {
59
                $status_changer = org_openpsa_widgets_contact::get($status_change->metadata->creator);
60
                $status_changer_label = $status_changer->show_inline();
61
            }
62
63
            if ($status_change->targetPerson) {
64
                $target_person = org_openpsa_widgets_contact::get($status_change->targetPerson);
65
                $target_person_label = $target_person->show_inline();
66
            }
67
68
            $entries[] = [
69
                'message' => sprintf($this->l10n->get($status_change->get_status_message()), $status_changer_label, $target_person_label),
70
                'timestamp' => $status_change->metadata->created
71
            ];
72
        }
73 1
        return $entries;
74
    }
75
}
76