Gitlab CSE Unil

observer.php 2.53 KB
Newer Older
M. Chardon's avatar
init  
M. Chardon committed
1
<?php
2

M. Chardon's avatar
init  
M. Chardon committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * An event observer.
 *
 * @package    assignfeedback_editpdfplus
22
23
 * @copyright  2016 Université de Lausanne
 * The code is based on mod/assign/feedback/editpdf/classes/event/observer.php by Damyon Wiese.
M. Chardon's avatar
init  
M. Chardon committed
24
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
26

M. Chardon's avatar
init  
M. Chardon committed
27
28
29
30
namespace assignfeedback_editpdfplus\event;

class observer {

31
32
33
34
    const BDDTABLEQUEUE = "assignfeedback_editpp_queue";
    const SUBMISSIONID = "submissionid";
    const SUBMISSIONATTEMPT = "submissionattempt";

M. Chardon's avatar
init  
M. Chardon committed
35
36
37
38
39
40
41
    /**
     * Listen to events and queue the submission for processing.
     * @param \mod_assign\event\submission_created $event
     */
    public static function submission_created(\mod_assign\event\submission_created $event) {
        global $DB;

42
43
44
        $submissionid = $event->other[self::SUBMISSIONID];
        $submissionattempt = $event->other[self::SUBMISSIONATTEMPT];
        $fields = array(self::SUBMISSIONID => $submissionid, self::SUBMISSIONATTEMPT => $submissionattempt);
M. Chardon's avatar
init  
M. Chardon committed
45
46
        $record = (object) $fields;

47
        $exists = $DB->get_records(self::BDDTABLEQUEUE, $fields);
M. Chardon's avatar
init  
M. Chardon committed
48
        if (!$exists) {
49
            $DB->insert_record(self::BDDTABLEQUEUE, $record);
M. Chardon's avatar
init  
M. Chardon committed
50
51
52
53
54
55
56
57
58
59
        }
    }

    /**
     * Listen to events and queue the submission for processing.
     * @param \mod_assign\event\submission_updated $event
     */
    public static function submission_updated(\mod_assign\event\submission_updated $event) {
        global $DB;

60
61
62
        $submissionid = $event->other[self::SUBMISSIONID];
        $submissionattempt = $event->other[self::SUBMISSIONATTEMPT];
        $fields = array(self::SUBMISSIONID => $submissionid, self::SUBMISSIONATTEMPT => $submissionattempt);
M. Chardon's avatar
init  
M. Chardon committed
63
64
        $record = (object) $fields;

65
        $exists = $DB->get_records(self::BDDTABLEQUEUE, $fields);
M. Chardon's avatar
init  
M. Chardon committed
66
        if (!$exists) {
67
            $DB->insert_record(self::BDDTABLEQUEUE, $record);
M. Chardon's avatar
init  
M. Chardon committed
68
69
        }
    }
70

M. Chardon's avatar
init  
M. Chardon committed
71
}