Skip to content
Permalink
Browse files
Merge branch 'MDL-65033-master2' of git://github.com/peterRd/moodle
  • Loading branch information
David Monllaó authored and stronk7 committed Apr 30, 2019
2 parents 8f7bb54 + cda9da9 commit 0b31a696f0b1157de671e1c0ddf8df09c2d2b925
Showing with 1,331 additions and 133 deletions.
  1. +5 −5 lib/classes/external/exporter.php
  2. +1 −0 lib/classes/output/icon_system_fontawesome.php
  3. +22 −3 lib/tests/exporter_test.php
  4. +1 −1 mod/forum/amd/build/discussion_list.min.js
  5. +1 −0 mod/forum/amd/build/favourite_toggle.min.js
  6. +1 −0 mod/forum/amd/build/pin_toggle.min.js
  7. +1 −1 mod/forum/amd/build/repository.min.js
  8. +1 −1 mod/forum/amd/build/selectors.min.js
  9. +73 −1 mod/forum/amd/src/discussion_list.js
  10. +80 −0 mod/forum/amd/src/favourite_toggle.js
  11. +86 −0 mod/forum/amd/src/pin_toggle.js
  12. +40 −2 mod/forum/amd/src/repository.js
  13. +7 −4 mod/forum/amd/src/selectors.js
  14. +155 −0 mod/forum/classes/local/builders/exported_discussion.php
  15. +24 −2 mod/forum/classes/local/builders/exported_discussion_summaries.php
  16. +12 −0 mod/forum/classes/local/entities/discussion.php
  17. +18 −4 mod/forum/classes/local/exporters/discussion.php
  18. +1 −0 mod/forum/classes/local/exporters/discussion_summaries.php
  19. +1 −0 mod/forum/classes/local/exporters/discussion_summary.php
  20. +16 −0 mod/forum/classes/local/factories/builder.php
  21. +7 −3 mod/forum/classes/local/factories/exporter.php
  22. +9 −1 mod/forum/classes/local/factories/renderer.php
  23. +15 −0 mod/forum/classes/local/factories/url.php
  24. +12 −0 mod/forum/classes/local/managers/capability.php
  25. +11 −30 mod/forum/classes/local/renderers/discussion.php
  26. +8 −2 mod/forum/classes/local/renderers/discussion_list.php
  27. +2 −1 mod/forum/classes/local/vaults/author.php
  28. +3 −1 mod/forum/classes/local/vaults/db_table_vault.php
  29. +2 −1 mod/forum/classes/local/vaults/discussion.php
  30. +50 −8 mod/forum/classes/local/vaults/discussion_list.php
  31. +2 −1 mod/forum/classes/local/vaults/forum.php
  32. +2 −1 mod/forum/classes/local/vaults/post.php
  33. +2 −1 mod/forum/classes/local/vaults/post_read_receipt_collection.php
  34. +7 −0 mod/forum/db/access.php
  35. +19 −0 mod/forum/db/services.php
  36. +151 −7 mod/forum/externallib.php
  37. +14 −0 mod/forum/lang/en/forum.php
  38. +1 −0 mod/forum/lib.php
  39. BIN mod/forum/pix/t/star.png
  40. +6 −0 mod/forum/pix/t/star.svg
  41. +5 −2 mod/forum/styles.css
  42. +61 −0 mod/forum/templates/discussion_favourite_toggle.mustache
  43. +13 −1 mod/forum/templates/discussion_list.mustache
  44. +4 −4 mod/forum/templates/discussion_lock_toggle.mustache
  45. +60 −0 mod/forum/templates/discussion_pin_toggle.mustache
  46. +1 −1 mod/forum/templates/discussion_subscription_toggle.mustache
  47. +70 −0 mod/forum/templates/forum_action_menu.mustache
  48. +16 −15 mod/forum/templates/forum_discussion.mustache
  49. +41 −0 mod/forum/templates/forum_discussion_favourite_toggle.mustache
  50. +13 −0 mod/forum/tests/behat/behat_mod_forum.php
  51. +4 −1 mod/forum/tests/behat/discussion_lock.feature
  52. +48 −0 mod/forum/tests/behat/favourite_discussion.feature
  53. +104 −1 mod/forum/tests/externallib_test.php
  54. +19 −16 mod/forum/tests/vaults_discussion_list_test.php
  55. BIN pix/t/emptystar.png
  56. +1 −0 pix/t/emptystar.svg
  57. +0 −3 theme/boost/scss/moodle/modules.scss
  58. +1 −4 theme/boost/style/moodle.css
  59. +1 −4 theme/classic/style/moodle.css
