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
|
|
|
* The assignsubmission_edulegit submission repository class. |
19
|
|
|
* |
20
|
|
|
* @package assignsubmission_edulegit |
21
|
|
|
* @author Alex Crosby <[email protected]> |
22
|
|
|
* @copyright @2024 EduLegit.com |
23
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace assignsubmission_edulegit; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class edulegit_submission_repository |
30
|
|
|
* |
31
|
|
|
* Handles database operations related to EduLegit submissions. |
32
|
|
|
*/ |
33
|
|
|
class edulegit_submission_repository { |
34
|
|
|
|
35
|
|
|
/** @var string The database table name for EduLegit submissions. */ |
36
|
|
|
const EDULEGIT_SUBMISSION_TABLE_NAME = 'assignsubmission_edulegit'; |
37
|
|
|
|
38
|
|
|
/** @var \moodle_database The Moodle database object. */ |
|
|
|
|
39
|
|
|
private $db; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor for dulegit_submission_repository. |
43
|
|
|
*/ |
44
|
|
|
public function __construct() { |
45
|
|
|
global $DB; |
46
|
|
|
$this->db = $DB; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Retrieves a submission by its id. |
51
|
|
|
* |
52
|
|
|
* @param int $id The ID of the submission. |
53
|
|
|
* @return edulegit_submission_entity|null The submission entity or null if not found. |
54
|
|
|
*/ |
55
|
|
|
public function get_by_id(int $id): ?edulegit_submission_entity { |
56
|
|
|
$submission = $this->db->get_record(self::EDULEGIT_SUBMISSION_TABLE_NAME, ['id' => $id]); |
57
|
|
|
return $submission ? new edulegit_submission_entity($submission) : null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Retrieves a submission by its submission id. |
62
|
|
|
* |
63
|
|
|
* @param int $submissionid The submission id. |
64
|
|
|
* @return edulegit_submission_entity|null The submission entity or null if not found. |
65
|
|
|
*/ |
66
|
|
|
public function get_submission(int $submissionid): ?edulegit_submission_entity { |
67
|
|
|
$submission = $this->db->get_record(self::EDULEGIT_SUBMISSION_TABLE_NAME, ['submission' => $submissionid]); |
68
|
|
|
return $submission ? new edulegit_submission_entity($submission) : null; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Deletes a submission by its submission id. |
73
|
|
|
* |
74
|
|
|
* @param int $submissionid The submission id. |
75
|
|
|
* @return bool True on success, false on failure. |
76
|
|
|
*/ |
77
|
|
|
public function delete_submission(int $submissionid): bool { |
78
|
|
|
return $this->db->delete_records(self::EDULEGIT_SUBMISSION_TABLE_NAME, ['submission' => $submissionid]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Deletes all submissions related to a specific assignment id. |
83
|
|
|
* |
84
|
|
|
* @param int $assignmentid The assignment id. |
85
|
|
|
* @return bool True on success, false on failure. |
86
|
|
|
*/ |
87
|
|
|
public function delete_assignment(int $assignmentid): bool { |
88
|
|
|
return $this->db->delete_records(self::EDULEGIT_SUBMISSION_TABLE_NAME, ['assignment' => $assignmentid]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Inserts a new submission record into the database. |
93
|
|
|
* |
94
|
|
|
* @param edulegit_submission_entity $edulegitsubmission The submission entity to insert. |
95
|
|
|
* @return int|false The inserted record's ID or false on failure. |
96
|
|
|
*/ |
97
|
|
|
public function insert_submission(edulegit_submission_entity $edulegitsubmission) { |
98
|
|
|
$edulegitsubmission->createdat ??= time(); |
99
|
|
|
$edulegitsubmission->updatedat ??= time(); |
100
|
|
|
return $this->db->insert_record(self::EDULEGIT_SUBMISSION_TABLE_NAME, $edulegitsubmission); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Updates an existing submission record in the database. |
105
|
|
|
* |
106
|
|
|
* @param edulegit_submission_entity $edulegitsubmission The submission entity to update. |
107
|
|
|
* @return bool True on success, false on failure. |
108
|
|
|
*/ |
109
|
|
|
public function update_submission(edulegit_submission_entity $edulegitsubmission): bool { |
110
|
|
|
$edulegitsubmission->updatedat = time(); |
111
|
|
|
return $this->db->update_record(self::EDULEGIT_SUBMISSION_TABLE_NAME, $edulegitsubmission); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Retrieves assignment information by assignment id. |
116
|
|
|
* |
117
|
|
|
* @param int $assignmentid The assignment id. |
118
|
|
|
* @return object|null The assignment information or null if not found. |
119
|
|
|
*/ |
120
|
|
|
public function get_assignment_info(int $assignmentid) { |
121
|
|
|
$params = ['id' => $assignmentid]; |
122
|
|
|
$sql = "SELECT a.id, a.course, a.name, a.intro, a.duedate, a.allowsubmissionsfromdate, a.gradingduedate, a.activity, |
123
|
|
|
c.shortname AS course_shortname, c.fullname AS course_fullname, c.summary AS course_summary, |
124
|
|
|
c.startdate AS course_startdate, c.enddate AS course_enddate |
125
|
|
|
FROM {assign} a |
126
|
|
|
JOIN {course} c ON c.id = a.course |
127
|
|
|
WHERE c.id = :id"; |
128
|
|
|
|
129
|
|
|
return $this->db->get_record_sql($sql, $params); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths