Completed
Push — master ( 55ac81...18168a )
by Richard
25s queued 20s
created

DateSelect::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 2.0001

Importance

Changes 0
Metric Value
cc 2
eloc 27
nc 2
nop 0
dl 0
loc 38
rs 9.488
c 0
b 0
f 0
ccs 27
cts 28
cp 0.9643
crap 2.0001
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Form;
13
14
/**
15
 * DateSelect - date entry element with calendar popup
16
 *
17
 * @category  Xoops\Form\DateSelect
18
 * @package   Xoops\Form
19
 * @author    Kazumi Ono <[email protected]>
20
 * @copyright 2001-2016 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @link      http://xoops.org
23
 */
24
class DateSelect extends Text
25
{
26
    /**
27
     * __construct
28
     *
29
     * @param string|array      $caption caption or array of all attributes
30
     * @param string            $name    name
31
     * @param integer|\DateTime $value   unix timestamp or DateTime object
32
     */
33 7
    public function __construct($caption, $name = null, $value = null)
34
    {
35 7
        if (is_array($caption)) {
36 5
            parent::__construct($caption);
37 5
            $this->setIfNotSet('size', 15);
38 5
            $this->setIfNotSet('value', 0);
39 5
            $this->set('value', \Xoops\Core\Locale\Time::cleanTime($this->get('value', null)));
40
        } else {
41 3
            parent::__construct([]);
42 3
            $this->setCaption($caption);
43 3
            $this->setName($name);
44 3
            $this->set('size', 15);
45 3
            $this->setValue(\Xoops\Core\Locale\Time::cleanTime($value));
46
        }
47 7
    }
48
49
    /**
50
     * defaultRender
51
     *
52
     * @return string rendered form element
53
     */
54 4
    public function defaultRender()
55
    {
56 4
        $xoops = \Xoops::getInstance();
57
58 4
        $display_value = \Xoops\Core\Locale\Time::formatDate($this->getValue(false));
59
60 4
        $dataList = $this->isDatalist();
61 4
        if (!empty($dataList)) {
62
            $this->add('list', 'list_' . $this->getName());
63
        }
64
65 4
        $this->suppressRender(['value']);
66 4
        $attributes = $this->renderAttributeString();
67 4
68
        $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss');
0 ignored issues
show
Bug introduced by
'@jqueryuicss' of type string is incompatible with the type array expected by parameter $assets of Xoops\Core\Theme\XoopsTh...dBaseStylesheetAssets(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
        $xoops->theme()->addBaseStylesheetAssets(/** @scrutinizer ignore-type */ '@jqueryuicss');
Loading history...
69 4
        $xoops->theme()->addBaseScriptAssets('@jqueryui');
0 ignored issues
show
Bug introduced by
'@jqueryui' of type string is incompatible with the type array expected by parameter $assets of Xoops\Core\Theme\XoopsTheme::addBaseScriptAssets(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
        $xoops->theme()->addBaseScriptAssets(/** @scrutinizer ignore-type */ '@jqueryui');
Loading history...
70 4
        \Xoops\Core\Locale\Time::localizeDatePicker();
71 4
72
        $xoops->theme()->addScript(
73 4
            '',
74 4
            '',
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type array expected by parameter $attributes of Xoops\Core\Theme\XoopsTheme::addScript(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
            /** @scrutinizer ignore-type */ '',
Loading history...
75 4
            ' $(function() { $( "#' . $this->get('id') . '" ).datepicker({' .
0 ignored issues
show
Bug introduced by
Are you sure $this->get('id') of type false|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

75
            ' $(function() { $( "#' . /** @scrutinizer ignore-type */ $this->get('id') . '" ).datepicker({' .
Loading history...
76 4
            'showOn: "focus", changeYear: true, constrainInput: false ' .
77 4
            ' }); }); '
78 4
        );
79
        $ret = '<div>';
80
        $ret .= '<input ' . $attributes . ' value="' . $display_value . '" ' . $this->getExtra() .' >';
81 4
        $ret .= '<span>';
82 4
        $ret .= '<button type="button" ';
83 4
        $ret .= 'data-toggle="tooltip" data-placement="left" title="' . \XoopsLocale::A_SELECT . '" ';
84 4
        $ret .= 'onclick="$( \'#' . $this->get('id') . '\' ).datepicker( \'show\' );"> ';
85 4
        $ret .= '<span>...</span></button>';
86 4
        $ret .= '</span></div>';
87 4
88 4
        return $ret;
89 4
            //'<input ' . $attributes . 'value="' . $display_value . '" ' . $this->getExtra() .' >';
90
    }
91
}
92