2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * core_notes data generator.
22 * @copyright 2013 Ankit Agarwal
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
29 * core_notes data generator class.
33 * @copyright 2013 Ankit Agarwal
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class core_notes_generator
extends component_generator_base
{
39 * @var number of created instances
41 protected $instancecount = 0;
44 * To be called from data reset code only,
45 * do not use in tests.
48 public function reset() {
49 $this->instancecount
= 0;
55 * @param array|stdClass $record
56 * @throws coding_exception
57 * @return stdClass activity record with extra cmid field
59 public function create_instance($record = null) {
61 require_once("$CFG->dirroot/notes/lib.php");
63 $this->instancecount++
;
64 $i = $this->instancecount
;
65 $record = (object)(array)$record;
67 if (empty($record->courseid
)) {
68 throw new coding_exception('Module generator requires $record->courseid.');
70 if (empty($record->userid
)) {
71 throw new coding_exception('Module generator requires $record->userid.');
73 if (!isset($record->module
)) {
74 $record->module
= 'notes';
76 if (!isset($record->groupid
)) {
79 if (!isset($record->moduleid
)) {
80 $record->moduleid
= 0;
82 if (!isset($record->coursemoduleid
)) {
83 $record->coursemoduleid
= 0;
85 if (!isset($record->subject
)) {
86 $record->subject
= '';
88 if (!isset($record->summary
)) {
89 $record->summary
= null;
91 if (!isset($record->content
)) {
92 $record->content
= "This is test generated note - $i .";
94 if (!isset($record->uniquehash
)) {
95 $record->uniquehash
= '';
97 if (!isset($record->rating
)) {
100 if (!isset($record->format
)) {
101 $record->format
= FORMAT_PLAIN
;
103 if (!isset($record->summaryformat
)) {
104 $record->summaryformat
= FORMAT_MOODLE
;
106 if (!isset($record->attachment
)) {
107 $record->attachment
= null;
109 if (!isset($record->publishstate
)) {
110 $record->publishstate
= NOTES_STATE_SITE
;
112 if (!isset($record->lastmodified
)) {
113 $record->lastmodified
= time();
115 if (!isset($record->created
)) {
116 $record->created
= time();
118 if (!isset($record->usermodified
)) {
119 $record->usermodified
= $USER->id
;