nyroFwk  0.2
form/range/date.class.php
Go to the documentation of this file.
1 <?php
11 
17  protected $dates = array();
18 
24  protected $set = array('min'=>false, 'max'=>false);
25 
26  protected function afterInit() {
27  parent::afterInit();
28  $this->dates = array(
29  'min'=>factory::getHelper('date', array(
30  'timestamp'=>$this->getValue('min') ? strtotime($this->getValue('min')) : $this->cfg->defaultDate,
31  'defaultFormat'=>array(
32  'type'=>'date',
33  'len'=>'mysql'
34  )
35  )),
36  'max'=>factory::getHelper('date', array(
37  'timestamp'=>$this->getValue('max') ? strtotime($this->getValue('max')) : $this->cfg->defaultDate+$this->cfg->defaultRange,
38  'defaultFormat'=>array(
39  'type'=>'date',
40  'len'=>'mysql'
41  )
42  ))
43  );
44  }
45 
46  public function setValue($value, $refill=false, $key=null) {
47  $value = utils::htmlOut($value);
48  if (is_array($value)) {
49  $min = array_key_exists('min', $value)? $value['min'] : (array_key_exists(0, $value)? $value[0] : null);
50  $max = array_key_exists('max', $value)? $value['max'] : (array_key_exists(1, $value)? $value[1] : null);
51  $this->setValue($min, $refill, 'min');
52  $this->setValue($max, $refill, 'max');
53  } else if (!is_null($key)) {
54  if ($refill)
55  $this->dates[$key]->set($value, 'formatDate', 'short2');
56  else
57  $this->dates[$key]->set($value);
58  $this->cfg->setInArray('rangeValue', $key, $this->dates[$key]->format());
59  $this->cfg->setInArray('value', $key, $value);
60  $this->set[$key] = true;
61  }
62  }
63 
64  public function getValue($key=null, $mode='raw') {
65  if (!is_null($key)) {
66  if ($mode == 'input') {
67  $ret = $this->set[$key]? $this->dates[$key]->format('date', 'short2') : null;
68  } else
69  $ret = $this->cfg->getInArray('rangeValue', $key);
70  } else
71  $ret = $this->rangeValue;
72  return utils::htmlDeOut($ret);
73  }
74 
75  public function toHtml() {
76  if ($this->cfg->useJs) {
77  $this->cfg->setInArray('html', 'class', $this->cfg->getInArray('html', 'class').' date');
78  $resp = response::getInstance();
79  $resp->addJs('jqueryui');
80  if (($lang = request::get('lang')) != 'en')
81  $resp->addJs('i18n_ui.datepicker-'.$lang);
82  $jsPrmMin = $this->cfg->jsPrm;
83  $jsPrmMax = $this->cfg->jsPrm;
84 
85  $minId = $this->makeId($this->name.'[0]');
86  $maxId = $this->makeId($this->name.'[1]');
87 
88  $minDate = $this->dates['min']->getJs(null);
89  $maxDate = $this->dates['max']->getJs(null);
90 
91  $jsPrmMin['onSelect'] = 'function(dateText) {$("#'.$maxId.'").datepicker("option", "minDate", $("#'.$minId.'").datepicker("getDate"));}';
92  if ($maxDate)
93  $jsPrmMin['maxDate'] = $maxDate;
94  $jsPrmMax['onSelect'] = 'function(dateText) {$("#'.$minId.'").datepicker("option", "maxDate", $("#'.$maxId.'").datepicker("getDate"));}';
95  if ($minDate)
96  $jsPrmMax['minDate'] = $minDate;
97 
98  $resp->blockJquery('
99  $("#'.$minId.'").datepicker('.utils::jsEncode($jsPrmMin).');
100  $("#'.$maxId.'").datepicker('.utils::jsEncode($jsPrmMax).');
101  ');
102  }
103 
104  return parent::toHtml();
105  }
106 
107  public function toXul() {
108  return '<textbox type="number" id="'.$this->name.'" value="'.$this->value.'" min="'.$this->min.'" max="'.$this->max.'" increment="'.$this->step.'" '.utils::htmlAttribute($this->more).'/>';
109  }
110 
111 }
static get($get=null)
static htmlOut($val, $key=false)
static htmlDeOut($val, $key=false)
static jsEncode($vars)
static getHelper($className, array $cfg=array())
setValue($value, $refill=false, $key=null)
static htmlAttribute(array $prm)
Definition: utils.class.php:90
static getInstance()
getValue($key=null, $mode='raw')
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13