/** * 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_getting_wall_instance() { $wall1 = wall::instance_by_location(context_system::instance(), 'block_foobar'); $this->assertInstanceOf('\\local_libwall\\wall', $wall1); $this->assertSame(context_system::instance(), $wall1->context); $this->assertSame('block_foobar', $wall1->component); $this->assertSame('', $wall1->area); $this->assertEquals(0, $wall1->itemid); $wall2 = wall::instance_by_id($wall1->id); $this->assertInstanceOf('\\local_libwall\\wall', $wall2); $this->assertEquals($wall1->id, $wall2->id); $this->assertSame($wall1->context, $wall2->context); $this->assertSame($wall1->component, $wall2->component); $this->assertSame($wall1->area, $wall2->area); $this->assertEquals($wall1->itemid, $wall2->itemid); $wall3 = wall::instance_by_location(context_system::instance(), 'block_foobar', 'test', 3); $this->assertNotEquals($wall1->id, $wall3->id); $this->assertSame('test', $wall3->area); $this->assertEquals(3, $wall3->itemid); }