|
| 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 | + * Test data generator for tool_corruptpdfdetector. |
| 19 | + * |
| 20 | + * @package tool_corruptpdfdetector |
| 21 | + * @category test |
| 22 | + * @copyright Catalyst IT |
| 23 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 24 | + */ |
| 25 | + |
| 26 | +defined('MOODLE_INTERNAL') || die(); |
| 27 | + |
| 28 | +/** |
| 29 | + * Data generator for tool_corruptpdfdetector. |
| 30 | + * |
| 31 | + * @package tool_corruptpdfdetector |
| 32 | + * @category test |
| 33 | + * @copyright Catalyst IT |
| 34 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 35 | + */ |
| 36 | +class tool_corruptpdfdetector_generator extends testing_module_generator { |
| 37 | + /** |
| 38 | + * Create a detection record in tool_corruptpdfdetector_assigns. |
| 39 | + * |
| 40 | + * Accepted keys in $record: |
| 41 | + * - assignid (int, default 0) |
| 42 | + * - submissionid (int, default auto-incremented unique value) |
| 43 | + * - coursename (string, default '') |
| 44 | + * - assignname (string, default '') |
| 45 | + * - userfullname (string, default '') |
| 46 | + * - email (string, default '') |
| 47 | + * - filename (string, default sha1 of submissionid) |
| 48 | + * - message (string, default '') |
| 49 | + * - submitted (int, default current time) |
| 50 | + * - detected (int, default current time) |
| 51 | + * - fixed (int, default 0) |
| 52 | + * |
| 53 | + * @param array|stdClass|null $record Detection record data. |
| 54 | + * @return stdClass Inserted record with id populated. |
| 55 | + */ |
| 56 | + public function create_detection($record = null): stdClass { |
| 57 | + global $DB; |
| 58 | + |
| 59 | + $record = (object)(array) $record; |
| 60 | + |
| 61 | + if (!isset($record->assignid)) { |
| 62 | + $record->assignid = 0; |
| 63 | + } |
| 64 | + if (!isset($record->submissionid)) { |
| 65 | + $record->submissionid = $DB->get_field_sql( |
| 66 | + 'SELECT COALESCE(MAX(submissionid), 0) + 1 FROM {tool_corruptpdfdetector_assigns}' |
| 67 | + ); |
| 68 | + } |
| 69 | + if (!isset($record->coursename)) { |
| 70 | + $record->coursename = ''; |
| 71 | + } |
| 72 | + if (!isset($record->assignname)) { |
| 73 | + $record->assignname = ''; |
| 74 | + } |
| 75 | + if (!isset($record->userfullname)) { |
| 76 | + $record->userfullname = ''; |
| 77 | + } |
| 78 | + if (!isset($record->email)) { |
| 79 | + $record->email = ''; |
| 80 | + } |
| 81 | + if (!isset($record->filename)) { |
| 82 | + $record->filename = sha1((string) $record->submissionid); |
| 83 | + } |
| 84 | + if (!isset($record->message)) { |
| 85 | + $record->message = ''; |
| 86 | + } |
| 87 | + if (!isset($record->submitted)) { |
| 88 | + $record->submitted = time(); |
| 89 | + } |
| 90 | + if (!isset($record->detected)) { |
| 91 | + $record->detected = time(); |
| 92 | + } |
| 93 | + if (!isset($record->fixed)) { |
| 94 | + $record->fixed = 0; |
| 95 | + } |
| 96 | + |
| 97 | + $record->id = $DB->insert_record('tool_corruptpdfdetector_assigns', $record); |
| 98 | + |
| 99 | + return $record; |
| 100 | + } |
| 101 | +} |
0 commit comments