From 8ae8bf8a14d7ea1d427308fea4bfc3b4f60bde0c Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 2 Jan 2010 13:17:54 +0000 Subject: [PATCH] MDL-21198 OUTPUT->action_icon improvements, refactoring and fixing conversion regressions --- admin/filters.php | 18 +-- .../block_global_navigation_tree.php | 28 ++--- blocks/rss_client/managefeeds.php | 20 ++-- .../block_settings_navigation_tree.php | 30 ++--- blog/external_blogs.php | 20 ++-- blog/locallib.php | 16 +-- grade/edit/tree/lib.php | 29 ++--- grade/export/keymanager.php | 22 +--- grade/import/keymanager.php | 20 +--- grade/lib.php | 106 ++++++------------ grade/report/grader/lib.php | 41 +++---- lib/deprecatedlib.php | 4 +- lib/outputactions.php | 6 +- lib/outputcomponents.php | 59 ---------- lib/outputrenderers.php | 72 +++++++----- lib/weblib.php | 4 +- repository/filepicker.php | 12 +- user/index.php | 9 +- user/portfoliologs.php | 16 +-- 19 files changed, 174 insertions(+), 358 deletions(-) diff --git a/admin/filters.php b/admin/filters.php index 9249be943b9..4cd44867147 100644 --- a/admin/filters.php +++ b/admin/filters.php @@ -224,18 +224,12 @@ /// Display helper functions =================================================== -function action_url($filterpath, $action) { +function filters_action_url($filterpath, $action) { global $returnurl; return $returnurl . '?sesskey=' . sesskey() . '&filterpath=' . urlencode($filterpath) . '&action=' . $action; } -function action_icon($url, $icon, $straction) { - global $CFG, $OUTPUT; - return '' . - '' . $straction . ' '; -} - function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) { global $CFG, $OUTPUT, $activechoices, $applytochoices, $filternames; $row = array(); @@ -249,7 +243,7 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) } // Disable/off/on - $select = html_select::make_popup_form(action_url($filter, 'setstate'), 'newstate', $activechoices, 'active' . basename($filter), $filterinfo->active); + $select = html_select::make_popup_form(filters_action_url($filter, 'setstate'), 'newstate', $activechoices, 'active' . basename($filter), $filterinfo->active); $select->nothinglabel = false; $select->form->button->text = get_string('save', 'admin'); $row[] = $OUTPUT->select($select); @@ -259,12 +253,12 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) $spacer = ' '; if ($filterinfo->active != TEXTFILTER_DISABLED) { if (!$isfirstrow) { - $updown .= action_icon(action_url($filter, 'up'), 'up', get_string('up')); + $updown .= $OUTPUT->action_icon(filters_action_url($filter, 'up'), get_string('up'), 't/up'); } else { $updown .= $spacer; } if (!$islastactive) { - $updown .= action_icon(action_url($filter, 'down'), 'down', get_string('down')); + $updown .= $OUTPUT->action_icon(filters_action_url($filter, 'down'), get_string('down'), 't/down'); } else { $updown .= $spacer; } @@ -272,7 +266,7 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) $row[] = $updown; // Apply to strings. - $select = html_select::make_popup_form(action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, 'applyto' . basename($filter), $applytostrings); + $select = html_select::make_popup_form(filters_action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, 'applyto' . basename($filter), $applytostrings); $select->nothinglabel = false; $select->disabled = $filterinfo->active == TEXTFILTER_DISABLED; $select->form->button->text = get_string('save', 'admin'); @@ -288,7 +282,7 @@ function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) // Delete if (substr($filter, 0, 4) != 'mod/') { - $row[] = '' . get_string('delete') . ''; + $row[] = '' . get_string('delete') . ''; } else { $row[] = ''; } diff --git a/blocks/global_navigation_tree/block_global_navigation_tree.php b/blocks/global_navigation_tree/block_global_navigation_tree.php index 9f7a65966b0..b5c54e4d36b 100644 --- a/blocks/global_navigation_tree/block_global_navigation_tree.php +++ b/blocks/global_navigation_tree/block_global_navigation_tree.php @@ -159,33 +159,21 @@ class block_global_navigation_tree extends block_tree { // Grab the items to display $this->content->items = array($this->page->navigation); - $reloadicon = new moodle_action_icon(); - $reloadicon->link->url = $this->page->url; - $reloadicon->link->url->param('regenerate','navigation'); - $reloadicon->link->add_class('customcommand'); - $reloadicon->image->src = $OUTPUT->pix_url('t/reload'); - $reloadicon->image->alt = get_string('reload'); - $reloadicon->title = get_string('reload'); - $this->content->footer .= $OUTPUT->action_icon($reloadicon); + $this->content->footer .= $OUTPUT->action_icon($this->page->url, get_string('reload'), array('class'=>'customcommand'), 't/reload'); if (empty($this->config->enablesidebarpopout) || $this->config->enablesidebarpopout == 'yes') { user_preference_allow_ajax_update('nav_in_tab_panel_globalnav'.block_global_navigation_tree::$navcount, PARAM_INT); - $moveicon = new moodle_action_icon(); - $moveicon->link->add_classes('moveto customcommand requiresjs'); - $moveicon->link->url = $this->page->url; + $movelink = new html_link($this->page->url); + $movelink->add_classes('moveto customcommand requiresjs'); if ($this->docked) { - $moveicon->image->src = $OUTPUT->pix_url('t/movetoblock'); - $moveicon->image->alt = $toggleblockdisplay; - $moveicon->image->title = $toggleblockdisplay; - $moveicon->link->url->param('undock', $this->instance->id); + $movelink->url->param('undock', $this->instance->id); + $moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetoblock'); } else { - $moveicon->image->src = $OUTPUT->pix_url('t/movetosidetab'); - $moveicon->image->alt = $togglesidetabdisplay; - $moveicon->image->title = $togglesidetabdisplay; - $moveicon->link->url->param('dock', $this->instance->id); + $movelink->url->param('dock', $this->instance->id); + $moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetosidetab'); } - $this->content->footer .= $OUTPUT->action_icon($moveicon); + $this->content->footer .= $moveicon; } // Set content generated to true so that we know it has been done diff --git a/blocks/rss_client/managefeeds.php b/blocks/rss_client/managefeeds.php index 6d6364efde0..650b41feb07 100644 --- a/blocks/rss_client/managefeeds.php +++ b/blocks/rss_client/managefeeds.php @@ -117,21 +117,15 @@ foreach($feeds as $feed) { '
' . $OUTPUT->link($feed->url, $feed->url) .'
' . '
' . $feed->description . '
'; - $editaction = new moodle_action_icon(); - $editaction->link->url = $CFG->wwwroot .'/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams; - $editaction->link->title = get_string('edit'); - $editaction->image->src = $OUTPUT->pix_url('t/edit'); - $editaction->image->alt = get_string('edit'); + $editurl = $CFG->wwwroot .'/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams; + $editaction = $OUTPUT->action_icon($editurl, get_string('edit'), 't/edit'); - $deleteaction = new moodle_action_icon(); - $deleteaction->link->url = $CFG->wwwroot .'/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . - '&sesskey=' . sesskey() . $extraparams; - $deleteaction->link->title = get_string('delete'); - $deleteaction->image->src = $OUTPUT->pix_url('t/delete'); - $deleteaction->image->alt = get_string('delete'); - $deleteaction->link->add_confirm_action(get_string('deletefeedconfirm', 'block_rss_client')); + $deleteurl = $CFG->wwwroot .'/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . '&sesskey=' . sesskey() . $extraparams; + $deletelink = new html_link($deleteurl); + $deletelink->add_confirm_action(get_string('deletefeedconfirm', 'block_rss_client')); + $deleteaction = $OUTPUT->action_icon($deletelink, get_string('delete'), 't/delete'); - $feedicons = $OUTPUT->action_icon($editaction) . ' ' . $OUTPUT->action_icon($deleteaction); + $feedicons = $editaction . ' ' . $deleteaction; $table->add_data(array($feedinfo, $feedicons)); } diff --git a/blocks/settings_navigation_tree/block_settings_navigation_tree.php b/blocks/settings_navigation_tree/block_settings_navigation_tree.php index d2a8783e60b..6b976197d31 100644 --- a/blocks/settings_navigation_tree/block_settings_navigation_tree.php +++ b/blocks/settings_navigation_tree/block_settings_navigation_tree.php @@ -140,35 +140,23 @@ class block_settings_navigation_tree extends block_tree { $this->content->footer = ''; } - $reloadicon = new moodle_action_icon(); - $url = $this->page->url; - $url->param('regenerate','navigation'); - $reloadicon->link->url = $url; - $reloadicon->link->add_class('customcommand'); - $reloadicon->image->src = $OUTPUT->pix_url('t/reload'); - $reloadicon->image->alt = get_string('reload'); - $reloadicon->title = get_string('reload'); + $reloadicon = $OUTPUT->action_icon($this->page->url, get_string('reload'), 't/reload', array('class'=>'customcommand')); - $this->content->footer .= $OUTPUT->action_icon($reloadicon); + $this->content->footer .= $reloadicon; if (!empty($this->config->enablesidebarpopout) && $this->config->enablesidebarpopout == 'yes') { user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings_navigation_tree::$navcount, PARAM_INT); - $moveicon = new moodle_action_icon(); - $moveicon->link->add_classes('moveto customcommand requiresjs'); - $moveicon->link->url = $this->page->url; + $movelink = new html_link($this->page->url); + $movelink->add_classes('moveto customcommand requiresjs'); if ($this->docked) { - $moveicon->image->src = $OUTPUT->pix_url('t/movetoblock'); - $moveicon->image->alt = $toggleblockdisplay; - $moveicon->image->title = $toggleblockdisplay; - $moveicon->link->url->param('undock', $this->instance->id); + $movelink->url->param('undock', $this->instance->id); + $moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetoblock'); } else { - $moveicon->image->src = $OUTPUT->pix_url('t/movetosidetab'); - $moveicon->image->alt = $togglesidetabdisplay; - $moveicon->image->title = $togglesidetabdisplay; - $moveicon->link->url->param('dock', $this->instance->id); + $movelink->url->param('dock', $this->instance->id); + $moveicon = $OUTPUT->action_icon($movelink, $toggleblockdisplay, 't/movetosidetab'); } - $this->content->footer .= $OUTPUT->action_icon($moveicon); + $this->content->footer .= $moveicon; } } diff --git a/blog/external_blogs.php b/blog/external_blogs.php index c69f8028685..92a165db42e 100644 --- a/blog/external_blogs.php +++ b/blog/external_blogs.php @@ -78,20 +78,14 @@ if (!empty($blogs)) { $validicon = $OUTPUT->image('i/tick_green_big', array('alt'=>get_string('feedisvalid', 'blog'), 'title'=>get_string('feedisvalid', 'blog'))); } - $editicon = new moodle_action_icon; - $editicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id)); - $editicon->link->title = get_string('editexternalblog', 'blog'); - $editicon->image->src = $OUTPUT->pix_url('t/edit'); - $editicon->image->alt = get_string('editexternalblog', 'blog'); + $editurl = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id)); + $editicon = $OUTPUT->action_icon($editurl, get_string('editexternalblog', 'blog'), 't/edit'); - $deleteicon = new moodle_action_icon; - $deleteicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey' => sesskey())); - $deleteicon->link->title = get_string('deleteexternalblog', 'blog'); - $deleteicon->image->src = $OUTPUT->pix_url('t/delete'); - $deleteicon->image->alt = get_string('deleteexternalblog', 'blog'); - $deleteicon->add_confirm_action(get_string('externalblogdeleteconfirm', 'blog')); - $icons = $OUTPUT->action_icon($editicon) . $OUTPUT->action_icon($deleteicon); - $table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $icons)); + $deletelink = new html_link(new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id, 'sesskey'=>sesskey()))); + $deletelink->add_confirm_action(get_string('externalblogdeleteconfirm', 'blog')); + $deleteicon = $OUTPUT->action_icon($deletelink, get_string('deleteexternalblog', 'blog'), 't/delete'); + + $table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $editicon . $deleteicon)); } echo $OUTPUT->table($table); } diff --git a/blog/locallib.php b/blog/locallib.php index 9da02c7a83f..c718a02cf37 100644 --- a/blog/locallib.php +++ b/blog/locallib.php @@ -237,11 +237,9 @@ class blog_entry { foreach ($blogassociations as $assocrec) { $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid)); if ($contextrec->contextlevel == CONTEXT_COURSE) { - $associcon = new moodle_action_icon(); - $associcon->link->url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $contextrec->instanceid)); - $associcon->image->src = $OUTPUT->pix_url('i/course'); - $associcon->linktext = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid)); - $assocstr .= $OUTPUT->action_icon($associcon); + $url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $contextrec->instanceid)); + $text = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid)); //TODO: performance!!!! + $assocstr .= $OUTPUT->action_icon($associconurl, $text, 'i/course'); $hascourseassocs = true; $assoctype = get_string('course'); } @@ -260,11 +258,9 @@ class blog_entry { $modinfo = $DB->get_record('course_modules', array('id' => $contextrec->instanceid)); $modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module)); - $associcon = new moodle_action_icon(); - $associcon->link->url = new moodle_url($CFG->wwwroot.'/mod/'.$modname.'/view.php', array('id' => $modinfo->id)); - $associcon->image->src = $OUTPUT->pix_url('icon', $modname); - $associcon->linktext = $DB->get_field($modname, 'name', array('id' => $modinfo->instance)); - $assocstr .= $OUTPUT->action_icon($associcon); + $url = new moodle_url($CFG->wwwroot.'/mod/'.$modname.'/view.php', array('id' => $modinfo->id)); + $text = $DB->get_field($modname, 'name', array('id' => $modinfo->instance)); //TODO: performance!!!! + $assocstr .= $OUTPUT->action_icon($associconurl, $text, $OUTPUT->pix_url('icon', $modname)); $assocstr .= ', '; $assoctype = get_string('modulename', $modname); diff --git a/grade/edit/tree/lib.php b/grade/edit/tree/lib.php index 0ad6c417d51..ef3e5a5a53b 100755 --- a/grade/edit/tree/lib.php +++ b/grade/edit/tree/lib.php @@ -135,22 +135,12 @@ class grade_edit_tree { if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) { if ($this->element_deletable($element)) { - $actionicon = new moodle_action_icon(); - $actionicon->link->url = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey())); - $actionicon->image->src = $OUTPUT->pix_url('t/delete'); - $actionicon->image->alt = get_string('delete'); - $actionicon->image->title = get_string('delete'); - $actionicon->image->add_class('iconsmall'); - $actions .= $OUTPUT->action_icon($actionicon); + $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey())); + $actions .= $OUTPUT->action_icon($aurl, get_string('delete'), 't/delete', array('class'=>'iconsmall')); } - $actionicon = new moodle_action_icon(); - $actionicon->link->url = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey())); - $actionicon->image->src = $OUTPUT->pix_url('t/move'); - $actionicon->image->alt = get_string('move'); - $actionicon->image->title = get_string('move'); - $actionicon->image->add_class('iconsmall'); - $actions .= $OUTPUT->action_icon($actionicon); + $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey())); + $actions .= $OUTPUT->action_icon($aurl, get_string('move'), 't/move', array('class'=>'iconsmall')); } $actions .= $this->gtree->get_hiding_icon($element, $this->gpr); @@ -218,19 +208,14 @@ class grade_edit_tree { $strmovehere = get_string('movehere'); $actions = ''; // no action icons when moving - $moveicon = new moodle_action_icon(); - $moveicon->link->url = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey())); + $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey())); if ($first) { - $moveicon->link->url->params($first); + $aurl->params($first); } - $moveicon->image->add_class('movetarget'); - $moveicon->image->src = $OUTPUT->pix_url('movehere'); - $moveicon->image->alt = $strmovehere; - $moveicon->image->title = $strmovehere; $cell = new html_table_cell(); $cell->colspan = 12; - $cell->text = $OUTPUT->action_icon($moveicon); + $cell->text = $OUTPUT->action_icon($aurl, $strmovehere, 'movehere', array('class'=>'movetarget')); $moveto = html_table_row::make(array($cell)); } diff --git a/grade/export/keymanager.php b/grade/export/keymanager.php index 84f0f246db8..d09d9c63513 100644 --- a/grade/export/keymanager.php +++ b/grade/export/keymanager.php @@ -53,26 +53,16 @@ if ($keys) { $line[1] = $key->iprestriction; $line[2] = empty($key->validuntil) ? get_string('always') : userdate($key->validuntil); - $icon = new moodle_action_icon(); - $icon->link->url = new moodle_url('key.php'); + $url = new moodle_url('key.php'); if (!empty($key->id)) { - $icon->link->url->param('id', $key->id); + $url->param('id', $key->id); } - $icon->image->add_class('iconsmall'); - $editicon = clone($icon); - $editicon->image->src = $OUTPUT->pix_url('t/edit'); - $editicon->image->title = $stredit; - $editicon->image->alt = $stredit; - $buttons = $OUTPUT->action_icon($editicon); + $buttons = $OUTPUT->action_icon($url, $stredit, 't/edit', array('class'=>'iconsmall')); - $deleteicon = clone($icon); - $deleteicon->image->src = $OUTPUT->pix_url('t/delete'); - $deleteicon->image->title = $strdelete; - $deleteicon->image->alt = $strdelete; - $deleteicon->link->url->param('delete', 1); - $deleteicon->link->url->param('sesskey', sesskey()); - $buttons .= $OUTPUT->action_icon($deleteicon); + $url->param('delete', 1); + $url->param('sesskey', sesskey()); + $buttons .= $OUTPUT->action_icon($url, $strdelete, 't/delete', array('class'=>'iconsmall')); $line[3] = $buttons; $data[] = $line; diff --git a/grade/import/keymanager.php b/grade/import/keymanager.php index 8d6ff0fef9d..46c4b7fbb5f 100644 --- a/grade/import/keymanager.php +++ b/grade/import/keymanager.php @@ -53,23 +53,13 @@ if ($keys = $DB->get_records_select('user_private_key', "script='grade/import' A $line[1] = $key->iprestriction; $line[2] = empty($key->validuntil) ? get_string('always') : userdate($key->validuntil); - $icon = new moodle_action_icon(); - $icon->link->url = new moodle_url('key.php', array('id' => $key->id)); - $icon->image->add_class('iconsmall'); + $url = new moodle_url('key.php', array('id' => $key->id)); - $editicon = clone($icon); - $editicon->image->src = $OUTPUT->pix_url('t/edit'); - $editicon->image->title = $stredit; - $editicon->image->alt = $stredit; - $buttons = $OUTPUT->action_icon($editicon); + $buttons = $OUTPUT->action_icon($url, $stredit, 't/edit'); - $deleteicon = clone($icon); - $deleteicon->image->src = $OUTPUT->pix_url('t/delete'); - $deleteicon->image->title = $strdelete; - $deleteicon->image->alt = $strdelete; - $deleteicon->link->url->param('delete', 1); - $deleteicon->link->url->param('sesskey', sesskey()); - $buttons .= $OUTPUT->action_icon($deleteicon); + $url->param('delete', 1); + $url->param('sesskey', sesskey()); + $buttons .= $OUTPUT->action_icon($url, $strdelete, 't/delete'); $line[3] = $buttons; $data[] = $line; diff --git a/grade/lib.php b/grade/lib.php index d835ba9da49..9593542be56 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -1456,14 +1456,7 @@ class grade_structure { } if ($url) { - $url = $gpr->add_url_params($url); - $editicon = new moodle_action_icon(); - $editicon->link->url = $url; - $editicon->image->src = $OUTPUT->pix_url('t/edit'); - $editicon->image->alt = $stredit; - $editicon->image->title = $stredit; - $editicon->image->add_class('iconsmall'); - return $OUTPUT->action_icon($editicon); + return $OUTPUT->action_icon($gpr->add_url_params($url), $stredit, 't/edit', array('class'=>'iconsmall')); } else { return ''; @@ -1490,37 +1483,29 @@ class grade_structure { $strshow = get_string('showverbose', 'grades', $strparams); $strhide = get_string('hideverbose', 'grades', $strparams); - $hideicon = new moodle_action_icon(); - $hideicon->image->add_class('iconsmall'); - $hideicon->link->add_class('hide'); - $hideicon->link->url = new moodle_url($CFG->wwwroot.'/grade/edit/tree/action.php', - array('id' => $this->courseid, 'sesskey' => sesskey(), 'eid' => $element['eid'])); + $url = new moodle_url($CFG->wwwroot.'/grade/edit/tree/action.php', array('id' => $this->courseid, 'sesskey' => sesskey(), 'eid' => $element['eid'])); + $url = $gpr->add_url_params($url); if ($element['object']->is_hidden()) { - $icon = 'show'; + $type = 'show'; $tooltip = $strshow; // Change the icon and add a tooltip showing the date if ($element['type'] != 'category' and $element['object']->get_hidden() > 1) { - $icon = 'hiddenuntil'; + $type = 'hiddenuntil'; $tooltip = get_string('hiddenuntildate', 'grades', userdate($element['object']->get_hidden())); } - $hideicon->link->url->param('action', 'show'); - $hideicon->image->src = $OUTPUT->pix_url('t/' . $icon); - $hideicon->image->alt = $strshow; - $hideicon->image->title = $tooltip; + $url->param('action', 'show'); + $hideicon = $OUTPUT->action_icon($url, $title, 't/'.$type, array('alt'=>$strshow, 'class'=>'iconsmall')); } else { - $hideicon->link->url->param('action', 'hide'); - $hideicon->image->src = $OUTPUT->pix_url('t/hide'); - $hideicon->image->alt = $strhide; - $hideicon->image->title = $strhide; + $url->param('action', 'hide'); + $hideicon = $OUTPUT->action_icon($url, $strhide, 't/hide', array('class'=>'iconsmall')); } - $hideicon->link->url = $gpr->add_url_params($hideicon->link->url); - return $OUTPUT->action_icon($hideicon); + return $hideicon; } /** @@ -1538,13 +1523,8 @@ class grade_structure { $strunlock = get_string('unlockverbose', 'grades', $strparams); $strlock = get_string('lockverbose', 'grades', $strparams); - $lockicon = new moodle_action_icon(); - $lockicon->link->url = new moodle_url($CFG->wwwroot.'/grade/edit/tree/action.php', array( - 'id' => $this->courseid, - 'sesskey' => sesskey(), - 'eid' => $element['eid'])); - $lockicon->link->url = $gpr->add_url_params($lockicon->link->url); - $lockicon->image->add_class('iconsmall'); + $url = new moodle_url($CFG->wwwroot.'/grade/edit/tree/action.php', array('id' => $this->courseid, 'sesskey' => sesskey(), 'eid' => $element['eid'])); + $url = $gpr->add_url_params($url); // Don't allow an unlocking action for a grade whose grade item is locked: just print a state icon if ($element['type'] == 'grade' && $element['object']->grade_item->is_locked()) { @@ -1553,42 +1533,34 @@ class grade_structure { $strnonunlockable = get_string('nonunlockableverbose', 'grades', $strparamobj); $action = $OUTPUT->image('t/unlock_gray', array('alt'=>$strnonunlockable, 'title'=>$strnonunlockable, 'class'=>'iconsmall')); - $action = $OUTPUT->image($lockicon); + } else if ($element['object']->is_locked()) { - $icon = 'unlock'; + $type = 'unlock'; $tooltip = $strunlock; // Change the icon and add a tooltip showing the date if ($element['type'] != 'category' and $element['object']->get_locktime() > 1) { - $icon = 'locktime'; + $type = 'locktime'; $tooltip = get_string('locktimedate', 'grades', userdate($element['object']->get_locktime())); } - if (!has_capability('moodle/grade:manage', $this->context) and - !has_capability('moodle/grade:unlock', $this->context)) { - return ''; + if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:unlock', $this->context)) { + $action = ''; + } else { + $url->param('action', 'unlock'); + $action = $OUTPUT->action_icon($url, $tooltip, 't/'.$type, array('alt'=>$strunlock, 'class'=>'smallicon')); } - $lockicon->link->url->param('action', 'unlock'); - $lockicon->link->add_class('lock'); - $lockicon->image->src = $OUTPUT->pix_url('t/'.$icon); - $lockicon->image->alt = $strunlock; - $lockicon->image->title = $tooltip; - $action = $OUTPUT->action_icon($lockicon); } else { - if (!has_capability('moodle/grade:manage', $this->context) and - !has_capability('moodle/grade:lock', $this->context)) { - return ''; + if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:lock', $this->context)) { + $action = ''; + } else { + $url->param('action', 'lock'); + $action = $OUTPUT->action_icon($url, $strlock, 't/lock', array('class'=>'smallicon')); } - - $lockicon->link->url->param('action', 'lock'); - $lockicon->link->add_class('lock'); - $lockicon->image->src = $OUTPUT->pix_url('t/lock'); - $lockicon->image->alt = $strlock; - $lockicon->image->title = $strlock; - $action = $OUTPUT->action_icon($lockicon); } + return $action; } @@ -1624,16 +1596,9 @@ class grade_structure { $icon = 't/calc_off'; } - $calcicon = new moodle_action_icon(); - $calcicon->link->url = new moodle_url($CFG->wwwroot.'/grade/edit/tree/calculation.php', - array('courseid' => $this->courseid, 'id' => $object->id)); - - $calcicon->link->url = $gpr->add_url_params($calcicon->link->url); - $calcicon->image->src = $OUTPUT->pix_url($icon); - $calcicon->add_class('iconsmall'); - $calcicon->alt = $streditcalculation; - $calcicon->title = $streditcalculation; - return $OUTPUT->action_icon($calcicon) . "\n"; + $url = new moodle_url($CFG->wwwroot.'/grade/edit/tree/calculation.php', array('courseid' => $this->courseid, 'id' => $object->id)); + $url = $gpr->add_url_params($url); + return $OUTPUT->action_icon($url, $streditcalculation, $icon, array('class'=>'smallicon')) . "\n"; } } @@ -2255,19 +2220,12 @@ function grade_button($type, $courseid, $object) { $strdelete = get_string('delete'); $stredit = get_string('edit'); - $icon = new moodle_action_icon(); - if ($type == 'delete') { - $icon->link->url = new moodle_url('index.php', array('id' => $courseid, $objectidstring => $object->id, 'action' => 'delete', 'sesskey' => sesskey())); + $url = new moodle_url('index.php', array('id' => $courseid, $objectidstring => $object->id, 'action' => 'delete', 'sesskey' => sesskey())); } else if ($type == 'edit') { - $icon->link->url = new moodle_url('edit.php', array('courseid' => $courseid, 'id' => $object->id)); + $url = new moodle_url('edit.php', array('courseid' => $courseid, 'id' => $object->id)); } - $icon->image->src = $OUTPUT->pix_url('t/'.$type); - $icon->image->add_class('iconsmall'); - $icon->image->title = ${'str'.$type}; - $icon->image->alt = ${'str'.$type}; - - return $OUTPUT->action_icon($icon); + return $OUTPUT->action_icon($url, ${'str'.$type}, 't/'.$type, array('class'=>'iconsmall')); } diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index fd9bf018e68..6f2e0d5b2d2 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -502,14 +502,10 @@ class grade_report_grader extends grade_report { $string = ${'str' . $showhide}; - $toggleicon = new moodle_action_icon(); - $toggleicon->image->src = $OUTPUT->pix_url($imagename); - $toggleicon->image->add_class('iconsmall'); - $toggleicon->alt = $string; - $toggleicon->title = $string; - $toggleicon->link->url = $this->baseurl->out(false, array('toggle' => $toggleaction, 'toggle_type' => $type), false); + $aurl = clone($this->baseurl); + $url->params(array('toggle' => $toggleaction, 'toggle_type' => $type)); - $retval = $OUTPUT->container($OUTPUT->action_icon($toggleicon, 'gradertoggle')); + $retval = $OUTPUT->container($OUTPUT->action_icon($url, $string, $imagename, array('class'=>'iconsmall'))); // TODO: this container looks wrong here return $retval; } @@ -614,12 +610,8 @@ class grade_report_grader extends grade_report { $userreportcell->header = true; $a->user = fullname($user); $strgradesforuser = get_string('gradesforuser', 'grades', $a); - $userreporticon = new moodle_action_icon(); - $userreporticon->link->url = new moodle_url($CFG->wwwroot.'/grade/report/'.$CFG->grade_profilereport.'/index.php', array('userid' => $user->id, 'id' => $this->course->id)); - $userreporticon->image->add_class('iconsmall'); - $userreporticon->image->src = $OUTPUT->pix_url('t/grades'); - $userreporticon->image->alt = $strgradesforuser; - $userreportcell->text = $OUTPUT->action_icon($userreporticon); + $url = new moodle_url($CFG->wwwroot.'/grade/report/'.$CFG->grade_profilereport.'/index.php', array('userid' => $user->id, 'id' => $this->course->id)); + $userreportcell->text = $OUTPUT->action_icon($url, $strgradesforuser, 't/grades', array('class'=>'iconsmall')); $userrow->cells[] = $userreportcell; } @@ -1414,22 +1406,21 @@ class grade_report_grader extends grade_report { $strswitchplus = $this->get_lang_string('gradesonly', 'grades'); $strswitchwhole = $this->get_lang_string('fullmode', 'grades'); - $contractexpandicon = new moodle_action_icon(); - $contractexpandicon->link->url = new moodle_url($this->gpr->get_return_url(null, array('target'=>$element['eid'], 'action'=>'switch_minus', 'sesskey'=>sesskey()))); - $contractexpandicon->image->add_class('iconsmall'); - $contractexpandicon->image->src = $OUTPUT->pix_url('t/switch_minus'); - $contractexpandicon->image->alt = $strswitchminus; + $url = new moodle_url($this->gpr->get_return_url(null, array('target'=>$element['eid'], 'sesskey'=>sesskey()))); if (in_array($element['object']->id, $this->collapsed['aggregatesonly'])) { - $contractexpandicon->image->src = $OUTPUT->pix_url('t/switch_plus'); - $contractexpandicon->image->alt = $strswitchplus; - $contractexpandicon->link->url->param('action', 'switch_plus'); - } elseif (in_array($element['object']->id, $this->collapsed['gradesonly'])) { + $url->param('action', 'switch_plus'); + $icon = $OUTPUT->action_icon($url, $strswitchplus, 't/switch_plus', array('class'=>'iconsmall')); + + } else if (in_array($element['object']->id, $this->collapsed['gradesonly'])) { + $url->param('action', 'switch_whole'); + $icon = $OUTPUT->action_icon($url, $strswitchwhole, 't/switch_whole', array('class'=>'iconsmall')); $contractexpandicon->image->src = $OUTPUT->pix_url('t/switch_whole'); - $contractexpandicon->image->alt = $strswitchwhole; - $contractexpandicon->link->url->param('action', 'switch_whole'); + + } else { + $url->param('action', 'switch_minus'); + $icon = $OUTPUT->action_icon($url, $strswitchminus, 't/switch_minus', array('class'=>'iconsmall')); } - $icon = $OUTPUT->action_icon($contractexpandicon); } return $icon; } diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index dbdbdee1a97..ed0eb460434 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2947,7 +2947,7 @@ function print_arrow($direction='up', $strsort=null, $return=false) { * @param string $iconpath The path to the icon to be displayed * @return string Either the link or an empty string */ -function doc_link($path='', $text='', $iconpath='') { +function doc_link($path='', $text='', $iconpath='ignored') { global $CFG, $OUTPUT; debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().'); @@ -2956,7 +2956,7 @@ function doc_link($path='', $text='', $iconpath='') { return ''; } - return $OUTPUT->doc_link($path, $text, $iconpath); + return $OUTPUT->doc_link($path, $text); } /** diff --git a/lib/outputactions.php b/lib/outputactions.php index a6b44a91cf5..b5681e26f5e 100644 --- a/lib/outputactions.php +++ b/lib/outputactions.php @@ -115,7 +115,11 @@ class popup_action extends component_action { global $CFG; $this->name = $name; - $url = new moodle_url($url); + if ($url instanceof moodle_url) { + $url = clone($url); + } else { + $url = new moodle_url($url); + } if ($this->name) { $_name = $this->name; diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 8572aa64437..a3eaa7a74ea 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -2088,65 +2088,6 @@ class help_icon extends html_image { } -/** - * Component representing an icon linking to a Moodle page. - * - * @copyright 2009 Nicolas Connault - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -class moodle_action_icon extends labelled_html_component { - /** - * @var string $linktext Optional text to display next to the icon - */ - public $linktext; - /** - * @var html_image $image The icon - */ - public $image; - /** - * @var html_link $link The link - */ - public $link; - - /** - * Constructor: sets up the other components in case they are needed - * @return void - */ - public function __construct() { - $this->image = new html_image(); - $this->link = new html_link(); - } - - /** - * @see lib/html_component#prepare() - * @return void - */ - public function prepare(renderer_base $output, moodle_page $page, $target) { - $this->image->add_class('action-icon'); - - if (!empty($this->actions)) { - foreach ($this->actions as $action) { - $this->link->add_action($action); - } - unset($this->actions); - } - - parent::prepare($output, $page, $target); - - if (empty($this->image->src)) { - throw new coding_exception('moodle_action_icon->image->src must not be empty'); - } - - if (empty($this->image->alt) && !empty($this->linktext)) { - $this->image->alt = $this->linktext; - } else if (empty($this->image->alt)) { - debugging('moodle_action_icon->image->alt should not be empty.', DEBUG_DEVELOPER); - } - } -} - - /** * This class represents how a block appears on a page. * diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 59df7501ce1..76294e9afe3 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1099,47 +1099,67 @@ class core_renderer extends renderer_base { * Also contains an icon by default. Shown to teachers and admin only. * @param string $path The page link after doc root and language, no leading slash. * @param string $text The text to be displayed for the link - * @param string $iconpath The path to the icon to be displayed + * @retrun string */ - public function doc_link($path, $text=false, $iconpath=false) { - global $CFG, $OUTPUT; - $icon = new moodle_action_icon(); - $icon->linktext = $text; - $icon->image->alt = $text; - $icon->image->add_class('iconhelp'); - $icon->link->url = new moodle_url(get_docs_url($path)); + public function doc_link($path, $text) { + global $CFG; - if (!empty($iconpath)) { - $icon->image->src = $iconpath; - } else { - $icon->image->src = $this->pix_url('docs')->out(false, array(), false); - } + $options = array('class'=>'iconhelp', 'alt'=>$text); + $url = new moodle_url(get_docs_url($path)); + + $icon = $this->icon('docs', $options); + + $link = new html_link($url, $icon.$text); if (!empty($CFG->doctonewwindow)) { - $icon->add_action(new popup_action('click', $icon->link->url)); + $link->add_action(new popup_action('click', $url)); } - return $this->action_icon($icon); - + return $this->link($link); } /** * Given a moodle_action_icon object, outputs an image linking to an action (URL or AJAX). * - * @param moodle_action_icon $icon A moodle_action_icon object + * @param mixed $link A html_link object or a string URL (text param required in second case) + * @param string $title link title and also image alt if no alt specified in $options + * @param html_image|moodle_url|string $image_or_url image or url of the image, + * it is also possible to use short pix name for core images + * @param array $options image attributes such as title, id, alt, widht, height + * @param bool $linktext show title next to image in link * @return string HTML fragment */ - public function action_icon(moodle_action_icon $icon) { - $icon = clone($icon); - $icon->prepare($this, $this->page, $this->target); - $imageoutput = $this->image($icon->image); - - if ($icon->linktext) { - $imageoutput .= $icon->linktext; + public function action_icon($url_or_link, $title, $image_or_url, array $options = null, $linktext=false) { + $options = (array)$options; + if (empty($options['class'])) { + // let ppl override the class via $options + $options['class'] = 'action-icon'; } - $icon->link->text = $imageoutput; - return $this->link($icon->link); + if (empty($title)) { + debugging('$title should not be empty in action_icon() call'); + } + + if (!$linktext) { + $options['alt'] = $itle; + } + + $icon = $this->icon($image_or_url, $options); + + if ($linktext) { + $icon = $icon.$itle; + } + + if ($url_or_link instanceof html_link) { + $link = clone($url_or_link); + $link->text = ($icon); + $url = $link->url; + } else { + $link = new html_link($url, $icon); + } + $link->add_action(new popup_action('click', $url)); + + return $this->link($link); } /* diff --git a/lib/weblib.php b/lib/weblib.php index bf572d8b390..d73113ce388 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -773,7 +773,7 @@ function close_window($delay = 0, $reloadopener = false) { * @param string $iconpath The path to the icon to be displayed * @return string The link to user documentation for this current page */ -function page_doc_link($text='', $iconpath='') { +function page_doc_link($text='') { global $CFG, $PAGE, $OUTPUT; if (empty($CFG->docroot) || during_initial_install()) { @@ -787,7 +787,7 @@ function page_doc_link($text='', $iconpath='') { if (!$path) { return ''; } - return $OUTPUT->doc_link($path, $text, $iconpath); + return $OUTPUT->doc_link($path, $text); } diff --git a/repository/filepicker.php b/repository/filepicker.php index 5c9d1f396c5..a3cd3ee698b 100755 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -307,16 +307,14 @@ case 'plugins': echo ''; echo ''; diff --git a/user/index.php b/user/index.php index f4f5bd89932..66e6ff687be 100644 --- a/user/index.php +++ b/user/index.php @@ -340,13 +340,8 @@ $contentheading = $group->name; if (has_capability('moodle/course:managegroups', $context)) { - $editgroupaction = new moodle_action_icon(); - $editgroupaction->link->url = new moodle_url($CFG->wwwroot.'/group/group.php', array('id' => $group->id, 'courseid' => $group->courseid)); - $editgroupaction->link->title = get_string('editgroupprofile'); - $editgroupaction->image->src = $OUTPUT->pix_url('t/edit'); - $editgroupaction->image->alt = get_string('editgroupprofile'); - - $contentheading .= ' ' . $OUTPUT->action_icon($editgroupaction); + $aurl = new moodle_url($CFG->wwwroot.'/group/group.php', array('id' => $group->id, 'courseid' => $group->courseid)); + $contentheading .= ' ' . $OUTPUT->action_icon($aurl, get_string('editgroupprofile'), 't/edit'); } $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'course_group_description', $group->id); diff --git a/user/portfoliologs.php b/user/portfoliologs.php index 3bf12694917..fce36a8373c 100644 --- a/user/portfoliologs.php +++ b/user/portfoliologs.php @@ -84,22 +84,12 @@ if (count($queued) > 0) { $e = portfolio_exporter::rewaken_object($q->id); $e->verify_rewaken(true); $queued = $e->get('queued'); - $base = $CFG->wwwroot . '/portfolio/add.php?id=' . $q->id . '&logreturn=1&sesskey=' . sesskey(); - $iconstr = ''; + $baseurl = new moodle_url($CFG->wwwroot . '/portfolio/add.php', array('id'=>$q->id, 'logreturn'=>1, 'sesskey'=>sesskey())); - $cancel = new moodle_action_icon(); - $cancel->link->url = new moodle_url($base . '&cancel=1'); - $cancel->image->src = $OUTPUT->pix_url('t/stop'); - $cancel->linktext = get_string('cancel'); - - $iconstr = $OUTPUT->action_icon($cancel); + $iconstr = $OUTPUT->action_icon(new moodle_url($baseurl, array('cancel'=>1)), get_string('cancel'), 't/stop'); if (!$e->get('queued') && $e->get('expirytime') > $now) { - $continue = new moodle_action_icon(); - $continue->link->url = new moodle_url($base); - $continue->image->src = $OUTPUT->pix_url('t/go'); - $continue->linktext = get_string('continue'); - $iconstr .= ' ' . $OUTPUT->action_icon($continue); + $iconstr .= ' ' . $OUTPUT->action_icon($baseurl, get_string('continue'), 't/go'); } $table->data[] = array( $e->get('caller')->display_name(),