[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * End of branch table 20 * 21 * @package mod_lesson 22 * @copyright 2009 Sam Hemelryk 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 **/ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** End of Branch page */ 29 define("LESSON_PAGE_ENDOFBRANCH", "21"); 30 31 class lesson_page_type_endofbranch extends lesson_page { 32 33 protected $type = lesson_page::TYPE_STRUCTURE; 34 protected $typeidstring = 'endofbranch'; 35 protected $typeid = LESSON_PAGE_ENDOFBRANCH; 36 protected $string = null; 37 protected $jumpto = null; 38 39 public function display($renderer, $attempt) { 40 return ''; 41 } 42 public function get_typeid() { 43 return $this->typeid; 44 } 45 public function get_typestring() { 46 if ($this->string===null) { 47 $this->string = get_string($this->typeidstring, 'lesson'); 48 } 49 return $this->string; 50 } 51 public function get_idstring() { 52 return $this->typeidstring; 53 } 54 public function callback_on_view($canmanage) { 55 $this->redirect_to_first_answer($canmanage); 56 exit; 57 } 58 59 public function redirect_to_first_answer($canmanage) { 60 global $USER, $PAGE; 61 $answer = array_shift($this->get_answers()); 62 $jumpto = $answer->jumpto; 63 if ($jumpto == LESSON_RANDOMBRANCH) { 64 65 $jumpto = lesson_unseen_branch_jump($this->lesson, $USER->id); 66 67 } elseif ($jumpto == LESSON_CLUSTERJUMP) { 68 69 if (!$canmanage) { 70 $jumpto = $this->lesson->cluster_jump($this->properties->id); 71 } else { 72 if ($this->properties->nextpageid == 0) { 73 $jumpto = LESSON_EOL; 74 } else { 75 $jumpto = $this->properties->nextpageid; 76 } 77 } 78 79 } else if ($answer->jumpto == LESSON_NEXTPAGE) { 80 81 if ($this->properties->nextpageid == 0) { 82 $jumpto = LESSON_EOL; 83 } else { 84 $jumpto = $this->properties->nextpageid; 85 } 86 87 } else if ($jumpto == 0) { 88 89 $jumpto = $this->properties->id; 90 91 } else if ($jumpto == LESSON_PREVIOUSPAGE) { 92 93 $jumpto = $this->properties->prevpageid; 94 95 } 96 redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$jumpto))); 97 } 98 public function get_grayout() { 99 return 1; 100 } 101 public function update($properties, $context = null, $maxbytes = null) { 102 global $DB, $PAGE; 103 104 $properties->id = $this->properties->id; 105 $properties->lessonid = $this->lesson->id; 106 if (empty($properties->qoption)) { 107 $properties->qoption = '0'; 108 } 109 $properties->timemodified = time(); 110 $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes), context_module::instance($PAGE->cm->id), 'mod_lesson', 'page_contents', $properties->id); 111 $DB->update_record("lesson_pages", $properties); 112 113 $answers = $this->get_answers(); 114 if (count($answers)>1) { 115 $answer = array_shift($answers); 116 foreach ($answers as $a) { 117 $DB->delete_record('lesson_answers', array('id'=>$a->id)); 118 } 119 } else if (count($answers)==1) { 120 $answer = array_shift($answers); 121 } else { 122 $answer = new stdClass; 123 } 124 125 $answer->timemodified = time(); 126 if (isset($properties->jumpto[0])) { 127 $answer->jumpto = $properties->jumpto[0]; 128 } 129 if (isset($properties->score[0])) { 130 $answer->score = $properties->score[0]; 131 } 132 if (!empty($answer->id)) { 133 $DB->update_record("lesson_answers", $answer->properties()); 134 } else { 135 $DB->insert_record("lesson_answers", $answer); 136 } 137 return true; 138 } 139 public function add_page_link($previd) { 140 global $PAGE, $CFG; 141 if ($previd != 0) { 142 $addurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$PAGE->cm->id, 'pageid'=>$previd, 'sesskey'=>sesskey(), 'qtype'=>LESSON_PAGE_ENDOFBRANCH)); 143 return array('addurl'=>$addurl, 'type'=>LESSON_PAGE_ENDOFBRANCH, 'name'=>get_string('addanendofbranch', 'lesson')); 144 } 145 return false; 146 } 147 public function valid_page_and_view(&$validpages, &$pageviews) { 148 return $this->properties->nextpageid; 149 } 150 } 151 152 class lesson_add_page_form_endofbranch extends lesson_add_page_form_base { 153 154 public $qtype = LESSON_PAGE_ENDOFBRANCH; 155 public $qtypestring = 'endofbranch'; 156 protected $standard = false; 157 158 public function custom_definition() { 159 global $PAGE; 160 161 $mform = $this->_form; 162 $lesson = $this->_customdata['lesson']; 163 $jumptooptions = lesson_page_type_branchtable::get_jumptooptions(optional_param('firstpage', false, PARAM_BOOL), $lesson); 164 165 $mform->addElement('hidden', 'firstpage'); 166 $mform->setType('firstpage', PARAM_BOOL); 167 168 $mform->addElement('hidden', 'qtype'); 169 $mform->setType('qtype', PARAM_TEXT); 170 171 $mform->addElement('text', 'title', get_string("pagetitle", "lesson"), array('size'=>70)); 172 $mform->setType('title', PARAM_TEXT); 173 174 $this->editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes); 175 $mform->addElement('editor', 'contents_editor', get_string("pagecontents", "lesson"), null, $this->editoroptions); 176 $mform->setType('contents_editor', PARAM_RAW); 177 178 $this->add_jumpto(0); 179 } 180 181 public function construction_override($pageid, lesson $lesson) { 182 global $DB, $CFG, $PAGE; 183 require_sesskey(); 184 185 // first get the preceeding page 186 187 $timenow = time(); 188 189 // the new page is not the first page (end of branch always comes after an existing page) 190 if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { 191 print_error('cannotfindpagerecord', 'lesson'); 192 } 193 // chain back up to find the (nearest branch table) 194 $btpage = clone($page); 195 $btpageid = $btpage->id; 196 while (($btpage->qtype != LESSON_PAGE_BRANCHTABLE) && ($btpage->prevpageid > 0)) { 197 $btpageid = $btpage->prevpageid; 198 if (!$btpage = $DB->get_record("lesson_pages", array("id" => $btpageid))) { 199 print_error('cannotfindpagerecord', 'lesson'); 200 } 201 } 202 203 if ($btpage->qtype == LESSON_PAGE_BRANCHTABLE) { 204 $newpage = new stdClass; 205 $newpage->lessonid = $lesson->id; 206 $newpage->prevpageid = $pageid; 207 $newpage->nextpageid = $page->nextpageid; 208 $newpage->qtype = $this->qtype; 209 $newpage->timecreated = $timenow; 210 $newpage->title = get_string("endofbranch", "lesson"); 211 $newpage->contents = get_string("endofbranch", "lesson"); 212 $newpageid = $DB->insert_record("lesson_pages", $newpage); 213 // update the linked list... 214 $DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid)); 215 if ($page->nextpageid) { 216 // the new page is not the last page 217 $DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid)); 218 } 219 // ..and the single "answer" 220 $newanswer = new stdClass; 221 $newanswer->lessonid = $lesson->id; 222 $newanswer->pageid = $newpageid; 223 $newanswer->timecreated = $timenow; 224 $newanswer->jumpto = $btpageid; 225 $newanswerid = $DB->insert_record("lesson_answers", $newanswer); 226 $lesson->add_message(get_string('addedanendofbranch', 'lesson'), 'notifysuccess'); 227 } else { 228 $lesson->add_message(get_string('nobranchtablefound', 'lesson')); 229 } 230 231 redirect($CFG->wwwroot."/mod/lesson/edit.php?id=".$PAGE->cm->id); 232 } 233 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |