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


PHP require_capability函数代码示例

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


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

示例1: process_edit

 public function process_edit()
 {
     require_capability('users:editcapabilities');
     $capability_id = (int) $this->input->post('capability_id');
     if (!empty($capability_id)) {
         $redirect_url = base_url() . 'users/capability/edit/' . $capability_id;
     }
     $this->form_validation->set_rules('name', 'Name', 'trim|required');
     $this->form_validation->set_rules('description', 'Description', 'trim|required');
     $this->form_validation->set_rules('dependson', 'Parent capability', 'required');
     $success = $this->form_validation->run();
     if (!$success) {
         add_message('Some of the fields were not filled correctly. Please check the messages below.', 'danger');
         return $this->edit($capability_id);
     }
     $capability_data = array('name' => $this->input->post('name'), 'description' => $this->input->post('description'), 'dependson' => $this->input->post('dependson'));
     $updated_or_added = empty($capability_id) ? 'added' : 'updated';
     if (empty($capability_id)) {
         if (!($capability_id = $this->capability_model->add($capability_data))) {
             add_message('Could not create this capability!', 'danger');
             redirect($redirect_url);
         }
     } else {
         if (!$this->capability_model->edit($capability_id, $capability_data)) {
             add_message('Could not update this capability!', 'danger');
             redirect($redirect_url);
         }
     }
     add_message("The {$capability_data['name']} capability has been successfully {$updated_or_added}!", 'success');
     redirect(base_url() . 'users/capability/browse');
 }
开发者ID:nicolasconnault,项目名称:streamliner,代码行数:31,代码来源:Capability.php

示例2: display

 function display()
 {
     global $CFG, $PAGE;
     require_capability('format/page:managepages', $this->context);
     $locks = format_page_lock::get_locks();
     $mform = new format_page_lock_form($CFG->wwwroot . '/course/format/page/format.php', format_page_lock::decode($this->page->locks));
     if ($mform->is_cancelled()) {
         redirect($PAGE->url_build('action', 'manage'));
     } else {
         if ($data = $mform->get_data()) {
             $lockdata = array();
             foreach ($locks as $lock) {
                 $lockdata = array_merge($lockdata, $lock->process_form($data));
             }
             $lockinfo = array();
             $lockinfo['showprereqs'] = $data->showprereqs;
             $lockinfo['visible'] = $data->visible;
             $lockinfo['locks'] = $lockdata;
             if (empty($lockinfo['locks'])) {
                 $lockinfo = '';
             } else {
                 $lockinfo = format_page_lock::encode($lockinfo);
             }
             if (!set_field('format_page', 'locks', $lockinfo, 'id', $this->page->id)) {
                 error('Failed to save lock information');
             }
             redirect($PAGE->url_build('page', $this->page->id, 'action', 'lock'));
         } else {
             $PAGE->print_tabs('manage');
             $mform->display();
         }
     }
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:33,代码来源:lock.php

示例3: praxe_view_headm

 function praxe_view_headm()
 {
     global $USER, $cm, $tab, $tab_modes, $CFG, $context;
     //$praxeaction = optional_param('praxeaction', null, PARAM_ALPHAEXT);
     //$school = optional_param('school', null, PARAM_INT);
     switch ($tab) {
         case PRAXE_TAB_HEADM_HOME:
             //$schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schools = praxe_get_schools($USER->id)) {
                 $this->content .= self::show_schools($schools, array('mode' => $tab_modes['headm'][PRAXE_TAB_HEADM_EDITSCHOOL]));
             } else {
                 $this->content .= get_string('noschoolsavailable', 'praxe');
             }
             break;
         case PRAXE_TAB_HEADM_ADDSCHOOL:
             self::addschool_form();
             break;
         case PRAXE_TAB_HEADM_TEACHERS:
             $schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schoolid > 0) {
                 $this->content .= self::school_teachers_by_schools($USER->id, $schoolid);
             } else {
                 $this->content .= self::school_teachers_by_schools($USER->id);
             }
             break;
         case PRAXE_TAB_HEADM_LOCATIONS:
             $schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schoolid > 0) {
                 $this->content .= self::show_locations($schoolid);
             } else {
                 $this->content .= self::show_locations(null, $USER->id);
                 $this->content .= "<p>" . get_string('to_create_location_choose_school', 'praxe') . "</p>";
             }
             break;
         case PRAXE_TAB_HEADM_EDITSCHOOL:
             $schoolid = required_param('schoolid', PARAM_INT);
             $school = praxe_get_school($schoolid);
             if (!praxe_has_capability('editownschool') || !is_object($school) || !$school->headmaster == $USER->id) {
                 print_error('notallowedaction', 'praxe');
             }
             self::addschool_form();
             $this->form->set_form_to_edit($school);
             break;
         case PRAXE_TAB_HEADM_ASSIGNTEACHERS:
             require_capability('mod/praxe:assignteachertoownschool', $context, $USER->id);
             $schoolid = required_param('schoolid', PARAM_INT);
             require_once $CFG->dirroot . '/mod/praxe/c_assignteachers.php';
             $this->form = new praxe_assignteachers($schoolid);
             break;
         case PRAXE_TAB_HEADM_ADDLOCATION:
             require_capability('mod/praxe:createownlocation', $context, $USER->id);
             $schoolid = required_param('schoolid', PARAM_INT);
             require_once $CFG->dirroot . '/mod/praxe/c_addlocation.php';
             $this->form = new praxe_addlocation($schoolid);
             break;
         default:
             redirect($CFG->wwwroot . '/mod/praxe/view.php?id=' . $cm->id);
             break;
     }
 }
