[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * mod_lesson data generator. 19 * 20 * @package mod_lesson 21 * @category test 22 * @copyright 2013 Marina Glancy 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * mod_lesson data generator class. 30 * 31 * @package mod_lesson 32 * @category test 33 * @copyright 2013 Marina Glancy 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class mod_lesson_generator extends testing_module_generator { 37 38 /** 39 * @var int keep track of how many pages have been created. 40 */ 41 protected $pagecount = 0; 42 43 /** 44 * To be called from data reset code only, 45 * do not use in tests. 46 * @return void 47 */ 48 public function reset() { 49 $this->pagecount = 0; 50 parent::reset(); 51 } 52 53 public function create_instance($record = null, array $options = null) { 54 global $CFG; 55 56 // Add default values for lesson. 57 $record = (array)$record + array( 58 'progressbar' => 0, 59 'ongoing' => 0, 60 'displayleft' => 0, 61 'displayleftif' => 0, 62 'slideshow' => 0, 63 'maxanswers' => $CFG->lesson_maxanswers, 64 'feedback' => 0, 65 'activitylink' => 0, 66 'available' => 0, 67 'deadline' => 0, 68 'usepassword' => 0, 69 'password' => '', 70 'dependency' => 0, 71 'timespent' => 0, 72 'completed' => 0, 73 'gradebetterthan' => 0, 74 'modattempts' => 0, 75 'review' => 0, 76 'maxattempts' => 1, 77 'nextpagedefault' => $CFG->lesson_defaultnextpage, 78 'maxpages' => 0, 79 'practice' => 0, 80 'custom' => 1, 81 'retake' => 0, 82 'usemaxgrade' => 0, 83 'minquestions' => 0, 84 'grade' => 100, 85 ); 86 if (!isset($record['mediafile'])) { 87 require_once($CFG->libdir.'/filelib.php'); 88 $record['mediafile'] = file_get_unused_draft_itemid(); 89 } 90 91 return parent::create_instance($record, (array)$options); 92 } 93 94 public function create_content($lesson, $record = array()) { 95 global $DB, $CFG; 96 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 97 $now = time(); 98 $this->pagecount++; 99 $record = (array)$record + array( 100 'lessonid' => $lesson->id, 101 'title' => 'Lesson page '.$this->pagecount, 102 'timecreated' => $now, 103 'qtype' => 20, // LESSON_PAGE_BRANCHTABLE 104 'pageid' => 0, // By default insert in the beginning. 105 ); 106 if (!isset($record['contents_editor'])) { 107 $record['contents_editor'] = array( 108 'text' => 'Contents of lesson page '.$this->pagecount, 109 'format' => FORMAT_MOODLE, 110 'itemid' => 0, 111 ); 112 } 113 $context = context_module::instance($lesson->cmid); 114 $page = lesson_page::create((object)$record, new lesson($lesson), $context, $CFG->maxbytes); 115 return $DB->get_record('lesson_pages', array('id' => $page->id), '*', MUST_EXIST); 116 } 117 }
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 |