/// Accessibility: markup as a list.
$blogmodon = false;
- $menulist = new html_list();
- $menulist->add_class('list');
+ $menulist = array();
if (!empty($blogheaders['strview']) && $CFG->useblogassociations) {
if ($blogheaders['url']->compare($PAGE->url) == URL_MATCH_EXACT) {
- $menulist->add_item(html_writer::tag('span', array('class'=>'current'), $blogheaders['strview']));
+ $menulist[] = html_writer::tag('span', array('class'=>'current'), $blogheaders['strview']);
} else {
- $menulist->add_item(html_writer::link($blogheaders['url'], $blogheaders['strview']));
+ $menulist[] = html_writer::link($blogheaders['url'], $blogheaders['strview']);
}
}
!$PAGE->url->param('modid') && !$PAGE->url->param('courseid') && !$PAGE->url->param('userid') && !$PAGE->url->param('entryid')) {
// no
} else {
- $menulist->add_item(html_writer::add($CFG->wwwroot .'/blog/index.php', get_string('viewsiteentries', 'blog')));
+ $menulist[] = html_writer::add($CFG->wwwroot .'/blog/index.php', get_string('viewsiteentries', 'blog'));
}
}
$murl = new moodle_url('/blog/index.php', array('userid' => $USER->id));
$murl->params($blogheaders['url']->params());
$murl->param('userid', $USER->id);
- $menulist->add_item(html_writer::link($murl, get_string('viewmyentries', 'blog')));
+ $menulist[] = html_writer::link($murl, get_string('viewmyentries', 'blog'));
}
// show "Add entry" or "Blog about this" link
$aurl = new moodle_url('/blog/edit.php', array('action' => 'add'));
$aurl->params($blogheaders['url']->params());
if ($PAGE->url->compare($aurl) != URL_MATCH_EXACT) {
- $menulist->add_item(html_writer::link($aurl, $blogheaders['stradd']));
+ $menulist[] =html_writer::link($aurl, $blogheaders['stradd']);
}
}
$this->content->footer = '';
}
- $this->content->text = $OUTPUT->htmllist($menulist);
+ $this->content->text = html_writer::alist($menulist, array('class'=>'list'));
}
}
$entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4);
if (!empty($entries)) {
- $entrieslist = new html_list();
- $entrieslist->add_class('list');
+ $entrieslist = array();
$viewblogurl = new moodle_url('/blog/index.php');
foreach ($entries as $entryid => $entry) {
$viewblogurl->param('entryid', $entryid);
$entrylink = html_writer::link($viewblogurl, shorten_text($entry->subject));
- $entrieslist->add_item($entrylink);
+ $entrieslist[] = $entrylink;
}
- $this->content->text .= $OUTPUT->htmllist($entrieslist);
+ $this->content->text .= html_writer::alist($entrieslist, array('class'=>'list'));
$strview = get_string('viewsiteentries', 'blog');
if (!empty($blogheaders['strview'])) {
$strview = $blogheaders['strview'];
echo $OUTPUT->notification(get_string('importsuccess', 'grades'), 'notifysuccess');
$unenrolledusers = get_unenrolled_users_in_import($importcode, $courseid);
if ($unenrolledusers) {
- $list = new html_list();
+ $list = array();
foreach ($unenrolledusers as $u) {
$u->fullname = fullname($u);
- $list->add_item(get_string('usergrade', 'grades', $u));
+ $list[] = get_string('usergrade', 'grades', $u);
}
- echo $OUTPUT->notification(get_string('unenrolledusersinimport', 'grades', $OUTPUT->htmllist($list)), 'notifysuccess');
+ echo $OUTPUT->notification(get_string('unenrolledusersinimport', 'grades', html_writer::alist($list)), 'notifysuccess');
}
echo $OUTPUT->continue_button($CFG->wwwroot.'/grade/index.php?id='.$courseid);
}
return $label.$timerselector;
}
+ /**
+ * Shortcut for quick making of lists
+ * @param array $items
+ * @param string $tag ul or ol
+ * @param array $attributes
+ * @return string
+ */
+ public static function alist(array $items, array $attributes = null, $tag = 'ul') {
+ //note: 'list' is a reserved keyword ;-)
+
+ $output = '';
+
+ foreach ($items as $item) {
+ $output .= html_writer::start_tag('li') . "\n";
+ $output .= $item . "\n";
+ $output .= html_writer::end_tag('li') . "\n";
+ }
+
+ return html_writer::tag($tag, $attributes, $output);
+ }
+
/**
* Returns hidden input fields created from url parameters.
* @param moodle_url $url
}
-/**
- * Component representing a list.
- *
- * The advantage of using this object instead of a flat array is that you can load it
- * with metadata (CSS classes, event handlers etc.) which can be used by the renderers.
- *
- * @copyright 2009 Nicolas Connault
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.0
- */
-class html_list extends html_component {
-
- /**
- * @var array $items An array of html_list_item or html_list objects
- */
- public $items = array();
-
- /**
- * @var string $type The type of list (ordered|unordered), definition type not yet supported
- */
- public $type = 'unordered';
-
- /**
- * @var string $text An optional descriptive text for the list. Will be output as a list item before opening the new list
- */
- public $text = false;
-
- /**
- * @see lib/html_component#prepare()
- * @return void
- */
- public function prepare(renderer_base $output, moodle_page $page, $target) {
- parent::prepare($output, $page, $target);
- }
-
- /**
- * 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++;
- }
- }
-
- /**
- * Adds a html_list_item or html_list to this list.
- * If the param is a string, a html_list_item will be added.
- * @param mixed $item String, html_list or html_list_item object
- * @return void
- */
- public function add_item($item) {
- if ($item instanceof html_list_item || $item instanceof html_list) {
- $this->items[] = $item;
- } else {
- $listitem = new html_list_item();
- $listitem->value = $item;
- $this->items[] = $item;
- }
- }
-}
-
-
-/**
- * Component representing a list item.
- *
- * @copyright 2009 Nicolas Connault
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.0
- */
-class html_list_item extends html_component {
- /**
- * @var string $value The value of the list item
- */
- public $value;
-
- /**
- * @see lib/html_component#prepare()
- * @return void
- */
- public function prepare(renderer_base $output, moodle_page $page, $target) {
- parent::prepare($output, $page, $target);
- }
-}
-
/// Complex components aggregating simpler components
return $this->single_button($url, $string);
}
- /**
- * Outputs a HTML nested list
- *
- * @param html_list $list A html_list object
- * @return string HTML structure
- */
- public function htmllist($list) {
- $list = clone($list);
- $list->prepare($this, $this->page, $this->target);
-
- $this->prepare_event_handlers($list);
-
- if ($list->type == 'ordered') {
- $tag = 'ol';
- } else if ($list->type == 'unordered') {
- $tag = 'ul';
- }
-
- $output = html_writer::start_tag($tag, array('class' => $list->get_classes_string()));
-
- foreach ($list->items as $listitem) {
- if ($listitem instanceof html_list) {
- $output .= html_writer::start_tag('li', array()) . "\n";
- $output .= $this->htmllist($listitem) . "\n";
- $output .= html_writer::end_tag('li') . "\n";
- } else if ($listitem instanceof html_list_item) {
- $listitem->prepare($this, $this->page, $this->target);
- $this->prepare_event_handlers($listitem);
- $output .= html_writer::tag('li', array('class' => $listitem->get_classes_string()), $listitem->value) . "\n";
- } else {
- $output .= html_writer::tag('li', array(), $listitem) . "\n";
- }
- }
-
- if ($list->text) {
- $output = $list->text . $output;
- }
-
- return $output . html_writer::end_tag($tag);
- }
-
/**
* Prints a simple button to close a window
*
$this->assertEqual('', $html);
}
- 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);
- }
-
public function test_userpicture() {
global $CFG;
// Set up the user with the required fields