Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1434 ariadna 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
 * Duplicate notification.
19
 *
20
 * @package     local_moofactory_notification
21
 * @copyright   2020 Patrick ROCHET <patrick.r@lmsfactory.com>
22
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once("../../config.php");
26
require_once('lib.php');
27
global $DB;
28
 
29
$id = optional_param('id', 0, PARAM_INT); // Id de la notification à dupliquer.
30
 
31
$record = $DB->get_record('local_mf_notification', array('id' => $id), 'base, type, name, subject, bodyhtml');
32
 
33
$data = new stdClass;
34
$data->base = 0;
35
$data->type = $record->type;
36
$data->name = $record->name." (2)";
37
$data->subject = $record->subject;
38
$data->bodyhtml = $record->bodyhtml;
39
 
40
$newid = $DB->insert_record('local_mf_notification', $data);
41
 
42
$type = $record->type;
43
switch($type){
44
    case "courseenroll":
45
        $customfieldname = 'courseenrollmentsnotification';
46
        break;
47
    case "courseaccess":
48
        $customfieldname = 'courseaccessnotification';
49
        break;
50
    case "courseevent":
51
        $customfieldname = 'courseeventsnotification';
52
        break;
53
}
54
 
55
// La nouvelle notification
56
$records = $DB->get_records('local_mf_notification', array('type'=>$type), 'base DESC, name ASC');
57
$index = 0;
58
foreach($records as $record) {
59
    $index++;
60
    if($record->id == $newid){
61
        $newnotif = $index;
62
    }
63
}
64
 
65
// Pour tous les cours
66
$sql = "SELECT id, fullname FROM {course} WHERE id <> 1";
67
$courses = $DB->get_records_sql($sql, array());
68
foreach ($courses as $course) {
69
    $courseid = $course->id;
70
    $coursenotif = (int)local_moofactory_notification_getCustomfield($courseid, $customfieldname, 'select');
71
 
72
    if($coursenotif >= $newnotif){
73
        local_moofactory_notification_setCustomfield($courseid, $customfieldname, 'select', $coursenotif + 1);
74
    }
75
}
76
 
77
$nexturl = new moodle_url($CFG->wwwroot . '/local/moofactory_notification/managenotif.php', array('id' => $newid));
78
redirect($nexturl);