コード例 #1
0
ファイル: testoutputlib.php プロジェクト: ajv/Offline-Caching
 public function test_html_list()
 {
     $htmllist = new html_list();
     $data = array('item1', 'item2', array('item1-1', 'item1-2'));
     $htmllist->load_data($data);
     $htmllist->items[2]->type = 'ordered';
     $html = $this->renderer->htmllist($htmllist);
 }
コード例 #2
0
 /**
  * This function takes a nested array of data and maps it into this list's $items array
  * as proper html_list_item and html_list objects, with appropriate metadata.
  *
  * @param array $tree A nested array (array keys are ignored);
  * @param int $row Used in identifying the iteration level and in ul classes
  * @return void
  */
 public function load_data($tree, $level = 0)
 {
     $this->add_class("list-{$level}");
     $i = 1;
     foreach ($tree as $key => $element) {
         if (is_array($element)) {
             $newhtmllist = new html_list();
             $newhtmllist->type = $this->type;
             $newhtmllist->load_data($element, $level + 1);
             $newhtmllist->text = $key;
             $this->items[] = $newhtmllist;
         } else {
             $listitem = new html_list_item();
             $listitem->value = $element;
             $listitem->add_class("list-item-{$level}-{$i}");
             $this->items[] = $listitem;
         }
         $i++;
     }
 }