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


PHP has_capability函数代码示例

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


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

示例1: assignfeedback_editpdf_pluginfile

/**
 * Serves assignment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignfeedback_editpdf_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB, $CFG;
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_login($course, false, $cm);
        $itemid = (int) array_shift($args);
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        $record = $DB->get_record('assign_grades', array('id' => $itemid), 'userid,assignment', MUST_EXIST);
        $userid = $record->userid;
        if ($assign->id != $record->assignment) {
            return false;
        }
        // Check is users feedback or has grading permission.
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/assignfeedback_editpdf/{$filearea}/{$itemid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Download MUST be forced - security!
        send_stored_file($file, 0, 0, true);
        // Check if we want to retrieve the stamps.
    }
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:40,代码来源:lib.php

示例2: get_submission_status

 /**
  * Search a list of modules.
  *
  * @param $modulecode
  * @return array [string]
  * @throws \invalid_parameter_exception
  */
 public static function get_submission_status($submissionid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::get_submission_status_parameters(), array('submissionid' => $submissionid));
     $submissionid = $params['submissionid'];
     $submission = $DB->get_record('turnitintooltwo_submissions', array('id' => $submissionid));
     if (!$submission) {
         return array('status' => 'error');
     }
     // Grab more data.
     $turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $submission->turnitintooltwoid));
     list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
     // Check this is our submission.
     if ($USER->id !== $submission->userid && !has_capability('mod/turnitintooltwo:grade', \context_module::instance($cm->id))) {
         return array('status' => 'nopermission');
     }
     // What is the status?
     $status = $DB->get_record('turnitintooltwo_sub_status', array('submissionid' => $submissionid));
     if (!$status) {
         return array('status' => 'queued');
     }
     // Decode the receipt.
     $digitalreceipt = (array) json_decode($status->receipt);
     // Woo!
     if ($status->status == \mod_turnitintooltwo\task\submit_assignment::STATUS_SUCCESS) {
         $turnitintooltwoview = new \turnitintooltwo_view();
         $digitalreceipt = $turnitintooltwoview->show_digital_receipt($digitalreceipt);
         $digitalreceipt = \html_writer::tag("div", $digitalreceipt, array("id" => "box_receipt"));
         return array('status' => 'success', 'message' => $digitalreceipt);
     }
     return array('status' => 'failed', 'message' => \html_writer::tag("div", $digitalreceipt["message"], array("class" => "alert alert-danger")));
 }
开发者ID:SkylarKelty,项目名称:moodle-mod_turnitintooltwo,代码行数:39,代码来源:external.php

示例3: definition

 function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $modcontext = $this->_customdata['modcontext'];
     $mform->addElement('header', 'general', get_string('export', 'quiz'));
     $mform->setHelpButton('general', array('export', get_string('export', 'quiz'), 'attforblock'));
     $groupmode = groups_get_activity_groupmode($cm);
     $groups = groups_get_activity_allowed_groups($cm, $USER->id);
     if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
         $grouplist[0] = get_string('allparticipants');
     }
     if ($groups) {
         foreach ($groups as $group) {
             $grouplist[$group->id] = $group->name;
         }
     }
     $mform->addElement('select', 'group', get_string('group'), $grouplist);
     $ident = array();
     $ident[] =& MoodleQuickForm::createElement('checkbox', 'id', '', get_string('studentid', 'attforblock'));
     $ident[] =& MoodleQuickForm::createElement('checkbox', 'uname', '', get_string('username'));
     $mform->addGroup($ident, 'ident', get_string('identifyby', 'attforblock'), array('<br />'), true);
     $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
     $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attforblock'), get_string('yes'));
     $mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attforblock'));
     $mform->disabledIf('sessionenddate', 'includenottaken', 'notchecked');
     $mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attforblock'), 'ooo' => get_string('downloadooo', 'attforblock'), 'text' => get_string('downloadtext', 'attforblock')));
     // buttons
     $submit_string = get_string('ok');
     $this->add_action_buttons(false, $submit_string);
     $mform->addElement('hidden', 'id', $cm->id);
     //        $mform->addElement('hidden', 'action', 'add');
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:35,代码来源:export_form.php

