MDL-38429 Lesson Module: improve lesson code by reseting NULL value to use lowercase.

This commit is contained in:
Rossiani Wijaya
2013-03-25 14:07:18 +08:00
parent 1b58651681
commit ecea65cace
11 changed files with 42 additions and 42 deletions
+2 -2
View File
@@ -283,7 +283,7 @@ function lesson_save_question_options($question, $lesson) {
class qformat_default {
var $displayerrors = true;
var $category = NULL;
var $category = null;
var $questionids = array();
var $qtypeconvert = array('numerical' => LESSON_PAGE_NUMERICAL,
'multichoice' => LESSON_PAGE_MULTICHOICE,
@@ -510,7 +510,7 @@ class qformat_default {
echo "<p>This flash question format has not yet been completed!</p>";
return NULL;
return null;
}
/**
+3 -3
View File
@@ -401,7 +401,7 @@ function lesson_update_grades($lesson, $userid=0, $nullifnone=true) {
} else if ($userid and $nullifnone) {
$grade = new stdClass();
$grade->userid = $userid;
$grade->rawgrade = NULL;
$grade->rawgrade = null;
lesson_grade_item_update($lesson, $grade);
} else {
@@ -449,7 +449,7 @@ function lesson_upgrade_grades() {
* @param array|object $grades optional array/object of grade(s); 'reset' means reset grades in gradebook
* @return int 0 if ok, error code otherwise
*/
function lesson_grade_item_update($lesson, $grades=NULL) {
function lesson_grade_item_update($lesson, $grades=null) {
global $CFG;
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php');
@@ -474,7 +474,7 @@ function lesson_grade_item_update($lesson, $grades=NULL) {
if ($grades === 'reset') {
$params['reset'] = true;
$grades = NULL;
$grades = null;
} else if (!empty($grades)) {
// Need to calculate raw grade (Note: $grades has many forms)
if (is_object($grades)) {
+7 -7
View File
@@ -774,12 +774,12 @@ abstract class lesson_add_page_form_base extends moodleform {
* Convenience function: Adds an answer editor
*
* @param int $count The count of the element to add
* @param string $label, NULL means default
* @param string $label, null means default
* @param bool $required
* @return void
*/
protected final function add_answer($count, $label = NULL, $required = false) {
if ($label === NULL) {
protected final function add_answer($count, $label = null, $required = false) {
if ($label === null) {
$label = get_string('answer', 'lesson');
}
$this->_form->addElement('editor', 'answer_editor['.$count.']', $label, array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
@@ -792,12 +792,12 @@ abstract class lesson_add_page_form_base extends moodleform {
* Convenience function: Adds an response editor
*
* @param int $count The count of the element to add
* @param string $label, NULL means default
* @param string $label, null means default
* @param bool $required
* @return void
*/
protected final function add_response($count, $label = NULL, $required = false) {
if ($label === NULL) {
protected final function add_response($count, $label = null, $required = false) {
if ($label === null) {
$label = get_string('response', 'lesson');
}
$this->_form->addElement('editor', 'response_editor['.$count.']', $label, array('rows'=>'4', 'columns'=>'80'), array('noclean'=>true));
@@ -963,7 +963,7 @@ class lesson extends lesson_base {
}
}
grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, NULL, array('deleted'=>1));
grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, null, array('deleted'=>1));
return true;
}
+1 -1
View File
@@ -153,7 +153,7 @@ class lesson_page_type_branchtable extends lesson_page {
global $USER, $DB, $PAGE, $CFG;
require_sesskey();
$newpageid = optional_param('jumpto', NULL, PARAM_INT);
$newpageid = optional_param('jumpto', null, PARAM_INT);
// going to insert into lesson_branch
if ($newpageid == LESSON_RANDOMBRANCH) {
$branchflag = 1;
+2 -2
View File
@@ -184,9 +184,9 @@ class lesson_page_type_essay extends lesson_page {
$formattextdefoptions->context = $answerpage->context;
foreach ($answers as $answer) {
if ($useranswer != NULL) {
if ($useranswer != null) {
$essayinfo = unserialize($useranswer->useranswer);
if ($essayinfo->response == NULL) {
if ($essayinfo->response == null) {
$answerdata->response = get_string("nocommentyet", "lesson");
} else {
$answerdata->response = s($essayinfo->response);
+9 -9
View File
@@ -71,7 +71,7 @@ class lesson_page_type_matching extends lesson_page {
$responses = array();
foreach ($answers as $answer) {
// get all the response
if ($answer->response != NULL) {
if ($answer->response != null) {
$responses[$answer->id] = trim($answer->response);
}
}
@@ -223,7 +223,7 @@ class lesson_page_type_matching extends lesson_page {
foreach ($answers as $answer) {
if ($n < 2) {
if ($answer->answer != NULL) {
if ($answer->answer != null) {
$cells = array();
if ($n == 0) {
$cells[] = "<span class=\"label\">".get_string("correctresponse", "lesson").'</span>';
@@ -377,8 +377,8 @@ class lesson_page_type_matching extends lesson_page {
$formattextdefoptions = new stdClass;
$formattextdefoptions->para = false; //I'll use it widely in this page
foreach ($answers as $answer) {
if ($n == 0 && $useranswer != NULL && $useranswer->correct) {
if ($answer->response == NULL && $useranswer != NULL) {
if ($n == 0 && $useranswer != null && $useranswer->correct) {
if ($answer->response == null && $useranswer != null) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
$answerdata->response = $answer->response;
@@ -388,8 +388,8 @@ class lesson_page_type_matching extends lesson_page {
} else {
$answerdata->score = get_string("receivedcredit", "lesson");
}
} elseif ($n == 1 && $useranswer != NULL && !$useranswer->correct) {
if ($answer->response == NULL && $useranswer != NULL) {
} elseif ($n == 1 && $useranswer != null && !$useranswer->correct) {
if ($answer->response == null && $useranswer != null) {
$answerdata->response = get_string("thatsthewronganswer", "lesson");
} else {
$answerdata->response = $answer->response;
@@ -402,7 +402,7 @@ class lesson_page_type_matching extends lesson_page {
} elseif ($n > 1) {
$data = '<label class="accesshide" for="answer_' . $n . '">' . get_string('answer', 'lesson') . '</label>';
$data .= "<select id=\"answer_". $n ."\" disabled=\"disabled\"><option selected=\"selected\">".strip_tags(format_string($answer->answer))."</option></select>";
if ($useranswer != NULL) {
if ($useranswer != null) {
$userresponse = explode(",", $useranswer->useranswer);
$data .= '<label class="accesshide" for="stu_answer_response_' . $n . '">' . get_string('matchesanswer', 'lesson') . '</label>';
$data .= "<select id=\"stu_answer_response_" . $n . "\" disabled=\"disabled\"><option selected=\"selected\">";
@@ -472,7 +472,7 @@ class lesson_add_page_form_matching extends lesson_add_page_form_base {
for ($i = 2; $i < $this->_customdata['lesson']->maxanswers+2; $i++) {
$this->_form->addElement('header', 'matchingpair'.($i-1), get_string('matchingpair', 'lesson', $i-1));
$this->add_answer($i, NULL, ($i < 4));
$this->add_answer($i, null, ($i < 4));
$required = ($i < 4);
$label = get_string('matchesanswer','lesson');
$count = $i;
@@ -520,7 +520,7 @@ class lesson_display_answer_form_matching extends moodleform {
$i = 0;
foreach ($answers as $answer) {
$mform->addElement('html', '<div class="answeroption">');
if ($answer->response != NULL) {
if ($answer->response != null) {
$responseid = 'response['.$answer->id.']';
if ($hasattempt) {
$responseid = 'response_'.$answer->id;
+6 -6
View File
@@ -353,7 +353,7 @@ class lesson_page_type_multichoice extends lesson_page {
foreach ($answers as $answer) {
if ($this->properties->qoption) {
if ($useranswer == NULL) {
if ($useranswer == null) {
$userresponse = array();
} else {
$userresponse = explode(",", $useranswer->useranswer);
@@ -362,7 +362,7 @@ class lesson_page_type_multichoice extends lesson_page {
// make checked
$data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[$i]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
if (!isset($answerdata->response)) {
if ($answer->response == NULL) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
@@ -391,10 +391,10 @@ class lesson_page_type_multichoice extends lesson_page {
$data .= format_text($answer->answer,$answer->answerformat,$formattextdefoptions);
}
} else {
if ($useranswer != NULL and $answer->id == $useranswer->answerid) {
if ($useranswer != null and $answer->id == $useranswer->answerid) {
// make checked
$data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[$i]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
if ($answer->response == NULL) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
@@ -449,9 +449,9 @@ class lesson_add_page_form_multichoice extends lesson_add_page_form_base {
for ($i = 0; $i < $this->_customdata['lesson']->maxanswers; $i++) {
$this->_form->addElement('header', 'answertitle'.$i, get_string('answer').' '.($i+1));
$this->add_answer($i, NULL, ($i<2));
$this->add_answer($i, null, ($i<2));
$this->add_response($i);
$this->add_jumpto($i, NULL, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE));
$this->add_jumpto($i, null, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE));
$this->add_score($i, null, ($i===0)?1:0);
}
}
+3 -3
View File
@@ -210,7 +210,7 @@ class lesson_page_type_numerical extends lesson_page {
$answerdata->answers[] = array($data, $percent);
if ($answer->id == $useranswer->answerid) {
if ($answer->response == NULL) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
@@ -249,9 +249,9 @@ class lesson_add_page_form_numerical extends lesson_add_page_form_base {
public function custom_definition() {
for ($i = 0; $i < $this->_customdata['lesson']->maxanswers; $i++) {
$this->_form->addElement('header', 'answertitle'.$i, get_string('answer').' '.($i+1));
$this->add_answer($i, NULL, ($i < 1));
$this->add_answer($i, null, ($i < 1));
$this->add_response($i);
$this->add_jumpto($i, NULL, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE));
$this->add_jumpto($i, null, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE));
$this->add_score($i, null, ($i===0)?1:0);
}
}
+2 -2
View File
@@ -273,7 +273,7 @@ class lesson_page_type_shortanswer extends lesson_page {
$answerdata->answers[] = array($data, $percent);
if ($answer->id == $useranswer->answerid) {
if ($answer->response == NULL) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
@@ -322,7 +322,7 @@ class lesson_add_page_form_shortanswer extends lesson_add_page_form_base {
$this->_form->addElement('header', 'answertitle'.$i, get_string('answer').' '.($i+1));
$this->add_answer($i);
$this->add_response($i);
$this->add_jumpto($i, NULL, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE));
$this->add_jumpto($i, null, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE));
$this->add_score($i, null, ($i===0)?1:0);
}
}
+6 -6
View File
@@ -239,7 +239,7 @@ class lesson_page_type_truefalse extends lesson_page {
$formattextdefoptions->noclean = true;
foreach ($answers as $answer) {
if ($this->properties->qoption) {
if ($useranswer == NULL) {
if ($useranswer == null) {
$userresponse = array();
} else {
$userresponse = explode(",", $useranswer->useranswer);
@@ -248,7 +248,7 @@ class lesson_page_type_truefalse extends lesson_page {
// make checked
$data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[$i]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
if (!isset($answerdata->response)) {
if ($answer->response == NULL) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
@@ -277,10 +277,10 @@ class lesson_page_type_truefalse extends lesson_page {
$data .= format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
}
} else {
if ($useranswer != NULL and $answer->id == $useranswer->answerid) {
if ($useranswer != null and $answer->id == $useranswer->answerid) {
// make checked
$data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[$i]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
if ($answer->response == NULL) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
@@ -328,13 +328,13 @@ class lesson_add_page_form_truefalse extends lesson_add_page_form_base {
public function custom_definition() {
$this->_form->addElement('header', 'answertitle0', get_string('correctresponse', 'lesson'));
$this->add_answer(0, NULL, true);
$this->add_answer(0, null, true);
$this->add_response(0);
$this->add_jumpto(0, get_string('correctanswerjump', 'lesson'), LESSON_NEXTPAGE);
$this->add_score(0, get_string('correctanswerscore', 'lesson'), 1);
$this->_form->addElement('header', 'answertitle1', get_string('wrongresponse', 'lesson'));
$this->add_answer(1, NULL, true);
$this->add_answer(1, null, true);
$this->add_response(1);
$this->add_jumpto(1, get_string('wronganswerjump', 'lesson'), LESSON_THISPAGE);
$this->add_score(1, get_string('wronganswerscore', 'lesson'), 0);
+1 -1
View File
@@ -30,7 +30,7 @@ require_once($CFG->dirroot.'/mod/lesson/view_form.php');
require_once($CFG->libdir . '/completionlib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$pageid = optional_param('pageid', NULL, PARAM_INT); // Lesson Page ID
$pageid = optional_param('pageid', null, PARAM_INT); // Lesson Page ID
$edit = optional_param('edit', -1, PARAM_BOOL);
$userpassword = optional_param('userpassword','',PARAM_RAW);
$backtocourse = optional_param('backtocourse', false, PARAM_RAW);