Skip to content

Commit

Permalink
MDL-20204 new pix_icon renderable widget
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Feb 11, 2010
1 parent 4aea3cc commit 000c278
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 16 deletions.
4 changes: 2 additions & 2 deletions blog/external_blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@

foreach ($blogs as $blog) {
if ($blog->failedlastsync) {
$validicon = $OUTPUT->image('i/cross_red_big', array('alt'=>get_string('feedisinvalid', 'blog'), 'title'=>get_string('feedisinvalid', 'blog')));
$validicon = $OUTPUT->pix_icon('i/cross_red_big', get_string('feedisinvalid', 'blog'));
} else {
$validicon = $OUTPUT->image('i/tick_green_big', array('alt'=>get_string('feedisvalid', 'blog'), 'title'=>get_string('feedisvalid', 'blog')));
$validicon = $OUTPUT->pix_icon('i/tick_green_big', get_string('feedisvalid', 'blog'));
}

$editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
Expand Down
7 changes: 3 additions & 4 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,18 @@ public function print_attachments($return=false) {
$icon = substr(mimeinfo_from_type("icon", $mimetype), 0, -4);
$type = mimeinfo_from_type("type", $mimetype);

$image = $OUTPUT->image("/f/$icon", array('alt'=>$filename, 'class'=>'icon'));
$image = $OUTPUT->pix_icon("/f/$icon", $filename, 'moodle', array('class'=>'icon'));

if ($return == "html") {
$output .= html_writer::link($ffurl, $OUTPUT->image($image));
$output .= html_writer::link($ffurl, $image);
$output .= html_writer::link($ffurl, $filename);

} else if ($return == "text") {
$output .= "$strattachment $filename:\n$ffurl\n";

} else {
if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links
$image = $OUTPUT->image($ffurl, array('alt'=>$filename));
$imagereturn .= "<br />" . $OUTPUT->image($image);
$imagereturn .= "<br />" . $OUTPUT->pix_icon($ffurl, $filename);
} else {
$imagereturn .= html_writer::link($ffurl, $image);
$imagereturn .= filter_text(html_writer::link($ffurl, $filename));
Expand Down
2 changes: 1 addition & 1 deletion course/pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
$strrequireskey = get_string('requireskey');

// Loop over requested courses.
$keyicon = $OUTPUT->image('i/key', array('alt'=>$strrequireskey, 'class'=>'icon'));
$keyicon = $OUTPUT->pix_icon('i/key', $strrequireskey, 'moodle', array('class'=>'icon'));

foreach ($pending as $course) {
$course = new course_request($course);
Expand Down
2 changes: 1 addition & 1 deletion course/report/outline/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
$activitycell = new html_table_cell();
$activitycell->add_class('activity');

$activityicon = $OUTPUT->image($OUTPUT->pix_url('icon', $cm->modname), array('alt'=>$modulename, 'class'=>'icon'));
$activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname, array('class'=>'icon'));

$attributes = array();
if (!$cm->visible) {
Expand Down
2 changes: 1 addition & 1 deletion grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ public function get_locking_icon($element, $gpr) {
$strparamobj->itemname = $element['object']->grade_item->itemname;
$strnonunlockable = get_string('nonunlockableverbose', 'grades', $strparamobj);

$action = $OUTPUT->image('t/unlock_gray', array('alt'=>$strnonunlockable, 'title'=>$strnonunlockable, 'class'=>'iconsmall'));
$action = $OUTPUT->pix_icon('t/unlock_gray', $strnonunlockable);

} else if ($element['object']->is_locked()) {
$type = 'unlock';
Expand Down
2 changes: 1 addition & 1 deletion lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2653,7 +2653,7 @@ function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=fa
*
*/
function print_png() {
throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->image() instead.');
throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
}


Expand Down
2 changes: 1 addition & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public function content($shorttext=false) {
}

if ($this->icon!==null) {
$icon = $OUTPUT->image($this->icon, array('alt'=>'', 'class'=>'icon'));
$icon = $OUTPUT->pix_icon($this->icon, '', 'moodle', array('class'=>'icon'));
$content = $icon.$content; // use CSS for spacing of icons
} else if ($this->helpbutton!==null) {
$content = sprintf('%s<span class="clearhelpbutton">%s</span>',trim($this->helpbutton),$content);
Expand Down
34 changes: 34 additions & 0 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,40 @@ public function __construct($helppage, $title, $component = 'moodle') {
}


/**
* Data structure representing an icon.
*
* @copyright 2010 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
class pix_icon implements renderable {
var $pix;
var $component;
var $attributes = array();

/**
* Constructor
* @param string $pix short icon name
* @param string $component component name
* @param array $attributes html attributes
*/
public function __construct($pix, $alt, $component='moodle', array $attributes = null) {
$this->icon = $pix;
$this->compondent = $component;
$this->attributes = (array)$attributes;

$this->attributes['alt'] = $alt;
if (empty($this->attributes['class'])) {
$this->attributes['class'] = 'smallicon';
}
if (!isset($this->attributes['title'])) {
$this->attributes['title'] = $this->attributes['alt'];
}
}
}


/**
* Data structure representing a simple form with only one button.
*
Expand Down
29 changes: 26 additions & 3 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1225,10 +1225,9 @@ protected function render_url_select(url_select $select) {
public function doc_link($path, $text) {
global $CFG;

$options = array('class'=>'iconhelp', 'alt'=>$text);
$url = new moodle_url(get_docs_url($path));
$icon = $this->pix_icon('docs', $text, 'moodle', array('class'=>'iconhelp'));

$icon = $this->image('docs', $options);
$url = new moodle_url(get_docs_url($path));

$link = new html_link($url, $icon.$text);

Expand All @@ -1239,6 +1238,30 @@ public function doc_link($path, $text) {
return $this->link($link);
}

/**
* Render icon
* @param string $pix short pix name
* @param string $alt mandatory alt attribute
* @param strin $component standard compoennt name like 'moodle', 'mod_form', etc.
* @param array $attributes htm lattributes
* @return string HTML fragment
*/
public function pix_icon($pix, $alt, $component='moodle', array $attributes = null) {
$icon = new pix_icon($pix, $alt, $component, $attributes);
return $this->render($icon);
}

/**
* Render icon
* @param pix_icon $icon
* @return string HTML fragment
*/
public function render_icon(pix_icon $icon) {
$attributes = $icon->attributes;
$attributes['src'] = $this->pix_url($icon->pix, $icon->component);
return html_writer::empty_tag('img', $atrributes);
}

/**
* Given a moodle_action_icon object, outputs an image linking to an action (URL or AJAX).
*
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ function quiz_question_preview_button($quiz, $question, $label = false) {
}

// Build the icon.
$image = $OUTPUT->image($OUTPUT->pix_url('t/preview'), array('class'=>'iconsmall', 'alt'=>$strpreviewquestion));
$image = $OUTPUT->pix_icon('t/preview', $strpreviewquestion);

$link = new html_link($CFG->wwwroot."/question/preview.php?id=$question->id&quizid=$quiz->id", $image, array('title' => $strpreviewquestion));
parse_str(QUESTION_PREVIEW_POPUP_OPTIONS, $options);
Expand Down
2 changes: 1 addition & 1 deletion question/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ protected function display_content($question, $rowclasses) {
global $OUTPUT;
if (question_has_capability_on($question, 'use')) {
// Build the icon.
$image = $OUTPUT->image($OUTPUT->pix_url('t/preview'), array('class'=>'iconsmall', 'alt'=>$this->strpreview));
$image = $OUTPUT->pix_icon('t/preview', $this->strpreview);

$link = new html_link($this->qbank->preview_question_url($question->id), $image, array('title' => $this->strpreview));
parse_str(QUESTION_PREVIEW_POPUP_OPTIONS, $options);
Expand Down

0 comments on commit 000c278

Please sign in to comment.