diff --git a/admin/tool/lp/classes/external/comment_area_exporter.php b/admin/tool/lp/classes/external/comment_area_exporter.php new file mode 100644 index 00000000000..7b49e97d93f --- /dev/null +++ b/admin/tool/lp/classes/external/comment_area_exporter.php @@ -0,0 +1,133 @@ +. + +/** + * Exporting a comment area. + * + * A comment area is the set of information about a defined comments area. + * + * @package tool_lp + * @copyright 2015 Frédéric Massart - FMCorz.net + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace tool_lp\external; +defined('MOODLE_INTERNAL') || die(); + +use comment; +use renderer_base; +use stdClass; + +/** + * Class for exporting a comment area. + * + * @package tool_lp + * @copyright 2015 Frédéric Massart - FMCorz.net + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class comment_area_exporter extends exporter { + + /** @var comment The comment instance. */ + protected $comment = null; + + public function __construct(comment $comment, $related = array()) { + $this->comment = $comment; + $data = new stdClass(); + $data->component = $comment->get_component(); + $data->commentarea = $comment->get_commentarea(); + $data->itemid = $comment->get_itemid(); + $data->courseid = $comment->get_courseid(); + $data->contextid = $comment->get_context()->id; + $data->cid = $comment->get_cid(); + parent::__construct($data, $related); + } + + protected static function define_properties() { + return array( + 'component' => array( + 'type' => PARAM_COMPONENT, + ), + 'commentarea' => array( + 'type' => PARAM_AREA, + ), + 'itemid' => array( + 'type' => PARAM_INT, + ), + 'courseid' => array( + 'type' => PARAM_INT, + ), + 'contextid' => array( + 'type' => PARAM_INT, + ), + 'cid' => array( + 'type' => PARAM_ALPHANUMEXT, + ), + ); + } + + protected static function define_other_properties() { + return array( + 'autostart' => array( + 'type' => PARAM_BOOL, + ), + 'canpost' => array( + 'type' => PARAM_BOOL, + ), + 'canview' => array( + 'type' => PARAM_BOOL, + ), + 'count' => array( + 'type' => PARAM_INT, + ), + 'collapsediconurl' => array( + 'type' => PARAM_URL, + ), + 'displaytotalcount' => array( + 'type' => PARAM_BOOL, + ), + 'displaycancel' => array( + 'type' => PARAM_BOOL, + ), + 'fullwidth' => array( + 'type' => PARAM_BOOL, + ), + 'linktext' => array( + 'type' => PARAM_RAW, + ), + 'notoggle' => array( + 'type' => PARAM_BOOL, + ), + 'template' => array( + 'type' => PARAM_RAW, + ), + ); + } + + public function get_other_values(renderer_base $output) { + $values = array(); + $values['autostart'] = $this->comment->get_autostart(); + $values['canpost'] = $this->comment->can_post(); + $values['canview'] = $this->comment->can_view(); + $values['collapsediconurl'] = $output->pix_url(right_to_left() ? 't/collapsed_rtl' : 't/collapsed')->out(false); + $values['count'] = $this->comment->count(); + $values['displaycancel'] = $this->comment->get_displaycancel(); + $values['displaytotalcount'] = $this->comment->get_displaytotalcount(); + $values['fullwidth'] = $this->comment->get_fullwidth(); + $values['linktext'] = $this->comment->get_linktext(); + $values['notoggle'] = $this->comment->get_notoggle(); + $values['template'] = $this->comment->get_template(); + return $values; + } +} diff --git a/admin/tool/lp/templates/comment_area.mustache b/admin/tool/lp/templates/comment_area.mustache new file mode 100644 index 00000000000..e2ac0646200 --- /dev/null +++ b/admin/tool/lp/templates/comment_area.mustache @@ -0,0 +1,113 @@ +{{! + 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 . +}} +{{! + @template tool_lp/comment_area + + IDs required for JS: + * all + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * autostart + * canpost + * cid + * collapsediconurl + * commentarea + * component + * contextid + * count + * courseid + * displaycancel + * fullwidth + * itemid + * linktext + * notoggle + * displaytotalcount + * template + * uniqid + + Example context (json): + { + } + +}} + +
+ {{^notoggle}} + + {{linktext}}{{linktext}} + {{#displaytotalcount}} + ({{count}}) + {{/displaytotalcount}} + + {{/notoggle}} + +
+
    +
  • +
+
+ + {{#canpost}} +
+
+ +
+
+ {{#str}}savecomment{{/str}} + {{#displaycancel}} + | {{#str}}cancel{{/str}} + {{/displaycancel}} +
+
+
+ {{/canpost}} + +
+
+{{#js}} +require(['core/str'], function(Str) { + // Preloading strings. + Str.get_strings([ + { key: 'addcomment', component: 'moodle' }, + { key: 'comments', component: 'moodle' }, + { key: 'commentscount', component: 'moodle' }, + { key: 'commentsrequirelogin', component: 'moodle' }, + { key: 'deletecomment', component: 'moodle' }, + ]).then(function() { + // Kick off when strings are loaded. + Y.use('core_comment', function(Y) { + M.core_comment.init(Y, { + client_id: '{{cid}}', + commentarea: '{{commentarea}}', + itemid: {{itemid}}, + page: 0, + courseid: {{courseid}}, + contextid: {{contextid}}, + component: '{{component}}', + notoggle: false, // {{notoggle}} True not supported just yet. + autostart: false // {{autostart}} True not supported just yet. + }); + }); + }); +}) +{{/js}} diff --git a/comment/lib.php b/comment/lib.php index d17d5bac5d4..7df025caad4 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -1039,6 +1039,87 @@ class comment { public function set_fullwidth($fullwidth = true) { $this->fullwidth = (bool)$fullwidth; } + + /** + * Return the template. + * + * @since 3.1 + * @return string + */ + public function get_template() { + return $this->template; + } + + /** + * Return the cid. + * + * @since 3.1 + * @return string + */ + public function get_cid() { + return $this->cid; + } + + /** + * Return the link text. + * + * @since 3.1 + * @return string + */ + public function get_linktext() { + return $this->linktext; + } + + /** + * Return no toggle. + * + * @since 3.1 + * @return bool + */ + public function get_notoggle() { + return $this->notoggle; + } + + /** + * Return display total count. + * + * @since 3.1 + * @return bool + */ + public function get_displaytotalcount() { + return $this->displaytotalcount; + } + + /** + * Return display cancel. + * + * @since 3.1 + * @return bool + */ + public function get_displaycancel() { + return $this->displaycancel; + } + + /** + * Return fullwidth. + * + * @since 3.1 + * @return bool + */ + public function get_fullwidth() { + return $this->fullwidth; + } + + /** + * Return autostart. + * + * @since 3.1 + * @return bool + */ + public function get_autostart() { + return $this->autostart; + } + } /** diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index b9a25384ce8..5bd654bdec9 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -296,6 +296,7 @@ class page_requirements_manager { // Every page should include definition of following modules. $this->js_module($this->find_module('core_filepicker')); + $this->js_module($this->find_module('core_comment')); } /**