/**
  * Renders the widget.
  *
  * @param  string $name        The element name
  * @param  string $value       The value selected in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (is_null($value)) {
         $value = array();
     }
     $choices = $this->getOption('choices');
     if ($choices instanceof sfCallable) {
         $choices = $choices->call();
     }
     $associated = array();
     $unassociated = array();
     foreach ($choices as $key => $option) {
         if (in_array(strval($key), $value)) {
             $associated[$key] = $option;
         } else {
             $unassociated[$key] = $option;
         }
     }
     // we sort unassociated array by name
     //asort($unassociated);
     array_multisort(array_map('strtolower', $unassociated), $unassociated);
     $size = isset($attributes['size']) ? $attributes['size'] : (isset($this->attributes['size']) ? $this->attributes['size'] : 10);
     $associatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $associated), array('size' => $size, 'class' => $this->getOption('class_select') . '-selected'));
     $unassociatedWidget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $unassociated), array('size' => $size, 'class' => $this->getOption('class_select')));
     return strtr($this->getOption('template'), array('%class%' => $this->getOption('class'), '%class_select%' => $this->getOption('class_select'), '%id%' => $this->generateId($name), '%label_associated%' => $this->getOption('label_associated'), '%label_unassociated%' => $this->getOption('label_unassociated'), '%associate%' => sprintf('<a href="#" onclick="%s">%s</a>', 'sfDoubleList.move(\'unassociated_' . $this->generateId($name) . '\', \'' . $this->generateId($name) . '\'); return false;', $this->getOption('associate')), '%unassociate%' => sprintf('<a href="#" onclick="%s">%s</a>', 'sfDoubleList.move(\'' . $this->generateId($name) . '\', \'unassociated_' . $this->generateId($name) . '\'); return false;', $this->getOption('unassociate')), '%associated%' => $associatedWidget->render($name), '%unassociated%' => $unassociatedWidget->render('unassociated_' . $name)));
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The time displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     // convert value to an array
     $default = array('hour' => null, 'minute' => null, 'second' => null);
     if (is_array($value)) {
         $value = array_merge($default, $value);
     } else {
         $value = ctype_digit($value) ? (int) $value : strtotime($value);
         if (false === $value) {
             $value = $default;
         } else {
             // int cast required to get rid of leading zeros
             $value = array('hour' => (int) date('H', $value), 'minute' => (int) date('i', $value), 'second' => (int) date('s', $value));
         }
     }
     $time = array();
     $emptyValues = $this->getOption('empty_values');
     // hours
     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['hour']) + $this->getOption('hours') : $this->getOption('hours')), array_merge($this->attributes, $attributes));
     $time['%hour%'] = $widget->render($name . '[hour]', $value['hour']);
     // minutes
     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['minute']) + $this->getOption('minutes') : $this->getOption('minutes')), array_merge($this->attributes, $attributes));
     $time['%minute%'] = $widget->render($name . '[minute]', $value['minute']);
     if ($this->getOption('with_seconds')) {
         // seconds
         $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['second']) + $this->getOption('seconds') : $this->getOption('seconds')), array_merge($this->attributes, $attributes));
         $time['%second%'] = $widget->render($name . '[second]', $value['second']);
     }
     return strtr($this->getOption('with_seconds') ? $this->getOption('format') : $this->getOption('format_without_seconds'), $time);
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The date displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     // convert value to an array
     $default = array('year' => null, 'month' => null, 'day' => null);
     if (is_array($value)) {
         $value = array_merge($default, $value);
     } else {
         $value = (string) $value == (string) (int) $value ? (int) $value : strtotime($value);
         if (false === $value) {
             $value = $default;
         } else {
             $value = array('year' => date('Y', $value), 'month' => date('n', $value), 'day' => date('j', $value));
         }
     }
     $date = array();
     $emptyValues = $this->getOption('empty_values');
     // days
     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes));
     $date['%day%'] = $widget->render($name . '[day]', $value['day']);
     // months
     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes));
     $date['%month%'] = $widget->render($name . '[month]', $value['month']);
     // years
     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes));
     $date['%year%'] = $widget->render($name . '[year]', $value['year']);
     return strtr($this->getOption('format'), $date);
 }
Example #4
0
 public function executeDcWidgetFormSelectDoubleListFinderPropel(sfWebRequest $request)
 {
     $widget = unserialize(base64_decode($request->getParameter('widget')));
     $values = unserialize(base64_decode($request->getParameter('values')));
     $values = is_null($values) ? array() : $values;
     $size = $request->getParameter('size');
     $letter = $request->getParameter('letter');
     $name = $request->getParameter('name');
     $method = $widget->getOption('method');
     $key_method = $widget->getOption('key_method');
     $column = strtoupper($widget->getOption('column'));
     $model = $widget->getOption('model') . 'Peer';
     $peer_method = $widget->getOption('peer_method');
     $connection = $widget->getOption('connection');
     if ($request->hasParameter('custom_handler')) {
         $handler = unserialize(base64_decode($request->getParameter('custom_handler')));
         @call_user_func($handler, $widget, $values);
     }
     $c = $widget->getOption('criteria');
     $c->add(constant($model . '::' . $column), $letter . '%', Criteria::LIKE);
     $choices = array();
     foreach (call_user_func(array($model, $peer_method), $c, $connection) as $choice) {
         if (!in_array($choice->getPrimaryKey(), $values)) {
             $choices[$choice->{$key_method}()] = $choice->{$method}();
         }
     }
     $widget = new sfWidgetFormSelect(array('multiple' => true, 'choices' => $choices), array('size' => $size, 'class' => $widget->getOption('class_select')));
     return $this->renderText($widget->render($name));
 }
Example #5
0
 protected function renderThemeSelect()
 {
     if ($this->container->getService('theme_manager')->getNbThemesEnabled() > 1) {
         $themeSelect = new sfWidgetFormSelect(array('choices' => $this->container->getService('theme_manager')->getThemesEnabled()));
         return $this->helper->tag('div.widget16.mt3', $themeSelect->render('dm_select_theme', $this->user->getTheme()->getName()));
     }
 }
 public function render($name, $value = 0, $attributes = array(), $errors = array())
 {
     if ($this->getOption('type') != 'select') {
         $radioWidget = new sfExtraWidgetFormSelectRadio(array('choices' => $this->getOption('choices')));
         return $radioWidget->render($name, $value, $attributes, $errors);
     } else {
         $selectWidget = new sfWidgetFormSelect(array('choices' => $this->getOption('choices')));
         return $selectWidget->render($name, $value, $attributes, $errors);
     }
 }
 /**
  * render
  *
  * @param string $name 
  * @param array  $value
  * @param array  $attributes
  * @param array  $errors
  *
  * @return string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = array(), $attributes = array(), $errors = array())
 {
     if (!is_array($value)) {
         $value = array('value' => $value, 'public_flag' => ProfileTable::PUBLIC_FLAG_SNS);
     } else {
         $value = array_merge(array('value' => null, 'public_flag' => ProfileTable::PUBLIC_FLAG_SNS), $value);
     }
     $input = $this->getOption('widget')->render($name . '[value]', $value['value'], $attributes, $errors);
     if (!$this->getOption('is_edit_public_flag')) {
         return $input;
     }
     $publicFlagWidget = new sfWidgetFormSelect(array('choices' => Doctrine::getTable('Profile')->getPublicFlags()));
     return strtr($this->getOption('template'), array('%input%' => $input, '%public_flag%' => $publicFlagWidget->render($name . '[public_flag]', $value['public_flag'], $attributes, $errors)));
 }
 /**
  * Renders the widget.
  *
  * @param  string $name        The element name
  * @param  string $value       The time displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (array_key_exists('class', $attributes)) {
         $attributes['class'] .= ' timepicker';
     } else {
         $attributes['class'] = 'timepicker';
     }
     // convert value to an array
     $default = array('hour' => null, 'minute' => null);
     if (is_array($value)) {
         $value = array_merge($default, $value);
     } else {
         $value = ctype_digit($value) ? (int) $value : strtotime($value);
         if (false === $value) {
             $value = $default;
         } else {
             // int cast required to get rid of leading zeros
             $value = array('hour' => (int) date('H', $value), 'minute' => (int) date('i', $value));
         }
     }
     $widget = new sfWidgetFormSelect(array('choices' => $this->getChoices(), 'id_format' => $this->getOption('id_format')), array_merge($this->attributes, $attributes));
     if (is_numeric($value['hour']) && is_numeric($value['minute'])) {
         $value = sprintf('%02d', $value['hour']) . ':' . sprintf('%02d', $value['minute']);
     } else {
         $value = '';
     }
     return $widget->render($name, $value);
 }
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $culture = sfContext::getInstance()->getUser()->getCulture();
     $this->addOption('culture', $culture);
     $this->addOption('languages');
     $languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($options['languages']) ? $options['languages'] : null);
     $cultures = sfCultureInfo::getInstance($culture)->getCultures();
     $countries = sfCultureInfo::getInstance($culture)->getCountries();
     $values = array();
     foreach ($cultures as $key => $culture_info) {
         if (strlen($culture_info) == 5) {
             $culture_small = substr($culture_info, 0, 2);
             $countrie_small = substr($culture_info, 3, 2);
             if (array_key_exists($culture_small, $languages) && array_key_exists($countrie_small, $countries)) {
                 $select_language = preg_replace('/^[' . $culture_small . ']{2}/i', $languages[$culture_small], $culture_info);
                 $select = preg_replace('/[' . $countrie_small . ']{2}$/i', '(' . $countries[$countrie_small] . ')', $select_language);
                 $values[$culture_info] = ucfirst(str_replace('_', ' ', $select));
             }
         }
     }
     if (count($values) == 0) {
         $values[''] = 'No languages found';
     }
     asort($values);
     $this->setOption('choices', $values);
 }
Example #10
0
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('text', 'Enllaç');
     $this->addRequiredOption('url', '#');
     $this->addRequiredOption('id', '');
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if ($value && is_string($value)) {
         $value = PetitionText::getHashForId($value);
     }
     return parent::render($name, $value, $attributes, $errors);
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $emptyValue = $this->getOption('empty_value');
     if ($this->getOption('use') == 'days') {
         $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValue) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes));
         $result = $widget->render($name, $value);
     }
     if ($this->getOption('use') == 'months') {
         $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValue) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes));
         $result = $widget->render($name, $value);
     }
     if ($this->getOption('use') == 'years') {
         $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValue) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes));
         $result = $widget->render($name, $value);
     }
     return $result;
 }
 /**
  * @see sfWidgetFormDate
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $dateTimeValue = is_array($value) ? sprintf('%04d-%02d-%02d', $value['year'], $value['month'], $value['day']) : $value;
     try {
         $dateTime = new DateTime($dateTimeValue);
     } catch (Exception $e) {
         $dateTime = new DateTime();
         $dateTimeValue = null;
     }
     $dayDefault = $dateTime->format('j');
     $monthDefault = $dateTime->format('n');
     $year = $dateTime->format('Y');
     $days = $this->getOption('days');
     $months = $this->getOption('months');
     if ($this->getOption('can_be_empty')) {
         $emptyValues = $this->getOption('empty_values');
         $days = array('' => $emptyValues['day']) + $days;
         $months = array('' => $emptyValues['month']) + $months;
         if (!$dateTimeValue) {
             $dayDefault = $emptyValues['day'];
             $monthDefault = $emptyValues['month'];
             $year = $emptyValues['year'];
         }
     }
     if (is_array($value) && !checkdate((int) $value['month'], (int) $value['day'], (int) $value['year'])) {
         $dayDefault = $value['day'];
         $monthDefault = $value['month'];
         $year = $value['year'];
     }
     // days
     $widget = new sfWidgetFormSelect(array('choices' => $days), array_merge($this->attributes, $attributes));
     $date['%day%'] = $widget->render($name . '[day]', $dayDefault);
     // months
     $widget = new sfWidgetFormSelect(array('choices' => $months), array_merge($this->attributes, $attributes));
     $date['%month%'] = $widget->render($name . '[month]', $monthDefault);
     // years
     $attributes['size'] = '5';
     $widget = new sfWidgetFormInput(array(), array_merge(array('class' => 'input_text'), $this->attributes, $attributes));
     if ('mobile_frontend' === sfConfig::get('sf_app')) {
         opToolkit::appendMobileInputModeAttributesForFormWidget($widget, 'numeric');
     }
     $date['%input_year%'] = $widget->render($name . '[year]', $year);
     return strtr($this->getOption('format'), $date);
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * model:      The model class (required)
  *  * add_empty:  Whether to add a first empty value or not (false by default)
  *                If the option is not a Boolean, the value will be used as the text value
  *  * method:     The method to use to display object values (__toString by default)
  *  * order_by:   An array composed of two fields:
  *                  * The column to order by the results (must be in the PhpName format)
  *                  * asc or desc
  *  * criteria:   A criteria to use when retrieving objects
  *  * connection: The Doctrine connection to use (null by default)
  *  * multiple:   true if the select tag must allow multiple selections
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     $this->addRequiredOption('model');
     $this->addOption('add_empty', false);
     $this->addOption('method', '__toString');
     $this->addOption('order_by', null);
     $this->addOption('criteria', null);
     $this->addOption('connection', null);
     $this->addOption('multiple', false);
     parent::configure($options, $attributes);
 }
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     //
     // option value for 'all' checkbox. Set to a valid option to enable the 'All' option
     //
     $this->addOption('show_all_option', true);
     $this->addOption('all_option_label', __('All'));
     $this->addOption('show_root', false);
     $this->addOption('indent', true);
     $this->addOption('indent_string', "&nbsp;&nbsp;");
     // Parent requires the 'choices' option.
     $this->addOption('choices', array());
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:    The culture to use for internationalized strings (required)
  *  * currencies: An array of currency codes to use (ISO 639-1)
  *  * add_empty:  Whether to add a first empty value or not (false by default)
  *                If the option is not a Boolean, the value will be used as the text value
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('culture');
     $this->addOption('currencies');
     $this->addOption('add_empty', false);
     // populate choices with all currencies
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $currencies = sfCultureInfo::getInstance($culture)->getCurrencies(isset($options['currencies']) ? $options['currencies'] : null);
     $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
     if (false !== $addEmpty) {
         $currencies = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $currencies);
     }
     $this->setOption('choices', $currencies);
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The value displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $input = parent::render($name, $value, $attributes, $errors);
     if (!$this->getOption('edit_mode')) {
         return $input;
     }
     if ($this->getOption('with_delete')) {
         $deleteName = ']' == substr($name, -1) ? substr($name, 0, -1) . '_delete]' : $name . '_delete';
         $delete = $this->renderTag('input', array_merge(array('type' => 'checkbox', 'name' => $deleteName), $attributes));
         $deleteLabel = $this->translate($this->getOption('delete_label'));
         $deleteLabel = $this->renderContentTag('label', $deleteLabel, array_merge(array('for' => $this->generateId($deleteName))));
     } else {
         $delete = '';
         $deleteLabel = '';
     }
     return strtr($this->getOption('template'), array('%input%' => $input, '%delete%' => $delete, '%delete_label%' => $deleteLabel));
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings (required)
  *  * languages: An array of language codes to use (ISO 639-1)
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('culture');
     $this->addOption('languages');
     // populate choices with all languages
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     $cultureInfo = new sfCultureInfo($culture);
     $languages = $cultureInfo->getLanguages();
     // restrict languages to a sub-set
     if (isset($options['languages'])) {
         if ($problems = array_diff($options['languages'], array_keys($languages))) {
             throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
         }
         $languages = array_intersect_key($languages, array_flip($options['languages']));
     }
     asort($languages);
     $this->setOption('choices', $languages);
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture:   The culture to use for internationalized strings (required)
  *  * languages: An array of language codes to use (ISO 639-1)
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     // populate choices with all cultures
     $choices = array();
     $cultures = sfCultureInfo::getCultures(sfCultureInfo::SPECIFIC);
     foreach ($cultures as $culture) {
         // skip en_US_POSIX
         if ($culture == "en_US_POSIX") {
             continue;
         }
         try {
             $choices[$culture] = sfCultureInfo::getInstance($culture)->getEnglishName();
         } catch (sfException $e) {
         }
     }
     asort($choices);
     $this->setOption('choices', $choices);
 }
Example #20
0
 protected function getSelectSettingWidget(DmSetting $setting)
 {
     $widget = new sfWidgetFormSelect(array('choices' => $setting->getParamsArray()));
     return $widget->setDefault($setting->get('value'));
 }
 /**
  * @param string $name
  * @param string $value
  * @param array $options
  * @param array $attributes
  * @return string rendered widget
  */
 protected function renderYearWidget($name, $value, $options, $attributes)
 {
   $widget = new sfWidgetFormSelect($options, $attributes);
   return $widget->render($name, $value);
 }