开发者ID:jerab,项目名称:moodle-mod-praxe,代码行数:60,代码来源:view_headm.php

示例4: fix_page

 public static function fix_page($pages)
 {
     //Don't forget to set it as static
     global $CFG, $DB;
     $params = self::validate_parameters(self::fix_page_parameters(), array('pages' => $pages));
     $transaction = $DB->start_delegated_transaction();
     //If an exception is thrown in the below code, all DB queries in this code will be rollback.
     $newpages = array();
     foreach ($params['pages'] as $page) {
         $page = (object) $page;
         if (!($student = $DB->get_record('user', array('id' => $page->studentid)))) {
             throw new invalid_parameter_exception('No student with the specified id');
         }
         list($cm, $emarking, $course, $context) = emarking_get_cm_course_instance_by_id($page->cmid);
         // now security checks
         self::validate_context($context);
         require_capability('mod/emarking:uploadexam', $context);
         // finally fix the page
         $page->id = emarking_fix_page($page->fileid, $student, $emarking, $context, $page->pagenumber);
         if ($page->id > 0) {
             $newpages[] = array('id' => $page->id);
         }
     }
     $transaction->allow_commit();
     return $newpages;
 }
开发者ID:hansnok,项目名称:emarking,代码行数:26,代码来源:externallib.php

示例5: tool_usertours_inplace_editable

/**
 * Manage inplace editable saves.
 *
 * @param   string      $itemtype       The type of item.
 * @param   int         $itemid         The ID of the item.
 * @param   mixed       $newvalue       The new value
 * @return  string
 */
function tool_usertours_inplace_editable($itemtype, $itemid, $newvalue)
{
    $context = \context_system::instance();
    external_api::validate_context($context);
    require_capability('tool/usertours:managetours', $context);
    if ($itemtype === 'tourname') {
        $tour = helper::get_tour($itemid);
        $tour->set_name($newvalue)->persist();
        return helper::render_tourname_inplace_editable($tour);
    } else {
        if ($itemtype === 'tourdescription') {
            $tour = helper::get_tour($itemid);
            $tour->set_description($newvalue)->persist();
            return helper::render_tourdescription_inplace_editable($tour);
        } else {
            if ($itemtype === 'tourenabled') {
                $tour = helper::get_tour($itemid);
                $tour->set_enabled(!!$newvalue)->persist();
                return helper::render_tourenabled_inplace_editable($tour);
            } else {
                if ($itemtype === 'stepname') {
                    $step = helper::get_step($itemid);
                    $step->set_title($newvalue)->persist();
                    return helper::render_stepname_inplace_editable($step);
                }
            }
        }
    }
}
开发者ID:dg711,项目名称:moodle,代码行数:37,代码来源:lib.php

