|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00030 define("LESSON_PAGE_ENDOFCLUSTER", "31"); 00031 00032 class lesson_page_type_endofcluster extends lesson_page { 00033 00034 protected $type = lesson_page::TYPE_STRUCTURE; 00035 protected $typeidstring = 'endofcluster'; 00036 protected $typeid = LESSON_PAGE_ENDOFCLUSTER; 00037 protected $string = null; 00038 protected $jumpto = null; 00039 00040 public function display($renderer, $attempt) { 00041 return ''; 00042 } 00043 public function get_typeid() { 00044 return $this->typeid; 00045 } 00046 public function get_typestring() { 00047 if ($this->string===null) { 00048 $this->string = get_string($this->typeidstring, 'lesson'); 00049 } 00050 return $this->string; 00051 } 00052 public function get_idstring() { 00053 return $this->typeidstring; 00054 } 00055 public function callback_on_view($canmanage) { 00056 $this->redirect_to_next_page($canmanage); 00057 exit; 00058 } 00059 public function redirect_to_next_page() { 00060 global $PAGE; 00061 if ($this->properties->nextpageid == 0) { 00062 $nextpageid = LESSON_EOL; 00063 } else { 00064 $nextpageid = $this->properties->nextpageid; 00065 } 00066 redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$nextpageid))); 00067 } 00068 public function get_grayout() { 00069 return 1; 00070 } 00071 public function update($properties) { 00072 global $DB, $PAGE; 00073 00074 $properties->id = $this->properties->id; 00075 $properties->lessonid = $this->lesson->id; 00076 if (empty($properties->qoption)) { 00077 $properties->qoption = '0'; 00078 } 00079 $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), get_context_instance(CONTEXT_MODULE, $PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id); 00080 $DB->update_record("lesson_pages", $properties); 00081 00082 $answers = $this->get_answers(); 00083 if (count($answers)>1) { 00084 $answer = array_shift($answers); 00085 foreach ($answers as $a) { 00086 $DB->delete_record('lesson_answers', array('id'=>$a->id)); 00087 } 00088 } else if (count($answers)==1) { 00089 $answer = array_shift($answers); 00090 } else { 00091 $answer = new stdClass; 00092 } 00093 00094 $answer->timemodified = time();; 00095 if (isset($properties->jumpto[0])) { 00096 $answer->jumpto = $properties->jumpto[0]; 00097 } 00098 if (isset($properties->score[0])) { 00099 $answer->score = $properties->score[0]; 00100 } 00101 if (!empty($answer->id)) { 00102 $DB->update_record("lesson_answers", $answer->properties()); 00103 } else { 00104 $DB->insert_record("lesson_answers", $answer); 00105 } 00106 return true; 00107 } 00108 public function override_next_page() { 00109 global $DB; 00110 $jump = $DB->get_field("lesson_answers", "jumpto", array("pageid" => $this->properties->id, "lessonid" => $this->lesson->id)); 00111 if ($jump == LESSON_NEXTPAGE) { 00112 if ($this->properties->nextpageid == 0) { 00113 return LESSON_EOL; 00114 } else { 00115 return $this->properties->nextpageid; 00116 } 00117 } else { 00118 return $jump; 00119 } 00120 } 00121 public function add_page_link($previd) { 00122 global $PAGE, $CFG; 00123 if ($previd != 0) { 00124 $addurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$PAGE->cm->id, 'pageid'=>$previd, 'sesskey'=>sesskey(), 'qtype'=>LESSON_PAGE_ENDOFCLUSTER)); 00125 return array('addurl'=>$addurl, 'type'=>LESSON_PAGE_ENDOFCLUSTER, 'name'=>get_string('addendofcluster', 'lesson')); 00126 } 00127 return false; 00128 } 00129 public function valid_page_and_view(&$validpages, &$pageviews) { 00130 return $this->properties->nextpageid; 00131 } 00132 } 00133 00134 class lesson_add_page_form_endofcluster extends lesson_add_page_form_base { 00135 00136 public $qtype = LESSON_PAGE_ENDOFCLUSTER; 00137 public $qtypestring = 'endofcluster'; 00138 protected $standard = false; 00139 00140 public function custom_definition() { 00141 global $PAGE; 00142 00143 $mform = $this->_form; 00144 $lesson = $this->_customdata['lesson']; 00145 $jumptooptions = lesson_page_type_branchtable::get_jumptooptions(optional_param('firstpage', false, PARAM_BOOL), $lesson); 00146 00147 $mform->addElement('hidden', 'firstpage'); 00148 $mform->setType('firstpage', PARAM_BOOL); 00149 00150 $mform->addElement('hidden', 'qtype'); 00151 $mform->setType('qtype', PARAM_TEXT); 00152 00153 $mform->addElement('text', 'title', get_string("pagetitle", "lesson"), array('size'=>70)); 00154 $mform->setType('title', PARAM_TEXT); 00155 00156 $this->editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes); 00157 $mform->addElement('editor', 'contents_editor', get_string("pagecontents", "lesson"), null, $this->editoroptions); 00158 $mform->setType('contents_editor', PARAM_RAW); 00159 00160 $this->add_jumpto(0); 00161 } 00162 00163 public function construction_override($pageid, $lesson) { 00164 global $CFG, $PAGE, $DB; 00165 require_sesskey(); 00166 00167 $timenow = time(); 00168 00169 // the new page is not the first page (end of cluster always comes after an existing page) 00170 if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { 00171 print_error('cannotfindpages', 'lesson'); 00172 } 00173 00174 // could put code in here to check if the user really can insert an end of cluster 00175 00176 $newpage = new stdClass; 00177 $newpage->lessonid = $lesson->id; 00178 $newpage->prevpageid = $pageid; 00179 $newpage->nextpageid = $page->nextpageid; 00180 $newpage->qtype = $this->qtype; 00181 $newpage->timecreated = $timenow; 00182 $newpage->title = get_string("endofclustertitle", "lesson"); 00183 $newpage->contents = get_string("endofclustertitle", "lesson"); 00184 $newpageid = $DB->insert_record("lesson_pages", $newpage); 00185 // update the linked list... 00186 $DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid)); 00187 if ($page->nextpageid) { 00188 // the new page is not the last page 00189 $DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid)); 00190 } 00191 // ..and the single "answer" 00192 $newanswer = new stdClass; 00193 $newanswer->lessonid = $lesson->id; 00194 $newanswer->pageid = $newpageid; 00195 $newanswer->timecreated = $timenow; 00196 $newanswer->jumpto = LESSON_NEXTPAGE; 00197 $newanswerid = $DB->insert_record("lesson_answers", $newanswer); 00198 $lesson->add_message(get_string('addedendofcluster', 'lesson'), 'notifysuccess'); 00199 redirect($CFG->wwwroot.'/mod/lesson/edit.php?id='.$PAGE->cm->id); 00200 } 00201 }