Ejemplo n.º 1
0
 static function create_select_option($element, $entries, $fake_val, $parents, $level)
 {
     $output = "";
     foreach ($entries as $key => $entry) {
         if ($element['subtype'] == 'cat') {
             if (isset($entry->term_id)) {
                 $id = $entry->term_id;
                 $title = $entry->name;
             }
         } else {
             if (!is_array($element['subtype'])) {
                 $id = $entry->ID;
                 $title = $entry->post_title;
             } else {
                 $id = $entry;
                 $title = $key;
             }
         }
         if (!empty($title) || isset($title) && $title === 0) {
             if (empty($fake_val)) {
                 $fake_val = $title;
             }
             $selected = "";
             if ($element['std'] == $id || is_array($element['std']) && in_array($id, $element['std'])) {
                 $selected = "selected='selected'";
                 $fake_val = $title;
             }
             $indent = "";
             for ($i = 0; $i < $level; $i++) {
                 $indent .= "- ";
             }
             if (strpos($title, 'option_group_') === 0) {
                 $output .= "<optgroup label='" . $id . "'>";
             } else {
                 if (strpos($title, 'close_option_group_') === 0) {
                     $output .= "</optgroup>";
                 } else {
                     $output .= "<option {$selected} value='" . $id . "'>" . $indent . $title . "</option>";
                 }
             }
             if (!empty($parents) && !empty($parents[$id])) {
                 $level++;
                 $output .= AviaHtmlHelper::create_select_option($element, $parents[$id], $fake_val, $parents, $level);
                 $level--;
             }
         }
     }
     return $output;
 }