示例#1
0
 /**
  * add_comment() implementation.
  *
  * @return array jsonable list of hashmaps
  */
 public static function add_comment($wallid, $content, $contentformat, $maxseqnum)
 {
     global $PAGE;
     $params = self::validate_parameters(self::add_comment_parameters(), ['wallid' => $wallid, 'content' => $content, 'contentformat' => $contentformat, 'maxseqnum' => $maxseqnum]);
     // TODO: Permissions checks.
     $wall = wall::instance_by_id($wallid);
     $wall->add_comment($content, $contentformat);
     // Load all the recent comments up the one already present on the client side.
     $wall->load_comments(null, $maxseqnum + 1);
     $output = $PAGE->get_renderer('local_libwall');
     // Export the whole wall for rendering via template.
     $data = $wall->export_for_template($output);
     // Selectively pick just those parts needed to update comments on the client side.
     return ['wall' => ['id' => $data['wall']['id'], 'maxseqnum' => $data['wall']['maxseqnum']], 'comments' => $data['comments']];
 }
 public function test_add_comment()
 {
     global $DB;
     $user = get_admin();
     $wall1 = wall::instance_by_location(context_system::instance(), 'core', 'test', 1);
     $wall2 = wall::instance_by_location(context_system::instance(), 'core', 'test', 2);
     $id11 = $wall1->add_comment('Wall 1 - 1st comment', FORMAT_MOODLE, $user);
     $id12 = $wall1->add_comment('Wall 1 - 2nd comment', FORMAT_MOODLE, $user);
     $id21 = $wall2->add_comment('Wall 2 - 1st comment', FORMAT_MOODLE, $user);
     $id13 = $wall1->add_comment('Wall 1 - 3rd comment', FORMAT_MOODLE, $user);
     $id22 = $wall2->add_comment('Wall 2 - 2nd comment', FORMAT_MOODLE, $user);
     $this->assertEquals(1, $DB->get_field('local_libwall_comments', 'seqnum', array('id' => $id11), MUST_EXIST));
     $this->assertEquals(2, $DB->get_field('local_libwall_comments', 'seqnum', array('id' => $id12), MUST_EXIST));
     $this->assertEquals(1, $DB->get_field('local_libwall_comments', 'seqnum', array('id' => $id21), MUST_EXIST));
     $this->assertEquals(3, $DB->get_field('local_libwall_comments', 'seqnum', array('id' => $id13), MUST_EXIST));
     $this->assertEquals(2, $DB->get_field('local_libwall_comments', 'seqnum', array('id' => $id22), MUST_EXIST));
 }
示例#3
0
 * @package     local_libwall
 * @copyright   2015 David Mudrak <*****@*****.**>
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require __DIR__ . '/../../config.php';
require_login();
if (!is_siteadmin()) {
    die('Site admins allowed only');
}
$plugin = new stdClass();
include __DIR__ . '/version.php';
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/local/libwall/demo.php');
$wall0 = \local_libwall\wall::instance_by_location(context_system::instance(), 'local_libwall', 'demo', 0);
$wall0->load_comments();
$wall1 = \local_libwall\wall::instance_by_location(context_system::instance(), 'local_libwall', 'demo', 1);
$wall1->load_comments();
$output = $PAGE->get_renderer('local_libwall');
echo $output->header();
echo $output->heading('Comments wall demo / libwall ' . $plugin->release . ' (build: ' . $plugin->version . ')');
echo '<div class="row-fluid">';
echo '<div class="span4">';
echo $output->heading('Wall demo/0', 3);
echo $output->render($wall0);
echo '</div>';
echo '<div class="span4">';
echo $output->heading('Wall demo/0 again', 3);
echo $output->render($wall0);
echo '</div>';
echo '<div class="span4">';
echo $output->heading('Wall demo/1', 3);