コード例 #1
0
 static function toString($array = null, $inner_glue = '=', $outer_glue = ' ', $keepOuterKey = false)
 {
     $output = array();
     if (is_array($array)) {
         foreach ($array as $key => $item) {
             if (is_array($item)) {
                 if ($keepOuterKey) {
                     $output[] = $key;
                 }
                 // This is value is an array, go and do it again!
                 $output[] = GantryArrayHelper::toString($item, $inner_glue, $outer_glue, $keepOuterKey);
             } else {
                 $output[] = $key . $inner_glue . '"' . $item . '"';
             }
         }
     }
     return implode($outer_glue, $output);
 }
コード例 #2
0
 /**
  * Generates an HTML radio list.
  *
  * @param array An array of objects
  * @param string The value of the HTML name attribute
  * @param string Additional HTML attributes for the <select> tag
  * @param mixed The key that is selected
  * @param string The name of the object variable for the option value
  * @param string The name of the object variable for the option text
  * @return string HTML for the select list
  */
 public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false)
 {
     reset($data);
     $html = '';
     if (is_array($attribs)) {
         $attribs = GantryArrayHelper::toString($attribs);
     }
     $id_text = $idtag ? $idtag : $name;
     foreach ($data as $ind => $obj) {
         $k = $obj->{$optKey};
         $t = $translate ? JText::_($obj->{$optText}) : $obj->{$optText};
         $id = isset($obj->id) ? $obj->id : null;
         $extra = '';
         $extra .= $id ? ' id="' . $obj->id . '"' : '';
         if (is_array($selected)) {
             foreach ($selected as $val) {
                 $k2 = is_object($val) ? $val->{$optKey} : $val;
                 if ($k == $k2) {
                     $extra .= ' selected="selected"';
                     break;
                 }
             }
         } else {
             $extra .= (string) $k == (string) $selected ? ' checked="checked"' : '';
         }
         $html .= "\n\t" . '<input type="radio" name="' . $name . '"' . ' id="' . $id_text . $k . '" value="' . $k . '"' . ' ' . $extra . ' ' . $attribs . '/>' . "\n\t" . '<label for="' . $id_text . $k . '" id="' . $id_text . $k . '-lbl" class="radiobtn_' . strtolower($obj->{$optText}) . '">' . $t . '</label>';
     }
     $html .= "\n";
     return $html;
 }