示例4: booktool_wordimport_extend_settings_navigation

/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $node The node to add module settings to
 */
function booktool_wordimport_extend_settings_navigation(settings_navigation $settings, navigation_node $node)
{
    global $PAGE;
    if ($PAGE->cm->modname !== 'book') {
        return;
    }
    $params = $PAGE->url->params();
    if (empty($params['id']) and empty($params['cmid'])) {
        return;
    }
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = get_context_module::instance($PAGE->cm->instance);
    }
    if (!(has_capability('booktool/wordimport:import', $PAGE->cm->context) and has_capability('mod/book:edit', $PAGE->cm->context))) {
        return;
    }
    // Configure Import link, and pass in the current chapter in case the insert should happen here rather than at the end.
    $url1 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid']));
    $node->add(get_string('importchapters', 'booktool_wordimport'), $url1, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
    // Configure Export links for book and current chapter.
    $url2 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'action' => 'export'));
    $node->add(get_string('exportbook', 'booktool_wordimport'), $url2, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
    $url3 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid'], 'action' => 'export'));
    $node->add(get_string('exportchapter', 'booktool_wordimport'), $url3, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
}
开发者ID:ecampbell,项目名称:moodle-booktool_wordimport,代码行数:31,代码来源:lib.php

示例5: definition

 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $syscontext = get_context_instance(CONTEXT_SYSTEM);
     $actions = array(0 => get_string('choose') . '...');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[1] = get_string('confirm');
     }
     if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
         $actions[2] = get_string('messageselectadd');
     }
     if (has_capability('moodle/user:delete', $syscontext)) {
         $actions[3] = get_string('delete');
     }
     $actions[4] = get_string('displayonpage');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[5] = get_string('download', 'admin');
     }
     if (has_capability('moodle/role:assign', $syscontext)) {
         $actions[6] = get_string('enrolmultipleusers', 'admin');
     }
     $objs = array();
     $objs[] =& $mform->createElement('select', 'action', null, $actions);
     $objs[] =& $mform->createElement('submit', 'doaction', get_string('go'));
     $mform->addElement('group', 'actionsgrp', get_string('withselectedusers'), $objs, ' ', false);
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:27,代码来源:user_bulk_forms.php

示例6: resource_base

 /**
  * Constructor for the base resource class
  *
  * Constructor for the base resource class.
  * If cmid is set create the cm, course, resource objects.
  * and do some checks to make sure people can be here, and so on.
  *
  * @param cmid   integer, the current course module id - not set for new resources
  */
 function resource_base($cmid = 0)
 {
     global $CFG, $COURSE;
     $this->navlinks = array();
     if ($cmid) {
         if (!($this->cm = get_coursemodule_from_id('resource', $cmid))) {
             error("Course Module ID was incorrect");
         }
         if (!($this->course = get_record("course", "id", $this->cm->course))) {
             error("Course is misconfigured");
         }
         if (!($this->resource = get_record("resource", "id", $this->cm->instance))) {
             error("Resource ID was incorrect");
         }
         $this->strresource = get_string("modulename", "resource");
         $this->strresources = get_string("modulenameplural", "resource");
         if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
             $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strresource);
             $navigation = build_navigation($this->navlinks, $this->cm);
             print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm));
             notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}");
         }
     } else {
         $this->course = $COURSE;
     }
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:35,代码来源:lib.php

示例7: __construct

 /**
  * Constructor.
  *
  * @param stdClass $cohort
  */
 public function __construct($cohort)
 {
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     $editable = has_capability('moodle/cohort:manage', $cohortcontext);
     $displayvalue = format_string($cohort->name, true, array('context' => $cohortcontext));
     parent::__construct('core_cohort', 'cohortname', $cohort->id, $editable, $displayvalue, $cohort->name, new lang_string('editcohortname', 'cohort'), new lang_string('newnamefor', 'cohort', $displayvalue));
 }
开发者ID:rushi963,项目名称:moodle,代码行数:12,代码来源:cohortname.php

