Beispiel #1
0
 /**
  * Generates a radio awlwct box from almost anything
  * @param array $displayList
  * @param array $attribs html attributes to generate
  * @param string $defaultValue matches the key in the displayList
  * @param boolean $blank true if you want to generate a blank row
  * @returns string The resulting HTML
  */
 static function radio($name, $displayList, $attribs = array())
 {
     // If an array is here
     if (is_array($displayList) && count($displayList) > 0) {
         if (isset($attribs['side'])) {
             $side = $attribs['side'];
             unset($attribs['side']);
         } else {
             $side = 'left';
         }
         if (isset($attribs['default'])) {
             $defaultValue = $attribs['default'];
             unset($attribs['default']);
         } else {
             $defaultValue = Request::get($name, null);
         }
         $tag = array();
         $idx = 0;
         foreach ($displayList as $key => $val) {
             if (is_int($key)) {
                 $key = $val;
             }
             $key = trim($key);
             $attribs['id'] = $name . $idx++;
             $label = Tag::label($attribs['id'], ucwords(strtolower($val)));
             $radio = Tag::radio($name, $key, $defaultValue == $key, $attribs);
             if ($side == 'left') {
                 $tag[$attribs['id']] = $label . ' ' . $radio;
             } else {
                 $tag[$attribs['id']] = $radio . ' ' . $label;
             }
         }
     } else {
         if (is_object($displayList) && $displayList instanceof DBTable) {
             $newDisplayList = array();
             for ($i = 0; $i < $displayList->getRowCount(); $i++) {
                 $key = $displayList->getValue(0, $i);
                 $val = $displayList->getColumnCount() > 1 ? $displayList->getValue(1, $i) : $key;
                 $newDisplayList[' ' . $key] = $val;
             }
             $tag = self::radio($name, $newDisplayList, $attribs);
         } else {
             if (is_string($displayList)) {
                 $table = new DBTable(DB::DEF, $displayList, null, DB::FETCH_NUM);
                 $tag = self::radio($name, $table, $attribs);
             } else {
                 if (isset($attribs['default'])) {
                     $tag = Tag::hidden($name, $attribs['default']);
                 } else {
                     $tag = false;
                 }
             }
         }
     }
     return $tag;
 }