This is the final batch.
/// FUNCTIONS THAT SIMPLY WRAP QUESTIONTYPE METHODS //////////////////////////////////
/**
- * Get the HTML that needs to be included in the head tag when the
- * questions in $questionlist are printed in the gives states.
+ * Give the questions in $questionlist a chance to request the CSS or JavaScript
+ * they need, before the header is printed.
+ *
+ * If your code is going to call the print_question function, it must call this
+ * funciton before print_header.
*
- * @global object
- * @global array
* @param array $questionlist a list of questionids of the questions what will appear on this page.
* @param array $questions an array of question objects, whose keys are question ids.
* Must contain all the questions in $questionlist
* @param array $states an array of question state objects, whose keys are question ids.
* Must contain the state of all the questions in $questionlist
*
- * @return string some HTML code that can go inside the head tag.
+ * @return string Deprecated. Some HTML code that can go inside the head tag.
*/
function get_html_head_contributions($questionlist, &$questions, &$states) {
global $CFG, $PAGE, $QTYPES;
$PAGE->requires->js('question/qengine.js');
// An inline script to record various lang strings, etc. that qengine.js needs.
- $contributions = array(question_init_qenginejs_script());
+ $contributions = array();
// Anything that questions on this page need.
foreach ($questionlist as $questionid) {
$question = $questions[$questionid];
- $contributions = array_merge($contributions,
- $QTYPES[$question->qtype]->get_html_head_contributions(
- $question, $states[$questionid]));
+ $newcontributions = $QTYPES[$question->qtype]->
+ get_html_head_contributions($question, $states[$questionid]);
+ if (!empty($newcontributions)) {
+ $contributions = array_merge($contributions, $newcontributions);
+ }
}
return implode("\n", array_unique($contributions));
}
/**
- * Like @see{get_html_head_contributions} but for the editing page
+ * Like {@link get_html_head_contributions()} but for the editing page
* question/question.php.
*
- * @global array
* @param $question A question object. Only $question->qtype is used.
- * @return string some HTML code that can go inside the head tag.
+ * @return string Deprecated. Some HTML code that can go inside the head tag.
*/
function get_editing_head_contributions($question) {
global $QTYPES;
$contributions = $QTYPES[$question->qtype]->get_editing_head_contributions();
+ if (empty($contributions)) {
+ $contributions = array();
+ }
return implode("\n", array_unique($contributions));
}
}
return md5($attemptid . "_" . $user->secret . "_" . $questionid . "_" . $sessionid);
}
-
-?>
require_once('../../config.php');
require_once($CFG->dirroot . '/mod/quiz/editlib.php');
require_once($CFG->dirroot . '/question/category_class.php');
-require_js(array('yui_yahoo', 'yui_dom-event', 'yui_container', 'yui_dragdrop'));
+$PAGE->requires->yui_lib('container');
+$PAGE->requires->yui_lib('dragdrop');
/**
* Callback function called from question_list() function
function definition() {
- global $COURSE, $CFG, $DB;
+ global $COURSE, $CFG, $DB, $PAGE;
$quizconfig = get_config('quiz');
$mform =& $this->_form;
if (!empty($this->_cm)) {
$pagegroup[] = &$mform->createElement('checkbox', 'repaginatenow', '', get_string('repaginatenow', 'quiz'), array('id' => 'id_repaginatenow'));
$mform->disabledIf('repaginatenow', 'shufflequestions', 'eq', 1);
- require_js(array('yui_yahoo', 'yui_dom', 'yui_event'));
- require_js('mod/quiz/edit.js');
+ $PAGE->requires->yui_lib('event');
+ $PAGE->requires->js('mod/quiz/edit.js');
}
$mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false);
}
/// Print the page header
- require_js('mod/quiz/quiz.js');
+ $PAGE->requires->js('mod/quiz/quiz.js');
$headtags = $attemptobj->get_html_head_contributions($page);
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
$accessmanager->setup_secure_page($attemptobj->get_course()->shortname.': '.format_string($attemptobj->get_quiz_name()), $headtags);
$attemptobj->load_question_states();
/// Print the page header
-require_js('mod/quiz/quiz.js');
+$PAGE->requires->js('mod/quiz/quiz.js');
$title = get_string('summaryofattempt', 'quiz');
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
$accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' .
if ($accessmanager->securewindow_required($canpreview)) {
$bodytags = 'onload="popupchecker(\'' . get_string('popupblockerwarning', 'quiz') . '\');"';
}
- require_js(array('yui_yahoo', 'yui_event'));
+ $PAGE->requires->yui_lib('event');
// Note: MDL-19010 there will be further changes to printing header and blocks.
// The code will be much nicer than this eventually.
* @param CFG global object
*/
function display() {
- global $CFG, $THEME, $USER;
+ global $CFG, $THEME, $USER, $PAGE;
/// Set up generic stuff first, including checking for access
parent::display();
/// display the resource into a object tag
if ($resource->options == "objectframe") {
///Yahoo javascript libaries for updating embedded object size
- require_js(array('yui_utilities'));
- require_js(array('yui_container'));
- require_js(array('yui_dom-event'));
- require_js(array('yui_dom'));
+ $PAGE->requires->yui_lib('container');
///Moodle Header and navigation bar
$navigation = build_navigation($this->navlinks, $cm);
require_once("lib.php");
#require_once("$CFG->dirroot/course/lib.php"); // For side-blocks
require_once($CFG->libdir . '/ajax/ajaxlib.php');
- require_js(array('yui_yahoo', 'yui_event', 'yui_connection'));
+ $PAGE->requires->yui_lib('connection');
$ewiki_action = optional_param('ewiki_action', '', PARAM_ALPHA); // Action on Wiki-Page
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
}
require_once($CFG->libdir.'/portfoliolib.php');
-require_js(array('yui_yahoo', 'yui_dom'));
+$PAGE->requires->yui_lib('dom');
$id = required_param('id', PARAM_INT);
require_login();
public function __construct(question_bank_view $qbank) {
$this->qbank = $qbank;
$this->init();
- require_js(array('yui_yahoo','yui_event'));
- require_js('question/qbank.js');
}
/**
$this->init_columns($this->wanted_columns());
$this->init_sort();
- $PAGE->requires->yui_lib('dom-event');
+ $PAGE->requires->yui_lib('container');
}
protected function wanted_columns() {
*/
public function display($tabname, $page, $perpage, $sortorder,
$sortorderdecoded, $cat, $recurse, $showhidden, $showquestiontext){
+ global $PAGE;
if ($this->process_actions_needing_ui()) {
return;
}
+ $PAGE->requires->js('question/qbank.js');
+
// Category selection form
print_heading(get_string('questionbank', 'question'), '', 2);
* @param boolean $disabled if true, the button will be disabled.
*/
function create_new_question_button($categoryid, $params, $caption, $tooltip = '', $disabled = false) {
- global $CFG;
+ global $CFG, $PAGE;
static $choiceformprinted = false;
$params['category'] = $categoryid;
print_single_button($CFG->wwwroot . '/question/addquestion.php', $params,
$caption,'get', '', false, $tooltip, $disabled);
helpbutton('types', get_string('createnewquestion', 'question'), 'question');
- require_js(array('yui_yahoo','yui_dom','yui_event', 'yui_dragdrop', 'yui_container'));
+ $PAGE->requires->yui_lib('dragdrop');
+ $PAGE->requires->yui_lib('container');
if (!$choiceformprinted) {
echo '<div id="qtypechoicecontainer">';
print_choose_qtype_to_add_form(array());
// This script, and the YUI libraries that it needs, are inluded by
-// the require_js calls in get_html_head_contributions in lib/questionlib.php.
+// the $PAGE->requires->js calls in get_html_head_contributions in lib/questionlib.php.
question_flag_changer = {
flag_state_listeners: new Object(),
// Used by the following function, so that it only returns results once per quiz page.
private $htmlheadalreadydone = false;
/**
- * If this question type requires extra CSS or JavaScript to function,
- * then this method will return an array of <link ...> tags that reference
- * those stylesheets. This function will also call require_js()
- * from ajaxlib.php, to get any necessary JavaScript linked in too.
+ * Hook to allow question types to include required JavaScrip or CSS on pages
+ * where they are going to be printed.
*
- * Remember that there may be more than one question of this type on a page.
- * try to avoid including JS and CSS more than once.
+ * If this question type requires extra CSS or JavaScript to function,
+ * then this method, which will be called before print_header on any page
+ * where this question is going to be printed, is a chance to call
+ * $PAGE->requires->js, $PAGE->requiers->css, and so on.
*
* The two parameters match the first two parameters of print_question.
*
* @param object $question The question object.
* @param object $state The state object.
*
- * @return an array of bits of HTML to add to the head of pages where
- * this question is print_question-ed in the body. The array should use
- * integer array keys, which have no significance.
+ * @return array Deprecated. An array of bits of HTML to add to the head of
+ * pages where this question is print_question-ed in the body. The array
+ * should use integer array keys, which have no significance.
*/
function get_html_head_contributions(&$question, &$state) {
// We only do this once for this question type, no matter how often this
// script.js or script.php that exist in the plugin folder.
// Core question types should not use this mechanism. Their styles
// should be included in the standard theme.
- return $this->find_standard_scripts_and_css();
+ $this->find_standard_scripts_and_css();
}
/**
// script.js or script.php that exist in the plugin folder.
// Core question types should not use this mechanism. Their styles
// should be included in the standard theme.
- return $this->find_standard_scripts_and_css();
+ $this->find_standard_scripts_and_css();
}
/**
* @return array as required by get_html_head_contributions or get_editing_head_contributions.
*/
protected function find_standard_scripts_and_css() {
+ global $PAGE;
+
$plugindir = $this->plugin_dir();
- $baseurl = $this->plugin_baseurl();
+ $plugindirrel = 'question/type/' . $this->name();
if (file_exists($plugindir . '/script.js')) {
- require_js($baseurl . '/script.js');
+ $PAGE->requires->js($plugindirrel . '/script.js');
}
if (file_exists($plugindir . '/script.php')) {
- require_js($baseurl . '/script.php');
+ $PAGE->requires->js($plugindirrel . '/script.php');
}
- $stylesheets = array();
if (file_exists($plugindir . '/styles.css')) {
- $stylesheets[] = 'styles.css';
+ $PAGE->requires->css($plugindirrel . '/styles.css');
}
if (file_exists($plugindir . '/styles.php')) {
- $stylesheets[] = 'styles.php';
- }
- $contributions = array();
- foreach ($stylesheets as $stylesheet) {
- $contributions[] = '<link rel="stylesheet" type="text/css" href="' .
- $baseurl . '/' . $stylesheet . '" />';
+ $PAGE->requires->css($plugindirrel . '/styles.php');
}
- return $contributions;
}
/**
*/
function coursetag_get_jscript($coursetagdivs = '') {
- global $CFG, $DB;
+ global $CFG, $DB, $PAGE;
$tabscript = '';
if ($coursetagdivs) {
//]]>
</script>';
- require_js('blocks/tags/coursetags.js');
+ $PAGE->requires->js('blocks/tags/coursetags.js');
return $str;
}
require_once('lib.php');
require_once('edit_form.php');
-require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
+$PAGE->requires->yui_lib('animation');
+$PAGE->requires->yui_lib('autocomplete');
require_login();
-<?php require_js(array('yui_yahoo','yui_dom','yui_event','yui_animation')); ?>
+<?php
+
+$PAGE->requires->yui_lib('animation')->in_head(); ?>
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpsthemewww ?>/lines/styles_ie7.css" />