/** * @param object $quiz the quiz * @param object $question the question * @param boolean $label if true, show the previewquestion label after the icon * @return the HTML for a preview question icon. */ function quiz_question_preview_button($quiz, $question, $label = false) { global $CFG, $COURSE, $OUTPUT; if (!question_has_capability_on($question, 'use', $question->category)) { return ''; } // Minor efficiency saving. Only get strings once, even if there are a lot of icons on one page. static $strpreview = null; static $strpreviewquestion = null; if ($strpreview === null) { $strpreview = get_string('preview', 'quiz'); $strpreviewquestion = get_string('previewquestion', 'quiz'); } // Do we want a label? $strpreviewlabel = ""; if ($label) { $strpreviewlabel = $strpreview; } // Build the icon. $image = new html_image(); $image->src = $OUTPUT->old_icon_url('t/preview'); $image->add_class('iconsmall'); $image->alt = $strpreviewquestion; $link = html_link::make("/question/preview.php?id={$question->id}&quizid={$quiz->id}", $strpreviewlabel); parse_str(QUESTION_PREVIEW_POPUP_OPTIONS, $options); $link->add_action(new popup_action('click', $link->url, 'questionpreview', $options)); $link->title = $strpreviewquestion; return $OUTPUT->link_to_popup($link, $image); }
/** * @see lib/moodle_html_component#prepare() * @return void */ public function prepare() { $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(); 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); } } }
public function test_spacer() { global $CFG; $spacer = new html_image(); $html = $this->renderer->spacer($spacer); $this->assert(new ContainsTagWithAttributes('img', array('class' => 'image spacer', 'src' => $CFG->wwwroot . '/pix/spacer.gif', 'alt' => '')), $html); $spacer = new html_image(); $spacer->src = $this->renderer->old_icon_url('myspacer'); $spacer->alt = 'sometext'; $spacer->add_class('my'); $html = $this->renderer->spacer($spacer); $this->assert(new ContainsTagWithAttributes('img', array('class' => 'my image spacer', 'src' => $this->renderer->old_icon_url('myspacer'), 'alt' => 'sometext')), $html); }
protected function display_content($question, $rowclasses) { global $OUTPUT; if (question_has_capability_on($question, 'use')) { parse_str(QUESTION_PREVIEW_POPUP_OPTIONS, $options); $image = new html_image(); $image->src = $OUTPUT->old_icon_url('t/preview'); $image->add_class('iconsmall'); $image->alt = $this->strpreview; $link = html_link::make($this->qbank->preview_question_url($question->id), $this->strpreview); $link->add_action(new popup_action('click', $link->url, 'questionpreview', $options)); $link->title = $this->strpreview; echo $OUTPUT->link_to_popup($link, $image); } }