@@ -79,14 +79,16 @@ public function __construct($data, $related = array()) {
}

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

if ($nullallowed && array_key_exists($key, $related) && $related[$key] === null) {
$this->related[$key] = $related[$key];
if ($nullallowed && (!array_key_exists($key, $related) || $related[$key] === null)) {
$this->related[$key] = null;

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

} else {
$scalartypes = ['string', 'int', 'bool', 'float'];
$scalarcheck = 'is_' . $classname;
if (array_key_exists($key, $related) &&
((in_array($classname, $scalartypes) && $scalarcheck($related[$key])) ||
($related[$key] instanceof $classname))) {
@@ -356,6 +356,7 @@ public function get_core_icon_map() {
'core:t/edit' => 'fa-cog',
'core:t/emailno' => 'fa-ban',
'core:t/email' => 'fa-envelope-o',
'core:t/emptystar' => 'fa-star-o',
'core:t/enrolusers' => 'fa-user-plus',
'core:t/expanded' => 'fa-caret-down',
'core:t/go' => 'fa-play',
@@ -47,15 +47,17 @@ public function setUp() {
'context' => null,
'aint' => 5,
'astring' => 'valid string',
'abool' => false
'abool' => false,
'ints' => []
);
$this->invalidrelated = array(
'simplestdClass' => 'a string',
'arrayofstdClass' => 5,
'context' => null,
'aint' => false,
'astring' => 4,
'abool' => 'not a boolean'
'abool' => 'not a boolean',
'ints' => null
);

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

public function test_invalid_related_all_cases() {
global $PAGE;

foreach ($this->invalidrelated as $key => $value) {
$data = $this->validrelated;
$data[$key] = $value;

try {
$exporter = new core_testable_exporter($this->validdata, $data);
$output = $PAGE->get_renderer('core');
$result = $exporter->export($output);
} catch (coding_exception $e) {
$this->assertNotFalse(strpos($e->getMessage(), $key));
}
}
}

public function test_valid_data_and_related() {
global $PAGE;
$output = $PAGE->get_renderer('core');
@@ -196,7 +215,7 @@ class core_testable_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the course.
return array('simplestdClass' => 'stdClass', 'arrayofstdClass' => 'stdClass[]', 'context' => 'context?',
'astring' => 'string', 'abool' => 'bool', 'aint' => 'int');
'astring' => 'string', 'abool' => 'bool', 'aint' => 'int', 'ints' => 'int[]');
}

protected function get_other_values(renderer_base $output) {

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -21,10 +21,82 @@
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['mod_forum/subscription_toggle'], function(SubscriptionToggle) {
define([
'jquery',
'core/templates',
'core/str',
'core/notification',
'mod_forum/subscription_toggle',
'mod_forum/selectors',
'mod_forum/repository',
], function(
$,
Templates,
String,
Notification,
SubscriptionToggle,
Selectors,
Repository
) {
var registerEventListeners = function(root) {
root.on('click', Selectors.favourite.toggle, function() {
var toggleElement = $(this);
var forumId = toggleElement.data('forumid');
var discussionId = toggleElement.data('discussionid');
var subscriptionState = toggleElement.data('targetstate');
Repository.setFavouriteDiscussionState(forumId, discussionId, subscriptionState)
.then(function() {
return location.reload();
})
.catch(Notification.exception);
});

root.on('click', Selectors.pin.toggle, function(e) {
e.preventDefault();
var toggleElement = $(this);
var forumId = toggleElement.data('forumid');
var discussionId = toggleElement.data('discussionid');
var state = toggleElement.data('targetstate');
Repository.setPinDiscussionState(forumId, discussionId, state)
.then(function() {
return location.reload();
})
.catch(Notification.exception);
});

root.on('click', Selectors.lock.toggle, function(e) {
var toggleElement = $(this);
var forumId = toggleElement.data('forumid');
var discussionId = toggleElement.data('discussionid');
var state = toggleElement.data('state');

Repository.setDiscussionLockState(forumId, discussionId, state)
.then(function(context) {
context.forumid = forumId;
return Templates.render('mod_forum/discussion_lock_toggle', context);
})
.then(function(html, js) {
return Templates.replaceNode(toggleElement, html, js);
})
.then(function() {
return String.get_string('lockupdated', 'forum')
.done(function(s) {
return Notification.addNotification({
message: s,
type: "info"
});
});
})
.catch(Notification.exception);

e.preventDefault();
});
};

return {
init: function(root) {
SubscriptionToggle.init(root);
registerEventListeners(root);
}
};
});
@@ -0,0 +1,80 @@
// 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/>.

/**
* Handle discussion subscription toggling on a discussion list in
* the forum view.
*
* @module mod_forum/favourite_toggle
* @package mod_forum
* @copyright 2019 Peter Dias <peter@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
'jquery',
'core/templates',
'core/notification',
'mod_forum/repository',
'mod_forum/selectors',
'core/str',
], function(
$,
Templates,
Notification,
Repository,
Selectors,
String
) {

/**
* Register event listeners for the subscription toggle.
*
* @param {object} root The discussion list root element
*/
var registerEventListeners = function(root) {
root.on('click', Selectors.favourite.toggle, function(e) {
var toggleElement = $(this);
var forumId = toggleElement.data('forumid');
var discussionId = toggleElement.data('discussionid');
var subscriptionState = toggleElement.data('targetstate');

Repository.setFavouriteDiscussionState(forumId, discussionId, subscriptionState)
.then(function(context) {
return Templates.render('mod_forum/discussion_favourite_toggle', context);
})
.then(function(html, js) {
return Templates.replaceNode(toggleElement, html, js);
})
.then(function() {
return String.get_string("favouriteupdated", "forum")
.done(function(s) {
return Notification.addNotification({
message: s,
type: "info"
});
});
})
.catch(Notification.exception);

e.preventDefault();
});
};

return {
init: function(root) {
registerEventListeners(root);
}
};
});
@@ -0,0 +1,86 @@
// 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/>.

/**
* This module is the highest level module for the calendar. It is
* responsible for initialising all of the components required for
* the calendar to run. It also coordinates the interaction between
* components by listening for and responding to different events
* triggered within the calendar UI.
*
* @module mod_forum/pin_toggle
* @package mod_forum
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
'jquery',
'core/ajax',
'core/str',
'core/templates',
'core/notification',
'mod_forum/repository',
'mod_forum/selectors',
'core/str',
], function(
$,
Ajax,
Str,
Templates,
Notification,
Repository,
Selectors,
String
) {

/**
* Registery event listeners for the pin toggle.
*
* @param {object} root The calendar root element
*/
var registerEventListeners = function(root) {
root.on('click', Selectors.pin.toggle, function(e) {
var toggleElement = $(this);
var forumid = toggleElement.data('forumid');
var discussionid = toggleElement.data('discussionid');
var pinstate = toggleElement.data('targetstate');
Repository.setPinDiscussionState(forumid, discussionid, pinstate)
.then(function(context) {
return Templates.render('mod_forum/discussion_pin_toggle', context);
})
.then(function(html, js) {
return Templates.replaceNode(toggleElement, html, js);
})
.then(function() {
return String.get_string("pinupdated", "forum")
.done(function(s) {
return Notification.addNotification({
message: s,
type: "info"
});
});
})
.fail(Notification.exception);

e.preventDefault();
});
};

return {
init: function(root) {
registerEventListeners(root);
}
};
});

0 comments on commit 0b31a69

Please sign in to comment.