예제 #1
0
    /**
     * Tests resetting a select box including option groups.
     */
    public function testReset()
    {
        $tag = new SelectBoxTag();
        $tag->setContent('<select:option value="1" selected="selected">One</select:option>
<select:group label="foo">
   <group:option value="2" selected="selected">Two</group:option>
   <group:option value="3" selected="selected">Three</group:option>
</select:group>
<select:option value="4" selected="selected">Four</select:option>');
        $tag->onParseTime();
        $tag->onAfterAppend();
        // test whether all items are selected
        foreach ($tag->getChildren() as &$child) {
            if ($child instanceof SelectBoxGroupTag) {
                foreach ($child->getChildren() as &$optionChild) {
                    $this->assertEquals('selected', $optionChild->getAttribute('selected'));
                }
            } else {
                $this->assertEquals('selected', $child->getAttribute('selected'));
            }
        }
        $tag->reset();
        // test whether all items are un-selected
        foreach ($tag->getChildren() as &$child) {
            if ($child instanceof SelectBoxGroupTag) {
                foreach ($child->getChildren() as &$optionChild) {
                    $this->assertNull($optionChild->getAttribute('selected'));
                }
            } else {
                $this->assertNull($child->getAttribute('selected'));
            }
        }
    }
예제 #2
0
 /**
  * Creates the children select fields for the date control.
  *
  * @author Christian Schäfer
  * @version
  * Version 0.1, 10.01.2007<br />
  * Version 0.2, 26.08.2007 (The "class" And "style" attributes are now optional)<br />
  */
 public function onParseTime()
 {
     $this->initYearRange();
     $this->initOffsetNames();
     // create select boxes
     $day = new SelectBoxTag();
     $month = new SelectBoxTag();
     $year = new SelectBoxTag();
     // apply context and language
     $day->setLanguage($this->language);
     $month->setLanguage($this->language);
     $year->setLanguage($this->language);
     $day->setContext($this->context);
     $month->setContext($this->context);
     $year->setContext($this->context);
     // apply field names and calculate id to be able access
     // the child elements using JS
     $name = $this->getAttribute('name');
     $dayIdent = $name . '[' . $this->offsetNames['Day'] . ']';
     $monthIdent = $name . '[' . $this->offsetNames['Month'] . ']';
     $yearIdent = $name . '[' . $this->offsetNames['Year'] . ']';
     $day->setAttribute('name', $dayIdent);
     $month->setAttribute('name', $monthIdent);
     $year->setAttribute('name', $yearIdent);
     $day->setAttribute('id', $dayIdent);
     $month->setAttribute('id', $monthIdent);
     $year->setAttribute('id', $yearIdent);
     // apply "tabindex" attribute to enhance usability
     $tabIndices = $this->getTabIndices();
     if ($tabIndices !== null) {
         $day->setAttribute('tabindex', $tabIndices[0]);
         $month->setAttribute('tabindex', $tabIndices[1]);
         $year->setAttribute('tabindex', $tabIndices[2]);
     }
     $prependEmptyOption = $this->getAttribute('prepend-empty-options', 'false') === 'true';
     // set the values for the day select box
     if ($prependEmptyOption === true) {
         $day->addOption('', '');
         $day->setOption2Selected('');
     }
     for ($i = 1; $i <= 31; $i++) {
         $i = $this->appendZero($i);
         $day->addOption($i, $i);
     }
     // set the values for the month select box
     if ($prependEmptyOption === true) {
         $month->addOption('', '');
         $month->setOption2Selected('');
     }
     for ($i = 1; $i <= 12; $i++) {
         $i = $this->appendZero($i);
         $month->addOption($i, $i);
     }
     // set the values for the year select box
     if ($prependEmptyOption === true) {
         $year->addOption('', '');
         $year->setOption2Selected('');
     }
     for ($i = (int) $this->yearRange['Start']; $i <= (int) $this->yearRange['End']; $i++) {
         $yearNumber = sprintf('%04s', $i);
         $year->addOption($yearNumber, $yearNumber);
     }
     // preset today's date on startup if we have no empty options
     $request = $this->getRequest();
     $value = $request->getParameter($name);
     if ($value === null && $prependEmptyOption !== true) {
         $day->setOption2Selected($this->appendZero(date('d')));
         $month->setOption2Selected($this->appendZero(date('m')));
         $year->setOption2Selected(date('Y'));
     }
     // execute the on parse time (important for presetting!)
     $day->onParseTime();
     $month->onParseTime();
     $year->onParseTime();
     // since the onParseTime() methods directly presets the value from the request, we have
     // to correct implausible dates using the PHP DateTime API.
     if ($value !== null && is_array($value)) {
         $date = DateTime::createFromFormat('Y-m-d', $value[$this->offsetNames['Year']] . '-' . $value[$this->offsetNames['Month']] . '-' . $value[$this->offsetNames['Day']]);
         if ($date !== false) {
             $day->setOption2Selected($date->format('d'));
             $month->setOption2Selected($date->format('m'));
             $year->setOption2Selected($date->format('Y'));
         }
     }
     // reference the father object and add to the children list
     $day->setParentObject($this);
     $month->setParentObject($this);
     $year->setParentObject($this);
     $this->children['d'] = $day;
     $this->children['m'] = $month;
     $this->children['y'] = $year;
     // execute onAfterAppend() to ensure native APF environment
     $this->children['d']->onAfterAppend();
     $this->children['m']->onAfterAppend();
     $this->children['y']->onAfterAppend();
 }
예제 #3
0
 /**
  * Initializes the known child taglibs, sets the validator style and adds the multiple attribute.
  *
  * @author Christian Schäfer
  * @version
  * Version 0.1, 07.01.2007<br />
  * Version 0.2, 03.03.2007 (Removed the "&" before the "new" operator)<br />
  * Version 0.3, 26.08.2007 (Added the "multiple" attribut)<br />
  * Version 0.4, 28.08.2010 (Added option groups)<br />
  */
 public function __construct()
 {
     parent::__construct();
     $this->setAttribute('multiple', 'multiple');
     $this->attributeWhiteList[] = 'multiple';
 }
예제 #4
0
 /**
  * Creates the children select fields for the time control.
  *
  * @author Werner Liemberger
  * @version
  * Version 0.1, 21.2.2011<br />
  */
 public function onParseTime()
 {
     $this->initHoursRange();
     $this->initOffsetNames();
     if (!empty($this->attributes['minutesinterval'])) {
         $this->minutesInterval = (int) $this->attributes['minutesinterval'];
     }
     if (!empty($this->attributes['showseconds']) && $this->attributes['showseconds'] == "false") {
         $this->showSeconds = false;
     }
     // create select boxes then apply context and language
     $hours = new SelectBoxTag();
     $hours->setLanguage($this->language);
     $hours->setContext($this->context);
     $minutes = new SelectBoxTag();
     $minutes->setLanguage($this->language);
     $minutes->setContext($this->context);
     $seconds = null;
     if ($this->showSeconds != false) {
         $seconds = new SelectBoxTag();
         $seconds->setLanguage($this->language);
         $seconds->setContext($this->context);
     }
     $name = $this->getAttribute('name');
     // apply field names and calculate id to be able access
     // the child elements using JS
     $hoursIdent = $name . '[' . $this->offsetNames['Hours'] . ']';
     $hours->setAttribute('name', $hoursIdent);
     $hours->setAttribute('id', $hoursIdent);
     $minutesIdent = $name . '[' . $this->offsetNames['Minutes'] . ']';
     $minutes->setAttribute('name', $minutesIdent);
     $minutes->setAttribute('id', $minutesIdent);
     if ($this->showSeconds != false) {
         $secondsIdent = $name . '[' . $this->offsetNames['Seconds'] . ']';
         $seconds->setAttribute('name', $secondsIdent);
         $seconds->setAttribute('id', $secondsIdent);
     }
     // set the values for the hours select box
     for ($i = (int) $this->hoursRange['Start']; $i <= (int) $this->hoursRange['End']; $i++) {
         $i = $this->appendZero($i);
         $hours->addOption($i, $i);
     }
     // set the values for the minutes select box
     $i = 0;
     while ($i < 60) {
         $i = $this->appendZero($i);
         $minutes->addOption($i, $i);
         $i += $this->minutesInterval;
     }
     // set the values for the seconds select box
     if ($this->showSeconds != false) {
         for ($i = 0; $i < 60; $i++) {
             $i = $this->appendZero($i);
             $seconds->addOption($i, $i);
         }
     }
     // preset today's time on startup
     if ($this->getRequest()->getParameter($name) === null) {
         $hours->setOption2Selected($this->appendZero(date('G')));
         $minutes->setOption2Selected($this->appendZero(date('i')));
         if ($this->showSeconds != false) {
             $seconds->setOption2Selected(date('s'));
         }
     }
     // execute the on parse time (important for presetting!)
     $hours->onParseTime();
     $minutes->onParseTime();
     if ($this->showSeconds != false) {
         $seconds->onParseTime();
     }
     // reference the father object and add to the children list
     $hours->setParentObject($this);
     $minutes->setParentObject($this);
     if ($this->showSeconds != false) {
         $seconds->setParentObject($this);
     }
     $this->children['h'] = $hours;
     $this->children['m'] = $minutes;
     if ($this->showSeconds != false) {
         $this->children['s'] = $seconds;
     }
     // execute onAfterAppend() to ensure native APF environment
     $this->children['h']->onAfterAppend();
     $this->children['m']->onAfterAppend();
     if ($this->showSeconds != false) {
         $this->children['s']->onAfterAppend();
     }
 }