XOOPS  2.6.0
DateSelect.php
Go to the documentation of this file.
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 
25 class DateSelect extends Text
26 {
27 
36  public function __construct($caption, $name, $size = 2, $value = 0)
37  {
38  if ($value !== '') {
39  $value = ($value === 0) ? time() : intval($value);
40  }
41  parent::__construct($caption, $name, $size, 2, $value);
42  }
43 
49  public function render()
50  {
51  static $included = false;
53 
54  $ele_value = (string) $this->getValue(false);
55  $display_value = $ele_value;
56  if (0 < intval($ele_value)) {
57  $display_value = date(\XoopsLocale::getFormatShortDate(), $ele_value);
58  }
59 
60  if ($this->getSize() > $this->getMaxcols()) {
61  $maxcols = $this->getMaxcols();
62  } else {
63  $maxcols = $this->getSize();
64  }
65  $this->addAttribute('class', 'span' . $maxcols);
66  $dlist = $this->isDatalist();
67  if (!empty($dlist)) {
68  $this->addAttribute('list', 'list_' . $this->getName());
69  }
70 
72 
73  $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss');
74  $xoops->theme()->addBaseScriptAssets('@jqueryui');
75 
76  // TODO - select and apply script by locale, example:
77  // $i18nScript = 'media/jquery/ui/i18n/datepicker-es.js';
78  // $xoops->theme()->addBaseScriptAssets($i18nScript);
79 
80  $xoops->theme()->addScript(
81  '',
82  '',
83  ' $(function() { $( "#' . $this->getAttribute('id') . '" ).datepicker({' .
84  'showOn: "button", buttonImageOnly: false, ' .
85  'buttonImage: "' . $xoops->url('media/xoops/images/icons/calendar.png') .'", ' .
86  'buttonImageOnly: false, buttonText: "' . \XoopsLocale::A_SELECT . '" }); }); '
87  );
88 
89  return '<input ' . $attributes . 'value="' . $display_value . '" '
90  . $this->getExtra() .' >';
91  }
92 }
__construct($caption, $name, $size=2, $value=0)
Definition: DateSelect.php:36
static getInstance()
Definition: Xoops.php:160
getValue($encode=false)
Definition: Element.php:180
$xoops
Definition: admin.php:25
getExtra($encode=false)
Definition: Element.php:539
const A_SELECT
Definition: en_US.php:125
addAttribute($name, $value)
Definition: Attributes.php:117
static getFormatShortDate()
Definition: Abstract.php:181