1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Library of interface functions and constants.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_stickynotes
|
|
|
21 |
* @copyright 2021 Olivier VALENTIN
|
|
|
22 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Execute mod_stickynotes upgrade from the given old version.
|
|
|
29 |
*
|
|
|
30 |
* @param int $oldversion
|
|
|
31 |
* @return bool
|
|
|
32 |
*/
|
|
|
33 |
function xmldb_stickynotes_upgrade($oldversion) {
|
|
|
34 |
global $DB;
|
|
|
35 |
|
|
|
36 |
$dbman = $DB->get_manager();
|
|
|
37 |
if ($oldversion < 2021051002) {
|
|
|
38 |
$table = new xmldb_table('stickynotes_note');
|
|
|
39 |
$field = $table->add_field('ordernote', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
|
|
40 |
|
|
|
41 |
if (!$dbman->field_exists($table, $field)) {
|
|
|
42 |
$dbman->add_field($table, $field);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
$ids = $DB->get_fieldset_sql('SELECT sn.id FROM {stickynotes} sn WHERE sn.id > 0');
|
|
|
46 |
if (!empty($ids)) {
|
|
|
47 |
foreach ($ids as $id) {
|
|
|
48 |
$cols = $DB->get_records('stickynotes_column', array('stickyid' => $id), '', '*');
|
|
|
49 |
foreach ($cols as $col) {
|
|
|
50 |
$notes = $DB->get_records('stickynotes_note', array('stickycolid' => $col->id), '', '*');
|
|
|
51 |
$i = 0;
|
|
|
52 |
foreach ($notes as $note) {
|
|
|
53 |
$obj = new stdClass();
|
|
|
54 |
$obj->id = $note->id;
|
|
|
55 |
$obj->ordernote = $i + 1;
|
|
|
56 |
$DB->update_record('stickynotes_note', $obj);
|
|
|
57 |
$i = $obj->ordernote;
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// Sticky notes savepoint reached.
|
|
|
64 |
upgrade_mod_savepoint(true, 2021051002, 'stickynotes');
|
|
|
65 |
}
|
|
|
66 |
if ($oldversion < 2021110403) {
|
|
|
67 |
$table = new xmldb_table('stickynotes');
|
|
|
68 |
$field1 = $table->add_field('displaystickydesc', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
|
|
69 |
$field2 = $table->add_field('displaystickycaption', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
|
|
70 |
|
|
|
71 |
if (!$dbman->field_exists($table, $field1)) {
|
|
|
72 |
$dbman->add_field($table, $field1);
|
|
|
73 |
}
|
|
|
74 |
if (!$dbman->field_exists($table, $field2)) {
|
|
|
75 |
$dbman->add_field($table, $field2);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
// Sticky notes savepoint reached.
|
|
|
79 |
upgrade_mod_savepoint(true, 2021110403, 'stickynotes');
|
|
|
80 |
}
|
|
|
81 |
if ($oldversion < 2021110404) {
|
|
|
82 |
// Upgrade code.
|
|
|
83 |
upgrade_mod_savepoint(true, 2021110404, 'stickynotes');
|
|
|
84 |
}
|
|
|
85 |
if ($oldversion < 2022071804) {
|
|
|
86 |
// Upgrade code.
|
|
|
87 |
upgrade_mod_savepoint(true, 2022071804, 'stickynotes');
|
|
|
88 |
}
|
|
|
89 |
// Add feature to move all notes or not for students.
|
|
|
90 |
if ($oldversion < 2023101706) {
|
|
|
91 |
$table = new xmldb_table('stickynotes');
|
|
|
92 |
$field1 = $table->add_field('moveallnotes', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
|
|
93 |
$field2 = $table->add_field('seeallnotes', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '1');
|
|
|
94 |
|
|
|
95 |
if (!$dbman->field_exists($table, $field1)) {
|
|
|
96 |
$dbman->add_field($table, $field1);
|
|
|
97 |
}
|
|
|
98 |
if (!$dbman->field_exists($table, $field2)) {
|
|
|
99 |
$dbman->add_field($table, $field2);
|
|
|
100 |
}
|
|
|
101 |
// Sticky notes savepoint reached.
|
|
|
102 |
upgrade_mod_savepoint(true, 2023101706, 'stickynotes');
|
|
|
103 |
}
|
|
|
104 |
if ($oldversion < 2023101707) {
|
|
|
105 |
// Upgrade code.
|
|
|
106 |
upgrade_mod_savepoint(true, 2023112307, 'stickynotes');
|
|
|
107 |
}
|
|
|
108 |
// Add completion on notes creation.
|
|
|
109 |
if ($oldversion < 2023112312) {
|
|
|
110 |
$table = new xmldb_table('stickynotes');
|
|
|
111 |
$field = $table->add_field('completionstickynotes', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
|
|
112 |
|
|
|
113 |
if (!$dbman->field_exists($table, $field)) {
|
|
|
114 |
$dbman->add_field($table, $field);
|
|
|
115 |
}
|
|
|
116 |
// Sticky notes savepoint reached.
|
|
|
117 |
upgrade_mod_savepoint(true, 2023112312, 'stickynotes');
|
|
|
118 |
}
|
|
|
119 |
// Add locks functions for notes creation and votes.
|
|
|
120 |
if ($oldversion < 2023121301) {
|
|
|
121 |
$table = new xmldb_table('stickynotes');
|
|
|
122 |
$field1 = $table->add_field('locknotes', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
|
|
123 |
$field2 = $table->add_field('lockvotes', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
|
|
124 |
|
|
|
125 |
if (!$dbman->field_exists($table, $field1)) {
|
|
|
126 |
$dbman->add_field($table, $field1);
|
|
|
127 |
}
|
|
|
128 |
if (!$dbman->field_exists($table, $field2)) {
|
|
|
129 |
$dbman->add_field($table, $field2);
|
|
|
130 |
}
|
|
|
131 |
// Sticky notes savepoint reached.
|
|
|
132 |
upgrade_mod_savepoint(true, 2023121301, 'stickynotes');
|
|
|
133 |
}
|
|
|
134 |
// Upgrade version - Text color and strings bug.
|
|
|
135 |
// Delete field to display description - function deleted in settings.
|
|
|
136 |
if ($oldversion < 2024021501) {
|
|
|
137 |
$table = new xmldb_table('stickynotes');
|
|
|
138 |
$field = new xmldb_field('displaystickydesc');
|
|
|
139 |
// Launch displaystickydesc field.
|
|
|
140 |
$dbman->drop_field($table, $field);
|
|
|
141 |
// Sticky notes savepoint reached.
|
|
|
142 |
upgrade_mod_savepoint(true, 2024021501, 'stickynotes');
|
|
|
143 |
}
|
|
|
144 |
return true;
|
|
|
145 |
}
|