<?php

$select = new sfWidgetFormSelect(array('choices' => $buses));
$result = $select->render('buses_from_route');
echo json_encode(array('buses' => $result));
 /**
  * Gets the stylesheet paths associated with the widget.
  *
  * The array keys are files and values are the media names (separated by a ,):
  *
  *   array('/path/to/file.css' => 'all', '/another/file.css' => 'screen,print')
  *
  * @return array An array of stylesheet paths
  */
 public function getStylesheets()
 {
     return array_merge(parent::getStylesheets(), array("/dcReloadedFormExtraPlugin/css/select_jquery_autocomplete.css" => "all"));
 }
slot('title');
?>
  <?php 
echo 'Online information of routes and itineraries - NoJam';
end_slot();
?>

<h1>Routes</h1>
<div class="column span-8 box">
    <div class="filter">
      <?php 
$select = new sfWidgetFormDoctrineChoice(array('model' => 'NjRoute', 'add_empty' => 'Select a route'), array('class' => 'select-box'));
echo $select->render('nj_route_id');
?>
      <?php 
$select = new sfWidgetFormSelect(array('choices' => $buses), array('class' => 'select-box'));
echo $select->render('buses_from_route');
?>
    </div>
    <br />
    <hr class="space"/>
    <div>
      <table>
        <thead>
          <th colspan="100%"><h2>Schedules</h2></th>
        </thead>
        <tfoot>
          <th colspan="100%">Schedules</th>
        </tfoot>
        <tbody>
          <?php 
 public function getStylesheets()
 {
     $styleSheets = parent::getStylesheets();
     $styleSheets[plugin_web_path('orangehrmCorePlugin', 'css/ohrmWidgetSelectableGroupDropDown.css')] = 'all';
     return $styleSheets;
 }
 /**
  * Configures the current widget.
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormSelect
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->setOption('multiple', true);
 }
 public function getStylesheets()
 {
     $styleSheets = parent::getStylesheets();
     $styleSheets['/orangehrmCorePlugin/css/ohrmWidgetSelectableGroupDropDown.css'] = 'all';
     return $styleSheets;
 }
 /**
  * @see sfWidget
  */
 protected function configure($options = array(), $attributes = array())
 {
     $this->addOption('add_empty', false);
     $this->addOption('full', true);
     parent::configure($options, $attributes);
 }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        if (empty($value) || !is_array($value)) {
            $value = array();
        }
        $defaultDuration = $this->getOption('default_duration');
        if (!isset($value['duration'])) {
            $value['duration'] = $defaultDuration;
        }
        if (!isset($value['ampm'])) {
            $value['ampm'] = self::HALF_DAY_AM;
        }
        if (!isset($value['time'])) {
            $value['time'] = $this->getDefaultTimeRangeValues();
        }
        $durationChoices = array();
        if ($this->getOption('enable_full_day')) {
            $durationChoices['full_day'] = __('Full Day');
        }
        if ($this->getOption('enable_half_day')) {
            $durationChoices['half_day'] = __('Half Day');
        }
        if ($this->getOption('enable_specify_time')) {
            $durationChoices['specify_time'] = __('Specify Time');
        }
        $hideCss = 'style="display:none"';
        $durationWidget = new sfWidgetFormSelect(array('choices' => $durationChoices), array('class' => 'leave_duration_dropdown'));
        $halfDayWidget = new sfWidgetFormSelect(array('choices' => array(self::HALF_DAY_AM => __('Morning'), self::HALF_DAY_PM => __('Afternoon'))), array('class' => 'leave_duration_ampm'));
        // if
        $timeWidget = new ohrmWidgetFormTimeRange(array('from_time' => new ohrmWidgetTimeDropDown(), 'to_time' => new ohrmWidgetTimeDropDown()));
        // IDs
        $fullDayContentId = $this->generateId($name . '[full_day_content]');
        $halfDayContentId = $this->generateId($name . '[half_day_content]');
        $specifyTimeContentId = $this->generateId($name . '[specify_time_content]');
        $fullDayContent = strtr($this->getOption('full_day_template'), array('%full_day_content_id%' => $fullDayContentId, '%display%' => $defaultDuration == 'full_day' ? '' : $hideCss));
        $halfDayContent = strtr($this->getOption('half_day_template'), array('%half_day_content_id%' => $halfDayContentId, '%am_pm%' => $halfDayWidget->render($name . '[ampm]', $value['ampm']), '%display%' => $defaultDuration == 'half_day' ? '' : $hideCss));
        $specifyTimeContent = strtr($this->getOption('specify_time_content'), array('%specify_time_content_id%' => $specifyTimeContentId, '%time_range%' => $timeWidget->render($name . '[time]', $value['time']), '%display%' => $defaultDuration == 'specify_time' ? '' : $hideCss));
        $html = strtr($this->getOption('template'), array('%duration%' => $durationWidget->render($name . '[duration]', $value['duration']), '%full_day_content%' => $fullDayContent, '%half_day_content%' => $halfDayContent, '%specify_time_content%' => $specifyTimeContent));
        $javaScript = <<<EOF
