Passed
Push — master ( aa71f6...c3a704 )
by Andreas
19:49 queued 02:04
created

org_openpsa_sales_viewer::get_unit_option()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package org.openpsa.sales
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
/**
10
 * Sales viewer interface class.
11
 *
12
 * @package org.openpsa.sales
13
 */
14
class org_openpsa_sales_viewer extends midcom_baseclasses_components_viewer
15
{
16
    /**
17
     * Generic request startup work:
18
     *
19
     * - Add the LINK HTML HEAD elements
20
     */
21 12
    public function _on_handle($handler, array $args)
22
    {
23 12
        $this->add_stylesheet(MIDCOM_STATIC_URL . "/org.openpsa.sales/sales.css");
24
25 12
        midcom::get()->auth->require_valid_user();
26 12
    }
27
28 1
    public static function get_unit_options() : array
29
    {
30 1
        $unit_options = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config')->get('unit_options');
31 1
        $l10n = midcom::get()->i18n->get_l10n('org.openpsa.products');
32 1
        return array_map([$l10n, 'get'], $unit_options);
33
    }
34
35 1
    public static function get_unit_option($unit) : string
36
    {
37 1
        $unit_options = self::get_unit_options();
38 1
        if (array_key_exists($unit, $unit_options)) {
39
            return $unit_options[$unit];
40
        }
41 1
        return '';
42
    }
43
}
44