当前位置: 首页>>代码示例>>PHP>>正文


PHP external_format_string函数代码示例

本文整理汇总了PHP中external_format_string函数的典型用法代码示例。如果您正苦于以下问题:PHP external_format_string函数的具体用法?PHP external_format_string怎么用?PHP external_format_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了external_format_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_get_public_config

 public function test_get_public_config()
 {
     global $CFG, $SITE, $OUTPUT;
     $this->resetAfterTest(true);
     $result = external::get_public_config();
     $result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
     // Test default values.
     $context = context_system::instance();
     list($authinstructions, $notusedformat) = external_format_text($CFG->auth_instructions, FORMAT_MOODLE, $context->id);
     list($maintenancemessage, $notusedformat) = external_format_text($CFG->maintenance_message, FORMAT_MOODLE, $context->id);
     $expected = array('wwwroot' => $CFG->wwwroot, 'httpswwwroot' => $CFG->httpswwwroot, 'sitename' => external_format_string($SITE->fullname, $context->id, true), 'guestlogin' => $CFG->guestloginbutton, 'rememberusername' => $CFG->rememberusername, 'authloginviaemail' => $CFG->authloginviaemail, 'registerauth' => $CFG->registerauth, 'forgottenpasswordurl' => $CFG->forgottenpasswordurl, 'authinstructions' => $authinstructions, 'authnoneenabled' => (int) is_enabled_auth('none'), 'enablewebservices' => $CFG->enablewebservices, 'enablemobilewebservice' => $CFG->enablemobilewebservice, 'maintenanceenabled' => $CFG->maintenance_enabled, 'maintenancemessage' => $maintenancemessage, 'typeoflogin' => api::LOGIN_VIA_APP, 'warnings' => array());
     $this->assertEquals($expected, $result);
     // Change some values.
     set_config('registerauth', 'email');
     $authinstructions = 'Something with <b>html tags</b>';
     set_config('auth_instructions', $authinstructions);
     set_config('typeoflogin', api::LOGIN_VIA_BROWSER, 'tool_mobile');
     set_config('logo', 'mock.png', 'core_admin');
     set_config('logocompact', 'mock.png', 'core_admin');
     list($authinstructions, $notusedformat) = external_format_text($authinstructions, FORMAT_MOODLE, $context->id);
     $expected['registerauth'] = 'email';
     $expected['authinstructions'] = $authinstructions;
     $expected['typeoflogin'] = api::LOGIN_VIA_BROWSER;
     $expected['launchurl'] = "{$CFG->wwwroot}/{$CFG->admin}/tool/mobile/launch.php";
     if ($logourl = $OUTPUT->get_logo_url()) {
         $expected['logourl'] = $logourl->out(false);
     }
     if ($compactlogourl = $OUTPUT->get_compact_logo_url()) {
         $expected['compactlogourl'] = $compactlogourl->out(false);
     }
     $result = external::get_public_config();
     $result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
     $this->assertEquals($expected, $result);
 }
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:34,代码来源:externallib_test.php

示例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;
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:37,代码来源:external.php

