function isSelectedUsingBeanWrapper(&$bindStatus, $candidateValue, $propertyName)
 {
     $boundValue = SelectedValueComparator::_getBoundValue(&$bindStatus);
     if (is_null($propertyName) || !is_object($boundValue) && !is_array($boundValue)) {
         return false;
     }
     if (is_array($boundValue)) {
         foreach ($boundValue as $value) {
             $bw = new BeanWrapper($value);
             $testValue = $bw->getPropertyValue($propertyName);
             if ($testValue == $candidateValue) {
                 return true;
             }
         }
     } else {
         $bw = new BeanWrapper($boundValue);
         $testValue = $bw->getPropertyValue($propertyName);
         return $testValue == $candidateValue;
     }
     return false;
 }
Esempio n. 2
0
function options($items, $itemValue = null, $itemLabel = null, $options = array())
{
    global $request;
    $bindStatus =& $request->getAttribute('select_listValue');
    assert_not_null($bindStatus, 'options tag must be used within a select tag');
    if (!is_array($items)) {
        show_error('$items must be an array');
    }
    $contents = '';
    foreach ($items as $key => $value) {
        //TODO: optgroup
        if (is_object($value)) {
            $bw = new BeanWrapper($value);
            $iVal = is_null($itemValue) ? $value : $bw->getPropertyValue($itemValue);
            $iLabel = is_null($itemLabel) ? $value : $bw->getPropertyValue($itemLabel);
        } else {
            if (is_string($key)) {
                $iVal = $key;
                $iLabel = $value;
            } else {
                $iVal = $value;
                $iLabel = $value;
            }
        }
        $iVal = _get_display_string($iVal, $bindStatus->getEditor());
        $iLabel = _get_display_string($iLabel, $bindStatus->getEditor());
        $opt_options = array('value' => $iVal);
        if (SelectedValueComparator::isSelected($bindStatus, $iVal) || SelectedValueComparator::isSelected($bindStatus, $iLabel)) {
            $opt_options['selected'] = 'selected';
        }
        $contents .= content_tag('option', $iLabel, $opt_options);
    }
    return $contents;
}