本文整理汇总了PHP中component_callback函数的典型用法代码示例。如果您正苦于以下问题:PHP component_callback函数的具体用法?PHP component_callback怎么用?PHP component_callback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了component_callback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: groups_remove_member_allowed
/**
* Checks whether the current user is permitted (using the normal UI) to
* remove a specific group member, assuming that they have access to remove
* group members in general.
*
* For automatically-created group member entries, this checks with the
* relevant plugin to see whether it is permitted. The default, if the plugin
* doesn't provide a function, is true.
*
* For other entries (and any which have already been deleted/don't exist) it
* just returns true.
*
* @param mixed $grouporid The group id or group object
* @param mixed $userorid The user id or user object
* @return bool True if permitted, false otherwise
*/
function groups_remove_member_allowed($grouporid, $userorid)
{
global $DB;
if (is_object($userorid)) {
$userid = $userorid->id;
} else {
$userid = $userorid;
}
if (is_object($grouporid)) {
$groupid = $grouporid->id;
} else {
$groupid = $grouporid;
}
// Get entry
if (!($entry = $DB->get_record('groups_members', array('groupid' => $groupid, 'userid' => $userid), '*', IGNORE_MISSING))) {
// If the entry does not exist, they are allowed to remove it (this
// is consistent with groups_remove_member below).
return true;
}
// If the entry does not have a component value, they can remove it
if (empty($entry->component)) {
return true;
}
// It has a component value, so we need to call a plugin function (if it
// exists); the default is to allow removal
return component_callback($entry->component, 'allow_group_member_remove', array($entry->itemid, $entry->groupid, $entry->userid), true);
}
示例2: lti_get_types
function lti_get_types()
{
global $OUTPUT;
$subtypes = array();
foreach (get_plugin_list('ltisource') as $name => $dir) {
if ($moretypes = component_callback("ltisource_{$name}", 'get_types')) {
$subtypes = array_merge($subtypes, $moretypes);
}
}
if (empty($subtypes)) {
return MOD_SUBTYPE_NO_CHILDREN;
}
$types = array();
$type = new stdClass();
$type->modclass = MOD_CLASS_ACTIVITY;
$type->type = 'lti_group_start';
$type->typestr = '--' . get_string('modulenameplural', 'mod_lti');
$types[] = $type;
$link = get_string('modulename_link', 'mod_lti');
$linktext = get_string('morehelp');
$help = get_string('modulename_help', 'mod_lti');
$help .= html_writer::tag('div', $OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
$type = new stdClass();
$type->modclass = MOD_CLASS_ACTIVITY;
$type->type = '';
$type->typestr = get_string('generaltool', 'mod_lti');
$type->help = $help;
$types[] = $type;
$types = array_merge($types, $subtypes);
$type = new stdClass();
$type->modclass = MOD_CLASS_ACTIVITY;
$type->type = 'lti_group_end';
$type->typestr = '--';
$types[] = $type;
return $types;
}
示例3: list
list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, false, $cm);
$url = new moodle_url('/rating/index.php', array('contextid' => $contextid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid));
if (!empty($sort)) {
$url->param('sort', $sort);
}
if (!empty($popup)) {
$url->param('popup', $popup);
}
$PAGE->set_url($url);
$PAGE->set_context($context);
if ($popup) {
$PAGE->set_pagelayout('popup');
}
$params = array('contextid' => $contextid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid);
if (!has_capability('moodle/rating:view', $context) || !component_callback($component, 'rating_can_see_item_ratings', array($params), true)) {
print_error('noviewrate', 'rating');
}
$canviewallratings = has_capability('moodle/rating:viewall', $context);
switch ($sort) {
case 'firstname':
$sqlsort = "u.firstname ASC";
break;
case 'rating':
$sqlsort = "r.rating ASC";
break;
default:
$sqlsort = "r.timemodified ASC";
}
$scalemenu = make_grades_menu($scaleid);
$strrating = get_string('rating', 'rating');
示例4: get_supported_reports
/**
* Get a list of reports that support the given store instance.
*
* @param string $logstore Name of the store.
*
* @return array List of supported reports
*/
public function get_supported_reports($logstore)
{
$allstores = self::get_store_plugins();
if (empty($allstores[$logstore])) {
// Store doesn't exist.
return array();
}
$reports = get_plugin_list_with_function('report', 'supports_logstore', 'lib.php');
$enabled = $this->stores;
if (empty($enabled[$logstore])) {
// Store is not enabled, init an instance.
$classname = '\\' . $logstore . '\\log\\store';
$instance = new $classname($this);
} else {
$instance = $enabled[$logstore];
}
$return = array();
foreach ($reports as $report => $fulldir) {
if (component_callback($report, 'supports_logstore', array($instance), false)) {
$return[$report] = get_string('pluginname', $report);
}
}
return $return;
}
示例5: set_coursemodule_visible
/**
* Set the visibility of a module and inherent properties.
*
* Note: Do not forget to trigger the event \core\event\course_module_updated as it needs
* to be triggered manually, refer to {@link \core\event\course_module_updated::create_from_cm()}.
*
* From 2.4 the parameter $prevstateoverrides has been removed, the logic it triggered
* has been moved to {@link set_section_visible()} which was the only place from which
* the parameter was used.
*
* @param int $id of the module
* @param int $visible state of the module
* @return bool false when the module was not found, true otherwise
*/
function set_coursemodule_visible($id, $visible)
{
global $DB, $CFG;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/calendar/lib.php';
// Trigger developer's attention when using the previously removed argument.
if (func_num_args() > 2) {
debugging('Wrong number of arguments passed to set_coursemodule_visible(), $prevstateoverrides
has been removed.', DEBUG_DEVELOPER);
}
if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) {
return false;
}
// Create events and propagate visibility to associated grade items if the value has changed.
// Only do this if it's changed to avoid accidently overwriting manual showing/hiding of student grades.
if ($cm->visible == $visible) {
return true;
}
if (!($modulename = $DB->get_field('modules', 'name', array('id' => $cm->module)))) {
return false;
}
if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
foreach ($events as $event) {
if ($visible) {
$event = new calendar_event($event);
$event->toggle_visibility(true);
} else {
$event = new calendar_event($event);
$event->toggle_visibility(false);
}
}
}
// Updating visible and visibleold to keep them in sync. Only changing a section visibility will
// affect visibleold to allow for an original visibility restore. See set_section_visible().
$cminfo = new stdClass();
$cminfo->id = $id;
$cminfo->visible = $visible;
$cminfo->visibleold = $visible;
$DB->update_record('course_modules', $cminfo);
// Hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there.
// Note that this must be done after updating the row in course_modules, in case
// the modules grade_item_update function needs to access $cm->visible.
if (plugin_supports('mod', $modulename, FEATURE_CONTROLS_GRADE_VISIBILITY) && component_callback_exists('mod_' . $modulename, 'grade_item_update')) {
$instance = $DB->get_record($modulename, array('id' => $cm->instance), '*', MUST_EXIST);
component_callback('mod_' . $modulename, 'grade_item_update', array($instance));
} else {
$grade_items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $cm->instance, 'courseid' => $cm->course));
if ($grade_items) {
foreach ($grade_items as $grade_item) {
$grade_item->set_hidden(!$visible);
}
}
}
rebuild_course_cache($cm->course, true);
return true;
}
示例6: get_mod_recent_activity
public function get_mod_recent_activity($context)
{
global $COURSE, $OUTPUT;
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$recentactivity = array();
$timestart = time() - 86400 * 7;
// 7 days ago.
if (optional_param('testing', false, PARAM_BOOL)) {
$timestart = time() - 86400 * 700;
// 700 days ago for testing purposes.
}
$modinfo = get_fast_modinfo($COURSE);
$usedmodules = $modinfo->get_used_module_names();
if (empty($usedmodules)) {
// No used modules so return null string.
return '';
}
foreach ($usedmodules as $modname => $modfullname) {
// Each module gets it's own logs and prints them.
ob_start();
$hascontent = component_callback('mod_' . $modname, 'print_recent_activity', array($COURSE, $viewfullnames, $timestart), false);
if ($hascontent) {
$content = ob_get_contents();
if (!empty($content)) {
$recentactivity[$modname] = $content;
}
}
ob_end_clean();
}
$output = '';
if (!empty($recentactivity)) {
foreach ($recentactivity as $modname => $moduleactivity) {
// Get mod icon, empty alt as title already there.
$img = html_writer::tag('img', '', array('src' => $OUTPUT->pix_url('icon', $modname), 'alt' => ''));
// Create media object for module activity.
$output .= "<div class='snap-media-object course-footer-update-{$modname}'>{$img}" . "<div class=snap-media-body>{$moduleactivity}</div></div>";
}
}
return $output;
}
示例7: definition
public function definition()
{
global $PAGE, $OUTPUT, $COURSE;
if ($type = optional_param('type', false, PARAM_ALPHA)) {
component_callback("ltisource_{$type}", 'add_instance_hook');
}
$this->typeid = 0;
$mform =& $this->_form;
// Adding the "general" fieldset, where all the common settings are shown.
$mform->addElement('header', 'general', get_string('general', 'form'));
// Adding the standard "name" field.
$mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size' => '64'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
// Adding the optional "intro" and "introformat" pair of fields.
$this->standard_intro_elements(get_string('basicltiintro', 'lti'));
$mform->setAdvanced('introeditor');
// Display the label to the right of the checkbox so it looks better & matches rest of the form.
if ($mform->elementExists('showdescription')) {
$coursedesc = $mform->getElement('showdescription');
if (!empty($coursedesc)) {
$coursedesc->setText(' ' . $coursedesc->getLabel());
$coursedesc->setLabel(' ');
}
}
$mform->setAdvanced('showdescription');
$mform->addElement('checkbox', 'showtitlelaunch', ' ', ' ' . get_string('display_name', 'lti'));
$mform->setAdvanced('showtitlelaunch');
$mform->setDefault('showtitlelaunch', true);
$mform->addHelpButton('showtitlelaunch', 'display_name', 'lti');
$mform->addElement('checkbox', 'showdescriptionlaunch', ' ', ' ' . get_string('display_description', 'lti'));
$mform->setAdvanced('showdescriptionlaunch');
$mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
// Tool settings.
$attributes = array();
if ($update = optional_param('update', false, PARAM_INT)) {
$attributes['disabled'] = 'disabled';
}
$attributes['class'] = 'lti_contentitem';
$tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array(), $attributes);
$typeid = optional_param('typeid', false, PARAM_INT);
$mform->getElement('typeid')->setValue($typeid);
$mform->addHelpButton('typeid', 'external_tool_type', 'lti');
$toolproxy = array();
// Array of tool type IDs that don't support ContentItemSelectionRequest.
$noncontentitemtypes = [];
foreach (lti_get_types_for_add_instance() as $id => $type) {
if (!empty($type->toolproxyid)) {
$toolproxy[] = $type->id;
$attributes = array('globalTool' => 1, 'toolproxy' => 1);
$enabledcapabilities = explode("\n", $type->enabledcapability);
if (!in_array('Result.autocreate', $enabledcapabilities)) {
$attributes['nogrades'] = 1;
}
if (!in_array('Person.name.full', $enabledcapabilities) && !in_array('Person.name.family', $enabledcapabilities) && !in_array('Person.name.given', $enabledcapabilities)) {
$attributes['noname'] = 1;
}
if (!in_array('Person.email.primary', $enabledcapabilities)) {
$attributes['noemail'] = 1;
}
} else {
if ($type->course == $COURSE->id) {
$attributes = array('editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain);
} else {
if ($id != 0) {
$attributes = array('globalTool' => 1, 'domain' => $type->tooldomain);
} else {
$attributes = array();
}
}
}
if (!$update && $id) {
$config = lti_get_type_config($id);
if (!empty($config['contentitem'])) {
$attributes['data-contentitem'] = 1;
$attributes['data-id'] = $id;
} else {
$noncontentitemtypes[] = $id;
}
}
$tooltypes->addOption($type->name, $id, $attributes);
}
// Add button that launches the content-item selection dialogue.
// Set contentitem URL.
$contentitemurl = new moodle_url('/mod/lti/contentitem.php');
$contentbuttonattributes['data-contentitemurl'] = $contentitemurl->out(false);
$mform->addElement('button', 'selectcontent', get_string('selectcontent', 'lti'), $contentbuttonattributes);
if ($update) {
$mform->disabledIf('selectcontent', 'typeid', 'neq', 0);
} else {
// Disable select content button if the selected tool doesn't support content item or it's set to Automatic.
$allnoncontentitemtypes = $noncontentitemtypes;
$allnoncontentitemtypes[] = '0';
// Add option value for "Automatic, based on launch URL".
$mform->disabledIf('selectcontent', 'typeid', 'in', $allnoncontentitemtypes);
}
$mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size' => '64'));
$mform->setType('toolurl', PARAM_URL);
$mform->addHelpButton('toolurl', 'launch_url', 'lti');
//.........这里部分代码省略.........
示例8: mod_hsuforum_comment_message
/**
* @param stdClass $comment
* @param stdClass $options
* @throws comment_exception
*/
function mod_hsuforum_comment_message(stdClass $comment, stdClass $options)
{
global $DB;
if ($options->commentarea != 'userposts_comments') {
throw new comment_exception('invalidcommentarea');
}
if (!($user = $DB->get_record('user', array('id' => $options->itemid)))) {
throw new comment_exception('invalidcommentitemid');
}
/** @var context $context */
$context = $options->context;
if (!($cm = get_coursemodule_from_id('hsuforum', $context->instanceid))) {
throw new comment_exception('invalidcontext');
}
// Get all the users with the ability to rate.
$recipients = get_users_by_capability($context, 'mod/hsuforum:rate');
// Add the item user if they are different from commenter.
if ($comment->userid != $user->id and has_capability('mod/hsuforum:replypost', $context, $user)) {
$recipients[$user->id] = $user;
}
// Sender is the author of the comment.
$sender = $DB->get_record('user', array('id' => $comment->userid));
// Make sure that the commenter is not getting the message.
unset($recipients[$comment->userid]);
if (\core_component::get_plugin_directory('local', 'joulegrader') !== null) {
// Joule Grader is installed and control panel enabled.
$gareaid = component_callback('local_joulegrader', 'area_from_context', array($context, 'hsuforum'));
$contexturl = new moodle_url('/local/joulegrader/view.php', array('courseid' => $cm->course, 'garea' => $gareaid, 'guser' => $user->id));
} else {
$contexturl = $context->get_url();
}
$params = array($comment, $recipients, $sender, $cm->name, $contexturl);
component_callback('local_mrooms', 'comment_send_messages', $params);
}
示例9: lti_get_shortcuts
/**
* Return aliases of this activity. LTI should have an alias for each configured tool type
* This is so you can add an external tool types directly to the activity chooser
*
* @param stdClass $defaultitem default item that would be added to the activity chooser if this callback was not present.
* It has properties: archetype, name, title, help, icon, link
* @return array An array of aliases for this activity. Each element is an object with same list of properties as $defaultitem,
* plus an additional property, helplink.
* Properties title and link are required
**/
function lti_get_shortcuts($defaultitem)
{
global $CFG, $COURSE;
require_once $CFG->dirroot . '/mod/lti/locallib.php';
$types = lti_get_configured_types($COURSE->id, $defaultitem->link->param('sr'));
$types[] = $defaultitem;
// Add items defined in ltisource plugins.
foreach (core_component::get_plugin_list('ltisource') as $pluginname => $dir) {
if ($moretypes = component_callback("ltisource_{$pluginname}", 'get_types')) {
// Callback 'get_types()' in 'ltisource' plugins is deprecated in 3.1 and will be removed in 3.5, TODO MDL-53697.
debugging('Deprecated callback get_types() is found in ltisource_' . $pluginname . ', use get_shortcuts() instead', DEBUG_DEVELOPER);
$grouptitle = get_string('modulenameplural', 'mod_lti');
foreach ($moretypes as $subtype) {
// Instead of adding subitems combine the name of the group with the name of the subtype.
$subtype->title = get_string('activitytypetitle', '', (object) ['activity' => $grouptitle, 'type' => $subtype->typestr]);
// Re-implement the logic of get_module_metadata() in Moodle 3.0 and below for converting
// subtypes into items in activity chooser.
$subtype->type = str_replace('&', '&', $subtype->type);
$subtype->name = preg_replace('/.*type=/', '', $subtype->type);
$subtype->link = new moodle_url($defaultitem->link, array('type' => $subtype->name));
if (empty($subtype->help) && !empty($subtype->name) && get_string_manager()->string_exists('help' . $subtype->name, $pluginname)) {
$subtype->help = get_string('help' . $subtype->name, $pluginname);
}
unset($subtype->typestr);
$types[] = $subtype;
}
}
// LTISOURCE plugins can also implement callback get_shortcuts() to add items to the activity chooser.
// The return values are the same as of the 'mod' callbacks except that $defaultitem is only passed for reference and
// should not be added to the return value.
if ($moretypes = component_callback("ltisource_{$pluginname}", 'get_shortcuts', array($defaultitem))) {
$types = array_merge($types, $moretypes);
}
}
return $types;
}
示例10: get_item_ratings
/**
* Retrieve a list of ratings for a given item (forum post etc)
*
* @param string $contextlevel course, module, user...
* @param int $instanceid the instance if for the context element
* @param string $component the name of the component
* @param string $ratingarea rating area
* @param int $itemid the item id
* @param int $scaleid the scale id
* @param string $sort sql order (firstname, rating or timemodified)
* @return array Result and possible warnings
* @throws moodle_exception
* @since Moodle 2.9
*/
public static function get_item_ratings($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $sort)
{
global $USER, $PAGE;
$warnings = array();
$arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'sort' => $sort);
// Validate and normalize parameters.
$params = self::validate_parameters(self::get_item_ratings_parameters(), $arrayparams);
$context = self::get_context_from_params($params);
self::validate_context($context);
// Minimal capability required.
$callbackparams = array('contextid' => $context->id, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid);
if (!has_capability('moodle/rating:view', $context) || !component_callback($component, 'rating_can_see_item_ratings', array($callbackparams), true)) {
throw new moodle_exception('noviewrate', 'rating');
}
list($context, $course, $cm) = get_context_info_array($context->id);
// Can we see all ratings?
$canviewallratings = has_capability('moodle/rating:viewall', $context);
// Create the Sql sort order string.
switch ($params['sort']) {
case 'firstname':
$sqlsort = "u.firstname ASC";
break;
case 'rating':
$sqlsort = "r.rating ASC";
break;
default:
$sqlsort = "r.timemodified ASC";
}
$ratingoptions = new stdClass();
$ratingoptions->context = $context;
$ratingoptions->component = $params['component'];
$ratingoptions->ratingarea = $params['ratingarea'];
$ratingoptions->itemid = $params['itemid'];
$ratingoptions->sort = $sqlsort;
$rm = new rating_manager();
$ratings = $rm->get_all_ratings_for_item($ratingoptions);
$scalemenu = make_grades_menu($params['scaleid']);
// If the scale was changed after ratings were submitted some ratings may have a value above the current maximum.
// We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0.
$maxrating = max(array_keys($scalemenu));
$results = array();
foreach ($ratings as $rating) {
if ($canviewallratings || $USER->id == $rating->userid) {
if ($rating->rating > $maxrating) {
$rating->rating = $maxrating;
}
// The rating object has all the required fields for generating the picture url.
$userpicture = new user_picture($rating);
$userpicture->size = 1;
// Size f1.
$profileimageurl = $userpicture->get_url($PAGE)->out(false);
$result = array();
$result['id'] = $rating->id;
$result['userid'] = $rating->userid;
$result['userpictureurl'] = $profileimageurl;
$result['userfullname'] = fullname($rating);
$result['rating'] = $scalemenu[$rating->rating];
$result['timemodified'] = $rating->timemodified;
$results[] = $result;
}
}
return array('ratings' => $results, 'warnings' => $warnings);
}
示例11: activity_has_subtypes
/**
* Checks if the activity type requires subtypes.
*
* @return bool|null (null if the check is not possible)
*/
public function activity_has_subtypes()
{
if (!($modname = $this->get_activitytype())) {
return null;
}
return component_callback('mod_' . $modname, 'get_types', array(), MOD_SUBTYPE_NO_CHILDREN) !== MOD_SUBTYPE_NO_CHILDREN;
}
示例12: definition
public function definition()
{
global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
if ($type = optional_param('type', false, PARAM_ALPHA)) {
component_callback("ltisource_{$type}", 'add_instance_hook');
}
$this->typeid = 0;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
// Adding the "general" fieldset, where all the common settings are shown
$mform->addElement('header', 'general', get_string('general', 'form'));
// Adding the standard "name" field
$mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size' => '64'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
// Adding the optional "intro" and "introformat" pair of fields
$this->add_intro_editor(false, get_string('basicltiintro', 'lti'));
$mform->setAdvanced('introeditor');
// Display the label to the right of the checkbox so it looks better & matches rest of the form
$coursedesc = $mform->getElement('showdescription');
if (!empty($coursedesc)) {
$coursedesc->setText(' ' . $coursedesc->getLabel());
$coursedesc->setLabel(' ');
}
$mform->setAdvanced('showdescription');
$mform->addElement('checkbox', 'showtitlelaunch', ' ', ' ' . get_string('display_name', 'lti'));
$mform->setAdvanced('showtitlelaunch');
$mform->setDefault('showtitlelaunch', true);
$mform->addHelpButton('showtitlelaunch', 'display_name', 'lti');
$mform->addElement('checkbox', 'showdescriptionlaunch', ' ', ' ' . get_string('display_description', 'lti'));
$mform->setAdvanced('showdescriptionlaunch');
$mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
// Tool settings
$tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
$mform->addHelpButton('typeid', 'external_tool_type', 'lti');
foreach (lti_get_types_for_add_instance() as $id => $type) {
if ($type->course == $COURSE->id) {
$attributes = array('editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain);
} else {
if ($id != 0) {
$attributes = array('globalTool' => 1, 'domain' => $type->tooldomain);
} else {
$attributes = array();
}
}
$tooltypes->addOption($type->name, $id, $attributes);
}
$mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size' => '64'));
$mform->setType('toolurl', PARAM_TEXT);
$mform->addHelpButton('toolurl', 'launch_url', 'lti');
$mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size' => '64'));
$mform->setType('securetoolurl', PARAM_TEXT);
$mform->setAdvanced('securetoolurl');
$mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti');
$mform->addElement('hidden', 'urlmatchedtypeid', '', array('id' => 'id_urlmatchedtypeid'));
$mform->setType('urlmatchedtypeid', PARAM_INT);
$launchoptions = array();
$launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti');
$launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
$launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
$launchoptions[LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW] = get_string('existing_window', 'lti');
$launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
$mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
$mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
$mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti');
$mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
$mform->setType('resourcekey', PARAM_TEXT);
$mform->setAdvanced('resourcekey');
$mform->addHelpButton('resourcekey', 'resourcekey', 'lti');
$mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
$mform->setType('password', PARAM_TEXT);
$mform->setAdvanced('password');
$mform->addHelpButton('password', 'password', 'lti');
$mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows' => 4, 'cols' => 60));
$mform->setType('instructorcustomparameters', PARAM_TEXT);
$mform->setAdvanced('instructorcustomparameters');
$mform->addHelpButton('instructorcustomparameters', 'custom', 'lti');
$mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size' => '64'));
$mform->setType('icon', PARAM_TEXT);
$mform->setAdvanced('icon');
$mform->addHelpButton('icon', 'icon_url', 'lti');
$mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size' => '64'));
$mform->setType('secureicon', PARAM_TEXT);
$mform->setAdvanced('secureicon');
$mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
//-------------------------------------------------------------------------------
// Add privacy preferences fieldset where users choose whether to send their data
$mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
$mform->addElement('advcheckbox', 'instructorchoicesendname', ' ', ' ' . get_string('share_name', 'lti'));
$mform->setDefault('instructorchoicesendname', '1');
$mform->addHelpButton('instructorchoicesendname', 'share_name', 'lti');
$mform->addElement('advcheckbox', 'instructorchoicesendemailaddr', ' ', ' ' . get_string('share_email', 'lti'));
$mform->setDefault('instructorchoicesendemailaddr', '1');
$mform->addHelpButton('instructorchoicesendemailaddr', 'share_email', 'lti');
$mform->addElement('advcheckbox', 'instructorchoiceacceptgrades', ' ', ' ' . get_string('accept_grades', 'lti'));
$mform->setDefault('instructorchoiceacceptgrades', '1');
$mform->addHelpButton('instructorchoiceacceptgrades', 'accept_grades', 'lti');
//$mform->addElement('checkbox', 'instructorchoiceallowroster', ' ', ' ' . get_string('share_roster', 'lti'));
//$mform->setDefault('instructorchoiceallowroster', '1');
//.........这里部分代码省略.........
示例13: test_update_inplace_editable
/**
* Test update_inplace_editable()
*/
public function test_update_inplace_editable()
{
global $CFG, $DB, $PAGE;
require_once $CFG->dirroot . '/lib/external/externallib.php';
$this->resetAfterTest(true);
$tag = $this->getDataGenerator()->create_tag();
$this->setUser($this->getDataGenerator()->create_user());
// Call service for core_tag component without necessary permissions.
try {
core_external::update_inplace_editable('core_tag', 'tagname', $tag->id, 'new tag name');
$this->fail('Exception expected');
} catch (moodle_exception $e) {
$this->assertEquals('Sorry, but you do not currently have permissions to do that (Manage all tags)', $e->getMessage());
}
// Change to admin user and make sure that tag name can be updated using web service update_inplace_editable().
$this->setAdminUser();
$res = core_external::update_inplace_editable('core_tag', 'tagname', $tag->id, 'New tag name');
$res = external_api::clean_returnvalue(core_external::update_inplace_editable_returns(), $res);
$this->assertEquals('New tag name', $res['value']);
$this->assertEquals('New tag name', $DB->get_field('tag', 'rawname', array('id' => $tag->id)));
// Call callback core_tag_inplace_editable() directly.
$tmpl = component_callback('core_tag', 'inplace_editable', array('tagname', $tag->id, 'Rename me again'));
$this->assertInstanceOf('core\\output\\inplace_editable', $tmpl);
$res = $tmpl->export_for_template($PAGE->get_renderer('core'));
$this->assertEquals('Rename me again', $res['value']);
$this->assertEquals('Rename me again', $DB->get_field('tag', 'rawname', array('id' => $tag->id)));
}
示例14: gradebook_accessible
/**
* Is the gradebook accessible - i.e. are there any reports accessible to this user
* @return bool
*/
public static function gradebook_accessible($context)
{
global $COURSE;
// Ask if user has not capabilities and if course is set to not to show the grades to students.
if (!has_capability('gradereport/grader:view', $context) && $COURSE->showgrades == 0) {
return false;
}
// Find all enabled reports.
$reports = core_component::get_plugin_list('gradereport');
foreach (array_keys($reports) as $report) {
if (!component_callback('gradereport_' . $report, 'is_enabled', array(), true)) {
unset($reports[$report]);
}
}
// Reduce reports list down to just those accessible to user.
foreach ($reports as $plugin => $plugindir) {
// Remove ones we can't see.
if (!has_capability('gradereport/' . $plugin . ':view', $context)) {
unset($reports[$plugin]);
}
}
return !empty($reports);
}
示例15: get_fragment
/**
* Get a HTML fragment for inserting into something. Initial use is for inserting mforms into
* a page using AJAX.
* This web service is designed to be called only via AJAX and not directly.
* Callbacks that are called by this web service are responsible for doing the appropriate security checks
* to access the information returned. This only does minimal validation on the context.
*
* @param string $component Name of the component.
* @param string $callback Function callback name.
* @param int $contextid Context ID this fragment is in.
* @param array $args optional arguments for the callback.
* @return array HTML and JavaScript fragments for insertion into stuff.
* @since Moodle 3.1
*/
public static function get_fragment($component, $callback, $contextid, $args = null)
{
global $OUTPUT, $PAGE;
$params = self::validate_parameters(self::get_fragment_parameters(), array('component' => $component, 'callback' => $callback, 'contextid' => $contextid, 'args' => $args));
// Reformat arguments into something less unwieldy.
$arguments = array();
foreach ($params['args'] as $paramargument) {
$arguments[$paramargument['name']] = $paramargument['value'];
}
$context = context::instance_by_id($contextid);
self::validate_context($context);
// Hack alert: Forcing bootstrap_renderer to initiate moodle page.
$OUTPUT->header();
// Overwriting page_requirements_manager with the fragment one so only JS included from
// this point is returned to the user.
$PAGE->start_collecting_javascript_requirements();
$data = component_callback($params['component'], 'output_fragment_' . $params['callback'], $arguments);
$jsfooter = $PAGE->requires->get_end_code();
$output = array('html' => $data, 'javascript' => $jsfooter);
return $output;
}