|
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_CLUSTER", "30"); 00031 00032 class lesson_page_type_cluster extends lesson_page { 00033 00034 protected $type = lesson_page::TYPE_STRUCTURE; 00035 protected $typeidstring = 'cluster'; 00036 protected $typeid = LESSON_PAGE_CLUSTER; 00037 protected $string = null; 00038 protected $jumpto = null; 00039 00040 public function display($renderer, $attempt) { 00041 return ''; 00042 } 00043 00044 public function get_typeid() { 00045 return $this->typeid; 00046 } 00047 public function get_typestring() { 00048 if ($this->string===null) { 00049 $this->string = get_string($this->typeidstring, 'lesson'); 00050 } 00051 return $this->string; 00052 } 00053 public function get_idstring() { 00054 return $this->typeidstring; 00055 } 00056 public function get_grayout() { 00057 return 1; 00058 } 00059 public function callback_on_view($canmanage) { 00060 global $USER; 00061 if (!$canmanage) { 00062 // Get the next page in the lesson cluster jump 00063 return $this->lesson->cluster_jump($this->properties->id); 00064 } else { 00065 // get the next page 00066 return $this->properties->nextpageid; 00067 } 00068 } 00069 public function override_next_page() { 00070 global $USER; 00071 return $this->lesson->cluster_jump($this->properties->id); 00072 } 00073 public function add_page_link($previd) { 00074 global $PAGE, $CFG; 00075 $addurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$PAGE->cm->id, 'pageid'=>$previd, 'sesskey'=>sesskey(), 'qtype'=>LESSON_PAGE_CLUSTER)); 00076 return array('addurl'=>$addurl, 'type'=>LESSON_PAGE_CLUSTER, 'name'=>get_string('addcluster', 'lesson')); 00077 } 00078 public function valid_page_and_view(&$validpages, &$pageviews) { 00079 $validpages[$this->properties->id] = 1; // add the cluster page as a valid page 00080 foreach ($this->lesson->get_sub_pages_of($this->properties->id, array(LESSON_PAGE_ENDOFCLUSTER)) as $subpage) { 00081 if (in_array($subpage->id, $pageviews)) { 00082 unset($pageviews[array_search($subpage->id, $pageviews)]); // remove it 00083 // since the user did see one page in the cluster, add the cluster pageid to the viewedpageids 00084 if (!in_array($this->properties->id, $pageviews)) { 00085 $pageviews[] = $this->properties->id; 00086 } 00087 } 00088 } 00089 return $this->properties->nextpageid; 00090 } 00091 } 00092 00093 class lesson_add_page_form_cluster extends lesson_add_page_form_base { 00094 00095 public $qtype = LESSON_PAGE_CLUSTER; 00096 public $qtypestring = 'cluster'; 00097 protected $standard = false; 00098 00099 public function custom_definition() { 00100 global $PAGE; 00101 00102 $mform = $this->_form; 00103 $lesson = $this->_customdata['lesson']; 00104 $jumptooptions = lesson_page_type_branchtable::get_jumptooptions(optional_param('firstpage', false, PARAM_BOOL), $lesson); 00105 00106 $mform->addElement('hidden', 'firstpage'); 00107 $mform->setType('firstpage', PARAM_BOOL); 00108 00109 $mform->addElement('hidden', 'qtype'); 00110 $mform->setType('qtype', PARAM_TEXT); 00111 00112 $mform->addElement('text', 'title', get_string("pagetitle", "lesson"), array('size'=>70)); 00113 $mform->setType('title', PARAM_TEXT); 00114 00115 $this->editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$PAGE->course->maxbytes); 00116 $mform->addElement('editor', 'contents_editor', get_string("pagecontents", "lesson"), null, $this->editoroptions); 00117 $mform->setType('contents_editor', PARAM_RAW); 00118 00119 $this->add_jumpto(0); 00120 } 00121 00122 00123 public function construction_override($pageid, lesson $lesson) { 00124 global $PAGE, $CFG, $DB; 00125 require_sesskey(); 00126 00127 $timenow = time(); 00128 00129 if ($pageid == 0) { 00130 if ($lesson->has_pages()) { 00131 if (!$page = $DB->get_record("lesson_pages", array("prevpageid" => 0, "lessonid" => $lesson->id))) { 00132 print_error('cannotfindpagerecord', 'lesson'); 00133 } 00134 } else { 00135 // This is the ONLY page 00136 $page = new stdClass; 00137 $page->id = 0; 00138 } 00139 } else { 00140 if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { 00141 print_error('cannotfindpagerecord', 'lesson'); 00142 } 00143 } 00144 $newpage = new stdClass; 00145 $newpage->lessonid = $lesson->id; 00146 $newpage->prevpageid = $pageid; 00147 if ($pageid != 0) { 00148 $newpage->nextpageid = $page->nextpageid; 00149 } else { 00150 $newpage->nextpageid = $page->id; 00151 } 00152 $newpage->qtype = $this->qtype; 00153 $newpage->timecreated = $timenow; 00154 $newpage->title = get_string("clustertitle", "lesson"); 00155 $newpage->contents = get_string("clustertitle", "lesson"); 00156 $newpageid = $DB->insert_record("lesson_pages", $newpage); 00157 // update the linked list... 00158 if ($pageid != 0) { 00159 $DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid)); 00160 } 00161 00162 if ($pageid == 0) { 00163 $page->nextpageid = $page->id; 00164 } 00165 if ($page->nextpageid) { 00166 // the new page is not the last page 00167 $DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid)); 00168 } 00169 // ..and the single "answer" 00170 $newanswer = new stdClass; 00171 $newanswer->lessonid = $lesson->id; 00172 $newanswer->pageid = $newpageid; 00173 $newanswer->timecreated = $timenow; 00174 $newanswer->jumpto = LESSON_CLUSTERJUMP; 00175 $newanswerid = $DB->insert_record("lesson_answers", $newanswer); 00176 $lesson->add_message(get_string('addedcluster', 'lesson'), 'notifysuccess'); 00177 redirect($CFG->wwwroot.'/mod/lesson/edit.php?id='.$PAGE->cm->id); 00178 } 00179 }