Skip to content

Commit

Permalink
MDL-34573 tag: convert to html_writer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rossiani Wijaya committed Sep 17, 2012
1 parent 68134e4 commit 41bf308
Showing 1 changed file with 51 additions and 34 deletions.
85 changes: 51 additions & 34 deletions tag/manage.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -246,67 +246,84 @@
$table->initialbars(true); // always initial bars $table->initialbars(true); // always initial bars
$table->pagesize($perpage, $totalcount); $table->pagesize($perpage, $totalcount);


//@todo MDL-35474 convert to mform
echo '<form class="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php"><div>'; echo '<form class="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php"><div>';


//retrieve tags from DB //retrieve tags from DB
if ($tagrecords = $DB->get_records_sql($query, $params, $table->get_page_start(), $table->get_page_size())) { if ($tagrecords = $DB->get_records_sql($query, $params, $table->get_page_start(), $table->get_page_size())) {


//populate table with data //populate table with data
foreach ($tagrecords as $tag) { foreach ($tagrecords as $tag) {
$id = $tag->id; $id = $tag->id;
$name = '<a href="'.$CFG->wwwroot.'/tag/index.php?id='.$tag->id.'">'. tag_display_name($tag) .'</a>'; $params = array('id' => $tag->id);
$owner = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$tag->owner.'">' . fullname($tag) . '</a>'; $taglink = new moodle_url($CFG->wwwroot . '/tag/index.php', $params);
$count = $tag->count; $name = html_writer::link($taglink, tag_display_name($tag));
$flag = $tag->flag; $params = array('id' => $tag->owner);
$timemodified = format_time(time() - $tag->timemodified); $ownerlink = new moodle_url($CFG->wwwroot . '/user/view.php', $params);
$checkbox = '<input type="checkbox" name="tagschecked[]" value="'.$tag->id.'" />'; $owner = html_writer::link($ownerlink, fullname($tag));
$text = html_writer::label(get_string('newname', 'tag'), 'newname_' . $tag->id, false, array('class' => 'accesshide')); $count = $tag->count;
$text .= '<input type="text" id="newname_' . $tag->id. '" name="newname['.$tag->id.']" />'; $flag = $tag->flag;
$tagtype = html_writer::label(get_string('tagtype', 'tag'), 'menutagtypes'. $tag->id, false, array('class' => 'accesshide')); $timemodified = format_time(time() - $tag->timemodified);
$tagtype .= html_writer::select($existing_tagtypes, 'tagtypes['.$tag->id.']', $tag->tagtype, false, array('id' => 'menutagtypes'. $tag->id)); $checkbox = html_writer::tag('input', '', array('type' => 'checkbox', 'name' => 'tagschecked[]', 'value' => $tag->id));
$attrs = array('type' => 'text', 'id' => 'newname_' . $tag->id, 'name' => 'newname["'.$tag->id.'"]');
$text = html_writer::label(get_string('newname', 'tag'), 'newname_' . $tag->id, false, array('class' => 'accesshide'));
$text .= html_writer::empty_tag('input', $attrs);
$tagtype = html_writer::label(get_string('tagtype', 'tag'), 'menutagtypes'. $tag->id, false, array('class' => 'accesshide'));
$tagtype .= html_writer::select($existing_tagtypes, 'tagtypes['.$tag->id.']', $tag->tagtype, false, array('id' => 'menutagtypes'. $tag->id));


//if the tag if flagged, highlight it //if the tag if flagged, highlight it
if ($tag->flag > 0) { if ($tag->flag > 0) {
$id = '<span class="flagged-tag">' . $id . '</span>'; $id = html_writer::tag('span', $id, array('class' => 'flagged-tag'));
$name = '<span class="flagged-tag">' . $name . '</span>'; $name = html_writer::tag('span', $name, array('class' => 'flagged-tag'));
$owner = '<span class="flagged-tag">' . $owner . '</span>'; $owner = html_writer::tag('span', $owner, array('class' => 'flagged-tag'));
$count = '<span class="flagged-tag">' . $count . '</span>'; $count = html_writer::tag('span', $count, array('class' => 'flagged-tag'));
$flag = '<span class="flagged-tag">' . $flag . '</span>'; $flag = html_writer::tag('span', $flag, array('class' => 'flagged-tag'));
$timemodified = '<span class="flagged-tag">' . $timemodified . '</span>'; $timemodified = html_writer::tag('span', $timemodified, array('class' => 'flagged-tag'));
$tagtype = '<span class="flagged-tag">'. $tagtype. '</span>'; $tagtype = html_writer::tag('span', $tagtype, array('class' => 'flagged-tag'));
} }


$data = array($id, $name, $owner, $count, $flag, $timemodified, $text, $tagtype, $checkbox); $data = array($id, $name, $owner, $count, $flag, $timemodified, $text, $tagtype, $checkbox);


$table->add_data($data); $table->add_data($data);
} }


echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> '; echo html_writer::empty_tag('input', array('type' => 'button', 'onclick' => 'checkall()', 'value' => get_string('selectall')));
echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> '; echo html_writer::empty_tag('input', array('type' => 'button', 'onclick' => 'checknone()', 'value' => get_string('deselectall')));
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" /> '; echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo '<br/><br/>'; echo html_writer::empty_tag('br');
echo html_writer::empty_tag('br');

echo html_writer::label(get_string('withselectedtags', 'tag'), 'menuformaction', false, array('class' => 'accesshide')); echo html_writer::label(get_string('withselectedtags', 'tag'), 'menuformaction', false, array('class' => 'accesshide'));
echo '<select id="menuformaction" name="action"> $options = array('' => get_string('withselectedtags', 'tag'),
<option value="" selected="selected">'. get_string('withselectedtags', 'tag') .'</option> 'reset' => get_string('resetflag', 'tag'),
<option value="reset">'. get_string('resetflag', 'tag') .'</option> 'delete' => get_string('delete', 'tag'),
<option value="delete">'. get_string('delete', 'tag') .'</option> 'changetype' => get_string('changetype', 'tag'),
<option value="changetype">'. get_string('changetype', 'tag') .'</option> 'changename' => get_string('changename', 'tag'));
<option value="changename">'. get_string('changename', 'tag') .'</option> echo html_writer::select($options, 'action', '', array(), array('id' => 'menuformaction'));
</select>';

echo html_writer::tag('button', get_string('ok'), array('id' => 'tag-management-submit', 'type' => 'submit'));
echo '<button id="tag-management-submit" type="submit">'. get_string('ok') .'</button>';
} }