示例8: definition_after_data

 function definition_after_data()
 {
     global $CFG;
     $mform =& $this->_form;
     $courseid = $mform->getElementValue('courseid');
     if ($id = $mform->getElementValue('id')) {
         $scale = grade_scale::fetch(array('id' => $id));
         $used = $scale->is_used();
         if ($used) {
             $mform->hardFreeze('scale');
         }
         if (empty($courseid)) {
             $mform->hardFreeze('standard');
         } else {
             if (empty($scale->courseid) and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
                 $mform->hardFreeze('standard');
             } else {
                 if ($used and !empty($scale->courseid)) {
                     $mform->hardFreeze('standard');
                 }
             }
         }
         $usedstr = $scale->is_used() ? get_string('yes') : get_string('no');
         $used_el =& $mform->getElement('used');
         $used_el->setValue($usedstr);
     } else {
         $mform->removeElement('used');
         if (empty($courseid) or !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
             $mform->hardFreeze('standard');
         }
     }
 }
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:32,代码来源:edit_form.php

示例9: print_tabs

 /**
  * Prints the tabs for the learning path type
  *
  * @param string $currenttab Tab to highlight
  * @return void
  **/
 function print_tabs($currenttab = 'layout')
 {
     global $COURSE;
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     $tabs = $row = $inactive = $active = array();
     $row[] = new tabobject('view', $this->url_get_full(), get_string('editpage', 'format_page'));
     if (has_capability('format/page:addpages', $context)) {
         $row[] = new tabobject('addpage', $this->url_build('action', 'editpage'), get_string('addpage', 'format_page'));
     }
     if (has_capability('format/page:managepages', $context)) {
         $row[] = new tabobject('manage', $this->url_build('action', 'manage'), get_string('manage', 'format_page'));
     }
     if (has_capability('moodle/local:managepageactivities', $context)) {
         $row[] = new tabobject('activities', $this->url_build('action', 'activities'), get_string('managemods', 'format_page'));
     }
     if (has_capability('moodle/local:classifylearningpath', $context)) {
         $row[] = new tabobject('classify', $this->url_build('action', 'classify'), get_string('classification', 'local'));
     }
     if (has_capability('moodle/local:savelearningpathtemplate', $context)) {
         $row[] = new tabobject('backup', $this->url_build('action', 'backup'), get_string('makebackup', 'local'));
     }
     $tabs[] = $row;
     if (in_array($currenttab, array('layout', 'settings', 'view'))) {
         $active[] = 'view';
         $row = array();
         $row[] = new tabobject('layout', $this->url_get_full(), get_string('layout', 'format_page'));
         $row[] = new tabobject('settings', $this->url_get_full(array('action' => 'editpage')), get_string('settings', 'format_page'));
         $tabs[] = $row;
     }
     print_tabs($tabs, $currenttab, $inactive, $active);
 }
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:37,代码来源:pagelib.php

示例10: get_content

 /**
  * block contents
  *
  * @return object
  */
 public function get_content()
 {
     global $CFG, $COURSE, $USER, $PAGE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if ($COURSE->id == SITEID) {
         $context = context_system::instance();
     } else {
         $context = context_course::instance($COURSE->id);
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     $mymoodle = 0;
     if (strcmp('my-index', $PAGE->pagetype) == 0) {
         $mymoodle = 1;
     }
     if (has_capability('block/enrolsurvey:edit', $context)) {
         $editpage = get_string('editpage', 'block_enrolsurvey');
         $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/edit_survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$editpage}</a><br\n/>";
     }
     if (has_capability('block/enrolsurvey:take', $context) && cm_get_crlmuserid($USER->id) !== false) {
         // MUST have ELIS user record to take survey!
         if (!empty($this->config->force_user) && !is_survey_taken($USER->id, $this->instance->id)) {
             redirect("{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}");
         }
         $takepage = get_string('takepage', 'block_enrolsurvey');
         $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$takepage}</a><br\n/>";
     }
     // $this->content->text .= "<br/> crontime = {$this->config->cron_time}";
     return $this->content;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:38,代码来源:block_enrolsurvey.php

示例11: module_specific_controls

/**
 * Callback function called from question_list() function (which is called from showbank())
 */