示例6: edit

 public function edit($invoice_tenancy_id, $order_id)
 {
     require_capability('orders:viewdocuments');
     $this->load->model('miniant/abbreviation_model');
     $this->load->model('miniant/invoice_tenancy_abbreviation_model');
     $invoice_tenancy = $this->invoice_tenancy_model->get($invoice_tenancy_id);
     $invoice = $this->invoice_model->get(array('order_id' => $order_id), true);
     $tenancy = $this->tenancy_model->get($invoice_tenancy->tenancy_id);
     $abbreviations = $this->abbreviation_model->get();
     $invoice_tenancy_abbreviations = $this->invoice_tenancy_abbreviation_model->get(array('invoice_tenancy_id' => $invoice_tenancy_id));
     $invoice_tenancy->system_time = $this->order_model->get_total_time($invoice->order_id);
     form_element::$default_data['technician_time_hours'] = floor($invoice_tenancy->technician_time / 60 / 60);
     form_element::$default_data['technician_time_minutes'] = ($invoice_tenancy->technician_time - form_element::$default_data['technician_time_hours'] * 60 * 60) / 60;
     foreach ($abbreviations as $key => $abbreviation) {
         $abbreviations[$key]->selected = false;
         foreach ($invoice_tenancy_abbreviations as $invoice_tenancy_abbreviation) {
             if ($invoice_tenancy_abbreviation->abbreviation_id == $abbreviation->id) {
                 $abbreviations[$key]->selected = true;
             }
         }
     }
     $title = "Edit invoice for {$tenancy->name}, job J{$order_id}";
     $help = "Use this form to edit the time spent by technicians on this job.";
     $this->config->set_item('replacer', array('miniant' => null, 'orders' => array('/miniant/orders/order/index|Jobs'), 'documents' => array('/miniant/orders/documents/index/html/' . $order_id . '/0|Tenancy invoices', $order_id => 'J' . $order_id, $invoice_tenancy_id => 'Edit invoice')));
     $this->config->set_item('exclude', array('edit'));
     $this->config->set_item('exclude_segment', array(7));
     $title_options = array('title' => $title, 'help' => $help, 'expand' => 'page', 'icons' => array());
     $pageDetails = array('title' => $title, 'title_options' => $title_options, 'content_view' => 'orders/documents/edit', 'tenancy' => $tenancy, 'invoice' => $invoice, 'order_id' => $order_id, 'abbreviations' => $abbreviations, 'invoice_tenancy_abbreviations' => $invoice_tenancy_abbreviations, 'invoice_tenancy' => $invoice_tenancy, 'jstoload' => array('bootstrap-slider'), 'feature_type' => 'Custom Feature', 'csstoload' => array('slider'));
     $this->load->view('template/default', $pageDetails);
 }
开发者ID:nicolasconnault,项目名称:streamliner,代码行数:30,代码来源:Documents.php

示例7: view_tree

 public function view_tree($unit_type_id)
 {
     $this->load->model('miniant/diagnostic_tree_model');
     require_capability('orders:viewdiagnosticrules');
     $tree = $this->diagnostic_tree_model->get_tree();
     // Remove parts that cannot have issues
     foreach ($tree as $this_unit_type_id => $unit_type_object) {
         if ($this_unit_type_id != $unit_type_id) {
             unset($tree[$this_unit_type_id]);
             continue;
         } else {
             $unit_type_name = $unit_type_object->unit_type;
         }
         foreach ($unit_type_object->part_types as $key => $part_type) {
             if (!$part_type->can_have_issues) {
                 unset($tree[$this_unit_type_id]->part_types[$key]);
             }
         }
     }
     $this->config->set_item('replacer', array('miniant' => null, 'steps' => array('/home|Administration', '/miniant/orders/steps/diagnostic_rules|Diagnostic rules'), 'orders' => null, 'view_tree' => array($unit_type_name)));
     $title = 'Diagnostic business rules';
     $help = 'This tree can be used to edit diagnostic business rules';
     $title_options = array('title' => $title, 'help' => $help, 'icons' => array());
     $pageDetails = array('title' => $title, 'title_options' => $title_options, 'content_view' => 'orders/steps', 'tree' => $tree, 'jstoload' => array('orders/steps'), 'feature_type' => 'Custom Feature', 'unit_type_name' => $unit_type_name, 'module' => 'miniant', 'csstoload' => array('tree'));
     $this->load->view('template/default', $pageDetails);
 }
开发者ID:nicolasconnault,项目名称:streamliner,代码行数:26,代码来源:Steps.php

