Completed
Push — master ( 23e787...2652bc )
by Andreas
33:54 queued 13:51
created

org_openpsa_widgets_calendar::get_lang()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 11
ccs 6
cts 8
cp 0.75
crap 3.1406
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package org.openpsa.widgets
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
 * fullcandar-based calendar widget
11
 *
12
 * @package org.openpsa.widgets
13
 */
14
class org_openpsa_widgets_calendar extends midcom_baseclasses_components_purecode
15
{
16
    private static $prefix = '/org.openpsa.widgets/fullcalendar-5.3.0/';
17
18 4
    public static function add_head_elements(array $views)
19
    {
20 4
        $head = midcom::get()->head;
21 4
        $head->add_jsfile(MIDCOM_STATIC_URL . self::$prefix . 'lib/main.min.js');
22 4
        if ($lang = self::get_lang()) {
23
            $head->add_jsfile(MIDCOM_STATIC_URL . self::$prefix . "lib/locales/{$lang}.js");
24
        }
25
26 4
        $head->add_stylesheet(MIDCOM_STATIC_URL . self::$prefix . 'lib/main.min.css');
27 4
        $head->add_stylesheet(MIDCOM_STATIC_URL . '/org.openpsa.calendar/calendar.css');
28
29 4
        $head->add_jsfile(MIDCOM_STATIC_URL . '/org.openpsa.calendar/calendar.js');
30 4
    }
31
32 4
    public static function get_lang() : ?string
33
    {
34 4
        $lang = midcom::get()->i18n->get_current_language();
35 4
        if (file_exists(MIDCOM_STATIC_ROOT . self::$prefix . "lib/locales/{$lang}.js")) {
36
            return $lang;
37
        }
38 4
        $lang = midcom::get()->i18n->get_fallback_language();
39 4
        if (file_exists(MIDCOM_STATIC_ROOT . self::$prefix . "lib/locales/{$lang}.js")) {
40
            return $lang;
41
        }
42 4
        return null;
43
    }
44
}
45