function module_specific_controls($totalnumber, $recurse, $category, $cmid)
{
    global $QTYPES;
    $out = '';
    $catcontext = get_context_instance_by_id($category->contextid);
    if (has_capability('moodle/question:useall', $catcontext)) {
        $randomusablequestions = $QTYPES['random']->get_usable_questions_from_category($category->id, $recurse, '0');
        $maxrand = count($randomusablequestions);
        if ($maxrand > 0) {
            for ($i = 1; $i <= min(10, $maxrand); $i++) {
                $randomcount[$i] = $i;
            }
            for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
                $randomcount[$i] = $i;
            }
            $out .= '<br />';
            $out .= get_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
            $out .= '<input type="hidden" name="recurse" value="' . $recurse . '" />';
            $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
            $out .= ' <input type="submit" name="addrandom" value="' . get_string('add') . '" />';
            $out .= helpbutton('random', get_string('random', 'quiz'), 'quiz', true, false, '', true);
        }
    }
    return $out;
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:28,代码来源:edit.php

示例12: get_content

 function get_content()
 {
     global $CFG, $OUTPUT;
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     /// MDL-13252 Always get the course context or else the context may be incorrect in the user/index.php
     $currentcontext = $this->page->context;
     if ($this->page->course->id == SITEID) {
         if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
             $this->content = '';
             return $this->content;
         }
     } else {
         if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
             $this->content = '';
             return $this->content;
         }
     }
     $icon = '<img src="' . $OUTPUT->pix_url('i/users') . '" class="icon" alt="" />&nbsp;';
     $this->content->items[] = '<a title="' . get_string('listofallpeople') . '" href="' . $CFG->wwwroot . '/user/index.php?contextid=' . $currentcontext->id . '">' . $icon . get_string('participants') . '</a>';
     return $this->content;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:28,代码来源:block_participants.php

示例13: definition

 /**
  * Form definition
  */
 function definition()
 {
     global $USER, $CFG, $COURSE;
     $coursecontext = context_course::instance($COURSE->id);
     $mform =& $this->_form;
     $editoroptions = $this->_customdata['editoroptions'];
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('groupingname', 'group'), 'maxlength="254" size="50"');
     $mform->addRule('name', get_string('required'), 'required', null, 'server');
     $mform->setType('name', PARAM_MULTILANG);
     $mform->addElement('text', 'idnumber', get_string('idnumbergrouping'), 'maxlength="100" size="10"');
     $mform->addHelpButton('idnumber', 'idnumbergrouping');
     $mform->setType('idnumber', PARAM_RAW);
     $mform->setAdvanced('idnumber');
     if (!has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
     }
     $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions);
     $mform->setType('description_editor', PARAM_RAW);
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $this->add_action_buttons();
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:28,代码来源:grouping_form.php

示例14: other_attempt_fields

 protected function other_attempt_fields(MoodleQuickForm $mform) {
     if (has_capability('mod/quiz:regrade', $this->_customdata['context'])) {
         $mform->addElement('advcheckbox', 'onlyregraded', '',
                 get_string('optonlyregradedattempts', 'quiz_overview'));
         $mform->disabledIf('onlyregraded', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     }
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:7,代码来源:overview_form.php

示例15: get_instance_info

 /**
  * Return guest enrolment instance information.
  *
  * @param int $instanceid instance id of guest enrolment plugin.
  * @return array warnings and instance information.
  * @since Moodle 3.1
  */
 public static function get_instance_info($instanceid)
 {
     global $DB;
     $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid));
     $warnings = array();
     // Retrieve guest enrolment plugin.
     $enrolplugin = enrol_get_plugin('guest');
     if (empty($enrolplugin)) {
         throw new moodle_exception('invaliddata', 'error');
     }
     require_login(null, false, null, false, true);
     $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
     $context = context_course::instance($course->id);
     if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
         throw new moodle_exception('coursehidden');
     }
     $instanceinfo = $enrolplugin->get_enrol_info($enrolinstance);
     // Specific instance information.
     $instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired;
     unset($instanceinfo->requiredparam);
     $result = array();
     $result['instanceinfo'] = $instanceinfo;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:rushi963,项目名称:moodle,代码行数:33,代码来源:external.php


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