<script type="text/javascript">

    \$(document).ready(function(){
        orangehrm.widgets.formLeaveDuration.handleDurationChange(\$("#%duration_id%").val(), '%full_day_content_id%', '%half_day_content_id%', '%specify_time_content_id%');
        \$("#%duration_id%").change(function() {
            orangehrm.widgets.formLeaveDuration.handleDurationChange(\$(this).val(), '%full_day_content_id%', '%half_day_content_id%', '%specify_time_content_id%');
        });    
    });

</script>
EOF;
        $javaScript = strtr($javaScript, array('%duration_id%' => $this->generateId($name . '[duration]'), '%full_day_content_id%' => $fullDayContentId, '%half_day_content_id%' => $halfDayContentId, '%specify_time_content_id%' => $specifyTimeContentId));
        return $html . $javaScript;
    }
$t->diag('choices as a callable');
function choice_callable()
{
    return array(1, 2, 3);
}
$w = new sfWidgetFormSelect(array('choices' => new sfCallable('choice_callable')));
$dom->loadHTML($w->render('foo'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('#foo option')->getNodes()), 3, '->render() accepts a sfCallable as a choices option');
// attributes
$t->diag('attributes');
$w = new sfWidgetFormSelect(array('choices' => array(0, 1, 2)));
$dom->loadHTML($w->render('foo', null, array('disabled' => 'disabled')));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 1, '->render() does not pass the select HTML attributes to the option tag');
$t->is(count($css->matchAll('option[disabled="disabled"]')->getNodes()), 0, '->render() does not pass the select HTML attributes to the option tag');
$w = new sfWidgetFormSelect(array('choices' => array(0, 1, 2)), array('disabled' => 'disabled'));
$dom->loadHTML($w->render('foo'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 1, '->render() does not pass the select HTML attributes to the option tag');
$t->is(count($css->matchAll('option[disabled="disabled"]')->getNodes()), 0, '->render() does not pass the select HTML attributes to the option tag');
// __clone()
$t->diag('__clone()');
$w = new sfWidgetFormSelect(array('choices' => new sfCallable(array($w, 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object');
$w = new sfWidgetFormSelect(array('choices' => new sfCallable(array($a = new stdClass(), 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($a), '__clone() changes nothing if the choices is a callable and the object is not an instance of the current object');