Completed
Push — master ( b0bf1d...042f37 )
by Andreas
14:04
created

org_openpsa_sales_viewer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 32
ccs 4
cts 16
cp 0.25
rs 10
c 2
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _on_handle() 0 5 1
A get_unit_options() 0 9 2
A get_unit_option() 0 7 2
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 13
    public function _on_handle($handler, array $args)
22
    {
23 13
        $this->add_stylesheet(MIDCOM_STATIC_URL . "/org.openpsa.sales/sales.css");
24
25 13
        midcom::get()->auth->require_valid_user();
26 13
    }
27
28
    public static function get_unit_options()
29
    {
30
        $unit_options = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config')->get('unit_options');
31
        $l10n = midcom::get()->i18n->get_l10n('org.openpsa.products');
32
        $options = [];
33
        foreach ($unit_options as $key => $name) {
34
            $options[$key] = $l10n->get($name);
35
        }
36
        return $options;
37
    }
38
39
    public static function get_unit_option($unit)
40
    {
41
        $unit_options = self::get_unit_options();
42
        if (array_key_exists($unit, $unit_options)) {
43
            return $unit_options[$unit];
44
        }
45
        return '';
46
    }
47
}
48