Skip to content

Commit

Permalink
MDL-38429 Lesson Module: improve lesson code by reseting NULL value t…
Browse files Browse the repository at this point in the history
…o use lowercase.
  • Loading branch information
Rossiani Wijaya committed Mar 25, 2013
1 parent 1b58651 commit ecea65c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions mod/lesson/format.php
Expand Up @@ -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,
Expand Down Expand Up @@ -510,7 +510,7 @@ protected function readquestion($lines) {

echo "<p>This flash question format has not yet been completed!</p>";

return NULL;
return null;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions mod/lesson/lib.php
Expand Up @@ -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 {
Expand Down Expand Up @@ -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');
Expand All @@ -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)) {
Expand Down
14 changes: 7 additions & 7 deletions mod/lesson/locallib.php
Expand Up @@ -774,12 +774,12 @@ protected final function add_score($name, $label=null, $value=null) {
* 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));
Expand All @@ -792,12 +792,12 @@ protected final function add_answer($count, $label = NULL, $required = false) {
* 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));
Expand Down Expand Up @@ -963,7 +963,7 @@ public function delete() {
}
}

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;
}

Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/pagetypes/branchtable.php
Expand Up @@ -153,7 +153,7 @@ public function check_answer() {
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;
Expand Down
4 changes: 2 additions & 2 deletions mod/lesson/pagetypes/essay.php
Expand Up @@ -184,9 +184,9 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$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);
Expand Down
18 changes: 9 additions & 9 deletions mod/lesson/pagetypes/matching.php
Expand Up @@ -71,7 +71,7 @@ protected function make_answer_form($attempt=null) {
$responses = array();
foreach ($answers as $answer) {
// get all the response
if ($answer->response != NULL) {
if ($answer->response != null) {
$responses[$answer->id] = trim($answer->response);
}
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public function display_answers(html_table $table) {

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>';
Expand Down Expand Up @@ -377,8 +377,8 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$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;
Expand All @@ -388,8 +388,8 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
} 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;
Expand All @@ -402,7 +402,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
} 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\">";
Expand Down Expand Up @@ -472,7 +472,7 @@ public function custom_definition() {

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;
Expand Down Expand Up @@ -520,7 +520,7 @@ public function definition() {
$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;
Expand Down
12 changes: 6 additions & 6 deletions mod/lesson/pagetypes/multichoice.php
Expand Up @@ -353,7 +353,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats

foreach ($answers as $answer) {
if ($this->properties->qoption) {
if ($useranswer == NULL) {
if ($useranswer == null) {
$userresponse = array();
} else {
$userresponse = explode(",", $useranswer->useranswer);
Expand All @@ -362,7 +362,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
// 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 {
Expand Down Expand Up @@ -391,10 +391,10 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$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 {
Expand Down Expand Up @@ -449,9 +449,9 @@ 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<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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions mod/lesson/pagetypes/numerical.php
Expand Up @@ -210,7 +210,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$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 {
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions mod/lesson/pagetypes/shortanswer.php
Expand Up @@ -273,7 +273,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$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 {
Expand Down Expand Up @@ -322,7 +322,7 @@ public function custom_definition() {
$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);
}
}
Expand Down
12 changes: 6 additions & 6 deletions mod/lesson/pagetypes/truefalse.php
Expand Up @@ -239,7 +239,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$formattextdefoptions->noclean = true;
foreach ($answers as $answer) {
if ($this->properties->qoption) {
if ($useranswer == NULL) {
if ($useranswer == null) {
$userresponse = array();
} else {
$userresponse = explode(",", $useranswer->useranswer);
Expand All @@ -248,7 +248,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
// 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 {
Expand Down Expand Up @@ -277,10 +277,10 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$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 {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/view.php
Expand Up @@ -30,7 +30,7 @@
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);
Expand Down

0 comments on commit ecea65c

Please sign in to comment.