$table->print_html(); $table->print_html();

//@todo MDL-35474 convert to mform
echo '</div></form>'; echo '</div></form>';


if ($perpage == SHOW_ALL_PAGE_SIZE) { if ($perpage == SHOW_ALL_PAGE_SIZE) {
echo '<div id="showall"><a href="'. $baseurl .'&amp;perpage='. DEFAULT_PAGE_SIZE .'">'. get_string('showperpage', '', DEFAULT_PAGE_SIZE) .'</a></div>'; echo html_writer::start_tag('div', array('id' => 'showall'));
$params = array('perpage' => DEFAULT_PAGE_SIZE);
$url = new moodle_url($baseurl, $params);
echo html_writer::link($url, get_string('showperpage', '', DEFAULT_PAGE_SIZE));
echo html_writer::end_tag('div');


} else if ($totalcount > 0 and $perpage < $totalcount) { } else if ($totalcount > 0 and $perpage < $totalcount) {
echo '<div id="showall"><a href="'. $baseurl .'&amp;perpage='. SHOW_ALL_PAGE_SIZE .'">'. get_string('showall', '', $totalcount) .'</a></div>'; echo html_writer::start_tag('div', array('id' => 'showall'));
$params = array('perpage' => SHOW_ALL_PAGE_SIZE);
$url = new moodle_url($baseurl, $params);
echo html_writer::link($url, get_string('showall', '', $totalcount));
echo html_writer::end_tag('div');
} }


echo '<br/>'; echo html_writer::empty_tag('br');


echo $OUTPUT->footer(); echo $OUTPUT->footer();

0 comments on commit 41bf308

Please sign in to comment.