diff --git a/course/lib.php b/course/lib.php
index 35be49b965a..a5628871397 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -3027,19 +3027,33 @@ function moveto_module($mod, $section, $beforemod=NULL) {
return true;
}
-function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-1, $section=-1) {
- global $CFG, $USER, $DB, $OUTPUT;
+/**
+ * Produces the editing buttons for a module
+ *
+ * @global core_renderer $OUTPUT
+ * @staticvar type $str
+ * @param stdClass $mod The module to produce editing buttons for
+ * @param bool $absolute If true an absolute link is produced (default true)
+ * @param bool $moveselect If true a move seleciton process is used (default true)
+ * @param int $indent The current indenting
+ * @param int $section The section to link back to
+ * @return string XHTML for the editing buttons
+ */
+function make_editing_buttons(stdClass $mod, $absolute = true, $moveselect = true, $indent=-1, $section=-1) {
+ global $CFG, $OUTPUT;
static $str;
- static $sesskey;
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $mod->course);
$modcontext = get_context_instance(CONTEXT_MODULE, $mod->id);
+
// no permission to edit
if (!has_capability('moodle/course:manageactivities', $modcontext)) {
return false;
}
if (!isset($str)) {
+ $str = new stdClass;
$str->assign = get_string("assignroles", 'role');
$str->delete = get_string("delete");
$str->move = get_string("move");
@@ -3056,89 +3070,21 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-
$str->groupsnone = get_string("groupsnone");
$str->groupsseparate = get_string("groupsseparate");
$str->groupsvisible = get_string("groupsvisible");
- $sesskey = sesskey();
- }
-
- if ($section >= 0) {
- $section = '&sr='.$section; // Section return
- } else {
- $section = '';
}
if ($absolute) {
- $path = $CFG->wwwroot.'/course';
+ $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
} else {
- $path = '.';
- }
- if (has_capability('moodle/course:activityvisibility', $modcontext)) {
- if ($mod->visible) {
- $hideshow = '
'."\n";
- } else {
- $hideshow = '
'."\n";
- }
- } else {
- $hideshow = '';
+ $baseurl = new moodle_url('mod.php', array('sesskey' => sesskey()));
}
- if ($mod->groupmode !== false) {
- if ($mod->groupmode == SEPARATEGROUPS) {
- $grouptitle = $str->groupsseparate;
- $groupclass = 'editing_groupsseparate';
- $groupimage = $OUTPUT->pix_url('t/groups') . '';
- $grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=0&sesskey='.$sesskey;
- } else if ($mod->groupmode == VISIBLEGROUPS) {
- $grouptitle = $str->groupsvisible;
- $groupclass = 'editing_groupsvisible';
- $groupimage = $OUTPUT->pix_url('t/groupv') . '';
- $grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=1&sesskey='.$sesskey;
- } else {
- $grouptitle = $str->groupsnone;
- $groupclass = 'editing_groupsnone';
- $groupimage = $OUTPUT->pix_url('t/groupn') . '';
- $grouplink = $path.'/mod.php?id='.$mod->id.'&groupmode=2&sesskey='.$sesskey;
- }
- if ($mod->groupmodelink) {
- $groupmode = ''.
- '
';
- } else {
- $groupmode = '
';
- }
- } else {
- $groupmode = "";
+ if ($section >= 0) {
+ $baseurl->param('sr', $section);
}
+ $actions = array();
- if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
- if ($moveselect) {
- $move = '
'."\n";
- } else {
- $move = '
'."\n".
- '
'."\n";
- }
- } else {
- $move = '';
- }
-
- $leftright = '';
- if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
-
+ // leftright
+ if (has_capability('moodle/course:update', $coursecontext)) {
if (right_to_left()) { // Exchange arrows on RTL
$rightarrow = 't/left';
$leftarrow = 't/right';
@@ -3148,39 +3094,141 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-
}
if ($indent > 0) {
- $leftright .= '
'."\n";
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')),
+ new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_moveleft', 'title' => $str->moveleft)
+ );
}
if ($indent >= 0) {
- $leftright .= '
'."\n";
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')),
+ new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_moveright', 'title' => $str->moveright)
+ );
}
}
- if (has_capability('moodle/course:managegroups', $modcontext)){
- $context = get_context_instance(CONTEXT_MODULE, $mod->id);
- $assign = '
';
- } else {
- $assign = '';
+
+ // move
+ if (has_capability('moodle/course:update', $coursecontext)) {
+ if ($moveselect) {
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('copy' => $mod->id)),
+ new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_move', 'title' => $str->move)
+ );
+ } else {
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('id' => $mod->id, 'move' => '-1')),
+ new pix_icon('t/up', $str->moveup, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_moveup', 'title' => $str->moveup)
+ );
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('id' => $mod->id, 'move' => '1')),
+ new pix_icon('t/down', $str->movedown, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_movedown', 'title' => $str->movedown)
+ );
+ }
}
- return ''."\n".$leftright.$move.
- '
'."\n".
- '
'."\n".
- '
'."\n".$hideshow.$groupmode."\n".$assign.'';
+ // Update
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('update' => $mod->id)),
+ new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_update', 'title' => $str->update)
+ );
+
+ // Duplicate
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('duplicate' => $mod->id)),
+ new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_duplicate', 'title' => $str->duplicate)
+ );
+
+ // Delete
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('delete' => $mod->id)),
+ new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_delete', 'title' => $str->delete)
+ );
+
+ // hideshow
+ if (has_capability('moodle/course:activityvisibility', $modcontext)) {
+ if ($mod->visible) {
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('hide' => $mod->id)),
+ new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_hide', 'title' => $str->hide)
+ );
+ } else {
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('show' => $mod->id)),
+ new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_show', 'title' => $str->show)
+ );
+ }
+ }
+
+ // groupmode
+ if ($mod->groupmode !== false) {
+ if ($mod->groupmode == SEPARATEGROUPS) {
+ $groupmode = 0;
+ $grouptitle = $str->groupsseparate;
+ $groupclass = 'editing_groupsseparate';
+ $groupimage = 't/groups';
+ } else if ($mod->groupmode == VISIBLEGROUPS) {
+ $groupmode = 1;
+ $grouptitle = $str->groupsvisible;
+ $groupclass = 'editing_groupsvisible';
+ $groupimage = 't/groupv';
+ } else {
+ $groupmode = 2;
+ $grouptitle = $str->groupsnone;
+ $groupclass = 'editing_groupsnone';
+ $groupimage = 't/groupn';
+ }
+ if ($mod->groupmodelink) {
+ $actions[] = new action_link(
+ new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $groupmode)),
+ new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => $groupclass, 'title' => $grouptitle.' ('.$str->clicktochange.')')
+ );
+ } else {
+ $actions[] = new pix_icon($groupimage, $grouptitle, 'moodle', array('title' => $grouptitle.' ('.$str->forcedmode.')', 'class' => 'iconsmall'));
+ }
+ }
+
+ // Assign
+ if (has_capability('moodle/course:managegroups', $modcontext)){
+ $actions[] = new action_link(
+ new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid' => $modcontext->id)),
+ new pix_icon('i/roles', $str->assign, 'moodle', array('class' => 'iconsmall')),
+ null,
+ array('class' => 'editing_assign', 'title' => $str->assign)
+ );
+ }
+
+ $output = html_writer::start_tag('span', array('class' => 'commands'));
+ foreach ($actions as $action) {
+ if ($action instanceof renderable) {
+ $output .= $OUTPUT->render($action);
+ } else {
+ $output .= $action;
+ }
+ }
+ $output .= html_writer::end_tag('span');
+ return $output;
}
/**
diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php
index c378b6286d0..8bb6d760cf3 100644
--- a/lib/outputcomponents.php
+++ b/lib/outputcomponents.php
@@ -373,6 +373,7 @@ class pix_icon implements renderable {
/**
* Constructor
* @param string $pix short icon name
+ * @param string $alt The alt text to use for the icon
* @param string $component component name
* @param array $attributes html attributes
*/
diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php
index b832df47ed1..8c223935a80 100644
--- a/lib/outputrenderers.php
+++ b/lib/outputrenderers.php
@@ -967,10 +967,16 @@ class core_renderer extends renderer_base {
protected function render_action_link(action_link $link) {
global $CFG;
+ if ($link->text instanceof renderable) {
+ $text = $this->render($link->text);
+ } else {
+ $text = $link->text;
+ }
+
// A disabled link is rendered as formatted text
if (!empty($link->attributes['disabled'])) {
// do not use div here due to nesting restriction in xhtml strict
- return html_writer::tag('span', $link->text, array('class'=>'currentlink'));
+ return html_writer::tag('span', $text, array('class'=>'currentlink'));
}
$attributes = $link->attributes;
@@ -989,7 +995,7 @@ class core_renderer extends renderer_base {
}
}
- return html_writer::tag('a', $link->text, $attributes);
+ return html_writer::tag('a', $text, $attributes);
}