本文整理汇总了PHP中external_format_text函数的典型用法代码示例。如果您正苦于以下问题:PHP external_format_text函数的具体用法?PHP external_format_text怎么用?PHP external_format_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了external_format_text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export_for_template
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output)
{
global $CFG;
require_once $CFG->libdir . '/externallib.php';
$r = new stdClass();
$r->id = (int) $this->record->id;
$r->rawname = clean_param($this->record->rawname, PARAM_TAG);
$r->name = clean_param($this->record->name, PARAM_TAG);
$format = clean_param($this->record->descriptionformat, PARAM_INT);
list($r->description, $r->descriptionformat) = external_format_text($this->record->description, $format, \context_system::instance()->id, 'core', 'tag', $r->id);
$r->flag = clean_param($this->record->flag, PARAM_INT);
if (isset($this->record->official)) {
$r->official = clean_param($this->record->official, PARAM_INT);
} else {
$r->official = $this->record->tagtype === 'official' ? 1 : 0;
}
$url = new moodle_url('/tag/index.php', array('id' => $this->record->id));
$r->viewurl = $url->out(false);
$manageurl = new moodle_url('/tag/manage.php', array('sesskey' => sesskey(), 'tagid' => $this->record->id));
$url = new moodle_url($manageurl);
$url->param('action', 'changetype');
$url->param('tagtype', $r->official ? 'default' : 'official');
$r->changetypeurl = $url->out(false);
$url = new moodle_url($manageurl);
$url->param('action', $this->record->flag ? 'resetflag' : 'setflag');
$r->changeflagurl = $url->out(false);
return $r;
}
示例2: get_glossaries_by_courses
/**
* Returns a list of glossaries in a provided list of courses.
*
* If no list is provided all glossaries that the user can view will be returned.
*
* @param array $courseids the course IDs.
* @return array of glossaries
* @since Moodle 3.1
*/
public static function get_glossaries_by_courses($courseids = array())
{
$params = self::validate_parameters(self::get_glossaries_by_courses_parameters(), array('courseids' => $courseids));
$warnings = array();
$courses = array();
$courseids = $params['courseids'];
if (empty($courseids)) {
$courses = enrol_get_my_courses();
$courseids = array_keys($courses);
}
// Array to store the glossaries to return.
$glossaries = array();
// Ensure there are courseids to loop through.
if (!empty($courseids)) {
list($courses, $warnings) = external_util::validate_courses($courseids, $courses);
// Get the glossaries in these courses, this function checks users visibility permissions.
$glossaries = get_all_instances_in_courses('glossary', $courses);
foreach ($glossaries as $glossary) {
$context = context_module::instance($glossary->coursemodule);
$glossary->name = external_format_string($glossary->name, $context->id);
list($glossary->intro, $glossary->introformat) = external_format_text($glossary->intro, $glossary->introformat, $context->id, 'mod_glossary', 'intro', null);
}
}
$result = array();
$result['glossaries'] = $glossaries;
$result['warnings'] = $warnings;
return $result;
}
示例3: export_for_template
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output)
{
global $CFG;
require_once $CFG->libdir . '/externallib.php';
$r = new stdClass();
$r->id = (int) $this->record->id;
$r->tagcollid = clean_param($this->record->tagcollid, PARAM_INT);
$r->rawname = clean_param($this->record->rawname, PARAM_TAG);
$r->name = clean_param($this->record->name, PARAM_TAG);
$format = clean_param($this->record->descriptionformat, PARAM_INT);
list($r->description, $r->descriptionformat) = external_format_text($this->record->description, $format, \context_system::instance()->id, 'core', 'tag', $r->id);
$r->flag = clean_param($this->record->flag, PARAM_INT);
if (isset($this->record->isstandard)) {
$r->isstandard = clean_param($this->record->isstandard, PARAM_INT) ? 1 : 0;
}
$r->official = $r->isstandard;
// For backwards compatibility.
$url = core_tag_tag::make_url($r->tagcollid, $r->rawname);
$r->viewurl = $url->out(false);
$manageurl = new moodle_url('/tag/manage.php', array('sesskey' => sesskey(), 'tagid' => $this->record->id));
$url = new moodle_url($manageurl);
$url->param('action', 'changetype');
$url->param('isstandard', $r->isstandard ? 0 : 1);
$r->changetypeurl = $url->out(false);
$url = new moodle_url($manageurl);
$url->param('action', $this->record->flag ? 'resetflag' : 'setflag');
$r->changeflagurl = $url->out(false);
return $r;
}
示例4: get_comments
/**
* Return a list of comments
*
* @param string $contextlevel ('system, course, user', etc..)
* @param int $instanceid
* @param string $component the name of the component
* @param int $itemid the item id
* @param string $area comment area
* @param int $page page number
* @return array of comments and warnings
* @since Moodle 2.9
*/
public static function get_comments($contextlevel, $instanceid, $component, $itemid, $area = '', $page = 0)
{
$warnings = array();
$arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'itemid' => $itemid, 'area' => $area, 'page' => $page);
$params = self::validate_parameters(self::get_comments_parameters(), $arrayparams);
$context = self::get_context_from_params($params);
self::validate_context($context);
require_capability('moodle/comment:view', $context);
$args = new stdClass();
$args->context = $context;
$args->area = $params['area'];
$args->itemid = $params['itemid'];
$args->component = $params['component'];
$commentobject = new comment($args);
$comments = $commentobject->get_comments($params['page']);
// False means no permissions to see comments.
if ($comments === false) {
throw new moodle_exception('nopermissions', 'error', '', 'view comments');
}
foreach ($comments as $key => $comment) {
list($comments[$key]->content, $comments[$key]->format) = external_format_text($comment->content, $comment->format, $context->id, $params['component'], '', 0);
}
$results = array('comments' => $comments, 'warnings' => $warnings);
return $results;
}
示例5: export_for_template
/**
* Export the step configuration.
*
* @param renderer_base $output The renderer.
* @return object
*/
public function export_for_template(\renderer_base $output)
{
global $PAGE;
$step = $this->step;
$result = (object) ['stepid' => $step->get_id(), 'title' => external_format_text(stepsource::get_string_from_input($step->get_title()), FORMAT_HTML, $PAGE->context->id, 'tool_usertours')[0], 'content' => external_format_text(stepsource::get_string_from_input($step->get_content()), FORMAT_HTML, $PAGE->context->id, 'tool_usertours')[0], 'element' => $step->get_target()->convert_to_css()];
$result->content = str_replace("\n", "<br>\n", $result->content);
foreach ($step->get_config_keys() as $key) {
$result->{$key} = $step->get_config($key);
}
return $result;
}
示例6: get_wikis_by_courses
/**
* Returns a list of wikis in a provided list of courses,
* if no list is provided all wikis that the user can view will be returned.
*
* @param array $courseids The courses IDs.
* @return array Containing a list of warnings and a list of wikis.
* @since Moodle 3.1
*/
public static function get_wikis_by_courses($courseids = array())
{
$returnedwikis = array();
$warnings = array();
$params = self::validate_parameters(self::get_wikis_by_courses_parameters(), array('courseids' => $courseids));
$mycourses = array();
if (empty($params['courseids'])) {
$mycourses = enrol_get_my_courses();
$params['courseids'] = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
// Get the wikis in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$wikis = get_all_instances_in_courses('wiki', $courses);
foreach ($wikis as $wiki) {
$context = context_module::instance($wiki->coursemodule);
// Entry to return.
$module = array();
// First, we return information that any user can see in (or can deduce from) the web interface.
$module['id'] = $wiki->id;
$module['coursemodule'] = $wiki->coursemodule;
$module['course'] = $wiki->course;
$module['name'] = external_format_string($wiki->name, $context->id);
$viewablefields = [];
if (has_capability('mod/wiki:viewpage', $context)) {
list($module['intro'], $module['introformat']) = external_format_text($wiki->intro, $wiki->introformat, $context->id, 'mod_wiki', 'intro', $wiki->id);
$viewablefields = array('firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend', 'section', 'visible', 'groupmode', 'groupingid');
}
// Check additional permissions for returning optional private settings.
if (has_capability('moodle/course:manageactivities', $context)) {
$additionalfields = array('timecreated', 'timemodified');
$viewablefields = array_merge($viewablefields, $additionalfields);
}
foreach ($viewablefields as $field) {
$module[$field] = $wiki->{$field};
}
// Check if user can add new pages.
$module['cancreatepages'] = wiki_can_create_pages($context);
$returnedwikis[] = $module;
}
}
$result = array();
$result['wikis'] = $returnedwikis;
$result['warnings'] = $warnings;
return $result;
}
示例7: export_for_template
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output)
{
global $CFG;
require_once $CFG->libdir . '/externallib.php';
$r = new stdClass();
$r->id = (int) $this->record->id;
$r->tagcollid = clean_param($this->record->tagcollid, PARAM_INT);
$r->rawname = clean_param($this->record->rawname, PARAM_TAG);
$r->name = clean_param($this->record->name, PARAM_TAG);
$format = clean_param($this->record->descriptionformat, PARAM_INT);
list($r->description, $r->descriptionformat) = external_format_text($this->record->description, $format, \context_system::instance()->id, 'core', 'tag', $r->id);
$r->flag = clean_param($this->record->flag, PARAM_INT);
if (isset($this->record->isstandard)) {
$r->isstandard = clean_param($this->record->isstandard, PARAM_INT) ? 1 : 0;
}
$r->official = $r->isstandard;
// For backwards compatibility.
$url = core_tag_tag::make_url($r->tagcollid, $r->rawname);
$r->viewurl = $url->out(false);
return $r;
}
示例8: test_external_format_text
public function test_external_format_text()
{
$settings = external_settings::get_instance();
$currentraw = $settings->get_raw();
$currentfilter = $settings->get_filter();
$settings->set_raw(true);
$settings->set_filter(false);
$context = context_system::instance();
$test = '$$ \\pi $$';
$testformat = FORMAT_MARKDOWN;
$correct = array($test, $testformat);
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0), $correct);
$settings->set_raw(false);
$settings->set_filter(true);
$test = '$$ \\pi $$';
$testformat = FORMAT_MARKDOWN;
$correct = array('<span class="nolink"><span class="filter_mathjaxloader_equation"><p>$$ \\pi $$</p>
</span></span>', FORMAT_HTML);
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0), $correct);
$settings->set_raw($currentraw);
$settings->set_filter($currentfilter);
}
示例9: get_quiz_feedback_for_grade
/**
* Get the feedback text that should be show to a student who got the given grade in the given quiz.
*
* @param int $quizid quiz instance id
* @param float $grade the grade to check
* @return array of warnings and status result
* @since Moodle 3.1
* @throws moodle_exception
*/
public static function get_quiz_feedback_for_grade($quizid, $grade)
{
global $DB;
$params = array('quizid' => $quizid, 'grade' => $grade);
$params = self::validate_parameters(self::get_quiz_feedback_for_grade_parameters(), $params);
$warnings = array();
list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']);
$result = array();
$result['feedbacktext'] = '';
$result['feedbacktextformat'] = FORMAT_MOODLE;
$feedback = quiz_feedback_record_for_grade($params['grade'], $quiz);
if (!empty($feedback->feedbacktext)) {
list($text, $format) = external_format_text($feedback->feedbacktext, $feedback->feedbacktextformat, $context->id, 'mod_quiz', 'feedback', $feedback->id);
$result['feedbacktext'] = $text;
$result['feedbacktextformat'] = $format;
}
$result['warnings'] = $warnings;
return $result;
}
示例10: get_course_groupings
/**
* Get all groupings in the specified course
*
* @param int $courseid id of course
* @return array of grouping objects (id, courseid, name, enrolmentkey)
* @since Moodle 2.3
*/
public static function get_course_groupings($courseid)
{
global $CFG;
require_once "{$CFG->dirroot}/group/lib.php";
require_once "{$CFG->libdir}/filelib.php";
$params = self::validate_parameters(self::get_course_groupings_parameters(), array('courseid' => $courseid));
// Now security checks.
$context = context_course::instance($params['courseid']);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
$gs = groups_get_all_groupings($params['courseid']);
$groupings = array();
foreach ($gs as $grouping) {
list($grouping->description, $grouping->descriptionformat) = external_format_text($grouping->description, $grouping->descriptionformat, $context->id, 'grouping', 'description', $grouping->id);
$groupings[] = (array) $grouping;
}
return $groupings;
}
示例11: get_databases_by_courses
/**
* Returns a list of databases in a provided list of courses,
* if no list is provided all databases that the user can view will be returned.
*
* @param array $courseids the course ids
* @return array the database details
* @since Moodle 2.9
*/
public static function get_databases_by_courses($courseids = array())
{
global $CFG;
$params = self::validate_parameters(self::get_databases_by_courses_parameters(), array('courseids' => $courseids));
$warnings = array();
if (!empty($params['courseids'])) {
$courses = array();
$courseids = $params['courseids'];
} else {
$courses = enrol_get_my_courses();
$courseids = array_keys($courses);
}
// Array to store the databases to return.
$arrdatabases = array();
// Ensure there are courseids to loop through.
if (!empty($courseids)) {
// Array of the courses we are going to retrieve the databases from.
$dbcourses = array();
// Go through the courseids.
foreach ($courseids as $cid) {
// Check the user can function in this context.
try {
$context = context_course::instance($cid);
self::validate_context($context);
// Check if this course was already loaded (by enrol_get_my_courses).
if (!isset($courses[$cid])) {
$courses[$cid] = get_course($cid);
}
$dbcourses[$cid] = $courses[$cid];
} catch (Exception $e) {
$warnings[] = array('item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context ' . $e->getMessage());
}
}
// Get the databases in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$databases = get_all_instances_in_courses("data", $dbcourses);
foreach ($databases as $database) {
$datacontext = context_module::instance($database->coursemodule);
// Entry to return.
$newdb = array();
// First, we return information that any user can see in the web interface.
$newdb['id'] = $database->id;
$newdb['coursemodule'] = $database->coursemodule;
$newdb['course'] = $database->course;
$newdb['name'] = $database->name;
// Format intro.
list($newdb['intro'], $newdb['introformat']) = external_format_text($database->intro, $database->introformat, $datacontext->id, 'mod_data', 'intro', null);
// This information should be only available if the user can see the database entries.
if (has_capability('mod/data:viewentry', $datacontext)) {
$viewablefields = array('comments', 'timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto', 'requiredentries', 'requiredentriestoview');
// This is for avoid a long repetitive list and for
// checking that we are retrieving all the required fields.
foreach ($viewablefields as $field) {
// We do not use isset because it won't work for existing null values.
if (!property_exists($database, $field)) {
throw new invalid_response_exception('Missing database module required field: ' . $field);
}
$newdb[$field] = $database->{$field};
}
}
// Check additional permissions for returning optional private settings.
// I avoid intentionally to use can_[add|update]_moduleinfo.
if (has_capability('moodle/course:manageactivities', $context)) {
$additionalfields = array('maxentries', 'rssarticles', 'singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter', 'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate', 'asearchtemplate', 'approval', 'scale', 'assessed', 'assesstimestart', 'assesstimefinish', 'defaultsort', 'defaultsortdir', 'editany', 'notification');
// This is for avoid a long repetitive list.
foreach ($additionalfields as $field) {
if (property_exists($database, $field)) {
$newdb[$field] = $database->{$field};
}
}
}
$arrdatabases[] = $newdb;
}
}
$result = array();
$result['databases'] = $arrdatabases;
$result['warnings'] = $warnings;
return $result;
}
示例12: get_chats_by_courses
/**
* Returns a list of chats in a provided list of courses,
* if no list is provided all chats that the user can view will be returned.
*
* @param array $courseids the course ids
* @return array of chats details
* @since Moodle 3.0
*/
public static function get_chats_by_courses($courseids = array())
{
global $CFG;
$returnedchats = array();
$warnings = array();
$params = self::validate_parameters(self::get_chats_by_courses_parameters(), array('courseids' => $courseids));
$courses = array();
if (empty($params['courseids'])) {
$courses = enrol_get_my_courses();
$params['courseids'] = array_keys($courses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
// Get the chats in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$chats = get_all_instances_in_courses("chat", $courses);
foreach ($chats as $chat) {
$chatcontext = context_module::instance($chat->coursemodule);
// Entry to return.
$chatdetails = array();
// First, we return information that any user can see in the web interface.
$chatdetails['id'] = $chat->id;
$chatdetails['coursemodule'] = $chat->coursemodule;
$chatdetails['course'] = $chat->course;
$chatdetails['name'] = external_format_string($chat->name, $chatcontext->id);
// Format intro.
list($chatdetails['intro'], $chatdetails['introformat']) = external_format_text($chat->intro, $chat->introformat, $chatcontext->id, 'mod_chat', 'intro', null);
if (has_capability('mod/chat:chat', $chatcontext)) {
$chatdetails['chatmethod'] = $CFG->chat_method;
$chatdetails['keepdays'] = $chat->keepdays;
$chatdetails['studentlogs'] = $chat->studentlogs;
$chatdetails['chattime'] = $chat->chattime;
$chatdetails['schedule'] = $chat->schedule;
}
if (has_capability('moodle/course:manageactivities', $chatcontext)) {
$chatdetails['timemodified'] = $chat->timemodified;
$chatdetails['section'] = $chat->section;
$chatdetails['visible'] = $chat->visible;
$chatdetails['groupmode'] = $chat->groupmode;
$chatdetails['groupingid'] = $chat->groupingid;
}
$returnedchats[] = $chatdetails;
}
}
$result = array();
$result['chats'] = $returnedchats;
$result['warnings'] = $warnings;
return $result;
}
示例13: get_plugins_data
/**
* Return information (files and text fields) for the given plugins in the assignment.
*
* @param assign $assign the assignment object
* @param array $assignplugins array of assignment plugins (submission or feedback)
* @param stdClass $item the item object (submission or grade)
* @return array an array containing the plugins returned information
*/
private static function get_plugins_data($assign, $assignplugins, $item)
{
global $CFG;
$plugins = array();
$fs = get_file_storage();
foreach ($assignplugins as $assignplugin) {
if (!$assignplugin->is_enabled() or !$assignplugin->is_visible()) {
continue;
}
$plugin = array('name' => $assignplugin->get_name(), 'type' => $assignplugin->get_type());
// Subtype is 'assignsubmission', type is currently 'file' or 'onlinetext'.
$component = $assignplugin->get_subtype() . '_' . $assignplugin->get_type();
$fileareas = $assignplugin->get_file_areas();
foreach ($fileareas as $filearea => $name) {
$fileareainfo = array('area' => $filearea);
$fileareainfo['files'] = external_util::get_area_files($assign->get_context()->id, $component, $filearea, $item->id);
$plugin['fileareas'][] = $fileareainfo;
}
$editorfields = $assignplugin->get_editor_fields();
foreach ($editorfields as $name => $description) {
$editorfieldinfo = array('name' => $name, 'description' => $description, 'text' => $assignplugin->get_editor_text($name, $item->id), 'format' => $assignplugin->get_editor_format($name, $item->id));
// Now format the text.
foreach ($fileareas as $filearea => $name) {
list($editorfieldinfo['text'], $editorfieldinfo['format']) = external_format_text($editorfieldinfo['text'], $editorfieldinfo['format'], $assign->get_context()->id, $component, $filearea, $item->id);
}
$plugin['editorfields'][] = $editorfieldinfo;
}
$plugins[] = $plugin;
}
return $plugins;
}
示例14: format_external_text
/**
* Format the text using the external API.
* This function should we used when text formatting is required in external functions.
*
* @return array an array containing the text formatted and the text format
*/
public function format_external_text()
{
if ($this->editorcontext === null) {
// Switch on the event type to decide upon the appropriate context to use for this event.
$this->editorcontext = $this->properties->context;
if ($this->properties->eventtype != 'user' && $this->properties->eventtype != 'course' && $this->properties->eventtype != 'site' && $this->properties->eventtype != 'group') {
// We don't have a context here, do a normal format_text.
return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id);
}
}
// Work out the item id for the editor, if this is a repeated event then the files will be associated with the original.
if (!empty($this->properties->repeatid) && $this->properties->repeatid > 0) {
$itemid = $this->properties->repeatid;
} else {
$itemid = $this->properties->id;
}
return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id, 'calendar', 'event_description', $itemid);
}
示例15: search_courses
/**
* Search courses following the specified criteria.
*
* @param string $criterianame Criteria name (search, modulelist (only admins), blocklist (only admins), tagid)
* @param string $criteriavalue Criteria value
* @param int $page Page number (for pagination)
* @param int $perpage Items per page
* @param array $requiredcapabilities Optional list of required capabilities (used to filter the list).
* @param int $limittoenrolled Limit to only enrolled courses
* @return array of course objects and warnings
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function search_courses($criterianame, $criteriavalue, $page = 0, $perpage = 0, $requiredcapabilities = array(), $limittoenrolled = 0)
{
global $CFG;
require_once $CFG->libdir . '/coursecatlib.php';
$warnings = array();
$parameters = array('criterianame' => $criterianame, 'criteriavalue' => $criteriavalue, 'page' => $page, 'perpage' => $perpage, 'requiredcapabilities' => $requiredcapabilities);
$params = self::validate_parameters(self::search_courses_parameters(), $parameters);
self::validate_context(context_system::instance());
$allowedcriterianames = array('search', 'modulelist', 'blocklist', 'tagid');
if (!in_array($params['criterianame'], $allowedcriterianames)) {
throw new invalid_parameter_exception('Invalid value for criterianame parameter (value: ' . $params['criterianame'] . '),' . 'allowed values are: ' . implode(',', $allowedcriterianames));
}
if ($params['criterianame'] == 'modulelist' or $params['criterianame'] == 'blocklist') {
require_capability('moodle/site:config', context_system::instance());
}
$paramtype = array('search' => PARAM_RAW, 'modulelist' => PARAM_PLUGIN, 'blocklist' => PARAM_INT, 'tagid' => PARAM_INT);
$params['criteriavalue'] = clean_param($params['criteriavalue'], $paramtype[$params['criterianame']]);
// Prepare the search API options.
$searchcriteria = array();
$searchcriteria[$params['criterianame']] = $params['criteriavalue'];
$options = array();
if ($params['perpage'] != 0) {
$offset = $params['page'] * $params['perpage'];
$options = array('offset' => $offset, 'limit' => $params['perpage']);
}
// Search the courses.
$courses = coursecat::search_courses($searchcriteria, $options, $params['requiredcapabilities']);
$totalcount = coursecat::search_courses_count($searchcriteria, $options, $params['requiredcapabilities']);
if (!empty($limittoenrolled)) {
// Get the courses where the current user has access.
$enrolled = enrol_get_my_courses(array('id', 'cacherev'));
}
$finalcourses = array();
$categoriescache = array();
foreach ($courses as $course) {
if (!empty($limittoenrolled)) {
// Filter out not enrolled courses.
if (!isset($enrolled[$course->id])) {
$totalcount--;
continue;
}
}
$coursecontext = context_course::instance($course->id);
// Category information.
if (!isset($categoriescache[$course->category])) {
$categoriescache[$course->category] = coursecat::get($course->category);
}
$category = $categoriescache[$course->category];
// Retrieve course overfiew used files.
$files = array();
foreach ($course->get_course_overviewfiles() as $file) {
$fileurl = moodle_url::make_webservice_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename())->out(false);
$files[] = array('filename' => $file->get_filename(), 'fileurl' => $fileurl, 'filesize' => $file->get_filesize());
}
// Retrieve the course contacts,
// we need here the users fullname since if we are not enrolled can be difficult to obtain them via other Web Services.
$coursecontacts = array();
foreach ($course->get_course_contacts() as $contact) {
$coursecontacts[] = array('id' => $contact['user']->id, 'fullname' => $contact['username']);
}
// Allowed enrolment methods (maybe we can self-enrol).
$enroltypes = array();
$instances = enrol_get_instances($course->id, true);
foreach ($instances as $instance) {
$enroltypes[] = $instance->enrol;
}
// Format summary.
list($summary, $summaryformat) = external_format_text($course->summary, $course->summaryformat, $coursecontext->id, 'course', 'summary', null);
$displayname = get_course_display_name_for_list($course);
$coursereturns = array();
$coursereturns['id'] = $course->id;
$coursereturns['fullname'] = external_format_string($course->fullname, $coursecontext->id);
$coursereturns['displayname'] = external_format_string($displayname, $coursecontext->id);
$coursereturns['shortname'] = external_format_string($course->shortname, $coursecontext->id);
$coursereturns['categoryid'] = $course->category;
$coursereturns['categoryname'] = $category->name;
$coursereturns['summary'] = $summary;
$coursereturns['summaryformat'] = $summaryformat;
$coursereturns['overviewfiles'] = $files;
$coursereturns['contacts'] = $coursecontacts;
$coursereturns['enrollmentmethods'] = $enroltypes;
$finalcourses[] = $coursereturns;
}
return array('total' => $totalcount, 'courses' => $finalcourses, 'warnings' => $warnings);
}