示例3: get_site_public_settings

 /**
  * Returns a list of the site public settings, those not requiring authentication.
  *
  * @return array with the settings and warnings
  */
 public static function get_site_public_settings()
 {
     global $CFG, $SITE, $PAGE;
     $context = context_system::instance();
     // We need this to make work the format text functions.
     $PAGE->set_context($context);
     $settings = array('wwwroot' => $CFG->wwwroot, 'httpswwwroot' => $CFG->httpswwwroot, 'sitename' => external_format_string($SITE->fullname, $context->id, true), 'guestlogin' => $CFG->guestloginbutton, 'rememberusername' => $CFG->rememberusername, 'authloginviaemail' => $CFG->authloginviaemail, 'registerauth' => $CFG->registerauth, 'forgottenpasswordurl' => $CFG->forgottenpasswordurl, 'authinstructions' => format_text($CFG->auth_instructions), 'authnoneenabled' => (int) is_enabled_auth('none'), 'enablewebservices' => $CFG->enablewebservices, 'enablemobilewebservice' => $CFG->enablemobilewebservice, 'maintenanceenabled' => $CFG->maintenance_enabled, 'maintenancemessage' => format_text($CFG->maintenance_message));
     return $settings;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:14,代码来源:api.php

示例4: get_surveys_by_courses

 /**
  * Returns a list of surveys in a provided list of courses,
  * if no list is provided all surveys that the user can view will be returned.
  *
  * @param array $courseids the course ids
  * @return array of surveys details
  * @since Moodle 3.0
  */
 public static function get_surveys_by_courses($courseids = array())
 {
     global $CFG, $USER, $DB;
     $returnedsurveys = array();
     $warnings = array();
     $params = self::validate_parameters(self::get_surveys_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 surveys in this course, this function checks users visibility permissions.
         // We can avoid then additional validate_context calls.
         $surveys = get_all_instances_in_courses("survey", $courses);
         foreach ($surveys as $survey) {
             $context = context_module::instance($survey->coursemodule);
             // Entry to return.
             $surveydetails = array();
             // First, we return information that any user can see in the web interface.
             $surveydetails['id'] = $survey->id;
             $surveydetails['coursemodule'] = $survey->coursemodule;
             $surveydetails['course'] = $survey->course;
             $surveydetails['name'] = external_format_string($survey->name, $context->id);
             if (has_capability('mod/survey:participate', $context)) {
                 $trimmedintro = trim($survey->intro);
                 if (empty($trimmedintro)) {
                     $tempo = $DB->get_field("survey", "intro", array("id" => $survey->template));
                     $survey->intro = get_string($tempo, "survey");
                 }
                 // Format intro.
                 list($surveydetails['intro'], $surveydetails['introformat']) = external_format_text($survey->intro, $survey->introformat, $context->id, 'mod_survey', 'intro', null);
                 $surveydetails['introfiles'] = external_util::get_area_files($context->id, 'mod_survey', 'intro', false, false);
                 $surveydetails['template'] = $survey->template;
                 $surveydetails['days'] = $survey->days;
                 $surveydetails['questions'] = $survey->questions;
                 $surveydetails['surveydone'] = survey_already_done($survey->id, $USER->id) ? 1 : 0;
             }
             if (has_capability('moodle/course:manageactivities', $context)) {
                 $surveydetails['timecreated'] = $survey->timecreated;
                 $surveydetails['timemodified'] = $survey->timemodified;
                 $surveydetails['section'] = $survey->section;
                 $surveydetails['visible'] = $survey->visible;
                 $surveydetails['groupmode'] = $survey->groupmode;
                 $surveydetails['groupingid'] = $survey->groupingid;
             }
             $returnedsurveys[] = $surveydetails;
         }
     }
     $result = array();
     $result['surveys'] = $returnedsurveys;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:64,代码来源:external.php

示例5: get_other_values

 protected function get_other_values(renderer_base $output)
 {
     $cm = $this->related['cm'];
     $context = $cm->context;
     $values = array('id' => $cm->id, 'name' => external_format_string($cm->name, $context->id), 'iconurl' => $cm->get_icon_url()->out());
     if ($cm->url) {
         $values['url'] = $cm->url->out();
     }
     return $values;
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:10,代码来源:course_module_summary_exporter.php

示例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;
 }
开发者ID:GaganJotSingh,项目名称:moodle,代码行数:56,代码来源:external.php

示例7: test_get_site_public_settings

 public function test_get_site_public_settings()
 {
     global $CFG, $SITE;
     $this->resetAfterTest(true);
     $result = external::get_site_public_settings();
     $result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result);
     // Test default values.
     $context = context_system::instance();
     $expected = array('wwwroot' => $CFG->wwwroot, 'httpswwwroot' => $CFG->httpswwwroot, 'sitename' => external_format_string($SITE->fullname, $context->id, true), 'guestlogin' => $CFG->guestloginbutton, 'rememberusername' => $CFG->rememberusername, 'authloginviaemail' => $CFG->authloginviaemail, 'registerauth' => $CFG->registerauth, 'forgottenpasswordurl' => $CFG->forgottenpasswordurl, 'authinstructions' => format_text($CFG->auth_instructions), 'authnoneenabled' => (int) is_enabled_auth('none'), 'enablewebservices' => $CFG->enablewebservices, 'enablemobilewebservice' => $CFG->enablemobilewebservice, 'maintenanceenabled' => $CFG->maintenance_enabled, 'maintenancemessage' => format_text($CFG->maintenance_message), 'warnings' => array());
     $this->assertEquals($expected, $result);
     // Change a value.
     set_config('registerauth', 'email');
     $authinstructions = 'Something with <b>html tags</b>';
     set_config('auth_instructions', $authinstructions);
     $expected['registerauth'] = 'email';
     $expected['authinstructions'] = format_text($authinstructions);
     $result = external::get_site_public_settings();
     $result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result);
     $this->assertEquals($expected, $result);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:externallib_test.php

示例8: get_forums_by_courses

 /**
  * Returns a list of forums in a provided list of courses,
  * if no list is provided all forums that the user can view
  * will be returned.
  *
  * @param array $courseids the course ids
  * @return array the forum details
  * @since Moodle 2.5
  */
 public static function get_forums_by_courses($courseids = array())
 {
     global $CFG;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     $params = self::validate_parameters(self::get_forums_by_courses_parameters(), array('courseids' => $courseids));
     $courses = array();
     if (empty($params['courseids'])) {
         $courses = enrol_get_my_courses();
         $params['courseids'] = array_keys($courses);
     }
     // Array to store the forums to return.
     $arrforums = array();
     $warnings = array();
     // Ensure there are courseids to loop through.
     if (!empty($params['courseids'])) {
         list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
         // Get the forums in this course. This function checks users visibility permissions.
         $forums = get_all_instances_in_courses("forum", $courses);
         foreach ($forums as $forum) {
             $course = $courses[$forum->course];
             $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
             $context = context_module::instance($cm->id);
             // Skip forums we are not allowed to see discussions.
             if (!has_capability('mod/forum:viewdiscussion', $context)) {
                 continue;
             }
             $forum->name = external_format_string($forum->name, $context->id);
             // Format the intro before being returning using the format setting.
             list($forum->intro, $forum->introformat) = external_format_text($forum->intro, $forum->introformat, $context->id, 'mod_forum', 'intro', 0);
             $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'intro', false, false);
             // Discussions count. This function does static request cache.
             $forum->numdiscussions = forum_count_discussions($forum, $cm, $course);
             $forum->cmid = $forum->coursemodule;
             $forum->cancreatediscussions = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
             // Add the forum to the array to return.
             $arrforums[$forum->id] = $forum;
         }
     }
     return $arrforums;
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:49,代码来源:externallib.php

示例9: 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();
     $mycourses = array();
     if (empty($params['courseids'])) {
         $mycourses = enrol_get_my_courses();
         $params['courseids'] = array_keys($mycourses);
     }
     // Array to store the databases to return.
     $arrdatabases = array();
     // Ensure there are courseids to loop through.
     if (!empty($params['courseids'])) {
         list($dbcourses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
         // 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'] = external_format_string($database->name, $datacontext->id);
             // Format intro.
             list($newdb['intro'], $newdb['introformat']) = external_format_text($database->intro, $database->introformat, $datacontext->id, 'mod_data', 'intro', null);
             $newdb['introfiles'] = external_util::get_area_files($datacontext->id, 'mod_data', 'intro', false, false);
             // 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', $datacontext)) {
                 $additionalfields = array('maxentries', 'rssarticles', 'singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter', 'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate', 'asearchtemplate', 'approval', 'manageapproved', 'scale', 'assessed', 'assesstimestart', 'assesstimefinish', 'defaultsort', 'defaultsortdir', 'editany', 'notification', 'timemodified');
                 // 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;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:70,代码来源:external.php

示例10: get_entries_by_category

 /**
  * Browse a glossary entries by category.
  *
  * @param int $id The glossary ID.
  * @param int $categoryid The category ID.
  * @param int $from Start returning records from here.
  * @param int $limit Number of records to return.
  * @param array $options Array of options.
  * @return array Containing count, entries and warnings.
  * @since Moodle 3.1
  * @throws moodle_exception
  * @throws invalid_parameter_exception
  */
 public static function get_entries_by_category($id, $categoryid, $from, $limit, $options)
 {
     global $DB;
     $params = self::validate_parameters(self::get_entries_by_category_parameters(), array('id' => $id, 'categoryid' => $categoryid, 'from' => $from, 'limit' => $limit, 'options' => $options));
     $id = $params['id'];
     $categoryid = $params['categoryid'];
     $from = $params['from'];
     $limit = $params['limit'];
     $options = $params['options'];
     $warnings = array();
     // Get and validate the glossary.
     list($glossary, $context) = self::validate_glossary($id);
     // Validate the mode.
     $modes = self::get_browse_modes_from_display_format($glossary->displayformat);
     if (!in_array('cat', $modes)) {
         throw new invalid_parameter_exception('invalidbrowsemode');
     }
     // Validate the category.
     if (in_array($categoryid, array(GLOSSARY_SHOW_ALL_CATEGORIES, GLOSSARY_SHOW_NOT_CATEGORISED))) {
         // All good.
     } else {
         if (!$DB->record_exists('glossary_categories', array('id' => $categoryid, 'glossaryid' => $id))) {
             throw new invalid_parameter_exception('invalidcategory');
         }
     }
     // Fetching the entries.
     $entries = array();
     list($records, $count) = glossary_get_entries_by_category($glossary, $context, $categoryid, $from, $limit, $options);
     foreach ($records as $key => $record) {
         self::fill_entry_details($record, $context);
         if ($record->categoryid === null) {
             $record->categoryid = GLOSSARY_SHOW_NOT_CATEGORISED;
         }
         if (isset($record->categoryname)) {
             $record->categoryname = external_format_string($record->categoryname, $context->id);
         }
         $entries[] = $record;
     }
     return array('count' => $count, 'entries' => $entries, 'warnings' => $warnings);
 }
开发者ID:janeklb,项目名称:moodle,代码行数:53,代码来源:external.php

示例11: export

 /**
  * Function to export the renderer data in a format that is suitable for a
  * mustache template. This means raw records are generated as in to_record,
  * but all strings are correctly passed through external_format_text (or external_format_string).
  *
  * @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
  * @return stdClass
  */
 public final function export(renderer_base $output)
 {
     $data = new stdClass();
     $properties = self::read_properties_definition();
     $context = $this->get_context();
     $values = (array) $this->data;
     $othervalues = $this->get_other_values($output);
     if (array_intersect_key($values, $othervalues)) {
         // Attempt to replace a standard property.
         throw new coding_exception('Cannot override a standard property value.');
     }
     $values += $othervalues;
     $record = (object) $values;
     foreach ($properties as $property => $definition) {
         if (isset($data->{$property})) {
             // This happens when we have already defined the format properties.
             continue;
         } else {
             if (!property_exists($record, $property) && array_key_exists('default', $definition)) {
                 // We have a default value for this property.
                 $record->{$property} = $definition['default'];
             } else {
                 if (!property_exists($record, $property) && !empty($definition['optional'])) {
                     // Fine, this property can be omitted.
                     continue;
                 } else {
                     if (!property_exists($record, $property)) {
                         // Whoops, we got something that wasn't defined.
                         throw new coding_exception('Unexpected property ' . $property);
                     }
                 }
             }
         }
         $data->{$property} = $record->{$property};
         // If the field is PARAM_RAW and has a format field.
         if ($propertyformat = self::get_format_field($properties, $property)) {
             if (!property_exists($record, $propertyformat)) {
                 // Whoops, we got something that wasn't defined.
                 throw new coding_exception('Unexpected property ' . $propertyformat);
             }
             $format = $record->{$propertyformat};
             list($text, $format) = external_format_text($data->{$property}, $format, $context->id, 'core_competency', '', 0);
             $data->{$property} = $text;
             $data->{$propertyformat} = $format;
         } else {
             if ($definition['type'] === PARAM_TEXT) {
                 if (!empty($definition['multiple'])) {
                     foreach ($data->{$property} as $key => $value) {
                         $data->{$property}[$key] = external_format_string($value, $context->id);
                     }
                 } else {
                     $data->{$property} = external_format_string($data->{$property}, $context->id);
                 }
             }
         }
     }
     return $data;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:66,代码来源:exporter.php

示例12: get_course_module

 /**
  * Return information about a course module.
  *
  * @param int $cmid the course module id
  * @return array of warnings and the course module
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function get_course_module($cmid)
 {
     $params = self::validate_parameters(self::get_course_module_parameters(), array('cmid' => $cmid));
     $warnings = array();
     $cm = get_coursemodule_from_id(null, $params['cmid'], 0, true, MUST_EXIST);
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // If the user has permissions to manage the activity, return all the information.
     if (has_capability('moodle/course:manageactivities', $context)) {
         $info = $cm;
     } else {
         // Return information is safe to show to any user.
         $info = new stdClass();
         $info->id = $cm->id;
         $info->course = $cm->course;
         $info->module = $cm->module;
         $info->modname = $cm->modname;
         $info->instance = $cm->instance;
         $info->section = $cm->section;
         $info->sectionnum = $cm->sectionnum;
         $info->groupmode = $cm->groupmode;
         $info->groupingid = $cm->groupingid;
         $info->completion = $cm->completion;
     }
     // Format name.
     $info->name = external_format_string($cm->name, $context->id);
     $result = array();
     $result['cm'] = $info;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:39,代码来源:externallib.php

示例13: get_course_module

 /**
  * Return information about a course module.
  *
  * @param int $cmid the course module id
  * @return array of warnings and the course module
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function get_course_module($cmid)
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::get_course_module_parameters(), array('cmid' => $cmid));
     $warnings = array();
     $cm = get_coursemodule_from_id(null, $params['cmid'], 0, true, MUST_EXIST);
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // If the user has permissions to manage the activity, return all the information.
     if (has_capability('moodle/course:manageactivities', $context)) {
         require_once $CFG->dirroot . '/course/modlib.php';
         require_once $CFG->libdir . '/gradelib.php';
         $info = $cm;
         // Get the extra information: grade, advanced grading and outcomes data.
         $course = get_course($cm->course);
         list($newcm, $newcontext, $module, $extrainfo, $cw) = get_moduleinfo_data($cm, $course);
         // Grades.
         $gradeinfo = array('grade', 'gradepass', 'gradecat');
         foreach ($gradeinfo as $gfield) {
             if (isset($extrainfo->{$gfield})) {
                 $info->{$gfield} = $extrainfo->{$gfield};
             }
         }
         if (isset($extrainfo->grade) and $extrainfo->grade < 0) {
             $info->scale = $DB->get_field('scale', 'scale', array('id' => abs($extrainfo->grade)));
         }
         // Advanced grading.
         if (isset($extrainfo->_advancedgradingdata)) {
             $info->advancedgrading = array();
             foreach ($extrainfo as $key => $val) {
                 if (strpos($key, 'advancedgradingmethod_') === 0) {
                     $info->advancedgrading[] = array('area' => str_replace('advancedgradingmethod_', '', $key), 'method' => $val);
                 }
             }
         }
         // Outcomes.
         foreach ($extrainfo as $key => $val) {
             if (strpos($key, 'outcome_') === 0) {
                 if (!isset($info->outcomes)) {
                     $info->outcomes = array();
                 }
                 $id = str_replace('outcome_', '', $key);
                 $outcome = grade_outcome::fetch(array('id' => $id));
                 $scaleitems = $outcome->load_scale();
                 $info->outcomes[] = array('id' => $id, 'name' => external_format_string($outcome->get_name(), $context->id), 'scale' => $scaleitems->scale);
             }
         }
     } else {
         // Return information is safe to show to any user.
         $info = new stdClass();
         $info->id = $cm->id;
         $info->course = $cm->course;
         $info->module = $cm->module;
         $info->modname = $cm->modname;
         $info->instance = $cm->instance;
         $info->section = $cm->section;
         $info->sectionnum = $cm->sectionnum;
         $info->groupmode = $cm->groupmode;
         $info->groupingid = $cm->groupingid;
         $info->completion = $cm->completion;
     }
     // Format name.
     $info->name = external_format_string($cm->name, $context->id);
     $result = array();
     $result['cm'] = $info;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:dg711,项目名称:moodle,代码行数:76,代码来源:externallib.php

示例14: get_assignments


//.........这里部分代码省略.........
  * This requires the parameter $courseids to not be empty.
  * @return An array of courses and warnings.
  * @since  Moodle 2.4
  */
 public static function get_assignments($courseids = array(), $capabilities = array(), $includenotenrolledcourses = false)
 {
     global $USER, $DB, $CFG;
     $params = self::validate_parameters(self::get_assignments_parameters(), array('courseids' => $courseids, 'capabilities' => $capabilities, 'includenotenrolledcourses' => $includenotenrolledcourses));
     $warnings = array();
     $courses = array();
     $fields = 'sortorder,shortname,fullname,timemodified';
     // If the courseids list is empty, we return only the courses where the user is enrolled in.
     if (empty($params['courseids'])) {
         $courses = enrol_get_users_courses($USER->id, true, $fields);
         $courseids = array_keys($courses);
     } else {
         if ($includenotenrolledcourses) {
             // In this case, we don't have to check here for enrolmnents. Maybe the user can see the course even if is not enrolled.
             $courseids = $params['courseids'];
         } else {
             // We need to check for enrolments.
             $mycourses = enrol_get_users_courses($USER->id, true, $fields);
             $mycourseids = array_keys($mycourses);
             foreach ($params['courseids'] as $courseid) {
                 if (!in_array($courseid, $mycourseids)) {
                     unset($courses[$courseid]);
                     $warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => '2', 'message' => 'User is not enrolled or does not have requested capability');
                 } else {
                     $courses[$courseid] = $mycourses[$courseid];
                 }
             }
             $courseids = array_keys($courses);
         }
     }
     foreach ($courseids as $cid) {
         try {
             $context = context_course::instance($cid);
             self::validate_context($context);
             // Check if this course was already loaded (by enrol_get_users_courses).
             if (!isset($courses[$cid])) {
                 $courses[$cid] = get_course($cid);
             }
             $courses[$cid]->contextid = $context->id;
         } catch (Exception $e) {
             unset($courses[$cid]);
             $warnings[] = array('item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context ' . $e->getMessage());
             continue;
         }
         if (count($params['capabilities']) > 0 && !has_all_capabilities($params['capabilities'], $context)) {
             unset($courses[$cid]);
         }
     }
     $extrafields = 'm.id as assignmentid, ' . 'm.course, ' . 'm.nosubmissions, ' . 'm.submissiondrafts, ' . 'm.sendnotifications, ' . 'm.sendlatenotifications, ' . 'm.sendstudentnotifications, ' . 'm.duedate, ' . 'm.allowsubmissionsfromdate, ' . 'm.grade, ' . 'm.timemodified, ' . 'm.completionsubmit, ' . 'm.cutoffdate, ' . 'm.teamsubmission, ' . 'm.requireallteammemberssubmit, ' . 'm.teamsubmissiongroupingid, ' . 'm.blindmarking, ' . 'm.revealidentities, ' . 'm.attemptreopenmethod, ' . 'm.maxattempts, ' . 'm.markingworkflow, ' . 'm.markingallocation, ' . 'm.requiresubmissionstatement, ' . 'm.preventsubmissionnotingroup, ' . 'm.intro, ' . 'm.introformat';
     $coursearray = array();
     foreach ($courses as $id => $course) {
         $assignmentarray = array();
         // Get a list of assignments for the course.
         if ($modules = get_coursemodules_in_course('assign', $courses[$id]->id, $extrafields)) {
             foreach ($modules as $module) {
                 $context = context_module::instance($module->id);
                 try {
                     self::validate_context($context);
                     require_capability('mod/assign:view', $context);
                 } catch (Exception $e) {
                     $warnings[] = array('item' => 'module', 'itemid' => $module->id, 'warningcode' => '1', 'message' => 'No access rights in module context');
                     continue;
                 }
                 $assign = new assign($context, null, null);
                 // Get configurations for only enabled plugins.
                 $plugins = $assign->get_submission_plugins();
                 $plugins = array_merge($plugins, $assign->get_feedback_plugins());
                 $configarray = array();
                 foreach ($plugins as $plugin) {
                     if ($plugin->is_enabled() && $plugin->is_visible()) {
                         $configrecords = $plugin->get_config_for_external();
                         foreach ($configrecords as $name => $value) {
                             $configarray[] = array('plugin' => $plugin->get_type(), 'subtype' => $plugin->get_subtype(), 'name' => $name, 'value' => $value);
                         }
                     }
                 }
                 $assignment = array('id' => $module->assignmentid, 'cmid' => $module->id, 'course' => $module->course, 'name' => $module->name, 'nosubmissions' => $module->nosubmissions, 'submissiondrafts' => $module->submissiondrafts, 'sendnotifications' => $module->sendnotifications, 'sendlatenotifications' => $module->sendlatenotifications, 'sendstudentnotifications' => $module->sendstudentnotifications, 'duedate' => $module->duedate, 'allowsubmissionsfromdate' => $module->allowsubmissionsfromdate, 'grade' => $module->grade, 'timemodified' => $module->timemodified, 'completionsubmit' => $module->completionsubmit, 'cutoffdate' => $module->cutoffdate, 'teamsubmission' => $module->teamsubmission, 'requireallteammemberssubmit' => $module->requireallteammemberssubmit, 'teamsubmissiongroupingid' => $module->teamsubmissiongroupingid, 'blindmarking' => $module->blindmarking, 'revealidentities' => $module->revealidentities, 'attemptreopenmethod' => $module->attemptreopenmethod, 'maxattempts' => $module->maxattempts, 'markingworkflow' => $module->markingworkflow, 'markingallocation' => $module->markingallocation, 'requiresubmissionstatement' => $module->requiresubmissionstatement, 'preventsubmissionnotingroup' => $module->preventsubmissionnotingroup, 'configs' => $configarray);
                 // Return or not intro and file attachments depending on the plugin settings.
                 if ($assign->show_intro()) {
                     list($assignment['intro'], $assignment['introformat']) = external_format_text($module->intro, $module->introformat, $context->id, 'mod_assign', 'intro', null);
                     $assignment['introfiles'] = external_util::get_area_files($context->id, 'mod_assign', 'intro', false, false);
                     $assignment['introattachments'] = external_util::get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
                 }
                 if ($module->requiresubmissionstatement) {
                     // Submission statement is required, return the submission statement value.
                     $adminconfig = get_config('assign');
                     list($assignment['submissionstatement'], $assignment['submissionstatementformat']) = external_format_text($adminconfig->submissionstatement, FORMAT_MOODLE, $context->id, 'mod_assign', '', 0);
                 }
                 $assignmentarray[] = $assignment;
             }
         }
         $coursearray[] = array('id' => $courses[$id]->id, 'fullname' => external_format_string($courses[$id]->fullname, $course->contextid), 'shortname' => external_format_string($courses[$id]->shortname, $course->contextid), 'timemodified' => $courses[$id]->timemodified, 'assignments' => $assignmentarray);
     }
     $result = array('courses' => $coursearray, 'warnings' => $warnings);
     return $result;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:101,代码来源:externallib.php

示例15: get_users_courses

 /**
  * Get list of courses user is enrolled in (only active enrolments are returned).
  * Please note the current user must be able to access the course, otherwise the course is not included.
  *
  * @param int $userid
  * @return array of courses
  */
 public static function get_users_courses($userid)
 {
     global $USER, $DB;
     // Do basic automatic PARAM checks on incoming data, using params description
     // If any problems are found then exceptions are thrown with helpful error messages
     $params = self::validate_parameters(self::get_users_courses_parameters(), array('userid' => $userid));
     $courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible,
                summary, summaryformat, format, showgrades, lang, enablecompletion, category');
     $result = array();
     foreach ($courses as $course) {
         $context = context_course::instance($course->id, IGNORE_MISSING);
         try {
             self::validate_context($context);
         } catch (Exception $e) {
             // current user can not access this course, sorry we can not disclose who is enrolled in this course!
             continue;
         }
         if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
             // we need capability to view participants
             continue;
         }
         list($enrolledsqlselect, $enrolledparams) = get_enrolled_sql($context);
         $enrolledsql = "SELECT COUNT('x') FROM ({$enrolledsqlselect}) enrolleduserids";
         $enrolledusercount = $DB->count_records_sql($enrolledsql, $enrolledparams);
         list($course->summary, $course->summaryformat) = external_format_text($course->summary, $course->summaryformat, $context->id, 'course', 'summary', null);
         $course->fullname = external_format_string($course->fullname, $context->id);
         $course->shortname = external_format_string($course->shortname, $context->id);
         $result[] = array('id' => $course->id, 'shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber, 'visible' => $course->visible, 'enrolledusercount' => $enrolledusercount, 'summary' => $course->summary, 'summaryformat' => $course->summaryformat, 'format' => $course->format, 'showgrades' => $course->showgrades, 'lang' => $course->lang, 'enablecompletion' => $course->enablecompletion, 'category' => $course->category);
     }
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:38,代码来源:externallib.php


注:本文中的external_format_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。