Skip to content

Commit

Permalink
MDL-32581 support additional format field with all text field in extr…
Browse files Browse the repository at this point in the history
…nal lib function + new possible ws params to decide how format is returned (which are stored in a singleton)
  • Loading branch information
mouneyrac committed May 31, 2012
1 parent 4631e39 commit 93ce0e8
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 88 deletions.
36 changes: 19 additions & 17 deletions course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ public static function get_course_contents($courseid, $options) {
$sectionvalues = array();
$sectionvalues['id'] = $section->id;
$sectionvalues['name'] = get_section_name($course, $section);
$summary = file_rewrite_pluginfile_urls($section->summary, 'webservice/pluginfile.php', $context->id, 'course', 'section', $section->id);
$sectionvalues['visible'] = $section->visible;
$sectionvalues['summary'] = format_text($summary, $section->summaryformat);
list($sectionvalues['summary'], $sectionvalues['summaryformat']) =
external_format_text($section->summary, $section->summaryformat,
$context->id, 'course', 'section', $section->id);
$sectioncontents = array();

//for each module of the section
Expand Down Expand Up @@ -205,6 +206,7 @@ public static function get_course_contents_returns() {
'name' => new external_value(PARAM_TEXT, 'Section name'),
'visible' => new external_value(PARAM_INT, 'is the section visible', VALUE_OPTIONAL),
'summary' => new external_value(PARAM_RAW, 'Section description'),
'summaryformat' => new external_format_value('summary'),
'modules' => new external_multiple_structure(
new external_single_structure(
array(
Expand Down Expand Up @@ -311,8 +313,8 @@ public static function get_courses($options) {
$courseinfo['fullname'] = $course->fullname;
$courseinfo['shortname'] = $course->shortname;
$courseinfo['categoryid'] = $course->category;
$courseinfo['summary'] = $course->summary;
$courseinfo['summaryformat'] = $course->summaryformat;
list($courseinfo['summary'], $courseinfo['summaryformat']) =
external_format_text($course->summary, $course->summaryformat, $context->id, 'course', 'summary', 0);
$courseinfo['format'] = $course->format;
$courseinfo['startdate'] = $course->startdate;
$courseinfo['numsections'] = $course->numsections;
Expand Down Expand Up @@ -367,8 +369,7 @@ public static function get_courses_returns() {
'fullname' => new external_value(PARAM_TEXT, 'full name'),
'idnumber' => new external_value(PARAM_RAW, 'id number', VALUE_OPTIONAL),
'summary' => new external_value(PARAM_RAW, 'summary'),
'summaryformat' => new external_value(PARAM_INT,
'the summary text Moodle format'),
'summaryformat' => new external_format_value('summary'),
'format' => new external_value(PARAM_PLUGIN,
'course format: weeks, topics, social, site,..'),
'showgrades' => new external_value(PARAM_INT,
Expand Down Expand Up @@ -435,8 +436,7 @@ public static function create_courses_parameters() {
'categoryid' => new external_value(PARAM_INT, 'category id'),
'idnumber' => new external_value(PARAM_RAW, 'id number', VALUE_OPTIONAL),
'summary' => new external_value(PARAM_RAW, 'summary', VALUE_OPTIONAL),
'summaryformat' => new external_value(PARAM_INT,
'the summary text Moodle format', VALUE_DEFAULT, FORMAT_MOODLE),
'summaryformat' => new external_format_value('summary', VALUE_DEFAULT),
'format' => new external_value(PARAM_PLUGIN,
'course format: weeks, topics, social, site,..',
VALUE_DEFAULT, $courseconfig->format),
Expand Down Expand Up @@ -560,6 +560,9 @@ public static function create_courses($courses) {

$course['category'] = $course['categoryid'];

// Summary format.
$course['summaryformat'] = external_validate_format($course['summaryformat']);

//Note: create_course() core function check shortname, idnumber, category
$course['id'] = create_course((object) $course)->id;

Expand Down Expand Up @@ -1085,13 +1088,9 @@ public static function get_categories($criteria = array(), $addsubcategories = t
$categoryinfo = array();
$categoryinfo['id'] = $category->id;
$categoryinfo['name'] = $category->name;
$categoryinfo['description'] = file_rewrite_pluginfile_urls($category->description,
'webservice/pluginfile.php', $context->id, 'coursecat', 'description', null);
$options = new stdClass;
$options->noclean = true;
$options->para = false;
$categoryinfo['description'] = format_text($categoryinfo['description'],
$category->descriptionformat, $options);
list($categoryinfo['description'], $categoryinfo['descriptionformat']) =
external_format_text($category->description, $category->descriptionformat,
$context->id, 'coursecat', 'description', null);
$categoryinfo['parent'] = $category->parent;
$categoryinfo['sortorder'] = $category->sortorder;
$categoryinfo['coursecount'] = $category->coursecount;
Expand Down Expand Up @@ -1160,6 +1159,7 @@ public static function get_categories_returns() {
'name' => new external_value(PARAM_TEXT, 'category name'),
'idnumber' => new external_value(PARAM_RAW, 'category id number', VALUE_OPTIONAL),
'description' => new external_value(PARAM_RAW, 'category description'),
'descriptionformat' => new external_format_value('description'),
'parent' => new external_value(PARAM_INT, 'parent category id'),
'sortorder' => new external_value(PARAM_INT, 'category sorting order'),
'coursecount' => new external_value(PARAM_INT, 'number of courses in this category'),
Expand Down Expand Up @@ -1193,6 +1193,7 @@ public static function create_categories_parameters() {
'the new category idnumber', VALUE_OPTIONAL),
'description' => new external_value(PARAM_RAW,
'the new category description', VALUE_OPTIONAL),
'descriptionformat' => new external_format_value('description', VALUE_DEFAULT),
'theme' => new external_value(PARAM_THEME,
'the new category theme. This option must be enabled on moodle',
VALUE_OPTIONAL),
Expand Down Expand Up @@ -1257,7 +1258,7 @@ public static function create_categories($categories) {
if (!empty($category['description'])) {
$newcategory->description = $category['description'];
}
$newcategory->descriptionformat = FORMAT_HTML;
$newcategory->descriptionformat = external_validate_format($category['descriptionformat']);
if (isset($category['theme']) and !empty($CFG->allowcategorythemes)) {
$newcategory->theme = $category['theme'];
}
Expand Down Expand Up @@ -1308,6 +1309,7 @@ public static function update_categories_parameters() {
'idnumber' => new external_value(PARAM_RAW, 'category id number', VALUE_OPTIONAL),
'parent' => new external_value(PARAM_INT, 'parent category id', VALUE_OPTIONAL),
'description' => new external_value(PARAM_RAW, 'category description', VALUE_OPTIONAL),
'descriptionformat' => new external_format_value('description', VALUE_DEFAULT),
'theme' => new external_value(PARAM_THEME,
'the category theme. This option must be enabled on moodle', VALUE_OPTIONAL),
)
Expand Down Expand Up @@ -1356,7 +1358,7 @@ public static function update_categories($categories) {
}
if (!empty($cat['description'])) {
$category->description = $cat['description'];
$category->descriptionformat = FORMAT_HTML;
$category->descriptionformat = external_validate_format($cat['descriptionformat']);
}
if (!empty($cat['theme'])) {
$category->theme = $cat['theme'];
Expand Down
3 changes: 2 additions & 1 deletion enrol/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static function get_enrolled_users_returns() {
'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL),
'lastaccess' => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL),
'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL),
'descriptionformat' => new external_value(PARAM_INT, 'User profile description format', VALUE_OPTIONAL),
'descriptionformat' => new external_format_value('description', VALUE_OPTIONAL),
'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
'url' => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL),
'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
Expand All @@ -298,6 +298,7 @@ public static function get_enrolled_users_returns() {
'id' => new external_value(PARAM_INT, 'group id'),
'name' => new external_value(PARAM_RAW, 'group name'),
'description' => new external_value(PARAM_RAW, 'group description'),
'descriptionformat' => new external_format_value('description'),
)
), 'user groups', VALUE_OPTIONAL),
'roles' => new external_multiple_structure(
Expand Down
Loading

0 comments on commit 93ce0e8

Please sign in to comment.