示例8: view_imscp

    /**
     * Simulate the imscp/view.php web interface page: trigger events, completion, etc...
     *
     * @param int $imscpid the imscp instance id
     * @return array of warnings and status result
     * @since Moodle 3.0
     * @throws moodle_exception
     */
    public static function view_imscp($imscpid) {
        global $DB, $CFG;
        require_once($CFG->dirroot . "/mod/imscp/lib.php");

        $params = self::validate_parameters(self::view_imscp_parameters(),
                                            array(
                                                'imscpid' => $imscpid
                                            ));
        $warnings = array();

        // Request and permission validation.
        $imscp = $DB->get_record('imscp', array('id' => $params['imscpid']), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($imscp, 'imscp');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        require_capability('mod/imscp:view', $context);

        // Call the imscp/lib API.
        imscp_view($imscp, $course, $cm, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
开发者ID:nickbert77,项目名称:moodle,代码行数:35,代码来源:external.php

示例9: tag_create

/**
 * Creates tags
 * Ex: tag_create('A VeRY   cOoL    Tag, Another NICE tag')
 * will create the following normalized {@link tag_normalize()} entries in tags table:
 *  'a very cool tag'
 *  'another nice tag'
 *
 * @param string $tag_names_csv CSV tag names (can be unnormalized) to be created.
 * @param string $tag_type type of tag to be created ("default" is the default value).
 * @return an array of tags ids, indexed by their normalized names
 */
function tag_create($tag_names_csv, $tag_type = "default")
{
    global $USER;
    $textlib = textlib_get_instance();
    $tags = explode(",", $tag_names_csv);
    $tag_object = new StdClass();
    $tag_object->tagtype = $tag_type;
    $tag_object->userid = $USER->id;
    $systemcontext = get_context_instance(CONTEXT_SYSTEM);
    $can_create_tags = has_capability('moodle/tag:create', $systemcontext);
    $norm_tag_names_csv = '';
    foreach ($tags as $tag) {
        // rawname keeps the original casing of the string
        $tag_object->rawname = tag_normalize($tag, false);
        // name lowercases the string
        $tag_object->name = tag_normalize($tag);
        $norm_tag_names_csv .= $tag_object->name . ',';
        $tag_object->timemodified = time();
        $exists = record_exists('tag', 'name', $tag_object->name);
        if (!$exists && is_tag_name_valid($tag_object->name)) {
            if ($can_create_tags) {
                insert_record('tag', $tag_object);
            } else {
                require_capability('moodle/tag:create', $systemcontext);
            }
        }
    }
    $norm_tag_names_csv = $textlib->substr($norm_tag_names_csv, 0, -1);
    return tags_id($norm_tag_names_csv);
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:41,代码来源:lib.php

示例10: update

 /**
  * Updates the value in database and returns itself, called from inplace_editable callback
  *
  * @param int $itemid
  * @param mixed $newvalue
  * @return \self
  */
 public static function update($itemid, $newvalue)
 {
     require_capability('moodle/tag:manage', context_system::instance());
     $tag = core_tag_tag::get($itemid, '*', MUST_EXIST);
     $tag->update(array('rawname' => $newvalue));
     return new self($tag);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:14,代码来源:tagname.php

示例11: zoom_get_instance_setup

/**
 * Get course/cm/zoom objects from url parameters, and check for login/permissions.
 *
 * @return array Array of ($course, $cm, $zoom)
 */
function zoom_get_instance_setup()
{
    global $DB;
    $id = optional_param('id', 0, PARAM_INT);
    // Course_module ID, or
    $n = optional_param('n', 0, PARAM_INT);
    // ... zoom instance ID - it should be named as the first character of the module.
    if ($id) {
        $cm = get_coursemodule_from_id('zoom', $id, 0, false, MUST_EXIST);
        $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
        $zoom = $DB->get_record('zoom', array('id' => $cm->instance), '*', MUST_EXIST);
    } else {
        if ($n) {
            $zoom = $DB->get_record('zoom', array('id' => $n), '*', MUST_EXIST);
            $course = $DB->get_record('course', array('id' => $zoom->course), '*', MUST_EXIST);
            $cm = get_coursemodule_from_instance('zoom', $zoom->id, $course->id, false, MUST_EXIST);
        } else {
            print_error('You must specify a course_module ID or an instance ID');
        }
    }
    require_login($course, true, $cm);
    $context = context_module::instance($cm->id);
    require_capability('mod/zoom:view', $context);
    return array($course, $cm, $zoom);
}
开发者ID:uofr,项目名称:moodle-mod_zoom,代码行数:30,代码来源:locallib.php

示例12: class_delete

 /**
  * Performs class deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function class_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::class_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Get the class.
     $clsid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $data['idnumber']));
     if (empty($clsid)) {
         throw new data_object_exception('ws_class_delete_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:class_delete', \local_elisprogram\context\pmclass::instance($clsid));
     // Delete the class.
     $pmclass = new pmclass($clsid);
     $pmclass->delete();
     // Verify class deleted & respond.
     if (!$DB->record_exists(pmclass::TABLE, array('id' => $clsid))) {
         return array('messagecode' => get_string('ws_class_delete_success_code', 'local_datahub'), 'message' => get_string('ws_class_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_class_delete_fail', 'local_datahub');
     }
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:37,代码来源:class_delete.class.php

示例13: view

    function view() {

        global $USER, $OUTPUT;

        $context = context_module::instance($this->cm->id);
        require_capability('mod/assignment:view', $context);

        add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);

        $this->view_header();

        $this->view_intro();

        $this->view_dates();

        $filecount = false;

        if ($submission = $this->get_submission($USER->id)) {
            $filecount = $this->count_user_files($submission->id);
            if ($submission->timemarked) {
                $this->view_feedback();
            }
            if ($filecount) {
                echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter');
            }
        }

        if (is_enrolled($this->context, $USER, 'mod/assignment:submit') && $this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
            $this->view_upload_form();
        }

        $this->view_footer();
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:33,代码来源:assignment.class.php

示例14: index

 public function index($assignment_id)
 {
     require_capability('servicequotes:writesqs');
     if (!($assignment = $this->assignment_model->get($assignment_id))) {
         die("The assignment ID {$assignment_id} could not be found!");
     }
     $this->assignment = $this->assignment_model->get($assignment_id);
     if (empty($this->assignment)) {
         add_message('This job is no longer on record.', 'warning');
         redirect(base_url());
     }
     $order = $this->order_model->get($this->assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     parent::update_time($order->id);
     $diagnostics = $this->diagnostic_model->get_for_technician($this->assignment, $this->session->userdata('technician_id'), $order->senior_technician_id);
     $diagnostic = reset($diagnostics);
     $tasks = $this->order_model->get_tasks($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'postjob_checklist', 'param' => $assignment_id, 'module' => 'miniant'));
     $title_options = array('title' => $order_type . ' post-job checklist', 'help' => 'You must complete these tasks before obtaining the client\'s signature', 'icons' => array());
     $complete = $this->order_model->has_statuses($order->id, array('POST-JOB COMPLETE'));
     if (!$complete) {
         add_message('You must complete all the tasks below before moving to the next section', 'warning');
     }
     $this->load_stage_view(array('tasks' => $tasks, 'completed' => $complete));
 }
开发者ID:nicolasconnault,项目名称:streamliner,代码行数:26,代码来源:Postjob_checklist.php

示例15: get_comments

 /**
  * Return a list of comments
  *
  * @param string $contextlevel ('system, course, user', etc..)
  * @param int $instanceid
  * @param string $component the name of the component
  * @param int $itemid the item id
  * @param string $area comment area
  * @param int $page page number
  * @return array of comments and warnings
  * @since Moodle 2.9
  */
 public static function get_comments($contextlevel, $instanceid, $component, $itemid, $area = '', $page = 0)
 {
     $warnings = array();
     $arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'itemid' => $itemid, 'area' => $area, 'page' => $page);
     $params = self::validate_parameters(self::get_comments_parameters(), $arrayparams);
     $context = self::get_context_from_params($params);
     self::validate_context($context);
     require_capability('moodle/comment:view', $context);
     $args = new stdClass();
     $args->context = $context;
     $args->area = $params['area'];
     $args->itemid = $params['itemid'];
     $args->component = $params['component'];
     $commentobject = new comment($args);
     $comments = $commentobject->get_comments($params['page']);
     // False means no permissions to see comments.
     if ($comments === false) {
         throw new moodle_exception('nopermissions', 'error', '', 'view comments');
     }
     foreach ($comments as $key => $comment) {
         list($comments[$key]->content, $comments[$key]->format) = external_format_text($comment->content, $comment->format, $context->id, $params['component'], '', 0);
     }
     $results = array('comments' => $comments, 'warnings' => $warnings);
     return $results;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:37,代码来源:external.php


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