[ Index ] |
PHP Cross Reference of Unnamed Project |
[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 102 public function add_page_link($previd) { 103 global $PAGE, $CFG; 104 if ($previd != 0) { 105 $addurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$PAGE->cm->id, 'pageid'=>$previd, 'sesskey'=>sesskey(), 'qtype'=>LESSON_PAGE_ENDOFBRANCH)); 106 return array('addurl'=>$addurl, 'type'=>LESSON_PAGE_ENDOFBRANCH, 'name'=>get_string('addanendofbranch', 'lesson')); 107 } 108 return false; 109 } 110 public function valid_page_and_view(&$validpages, &$pageviews) { 111 return $this->properties->nextpageid; 112 } 113 } 114 115 class lesson_add_page_form_endofbranch extends lesson_add_page_form_base { 116 117 public $qtype = LESSON_PAGE_ENDOFBRANCH; 118 public $qtypestring = 'endofbranch'; 119 protected $standard = false; 120 121 public function custom_definition() { 122 global $PAGE; 123 124 $mform = $this->_form; 125 $lesson = $this->_customdata['lesson']; 126 $jumptooptions = lesson_page_type_branchtable::get_jumptooptions(optional_param('firstpage', false, PARAM_BOOL), $lesson); 127 128 $mform->addElement('hidden', 'firstpage'); 129 $mform->setType('firstpage', PARAM_BOOL); 130 131 $mform->addElement('hidden', 'qtype'); 132 $mform->setType('qtype', PARAM_TEXT); 133 134 $mform->addElement('text', 'title', get_string("pagetitle", "lesson"), array('size'=>70)); 135 $mform->setType('title', PARAM_TEXT); 136 137 $this->editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes); 138 $mform->addElement('editor', 'contents_editor', get_string("pagecontents", "lesson"), null, $this->editoroptions); 139 $mform->setType('contents_editor', PARAM_RAW); 140 141 $this->add_jumpto(0); 142 } 143 144 public function construction_override($pageid, lesson $lesson) { 145 global $DB, $CFG, $PAGE; 146 require_sesskey(); 147 148 // first get the preceeding page 149 150 $timenow = time(); 151 152 // the new page is not the first page (end of branch always comes after an existing page) 153 if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { 154 print_error('cannotfindpagerecord', 'lesson'); 155 } 156 // chain back up to find the (nearest branch table) 157 $btpage = clone($page); 158 $btpageid = $btpage->id; 159 while (($btpage->qtype != LESSON_PAGE_BRANCHTABLE) && ($btpage->prevpageid > 0)) { 160 $btpageid = $btpage->prevpageid; 161 if (!$btpage = $DB->get_record("lesson_pages", array("id" => $btpageid))) { 162 print_error('cannotfindpagerecord', 'lesson'); 163 } 164 } 165 166 if ($btpage->qtype == LESSON_PAGE_BRANCHTABLE) { 167 $newpage = new stdClass; 168 $newpage->lessonid = $lesson->id; 169 $newpage->prevpageid = $pageid; 170 $newpage->nextpageid = $page->nextpageid; 171 $newpage->qtype = $this->qtype; 172 $newpage->timecreated = $timenow; 173 $newpage->title = get_string("endofbranch", "lesson"); 174 $newpage->contents = get_string("endofbranch", "lesson"); 175 $newpageid = $DB->insert_record("lesson_pages", $newpage); 176 // update the linked list... 177 $DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid)); 178 if ($page->nextpageid) { 179 // the new page is not the last page 180 $DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid)); 181 } 182 // ..and the single "answer" 183 $newanswer = new stdClass; 184 $newanswer->lessonid = $lesson->id; 185 $newanswer->pageid = $newpageid; 186 $newanswer->timecreated = $timenow; 187 $newanswer->jumpto = $btpageid; 188 $newanswerid = $DB->insert_record("lesson_answers", $newanswer); 189 $lesson->add_message(get_string('addedanendofbranch', 'lesson'), 'notifysuccess'); 190 } else { 191 $lesson->add_message(get_string('nobranchtablefound', 'lesson')); 192 } 193 194 redirect($CFG->wwwroot."/mod/lesson/edit.php?id=".$PAGE->cm->id); 195 } 196 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |