Skip to content

Commit 0b31a69

Browse files
David Monllaóstronk7
David Monllaó
authored andcommitted
Merge branch 'MDL-65033-master2' of git://github.com/peterRd/moodle
2 parents 8f7bb54 + cda9da9 commit 0b31a69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1331
-133
lines changed

lib/classes/external/exporter.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,16 @@ public function __construct($data, $related = array()) {
7979
}
8080

8181
$missingdataerr = 'Exporter class is missing required related data: (' . get_called_class() . ') ';
82+
$scalartypes = ['string', 'int', 'bool', 'float'];
83+
$scalarcheck = 'is_' . $classname;
8284

83-
if ($nullallowed && array_key_exists($key, $related) && $related[$key] === null) {
84-
$this->related[$key] = $related[$key];
85+
if ($nullallowed && (!array_key_exists($key, $related) || $related[$key] === null)) {
86+
$this->related[$key] = null;
8587

8688
} else if ($isarray) {
8789
if (array_key_exists($key, $related) && is_array($related[$key])) {
8890
foreach ($related[$key] as $index => $value) {
89-
if (!$value instanceof $classname) {
91+
if (!$value instanceof $classname && !$scalarcheck($value)) {
9092
throw new coding_exception($missingdataerr . $key . ' => ' . $classname . '[]');
9193
}
9294
}
@@ -96,8 +98,6 @@ public function __construct($data, $related = array()) {
9698
}
9799

98100
} else {
99-
$scalartypes = ['string', 'int', 'bool', 'float'];
100-
$scalarcheck = 'is_' . $classname;
101101
if (array_key_exists($key, $related) &&
102102
((in_array($classname, $scalartypes) && $scalarcheck($related[$key])) ||
103103
($related[$key] instanceof $classname))) {

lib/classes/output/icon_system_fontawesome.php

+1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ public function get_core_icon_map() {
356356
'core:t/edit' => 'fa-cog',
357357
'core:t/emailno' => 'fa-ban',
358358
'core:t/email' => 'fa-envelope-o',
359+
'core:t/emptystar' => 'fa-star-o',
359360
'core:t/enrolusers' => 'fa-user-plus',
360361
'core:t/expanded' => 'fa-caret-down',
361362
'core:t/go' => 'fa-play',

lib/tests/exporter_test.php

+22-3
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ public function setUp() {
4747
'context' => null,
4848
'aint' => 5,
4949
'astring' => 'valid string',
50-
'abool' => false
50+
'abool' => false,
51+
'ints' => []
5152
);
5253
$this->invalidrelated = array(
5354
'simplestdClass' => 'a string',
5455
'arrayofstdClass' => 5,
5556
'context' => null,
5657
'aint' => false,
5758
'astring' => 4,
58-
'abool' => 'not a boolean'
59+
'abool' => 'not a boolean',
60+
'ints' => null
5961
);
6062

6163
$this->validdata = array('stringA' => 'A string', 'stringAformat' => FORMAT_HTML, 'intB' => 4);
@@ -118,6 +120,23 @@ public function test_invalid_related() {
118120
$result = $exporter->export($output);
119121
}
120122

123+
public function test_invalid_related_all_cases() {
124+
global $PAGE;
125+
126+
foreach ($this->invalidrelated as $key => $value) {
127+
$data = $this->validrelated;
128+
$data[$key] = $value;
129+
130+
try {
131+
$exporter = new core_testable_exporter($this->validdata, $data);
132+
$output = $PAGE->get_renderer('core');
133+
$result = $exporter->export($output);
134+
} catch (coding_exception $e) {
135+
$this->assertNotFalse(strpos($e->getMessage(), $key));
136+
}
137+
}
138+
}
139+
121140
public function test_valid_data_and_related() {
122141
global $PAGE;
123142
$output = $PAGE->get_renderer('core');
@@ -196,7 +215,7 @@ class core_testable_exporter extends \core\external\exporter {
196215
protected static function define_related() {
197216
// We cache the context so it does not need to be retrieved from the course.
198217
return array('simplestdClass' => 'stdClass', 'arrayofstdClass' => 'stdClass[]', 'context' => 'context?',
199-
'astring' => 'string', 'abool' => 'bool', 'aint' => 'int');
218+
'astring' => 'string', 'abool' => 'bool', 'aint' => 'int', 'ints' => 'int[]');
200219
}
201220

202221
protected function get_other_values(renderer_base $output) {

mod/forum/amd/build/discussion_list.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod/forum/amd/build/favourite_toggle.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod/forum/amd/build/pin_toggle.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod/forum/amd/build/repository.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod/forum/amd/build/selectors.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod/forum/amd/src/discussion_list.js

+73-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,82 @@
2121
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
24-
define(['mod_forum/subscription_toggle'], function(SubscriptionToggle) {
24+
define([
25+
'jquery',
26+
'core/templates',
27+
'core/str',
28+
'core/notification',
29+
'mod_forum/subscription_toggle',
30+
'mod_forum/selectors',
31+
'mod_forum/repository',
32+
], function(
33+
$,
34+
Templates,
35+
String,
36+
Notification,
37+
SubscriptionToggle,
38+
Selectors,
39+
Repository
40+
) {
41+
var registerEventListeners = function(root) {
42+
root.on('click', Selectors.favourite.toggle, function() {
43+
var toggleElement = $(this);
44+
var forumId = toggleElement.data('forumid');
45+
var discussionId = toggleElement.data('discussionid');
46+
var subscriptionState = toggleElement.data('targetstate');
47+
Repository.setFavouriteDiscussionState(forumId, discussionId, subscriptionState)
48+
.then(function() {
49+
return location.reload();
50+
})
51+
.catch(Notification.exception);
52+
});
53+
54+
root.on('click', Selectors.pin.toggle, function(e) {
55+
e.preventDefault();
56+
var toggleElement = $(this);
57+
var forumId = toggleElement.data('forumid');
58+
var discussionId = toggleElement.data('discussionid');
59+
var state = toggleElement.data('targetstate');
60+
Repository.setPinDiscussionState(forumId, discussionId, state)
61+
.then(function() {
62+
return location.reload();
63+
})
64+
.catch(Notification.exception);
65+
});
66+
67+
root.on('click', Selectors.lock.toggle, function(e) {
68+
var toggleElement = $(this);
69+
var forumId = toggleElement.data('forumid');
70+
var discussionId = toggleElement.data('discussionid');
71+
var state = toggleElement.data('state');
72+
73+
Repository.setDiscussionLockState(forumId, discussionId, state)
74+
.then(function(context) {
75+
context.forumid = forumId;
76+
return Templates.render('mod_forum/discussion_lock_toggle', context);
77+
})
78+
.then(function(html, js) {
79+
return Templates.replaceNode(toggleElement, html, js);
80+
})
81+
.then(function() {
82+
return String.get_string('lockupdated', 'forum')
83+
.done(function(s) {
84+
return Notification.addNotification({
85+
message: s,
86+
type: "info"
87+
});
88+
});
89+
})
90+
.catch(Notification.exception);
91+
92+
e.preventDefault();
93+
});
94+
};
95+
2596
return {
2697
init: function(root) {
2798
SubscriptionToggle.init(root);
99+
registerEventListeners(root);
28100
}
29101
};
30102
});

mod/forum/amd/src/favourite_toggle.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// This file is part of Moodle - http://moodle.org/
2+
//
3+
// Moodle is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// Moodle is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15+
16+
/**
17+
* Handle discussion subscription toggling on a discussion list in
18+
* the forum view.
19+
*
20+
* @module mod_forum/favourite_toggle
21+
* @package mod_forum
22+
* @copyright 2019 Peter Dias <peter@moodle.com>
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
define([
26+
'jquery',
27+
'core/templates',
28+
'core/notification',
29+
'mod_forum/repository',
30+
'mod_forum/selectors',
31+
'core/str',
32+
], function(
33+
$,
34+
Templates,
35+
Notification,
36+
Repository,
37+
Selectors,
38+
String
39+
) {
40+
41+
/**
42+
* Register event listeners for the subscription toggle.
43+
*
44+
* @param {object} root The discussion list root element
45+
*/
46+
var registerEventListeners = function(root) {
47+
root.on('click', Selectors.favourite.toggle, function(e) {
48+
var toggleElement = $(this);
49+
var forumId = toggleElement.data('forumid');
50+
var discussionId = toggleElement.data('discussionid');
51+
var subscriptionState = toggleElement.data('targetstate');
52+
53+
Repository.setFavouriteDiscussionState(forumId, discussionId, subscriptionState)
54+
.then(function(context) {
55+
return Templates.render('mod_forum/discussion_favourite_toggle', context);
56+
})
57+
.then(function(html, js) {
58+
return Templates.replaceNode(toggleElement, html, js);
59+
})
60+
.then(function() {
61+
return String.get_string("favouriteupdated", "forum")
62+
.done(function(s) {
63+
return Notification.addNotification({
64+
message: s,
65+
type: "info"
66+
});
67+
});
68+
})
69+
.catch(Notification.exception);
70+
71+
e.preventDefault();
72+
});
73+
};
74+
75+
return {
76+
init: function(root) {
77+
registerEventListeners(root);
78+
}
79+
};
80+
});

mod/forum/amd/src/pin_toggle.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// This file is part of Moodle - http://moodle.org/
2+
//
3+
// Moodle is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// Moodle is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15+
16+
/**
17+
* This module is the highest level module for the calendar. It is
18+
* responsible for initialising all of the components required for
19+
* the calendar to run. It also coordinates the interaction between
20+
* components by listening for and responding to different events
21+
* triggered within the calendar UI.
22+
*
23+
* @module mod_forum/pin_toggle
24+
* @package mod_forum
25+
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
26+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27+
*/
28+
define([
29+
'jquery',
30+
'core/ajax',
31+
'core/str',
32+
'core/templates',
33+
'core/notification',
34+
'mod_forum/repository',
35+
'mod_forum/selectors',
36+
'core/str',
37+
], function(
38+
$,
39+
Ajax,
40+
Str,
41+
Templates,
42+
Notification,
43+
Repository,
44+
Selectors,
45+
String
46+
) {
47+
48+
/**
49+
* Registery event listeners for the pin toggle.
50+
*
51+
* @param {object} root The calendar root element
52+
*/
53+
var registerEventListeners = function(root) {
54+
root.on('click', Selectors.pin.toggle, function(e) {
55+
var toggleElement = $(this);
56+
var forumid = toggleElement.data('forumid');
57+
var discussionid = toggleElement.data('discussionid');
58+
var pinstate = toggleElement.data('targetstate');
59+
Repository.setPinDiscussionState(forumid, discussionid, pinstate)
60+
.then(function(context) {
61+
return Templates.render('mod_forum/discussion_pin_toggle', context);
62+
})
63+
.then(function(html, js) {
64+
return Templates.replaceNode(toggleElement, html, js);
65+
})
66+
.then(function() {
67+
return String.get_string("pinupdated", "forum")
68+
.done(function(s) {
69+
return Notification.addNotification({
70+
message: s,
71+
type: "info"
72+
});
73+
});
74+
})
75+
.fail(Notification.exception);
76+
77+
e.preventDefault();
78+
});
79+
};
80+
81+
return {
82+
init: function(root) {
83+
registerEventListeners(root);
84+
}
85+
};
86+
});

0 commit comments

Comments
 (0)