public function test_attributes() { $tag = new mr_html_tag(); $link = $tag->a('Click me!')->title('This " should be encoded')->href('http://google.com')->class('foo'); $link->prepend_class('bar')->append_class('baz')->remove_title(); $this->assertEqual($link->close(), '<a href="http://google.com" class="bar foo baz">Click me!</a>'); $strong = $tag->strong()->foo('bar'); $strong->append_attributes(array('foo' => 'har', 'bat' => 'baz')); $strong->prepend_attributes(array('foo' => 'tar', 'bat' => 'haz', 'foo2' => 'bar2')); $strong->add_attributes(array('dingo' => '8', 'jet' => 'jaz')); $this->assertEqual($strong->get_foo(), 'tar bar har'); $this->assertEqual($strong->get_bat(), 'haz baz'); $this->assertEqual($strong->get_dingo(), '8'); $this->assertEqual($strong->get_jet(), 'jaz'); $this->assertEqual($strong->get_foo2(), 'bar2'); $strong->remove_attributes(array('foo', 'bat')); $this->assertFalse($strong->get_foo()); $this->assertFalse($strong->get_bat()); }
/** * Render mr_html_table * * @param mr_html_table $table mr_html_table instance * @return string */ protected function render_mr_html_table(mr_html_table $table) { $tag = new mr_html_tag(); $rows = $table->get_rows(); $columns = $table->get_columns(true); // Table setup $htmltable = new html_table(); $htmltable->data = array(); foreach ($table->get_attributes() as $name => $value) { if (property_exists($htmltable, $name)) { $htmltable->{$name} = $value; } else { $htmltable->attributes[$name] = $value; } } // Check if we have any column headings $haveheadings = false; foreach ($columns as $column) { if ($column->has_heading()) { $haveheadings = true; break; } } if ($haveheadings) { $htmltable->head = array(); foreach ($columns as $column) { // Must set sortable to false if table is not sort enabled or if empty $rows if (!$table->get_sortenabled() or empty($rows)) { $column->set_config('sortable', false); } $config = $column->get_config(); // Figure out column sort controls if ($config->sortable) { $icon = ''; $sortstr = get_string('asc'); $sortord = SORT_ASC; if ($table->get_sort() == $column->get_name()) { if ($table->get_order() == SORT_ASC) { $icon = $tag->img()->src($this->output->pix_url('t/down'))->alt(get_string('asc')); $sortstr = get_string('asc'); $sortord = SORT_DESC; } else { $icon = $tag->img()->src($this->output->pix_url('t/up'))->alt(get_string('desc')); } } $url = $table->get_url()->out(false, array('tsort' => $config->name, 'torder' => $sortord)); $heading = get_string('sortby') . ' ' . $config->heading . ' ' . $sortstr; $heading = $config->heading . get_accesshide($heading); $heading = $tag->a($heading)->href($url) . $icon; } else { $heading = $config->heading; } $cell = new html_table_cell($heading); $cell->attributes = array_merge($cell->attributes, $config->attributes); $htmltable->head[] = $cell; } } if (empty($rows)) { $cell = new html_table_cell($table->get_emptymessage()); $cell->colspan = count($htmltable->head); $htmltable->data[] = new html_table_row(array($cell)); } else { $htmltable->data = $this->convert_to_htmlrows($table); } return html_writer::tag('div', html_writer::table($htmltable), array('class' => 'mr_html_table')); }