Commit 6c344ff2 authored by Juan Leyva's avatar Juan Leyva
Browse files

MDL-64656 core_tag: Return tags in modules and blog

parent 52fcc0b8
......@@ -29,6 +29,7 @@ use external_util;
use external_files;
use renderer_base;
use context_system;
use core_tag\external\tag_item_exporter;
/**
* Class for exporting a blog post (entry).
......@@ -171,6 +172,12 @@ class post_exporter extends exporter {
'multiple' => true,
'optional' => true
),
'tags' => array(
'type' => tag_item_exporter::read_properties_definition(),
'description' => 'Tags.',
'multiple' => true,
'optional' => true,
),
);
}
......@@ -179,6 +186,12 @@ class post_exporter extends exporter {
$values['summaryfiles'] = external_util::get_area_files($context->id, 'blog', 'post', $this->data->id);
$values['attachmentfiles'] = external_util::get_area_files($context->id, 'blog', 'attachment', $this->data->id);
if ($this->data->module == 'blog_external') {
// For external blogs, the content field has the external blog id.
$values['tags'] = \core_tag\external\util::get_item_tags('core', 'blog_external', $this->data->content);
} else {
$values['tags'] = \core_tag\external\util::get_item_tags('core', 'post', $this->data->id);
}
return $values;
}
......
......@@ -108,6 +108,9 @@ class core_blog_external_testcase extends advanced_testcase {
$result = core_blog\external::get_entries();
$result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertCount(1, $result['entries'][0]['tags']);
$this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
}
......@@ -141,6 +144,9 @@ class core_blog_external_testcase extends advanced_testcase {
$result = core_blog\external::get_entries();
$result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertCount(1, $result['entries'][0]['tags']);
$this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
}
......@@ -331,6 +337,9 @@ class core_blog_external_testcase extends advanced_testcase {
$result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
$this->assertCount(2, $result['entries']);
$this->assertEquals(2, $result['totalentries']);
$this->assertCount(0, $result['entries'][0]['tags']);
$this->assertCount(1, $result['entries'][1]['tags']);
$this->assertEquals('tag1', $result['entries'][1]['tags'][0]['rawname']);
$result = core_blog\external::get_entries(array(), 0, 1);
$result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
......@@ -365,6 +374,8 @@ class core_blog_external_testcase extends advanced_testcase {
$result = core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $this->courseid)));
$result = external_api::clean_returnvalue(core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertCount(1, $result['entries'][0]['tags']);
$this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
// There is no entry associated with a wrong course.
$result = core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $anothercourse->id)));
......
This files describes API changes in /blog/* ,
information provided here is intended especially for developers.
=== 3.7 ===
* External function get_entries now returns an additional field "tags" returning the post tags.
=== 2.7 ===
* blog_entry->add_associations() does not accept any params.
......
......@@ -494,6 +494,10 @@ class core_course_external extends external_api {
'userid' => new external_value(PARAM_INT, 'User who added this content to moodle'),
'author' => new external_value(PARAM_TEXT, 'Content owner'),
'license' => new external_value(PARAM_TEXT, 'Content license'),
'tags' => new external_multiple_structure(
\core_tag\external\tag_item_exporter::get_read_structure(), 'Tags',
VALUE_OPTIONAL
),
)
), VALUE_DEFAULT, array()
),
......
......@@ -6,6 +6,8 @@ information provided here is intended especially for developers.
* External function core_course_external::get_course_contents new returns the following additional completiondata field:
- valueused (indicates whether the completion state affects the availability of other content)
* External function core_course_external::get_course_contents now returns a new contentsinfo field with summary files information.
* External function core_course_external::get_course_contents now returns an additional field "tags" returning the content tags.
=== 3.6 ===
......
......@@ -611,6 +611,7 @@ function book_export_contents($cm, $baseurl) {
$chapterindexfile['userid'] = null;
$chapterindexfile['author'] = null;
$chapterindexfile['license'] = null;
$chapterindexfile['tags'] = \core_tag\external\util::get_item_tags('mod_book', 'book_chapters', $chapter->id);
$contents[] = $chapterindexfile;
// Chapter files (images usually).
......
......@@ -45,7 +45,8 @@ class mod_book_lib_testcase extends advanced_testcase {
}
public function test_export_contents() {
global $DB;
global $DB, $CFG;
require_once($CFG->dirroot . '/course/externallib.php');
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course(array('enablecomment' => 1));
......@@ -57,7 +58,10 @@ class mod_book_lib_testcase extends advanced_testcase {
$cm = get_coursemodule_from_id('book', $book->cmid);
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
$chapter1 = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 1));
$chapter1 = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 1,
'tags' => array('Cats', 'Dogs')));
$tag = core_tag_tag::get_by_name(0, 'Cats');
$chapter2 = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 2));
$subchapter = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 3, "subchapter" => 1));
$chapter3 = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 4, "hidden" => 1));
......@@ -71,11 +75,24 @@ class mod_book_lib_testcase extends advanced_testcase {
$this->assertEquals('structure', $contents[0]['filename']);
$this->assertEquals('index.html', $contents[1]['filename']);
$this->assertEquals('Chapter 1', $contents[1]['content']);
$this->assertCount(2, $contents[1]['tags']);
$this->assertEquals('Cats', $contents[1]['tags'][0]['rawname']);
$this->assertEquals($tag->id, $contents[1]['tags'][0]['id']);
$this->assertEquals('Dogs', $contents[1]['tags'][1]['rawname']);
$this->assertEquals('index.html', $contents[2]['filename']);
$this->assertEquals('Chapter 2', $contents[2]['content']);
$this->assertEquals('index.html', $contents[3]['filename']);
$this->assertEquals('Chapter 3', $contents[3]['content']);
// Now, test the function via the external API.
$contents = core_course_external::get_course_contents($course->id, array());
$contents = external_api::clean_returnvalue(core_course_external::get_course_contents_returns(), $contents);
$this->assertEquals('book', $contents[0]['modules'][0]['modname']);
$this->assertEquals($cm->id, $contents[0]['modules'][0]['id']);
$this->assertCount(2, $contents[0]['modules'][0]['contents'][1]['tags']);
$this->assertEquals('Cats', $contents[0]['modules'][0]['contents'][1]['tags'][0]['rawname']);
$this->assertEquals('Dogs', $contents[0]['modules'][0]['contents'][1]['tags'][1]['rawname']);
// Test empty book.
$emptybook = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
$cm = get_coursemodule_from_id('book', $emptybook->cmid);
......
This files describes API changes in the book code.
=== 3.7 ===
* book_export_contents() callback now returns tags information for every chapter.
=== 3.1 ===
* The following functions, previously used (exclusively) by upgrade steps are not available
......
......@@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use core_user;
use core_tag\external\tag_item_exporter;
/**
* Class for exporting record data.
......@@ -102,6 +103,12 @@ class record_exporter extends exporter {
'multiple' => true,
'optional' => true,
),
'tags' => array(
'type' => tag_item_exporter::read_properties_definition(),
'description' => 'Tags.',
'multiple' => true,
'optional' => true,
),
);
}
......@@ -128,6 +135,9 @@ class record_exporter extends exporter {
}
$values['contents'] = $contents;
}
$values['tags'] = \core_tag\external\util::get_item_tags('mod_data', 'data_records', $this->data->id);
return $values;
}
}
......@@ -412,9 +412,9 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
}
$this->setUser($this->student1);
$entry11 = $generator->create_entry($this->database, $fieldcontents, $this->group1->id);
$entry11 = $generator->create_entry($this->database, $fieldcontents, $this->group1->id, ['Cats', 'Dogs']);
$this->setUser($this->student2);
$entry12 = $generator->create_entry($this->database, $fieldcontents, $this->group1->id);
$entry12 = $generator->create_entry($this->database, $fieldcontents, $this->group1->id, ['Cats']);
$entry13 = $generator->create_entry($this->database, $fieldcontents, $this->group1->id);
// Entry not in group.
$entry14 = $generator->create_entry($this->database, $fieldcontents, 0);
......@@ -447,10 +447,13 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
$this->assertCount(3, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
$this->assertEquals($entry11, $result['entries'][0]['id']);
$this->assertCount(2, $result['entries'][0]['tags']);
$this->assertEquals($this->student1->id, $result['entries'][0]['userid']);
$this->assertEquals($this->group1->id, $result['entries'][0]['groupid']);
$this->assertEquals($this->database->id, $result['entries'][0]['dataid']);
$this->assertEquals($entry12, $result['entries'][1]['id']);
$this->assertCount(1, $result['entries'][1]['tags']);
$this->assertEquals('Cats', $result['entries'][1]['tags'][0]['rawname']);
$this->assertEquals($this->student2->id, $result['entries'][1]['userid']);
$this->assertEquals($this->group1->id, $result['entries'][1]['groupid']);
$this->assertEquals($this->database->id, $result['entries'][1]['dataid']);
......
This files describes API changes in /mod/data - plugins,
information provided here is intended especially for developers.
=== 3.7 ===
* External functions get_entries, get_entry and search_entries now return an additional field "tags" containing the entry tags.
=== 3.4 ===
* External function mod_data_external::search_entries() now returns the maxcount field: Total count of records that the user could
see in the database (if all the search criterias were removed).
......
......@@ -419,6 +419,8 @@ class mod_forum_external extends external_api {
if (!empty($messageinlinefiles)) {
$post->messageinlinefiles = $messageinlinefiles;
}
// Post tags.
$post->tags = \core_tag\external\util::get_item_tags('mod_forum', 'forum_posts', $post->id);
$posts[] = $post;
}
......@@ -465,6 +467,9 @@ class mod_forum_external extends external_api {
'userpictureurl' => new external_value(PARAM_URL, 'Post author picture.', VALUE_OPTIONAL),
'deleted' => new external_value(PARAM_BOOL, 'This post has been removed.'),
'isprivatereply' => new external_value(PARAM_BOOL, 'The post is a private reply'),
'tags' => new external_multiple_structure(
\core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL
),
), 'post'
)
),
......
......@@ -260,6 +260,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$record->parent = $discussion1reply1->id;
$record->userid = $user3->id;
$record->tags = array('Cats', 'Dogs');
$discussion1reply2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
// Enrol the user in the course.
......@@ -311,7 +312,12 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'userpictureurl' => '',
'deleted' => false,
'isprivatereply' => false,
'tags' => \core_tag\external\util::get_item_tags('mod_forum', 'forum_posts', $discussion1reply2->id),
);
// Cast to expected.
$this->assertCount(2, $expectedposts['posts'][0]['tags']);
$expectedposts['posts'][0]['tags'][0]['isstandard'] = (bool) $expectedposts['posts'][0]['tags'][0]['isstandard'];
$expectedposts['posts'][0]['tags'][1]['isstandard'] = (bool) $expectedposts['posts'][0]['tags'][1]['isstandard'];
$expectedposts['posts'][] = array(
'id' => $discussion1reply1->id,
......@@ -348,6 +354,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'userpictureurl' => '',
'deleted' => false,
'isprivatereply' => false,
'tags' => array(),
);
// Test a discussion with two additional posts (total 3 posts).
......
......@@ -9,6 +9,7 @@ information provided here is intended especially for developers.
* The get_forum_discussion_posts web service has been deprecated in favour of get_discussion_posts.
* The forum_count_replies function has been deprecated in favour of get_reply_count_for_post_id_in_discussion_id in
the Post vault.
* External function get_forum_discussion_posts now returns an additional field "tags" returning the post tags.
=== 3.6 ===
......
......@@ -101,6 +101,9 @@ class mod_glossary_external extends external_api {
'casesensitive' => new external_value(PARAM_BOOL, 'When true, the matching is case sensitive'),
'fullmatch' => new external_value(PARAM_BOOL, 'When true, the matching is done on full words only'),
'approved' => new external_value(PARAM_BOOL, 'Whether the entry was approved'),
'tags' => new external_multiple_structure(
\core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL
),
);
if ($includecat) {
......@@ -149,6 +152,8 @@ class mod_glossary_external extends external_api {
if (!empty($definitioninlinefiles)) {
$entry->definitioninlinefiles = $definitioninlinefiles;
}
$entry->tags = \core_tag\external\util::get_item_tags('mod_glossary', 'glossary_entries', $entry->id);
}
/**
......
......@@ -203,7 +203,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$ctx = context_module::instance($g1->cmid);
$this->getDataGenerator()->enrol_user($u1->id, $c1->id);
$e1a = $gg->create_content($g1, array('approved' => 0, 'concept' => 'Bob', 'userid' => 2));
$e1a = $gg->create_content($g1, array('approved' => 0, 'concept' => 'Bob', 'userid' => 2, 'tags' => array('Cats', 'Dogs')));
$e1b = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Jane', 'userid' => 2));
$e1c = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Alice', 'userid' => $u1->id));
$e1d = $gg->create_content($g1, array('approved' => 0, 'concept' => '0-day', 'userid' => $u1->id));
......@@ -218,6 +218,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1c->id, $return['entries'][0]['id']);
$this->assertEquals($e1a->id, $return['entries'][1]['id']);
$this->assertEquals('Cats', $return['entries'][1]['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entries'][1]['tags'][1]['rawname']);
$this->assertEquals($e1b->id, $return['entries'][2]['id']);
// An admin user requesting all the entries.
......@@ -311,7 +313,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$now = time();
$e1a = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Bob', 'userid' => $u1->id,
'timecreated' => 1, 'timemodified' => $now + 3600));
'timecreated' => 1, 'timemodified' => $now + 3600, 'tags' => array('Cats', 'Dogs')));
$e1b = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Jane', 'userid' => $u1->id,
'timecreated' => $now + 3600, 'timemodified' => 1));
$e1c = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Alice', 'userid' => $u1->id,
......@@ -328,6 +330,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
$this->assertEquals('Cats', $return['entries'][0]['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entries'][0]['tags'][1]['rawname']);
$this->assertEquals($e1c->id, $return['entries'][1]['id']);
$this->assertEquals($e1b->id, $return['entries'][2]['id']);
......@@ -425,7 +429,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$u1 = $this->getDataGenerator()->create_user();
$ctx = context_module::instance($g1->cmid);
$e1a1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
$e1a1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id, 'tags' => array('Cats', 'Dogs')));
$e1a2 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
$e1a3 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
$e1b1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
......@@ -448,6 +452,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a1->id, $return['entries'][0]['id']);
$this->assertEquals('Cats', $return['entries'][0]['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entries'][0]['tags'][1]['rawname']);
$this->assertEquals($e1a2->id, $return['entries'][1]['id']);
$this->assertEquals($e1a3->id, $return['entries'][2]['id']);
......@@ -562,7 +568,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$e1a2 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
$e1a3 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
$e1b1 = $gg->create_content($g1, array('approved' => 0, 'userid' => $u2->id));
$e1b2 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u2->id));
$e1b2 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u2->id, 'tags' => array('Cats', 'Dogs')));
$e1c1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u3->id));
$e1d1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u4->id));
$e2a = $gg->create_content($g2, array('approved' => 1, 'userid' => $u1->id));
......@@ -575,6 +581,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1b2->id, $return['entries'][0]['id']);
$this->assertEquals('Cats', $return['entries'][0]['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entries'][0]['tags'][1]['rawname']);
$this->assertEquals($e1a1->id, $return['entries'][1]['id']);
$this->assertEquals($e1a2->id, $return['entries'][2]['id']);
$this->assertEquals($e1a3->id, $return['entries'][3]['id']);
......@@ -780,7 +788,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$e1 = $gg->create_content($g1, array('approved' => 1, 'concept' => 'House', 'timecreated' => time() + 3600));
$e2 = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Mouse', 'timemodified' => 1));
$e3 = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Hero'));
$e3 = $gg->create_content($g1, array('approved' => 1, 'concept' => 'Hero', 'tags' => array('Cats', 'Dogs')));
$e4 = $gg->create_content($g1, array('approved' => 0, 'concept' => 'Toulouse'));
$e5 = $gg->create_content($g1, array('approved' => 1, 'definition' => 'Heroes', 'concept' => 'Abcd'));
$e6 = $gg->create_content($g1, array('approved' => 0, 'definition' => 'When used for Heroes'));
......@@ -798,6 +806,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e3->id, $return['entries'][0]['id']);
$this->assertEquals('Cats', $return['entries'][0]['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entries'][0]['tags'][1]['rawname']);
// Enabling full search.
$query = 'hero';
......@@ -893,7 +903,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$this->setAdminUser();
$e1 = $gg->create_content($g1, array('userid' => $u1->id, 'approved' => 1, 'concept' => 'cat'));
$e1 = $gg->create_content($g1, array('userid' => $u1->id, 'approved' => 1, 'concept' => 'cat',
'tags' => array('Cats', 'Dogs')));
$e2 = $gg->create_content($g1, array('userid' => $u1->id, 'approved' => 1), array('cat', 'dog'));
$e3 = $gg->create_content($g1, array('userid' => $u1->id, 'approved' => 1), array('dog'));
$e4 = $gg->create_content($g1, array('userid' => $u1->id, 'approved' => 0, 'concept' => 'dog'));
......@@ -908,6 +919,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$expected = array($e1->id, $e2->id);
$actual = array($return['entries'][0]['id'], $return['entries'][1]['id']);
$this->assertEquals($expected, $actual, '', 0.0, 10, true);
$this->assertEquals('Cats', $return['entries'][0]['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entries'][0]['tags'][1]['rawname']);
// Search alias.
$return = mod_glossary_external::get_entries_by_term($g1->id, 'dog', 0, 20, array('includenotapproved' => false));
......@@ -1063,7 +1076,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$ctx = context_module::instance($g1->cmid);
$this->getDataGenerator()->enrol_user($u1->id, $c1->id);
$e1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id));
$e1 = $gg->create_content($g1, array('approved' => 1, 'userid' => $u1->id, 'tags' => array('Cats', 'Dogs')));
// Add a fake inline image to the entry.
$filename = 'shouldbeanimage.jpg';
$filerecordinline = array(
......@@ -1085,6 +1098,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
$return = mod_glossary_external::get_entry_by_id($e1->id);
$return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
$this->assertEquals($e1->id, $return['entry']['id']);
$this->assertEquals('Cats', $return['entry']['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entry']['tags'][1]['rawname']);
$this->assertEquals($filename, $return['entry']['definitioninlinefiles'][0]['filename']);
$return = mod_glossary_external::get_entry_by_id($e2->id);
......
This files describes API changes in /mod/glossary/*,
information provided here is intended especially for developers.
=== 3.7 ===
* External functions get_entries_by_* and get_entry now return an additional field "tags" containing the entry tags.
=== 3.4 ===
* External functions returning entries now return an additional field "ratinginfo" containing the entry rating information.
......
......@@ -492,7 +492,8 @@ class mod_wiki_external extends external_api {
'pageviews' => $page->pageviews,
'readonly' => $page->readonly,
'caneditpage' => $caneditpages,
'firstpage' => $page->id == $firstpage->id
'firstpage' => $page->id == $firstpage->id,
'tags' => \core_tag\external\util::get_item_tags('mod_wiki', 'wiki_pages', $page->id),
);
// Refresh page cached content if needed.
......@@ -555,6 +556,9 @@ class mod_wiki_external extends external_api {
'contentformat' => new external_format_value('cachedcontent', VALUE_OPTIONAL),
'contentsize' => new external_value(PARAM_INT, 'Size of page contents in bytes (doesn\'t include'.
' size of attached files).', VALUE_OPTIONAL),
'tags' => new external_multiple_structure(
\core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL
),
), 'Pages'
)
),
......@@ -623,6 +627,7 @@ class mod_wiki_external extends external_api {
$returnedpage['groupid'] = $subwiki->groupid;
$returnedpage['userid'] = $subwiki->userid;
$returnedpage['title'] = $page->title;
$returnedpage['tags'] = \core_tag\external\util::get_item_tags('mod_wiki', 'wiki_pages', $page->id);
// Refresh page cached content if needed.
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
......@@ -668,6 +673,9 @@ class mod_wiki_external extends external_api {
'contentformat' => new external_format_value('cachedcontent', VALUE_OPTIONAL),
'caneditpage' => new external_value(PARAM_BOOL, 'True if user can edit the page.'),
'version' => new external_value(PARAM_INT, 'Latest version of the page.', VALUE_OPTIONAL),
'tags' => new external_multiple_structure(
\core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL
),
), 'Page'
),
'warnings' => new external_warnings()
......
......@@ -69,7 +69,8 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherrole->id, 'manual');
// Create first pages.
$this->firstpage = $this->getDataGenerator()->get_plugin_generator('mod_wiki')->create_first_page($this->wiki);
$this->firstpage = $this->getDataGenerator()->get_plugin_generator('mod_wiki')->create_first_page($this->wiki,
array('tags' => array('Cats', 'Dogs')));
}
/**
......@@ -616,6 +617,10 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedfirstpage['caneditpage'] = true; // No groups and students have 'mod/wiki:editpage' capability.
$expectedfirstpage['firstpage'] = true;
$expectedfirstpage['contentformat'] = 1;
$expectedfirstpage['tags'] = \core_tag\external\util::get_item_tags('mod_wiki', 'wiki_pages', $this->firstpage->id);
// Cast to expected.
$expectedfirstpage['tags'][0]['isstandard'] = (bool) $expectedfirstpage['tags'][0]['isstandard'];
$expectedfirstpage['tags'][1]['isstandard'] = (bool) $expectedfirstpage['tags'][1]['isstandard'];
$expectedpages[] = $expectedfirstpage;
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id);
......@@ -640,6 +645,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectednewpage['caneditpage'] = true; // No groups and students have 'mod/wiki:editpage' capability.
$expectednewpage['firstpage'] = false;
$expectednewpage['contentformat'] = 1;
$expectednewpage['tags'] = array();
array_unshift($expectedpages, $expectednewpage); // Add page to the beginning since it orders by title by default.
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id);
......@@ -692,6 +698,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedteacherpage['caneditpage'] = true;
$expectedteacherpage['firstpage'] = true;
$expectedteacherpage['contentformat'] = 1;
$expectedteacherpage['tags'] = array();
$expectedpages = array($expectedteacherpage);
$result = mod_wiki_external::get_subwiki_pages($indwiki->id, 0, $this->teacher->id);
......@@ -703,6 +710,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedstudentpage['caneditpage'] = true;
$expectedstudentpage['firstpage'] = true;
$expectedstudentpage['contentformat'] = 1;
$expectedstudentpage['tags'] = array();
$expectedpages = array($expectedstudentpage);
$result = mod_wiki_external::get_subwiki_pages($indwiki->id, 0, $this->student->id);
......@@ -738,6 +746,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = true; // User belongs to group and has 'mod/wiki:editpage' capability.
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;
$expectedpage['tags'] = array();
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisep->id, $this->group1->id);
......@@ -760,6 +769,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = true;
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;
$expectedpage['tags'] = array();
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisep->id, 0);
......@@ -783,6 +793,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = true; // User belongs to group and has 'mod/wiki:editpage' capability.
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;
$expectedpage['tags'] = array();
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivis->id, $this->group1->id);
......@@ -794,6 +805,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = false; // User doesn't belong to group so he can't edit the page.
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;
$expectedpage['tags'] = array();
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivis->id, $this->group2->id);
......@@ -805,6 +817,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = false;
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;
$expectedpage['tags'] = array();
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivis->id, 0);
......@@ -827,6 +840,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = true;
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;
$expectedpage['tags'] = array();
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisepind->id, $this->group1->id, $this->student->id);
......@@ -850,6 +864,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = false;
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;
$expectedpage['tags'] = array();
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisepind->id, $this->group1->id, $this->student2->id);
......@@ -872,6 +887,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
$expectedpage['caneditpage'] = true;
$expectedpage['firstpage'] = true;
$expectedpage['contentformat'] = 1;