Beispiel #1
0
 /**
  * Ajoute un element de type creneau de date
  *
  * @access public
  * @param  $begin array pour construire le 1er widget de date
  * @param  $end array pour construire le 2nd widget de date
  * @param  $defaultValues array valeurs par defaut
  * @return void
  */
 public function addDate2DateElement($begin, $end, $defaultValues)
 {
     /*  Construction du formulaire  */
     // L'affichage depend de la langue du user connecte
     if (!isset($begin['Format']['language'])) {
         $begin['Format']['language'] = I18N::getLocaleCode(true);
     }
     if (!isset($begin['Format']['format'])) {
         $begin['Format']['format'] = I18N::getHTMLSelectDateFormat();
     }
     if (!isset($begin['Label'])) {
         $begin['Label'] = _('From');
     }
     if (!isset($begin['Format']['minYear'])) {
         $begin['Format']['minYear'] = date('Y') - 5;
     }
     if (!isset($begin['Format']['maxYear'])) {
         $begin['Format']['maxYear'] = date('Y') + 5;
     }
     /////
     if (!isset($end['Format']['language'])) {
         $end['Format']['language'] = I18N::getLocaleCode(true);
     }
     if (!isset($end['Format']['format'])) {
         $end['Format']['format'] = I18N::getHTMLSelectDateFormat();
     }
     if (!isset($end['Label'])) {
         $end['Label'] = _(' to ');
     }
     if (!isset($end['Format']['minYear'])) {
         $end['Format']['minYear'] = date('Y') - 5;
     }
     if (!isset($end['Format']['maxYear'])) {
         $end['Format']['maxYear'] = date('Y') + 5;
     }
     $addInstruction = "\$this->_form->addElement('date', \$begin['Name'], \$begin['Label'], \$begin['Format']);";
     $addInstruction .= "\$this->_form->addElement('date', \$end['Name'], \$end['Label'], \$end['Format']);";
     eval($addInstruction);
     // le type est dynamique, pour lier ensemble les 2 criteres begin et end
     $types = array_values($this->_elementsToDisplay);
     $nbTypeDate2Date = 0;
     for ($i = 0; $i < count($types); $i++) {
         if (!(false === strpos($types[$i], 'date2date'))) {
             $nbTypeDate2Date += 1;
         }
     }
     $Date2DateIndex = $nbTypeDate2Date / 2 + 1;
     $this->_elementsToDisplay[$begin['Name']] = 'date2date' . $Date2DateIndex;
     $this->_elementsToDisplay[$end['Name']] = 'date2date' . $Date2DateIndex;
     $Default = $this->getDefaultValues();
     // affiche le form avec les valeurs par defaut
     $this->setDefaultValues(array_merge($Default, $defaultValues));
     $smarty = $this->_smarty;
     $smarty->assign('DisplayDate' . $Date2DateIndex, 'none');
     /*  Traitement special pour les creneaux de date  */
     $FilterComponentArray = array();
     if (isset($_REQUEST['DateOrder' . $Date2DateIndex]) || isset($_SESSION['DateOrder' . $Date2DateIndex]) && (!isset($_REQUEST['formSubmitted']) && !$this->isFirstArrival())) {
         $FilterComponentArray = $this->getDate2DateFilterComponent($Date2DateIndex, $begin, $end);
     }
     // n'est pas vide si des creneaux de date
     $initFilterComponentArray = $this->_filterComponentArray;
     $this->_filterComponentArray = array_merge($initFilterComponentArray, $FilterComponentArray);
 }