本文整理汇总了PHP中plugin_callback函数的典型用法代码示例。如果您正苦于以下问题:PHP plugin_callback函数的具体用法?PHP plugin_callback怎么用?PHP plugin_callback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了plugin_callback函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: available_areas
/**
* Returns the list of gradable areas provided by the given component
*
* This performs a callback to the library of the relevant plugin to obtain
* the list of supported areas.
*
* @param string $component normalized component name
* @return array of (string)areacode => (string)localized title of the area
*/
public static function available_areas($component)
{
global $CFG;
list($plugintype, $pluginname) = core_component::normalize_component($component);
if ($component === 'core_grading') {
return array();
} else {
if ($plugintype === 'mod') {
return plugin_callback('mod', $pluginname, 'grading', 'areas_list', null, array());
} else {
throw new coding_exception('Unsupported area location');
}
}
}
示例2: check_item_and_owner
/**
* Checks if the item exists and is NOT owned by the current owner. Uses a callback to find out what table to look in.
* @param string plugintype the type of plugin ie 'mod'
* @param string pluginname the name of the plugin ie 'forum'
* @return boolean True if the callback doesn't exist. True if the item exists and doesn't belong to the current user. False otherwise.
*/
public function check_item_and_owner($plugintype, $pluginname, $itemid) {
global $DB, $USER;
list($tablename,$itemidcol,$useridcol) = plugin_callback($plugintype, $pluginname, 'rating', 'item_check_info');
if (!empty($tablename)) {
$item = $DB->get_record($tablename, array($itemidcol=>$itemid), $useridcol);
if ($item) {
if ($item->userid!=$USER->id) {
return true;
}
}
return false;//item doesn't exist or belongs to the current user
} else {
return true;//callback doesn't exist
}
}
示例3: handle_other_upload
/**
* Handle uploads not containing file - create the course module, ask the mod to
* set itself up, then return the result to the browser
*
* @param string $content the content uploaded to the browser
*/
protected function handle_other_upload($content)
{
// Check this plugin is registered to handle this type of upload
if (!$this->dnduploadhandler->has_type_handler($this->module->name, $this->type)) {
$info = (object) array('modname' => $this->module->name, 'type' => $this->type);
throw new moodle_exception('moddoesnotsupporttype', 'moodle', $info);
}
// Create a course module to hold the new instance.
$this->create_course_module();
// Ask the module to set itself up.
$moduledata = $this->prepare_module_data(null, $content);
$instanceid = plugin_callback('mod', $this->module->name, 'dndupload', 'handle', array($moduledata), 'invalidfunction');
if ($instanceid === 'invalidfunction') {
throw new coding_exception("{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function");
}
// Finish setting up the course module.
$this->finish_setup_course_module($instanceid);
}
示例4: validate
/**
* Revoke validate callbacks
*
* @param stdClass $params addtionall parameters need to add to callbacks
*/
protected function validate($params = array())
{
foreach ($params as $key => $value) {
$this->comment_param->{$key} = $value;
}
$validation = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'validate', array($this->comment_param), false);
if (!$validation) {
throw new comment_exception('invalidcommentparam');
}
}
示例5: check_rating_is_valid
/**
* Validates a submitted rating
* @param array $params submitted data
* context => object the context in which the rated items exists [required]
* component => The component the rating belongs to [required]
* ratingarea => The ratingarea the rating is associated with [required]
* itemid => int the ID of the object being rated [required]
* scaleid => int the scale from which the user can select a rating. Used for bounds checking. [required]
* rating => int the submitted rating
* rateduserid => int the id of the user whose items have been rated. NOT the user who submitted the ratings. 0 to update all. [required]
* aggregation => int the aggregation method to apply when calculating grades ie RATING_AGGREGATE_AVERAGE [optional]
* @return boolean true if the rating is valid. False if callback wasnt found and will throw rating_exception if rating is invalid
*/
public function check_rating_is_valid($params)
{
if (!isset($params['context'])) {
throw new coding_exception('The context option is a required option when checking rating validity.');
}
if (!isset($params['component'])) {
throw new coding_exception('The component option is now a required option when checking rating validity');
}
if (!isset($params['ratingarea'])) {
throw new coding_exception('The ratingarea option is now a required option when checking rating validity');
}
if (!isset($params['itemid'])) {
throw new coding_exception('The itemid option is now a required option when checking rating validity');
}
if (!isset($params['scaleid'])) {
throw new coding_exception('The scaleid option is now a required option when checking rating validity');
}
if (!isset($params['rateduserid'])) {
throw new coding_exception('The rateduserid option is now a required option when checking rating validity');
}
list($plugintype, $pluginname) = normalize_component($params['component']);
//this looks for a function like forum_rating_validate() in mod_forum lib.php
//wrapping the params array in another array as call_user_func_array() expands arrays into multiple arguments
$isvalid = plugin_callback($plugintype, $pluginname, 'rating', 'validate', array($params), null);
//if null then the callback doesn't exist
if ($isvalid === null) {
$isvalid = false;
debugging('rating validation callback not found for component ' . clean_param($component, PARAM_ALPHANUMEXT));
}
return $isvalid;
}
示例6: add
/**
* Add a new comment
* @param string $content
* @return mixed
*/
public function add($content)
{
global $CFG, $DB, $USER, $OUTPUT;
if (empty($this->postcap)) {
return COMMENT_ERROR_INSUFFICIENT_CAPS;
}
$now = time();
$newcmt = new stdclass();
$newcmt->contextid = $this->contextid;
$newcmt->commentarea = $this->commentarea;
$newcmt->itemid = $this->itemid;
$newcmt->content = $content;
$newcmt->format = FORMAT_MOODLE;
$newcmt->userid = $USER->id;
$newcmt->timecreated = $now;
if (!empty($this->plugintype)) {
// moodle module will check content
$ret = plugin_callback($this->plugintype, $this->pluginname, FEATURE_COMMENT, 'add', array(&$newcmt, $this->options), true);
if (!$ret) {
return COMMENT_ERROR_MODULE_REJECT;
}
}
$cmt_id = $DB->insert_record('comments', $newcmt);
if (!empty($cmt_id)) {
$newcmt->id = $cmt_id;
$newcmt->time = userdate($now, get_string('strftimerecent', 'langconfig'));
$newcmt->username = fullname($USER);
$newcmt->content = format_text($newcmt->content);
$userpic = moodle_user_picture::make($USER, $this->course->id);
$userpic->size = 16;
$newcmt->avatar = $OUTPUT->user_picture($userpic);
return $newcmt;
} else {
return COMMENT_ERROR_DB;
}
}
示例7: print_comments
/**
* Print comments
* @param int $page
* @return bool return false if no comments available
*/
public function print_comments($page = 0)
{
global $OUTPUT, $CFG, $OUTPUT, $DB;
$count = $DB->count_records('comments');
$comments = $this->get_comments($page);
if (count($comments) == 0) {
echo $OUTPUT->notification(get_string('nocomments', 'moodle'));
return false;
}
$table = new html_table();
$table->head = array(html_writer::checkbox('selectall', '', false, get_string('selectall'), array('id' => 'comment_select_all', 'class' => 'comment-report-selectall')), get_string('author', 'search'), get_string('content'), get_string('action'));
$table->align = array('left', 'left', 'left', 'left');
$table->attributes = array('class' => 'generaltable commentstable');
$table->data = array();
$link = new moodle_url('/comment/index.php', array('action' => 'delete', 'sesskey' => sesskey()));
foreach ($comments as $c) {
$this->setup_plugin($c);
if (!empty($this->plugintype)) {
$context_url = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'url', array($c));
}
$checkbox = html_writer::checkbox('comments', $c->id, false);
$action = html_writer::link(new moodle_url($link, array('commentid' => $c->id)), get_string('delete'));
if (!empty($context_url)) {
$action .= html_writer::empty_tag('br');
$action .= html_writer::link($context_url, get_string('commentincontext'), array('target' => '_blank'));
}
$table->data[] = array($checkbox, $c->fullname, $c->content, $action);
}
echo html_writer::table($table);
echo $OUTPUT->paging_bar($count, $page, $this->perpage, $CFG->wwwroot . '/comment/index.php');
return true;
}
示例8: add
/**
* Add a new comment
* @param string $content
* @return mixed
*/
public function add($content, $format = FORMAT_MOODLE)
{
global $CFG, $DB, $USER, $OUTPUT;
if (empty($this->postcap)) {
throw new comment_exception('nopermissiontocomment');
}
$now = time();
$newcmt = new stdClass();
$newcmt->contextid = $this->contextid;
$newcmt->commentarea = $this->commentarea;
$newcmt->itemid = $this->itemid;
$newcmt->content = $content;
$newcmt->format = $format;
$newcmt->userid = $USER->id;
$newcmt->timecreated = $now;
if (!empty($this->plugintype)) {
// moodle module will check content
$ret = plugin_callback($this->plugintype, $this->pluginname, FEATURE_COMMENT, 'add', array(&$newcmt, $this->args), true);
if (!$ret) {
throw new comment_exception('modulererejectcomment');
}
}
$cmt_id = $DB->insert_record('comments', $newcmt);
if (!empty($cmt_id)) {
$newcmt->id = $cmt_id;
$newcmt->time = userdate($now, get_string('strftimerecent', 'langconfig'));
$newcmt->fullname = fullname($USER);
$url = new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $this->courseid));
$newcmt->profileurl = $url->out();
$newcmt->content = format_text($newcmt->content, $format, array('overflowdiv' => true));
$newcmt->avatar = $OUTPUT->user_picture($USER, array('size' => 16));
return $newcmt;
} else {
throw new comment_exception('dbupdatefailed');
}
}
示例9: print_comments
/**
* Print comments
* @param int $page
*/
function print_comments($page = 0)
{
global $CFG, $OUTPUT, $DB;
$this->perpage = 10;
$count = $DB->count_records_sql('SELECT COUNT(*) FROM {comments} c');
$comments = $this->get_comments($page);
$table = new html_table();
$table->head = array('<input type="checkbox" id="comment_select_all"/>', 'author', 'content', 'action');
$table->align = array('left', 'left', 'left', 'left');
$table->width = "95%";
$table->data = array();
foreach ($comments as $c) {
$this->_setup_plugin($c);
if (!empty($this->plugintype)) {
$url = plugin_callback($this->plugintype, $this->pluginname, FEATURE_COMMENT, 'url', array($c));
}
$checkbox = '<input type="checkbox" name="comments" value="' . $c->id . '" />';
$action = '';
$action .= "<a href='{$CFG->wwwroot}/comment/index.php?action=delete&sesskey=" . sesskey() . "&commentid={$c->id}'>" . get_string('delete') . '</a>';
$action .= "<br />";
if (!empty($url)) {
$action .= "<a target='_blank' href='{$url}'>" . get_string('commentincontext') . '</a>';
}
$table->data[] = array($checkbox, $c->username, $c->content, $action);
}
echo $OUTPUT->table($table);
echo $OUTPUT->paging_bar(moodle_paging_bar::make($count, $page, $this->perpage, $CFG->wwwroot . '/comment/index.php'));
}
示例10: print_comments
/**
* Print comments
* @param int $page
*/
function print_comments($page = 0)
{
global $CFG, $OUTPUT, $DB;
$count = $DB->count_records_sql('SELECT COUNT(*) FROM {comments} c');
$comments = $this->get_comments($page);
$table = new html_table();
$table->head = array(html_writer::checkbox('selectall', '', false, get_string('selectall'), array('id' => 'comment_select_all', 'class' => 'comment-report-selectall')), get_string('author', 'search'), get_string('content'), get_string('action'));
$table->align = array('left', 'left', 'left', 'left');
$table->attributes = array('class' => 'generaltable commentstable');
$table->data = array();
$linkbase = $CFG->wwwroot . '/comment/index.php?action=delete&sesskey=' . sesskey();
foreach ($comments as $c) {
$link = $linkbase . '&commentid=' . $c->id;
$this->setup_plugin($c);
if (!empty($this->plugintype)) {
$context_url = plugin_callback($this->plugintype, $this->pluginname, FEATURE_COMMENT, 'url', array($c));
}
$checkbox = html_writer::checkbox('comments', $c->id, false);
$action = html_writer::link($link, get_string('delete'));
if (!empty($context_url)) {
$action .= html_writer::tag('br', null);
$action .= html_writer::link($context_url, get_string('commentincontext'), array('target' => '_blank'));
}
$table->data[] = array($checkbox, $c->fullname, $c->content, $action);
}
echo html_writer::table($table);
echo $OUTPUT->paging_bar($count, $page, $this->perpage, $CFG->wwwroot . '/comment/index.php');
}