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


PHP get_roles_with_cap_in_context函数代码示例

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


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

示例1: definition

 /**
  * Define the form.
  */
 protected function definition()
 {
     global $CFG;
     $mform = $this->_form;
     list($context, $capability, $overridableroles) = $this->_customdata;
     list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name);
     foreach ($needed as $id => $unused) {
         unset($overridableroles[$id]);
     }
     foreach ($forbidden as $id => $unused) {
         unset($overridableroles[$id]);
     }
     $mform->addElement('header', 'allowheader', get_string('roleallowheader', 'core_role'));
     $mform->addElement('select', 'roleid', get_string('roleselect', 'core_role'), $overridableroles);
     $mform->addElement('hidden', 'capability');
     $mform->setType('capability', PARAM_CAPABILITY);
     $mform->setDefault('capability', $capability->name);
     $mform->addElement('hidden', 'contextid');
     $mform->setType('contextid', PARAM_INT);
     $mform->setDefault('contextid', $context->id);
     $mform->addElement('hidden', 'allow');
     $mform->setType('allow', PARAM_INT);
     $mform->setDefault('allow', 1);
     $this->add_action_buttons(true, get_string('allow', 'core_role'));
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:28,代码来源:permission_allow_form.php

示例2: add_row_cells

 protected function add_row_cells($capability)
 {
     global $OUTPUT, $PAGE;
     $renderer = $PAGE->get_renderer('core');
     $adminurl = new moodle_url("/admin/");
     $context = $this->context;
     $contextid = $this->context->id;
     $allowoverrides = $this->allowoverrides;
     $allowsafeoverrides = $this->allowsafeoverrides;
     $overridableroles = $this->overridableroles;
     $roles = $this->roles;
     list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name);
     $neededroles = array();
     $forbiddenroles = array();
     $allowable = $overridableroles;
     $forbitable = $overridableroles;
     foreach ($neededroles as $id => $unused) {
         unset($allowable[$id]);
     }
     foreach ($forbidden as $id => $unused) {
         unset($allowable[$id]);
         unset($forbitable[$id]);
     }
     foreach ($roles as $id => $name) {
         if (isset($needed[$id])) {
             $templatecontext = array("rolename" => $name, "roleid" => $id, "action" => "prevent", "spanclass" => "allowed", "linkclass" => "preventlink", "adminurl" => $adminurl->out(), "imageurl" => "");
             if (isset($overridableroles[$id]) and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
                 $templatecontext['imageurl'] = $renderer->pix_url('t/delete');
             }
             $neededroles[$id] = $renderer->render_from_template('core/permissionmanager_role', $templatecontext);
         }
     }
     $neededroles = implode(' ', $neededroles);
     foreach ($roles as $id => $name) {
         if (isset($forbidden[$id]) and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
             $templatecontext = array("rolename" => $name, "roleid" => $id, "action" => "unprohibit", "spanclass" => "forbidden", "linkclass" => "unprohibitlink", "adminurl" => $adminurl->out(), "imageurl" => "");
             if (isset($overridableroles[$id]) and prohibit_is_removable($id, $context, $capability->name)) {
                 $templatecontext['imageurl'] = $renderer->pix_url('t/delete');
             }
             $forbiddenroles[$id] = $renderer->render_from_template('core/permissionmanager_role', $templatecontext);
         }
     }
     $forbiddenroles = implode(' ', $forbiddenroles);
     if ($allowable and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
         $allowurl = new moodle_url($PAGE->url, array('contextid' => $contextid, 'capability' => $capability->name, 'allow' => 1));
         $allowicon = $OUTPUT->action_icon($allowurl, new pix_icon('t/add', get_string('allow', 'core_role')), null, array('class' => 'allowlink', 'data-action' => 'allow'));
         $neededroles .= html_writer::div($allowicon, 'allowmore');
     }
     if ($forbitable and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
         $prohibiturl = new moodle_url($PAGE->url, array('contextid' => $contextid, 'capability' => $capability->name, 'prohibit' => 1));
         $prohibiticon = $OUTPUT->action_icon($prohibiturl, new pix_icon('t/add', get_string('prohibit', 'core_role')), null, array('class' => 'prohibitlink', 'data-action' => 'prohibit'));
         $forbiddenroles .= html_writer::div($prohibiticon, 'prohibitmore');
     }
     $risks = $this->get_risks($capability);
     $contents = html_writer::tag('td', $risks, array('class' => 'risks text-nowrap'));
     $contents .= html_writer::tag('td', $neededroles, array('class' => 'allowedroles'));
     $contents .= html_writer::tag('td', $forbiddenroles, array('class' => 'forbiddenroles'));
     return $contents;
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:59,代码来源:permissions_table.php

示例3: add_row_cells

 protected function add_row_cells($capability)
 {
     global $OUTPUT, $PAGE;
     $context = $this->context;
     $contextid = $this->context->id;
     $allowoverrides = $this->allowoverrides;
     $allowsafeoverrides = $this->allowsafeoverrides;
     $overridableroles = $this->overridableroles;
     $roles = $this->roles;
     list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name);
     $neededroles = array();
     $forbiddenroles = array();
     $allowable = $overridableroles;
     $forbitable = $overridableroles;
     foreach ($neededroles as $id => $unused) {
         unset($allowable[$id]);
     }
     foreach ($forbidden as $id => $unused) {
         unset($allowable[$id]);
         unset($forbitable[$id]);
     }
     foreach ($roles as $id => $name) {
         if (isset($needed[$id])) {
             $neededroles[$id] = $roles[$id];
             if (isset($overridableroles[$id]) and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
                 $preventurl = new moodle_url($PAGE->url, array('contextid' => $contextid, 'roleid' => $id, 'capability' => $capability->name, 'prevent' => 1));
                 $neededroles[$id] .= $OUTPUT->action_icon($preventurl, new pix_icon('t/delete', get_string('prevent', 'core_role')));
             }
         }
     }
     $neededroles = implode(', ', $neededroles);
     foreach ($roles as $id => $name) {
         if (isset($forbidden[$id]) and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
             $forbiddenroles[$id] = $roles[$id];
             if (isset($overridableroles[$id]) and prohibit_is_removable($id, $context, $capability->name)) {
                 $unprohibiturl = new moodle_url($PAGE->url, array('contextid' => $contextid, 'roleid' => $id, 'capability' => $capability->name, 'unprohibit' => 1));
                 $forbiddenroles[$id] .= $OUTPUT->action_icon($unprohibiturl, new pix_icon('t/delete', get_string('delete')));
             }
         }
     }
     $forbiddenroles = implode(', ', $forbiddenroles);
     if ($allowable and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
         $allowurl = new moodle_url($PAGE->url, array('contextid' => $contextid, 'capability' => $capability->name, 'allow' => 1));
         $neededroles .= '<div class="allowmore">' . $OUTPUT->action_icon($allowurl, new pix_icon('t/add', get_string('allow', 'core_role'))) . '</div>';
     }
     if ($forbitable and ($allowoverrides or $allowsafeoverrides and is_safe_capability($capability))) {
         $prohibiturl = new moodle_url($PAGE->url, array('contextid' => $contextid, 'capability' => $capability->name, 'prohibit' => 1));
         $forbiddenroles .= '<div class="prohibitmore">' . $OUTPUT->action_icon($prohibiturl, new pix_icon('t/add', get_string('prohibit', 'core_role'))) . '</div>';
     }
     $risks = $this->get_risks($capability);
     echo '<td>' . $risks . '</td>';
     echo '<td>' . $neededroles . '</td>';
     echo '<td>' . $forbiddenroles . '</td>';
 }
开发者ID:bobpuffer,项目名称:moodleUCLA-LUTH,代码行数:54,代码来源:permissions_table.php

示例4: get_roles_with_caps_in_context

/**
 * Returns an array of role IDs that have ALL of the the supplied capabilities
 * Uses get_roles_with_cap_in_context(). Returns $allowed minus $forbidden
 *
 * @param object $context
 * @param array $capabilities An array of capabilities
 * @return array of roles with all of the required capabilities
 */
function get_roles_with_caps_in_context($context, $capabilities)
{
    $neededarr = array();
    $forbiddenarr = array();
    foreach ($capabilities as $caprequired) {
        list($neededarr[], $forbiddenarr[]) = get_roles_with_cap_in_context($context, $caprequired);
    }
    $rolesthatcanrate = array();
    if (!empty($neededarr)) {
        foreach ($neededarr as $needed) {
            if (empty($rolesthatcanrate)) {
                $rolesthatcanrate = $needed;
            } else {
                //only want roles that have all caps
                $rolesthatcanrate = array_intersect_key($rolesthatcanrate, $needed);
            }
        }
    }
    if (!empty($forbiddenarr) && !empty($rolesthatcanrate)) {
        foreach ($forbiddenarr as $forbidden) {
            //remove any roles that are forbidden any of the caps
            $rolesthatcanrate = array_diff($rolesthatcanrate, $forbidden);
        }
    }
    return $rolesthatcanrate;
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:34,代码来源:accesslib.php

示例5: after_execute

 protected function after_execute()
 {
     global $DB;
     // Add course related files, without itemid to match
     $this->add_related_files('course', 'summary', null);
     $this->add_related_files('course', 'overviewfiles', null);
     // Deal with legacy allowed modules.
     if ($this->legacyrestrictmodules) {
         $context = context_course::instance($this->get_courseid());
         list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
         list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
         foreach ($managerroleids as $roleid) {
             unset($roleids[$roleid]);
         }
         foreach (core_component::get_plugin_list('mod') as $modname => $notused) {
             if (isset($this->legacyallowedmodules[$modname])) {
                 // Module is allowed, no worries.
                 continue;
             }
             $capability = 'mod/' . $modname . ':addinstance';
             foreach ($roleids as $roleid) {
                 assign_capability($capability, CAP_PREVENT, $roleid, $context);
             }
         }
     }
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:26,代码来源:restore_stepslib.php

示例6: xmldb_main_upgrade


//.........这里部分代码省略.........
            $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1');
        } else {
            if ($CFG->restrictmodulesfor === 'requested') {
                $courses = $DB->get_records_menu('course', array('retrictmodules' => 1), 'id', 'id, 1');
            } else {
                $courses = array();
            }
        }
        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }
        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');
        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }
        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60);
            // 1 minute per course should be fine.
            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }
            $context = context_course::instance($courseid);
            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }
            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }
                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }
            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - {$i}/{$coursecount}.");
        }
        if ($coursecount) {
            $transaction->allow_commit();
        }
        upgrade_main_savepoint(true, 2012031500.01);
    }
    if ($oldversion < 2012031500.02) {
        // Define field retrictmodules to be dropped from course
        $table = new xmldb_table('course');
        $field = new xmldb_field('restrictmodules');
        // Conditionally launch drop field requested
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        upgrade_main_savepoint(true, 2012031500.02);
    }
    if ($oldversion < 2012031500.03) {
开发者ID:nigeli,项目名称:moodle,代码行数:67,代码来源:upgrade.php

示例7: xmldb_main_upgrade


//.........这里部分代码省略.........
            $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1');
        } else {
            if ($CFG->restrictmodulesfor === 'requested') {
                $courses = $DB->get_records_menu('course', array('restrictmodules' => 1), 'id', 'id, 1');
            } else {
                $courses = array();
            }
        }
        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }
        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');
        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }
        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60);
            // 1 minute per course should be fine.
            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }
            $context = context_course::instance($courseid);
            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }
            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }
                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }
            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - {$i}/{$coursecount}.");
        }
        if ($coursecount) {
            $transaction->allow_commit();
        }
        upgrade_main_savepoint(true, 2012031500.01);
    }
    if ($oldversion < 2012031500.02) {
        // Define field restrictmodules to be dropped from course
        $table = new xmldb_table('course');
        $field = new xmldb_field('restrictmodules');
        // Conditionally launch drop field requested
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        // Since structure of 'course' table has changed we need to re-read $SITE from DB.
        $SITE = $DB->get_record('course', array('id' => $SITE->id));
        $COURSE = clone $SITE;
开发者ID:HuiChangZhai,项目名称:moodle,代码行数:67,代码来源:upgrade.php

示例8: get_assignable_roles

 /**
  * Gets all of the assignable roles for this course.
  *
  * @return array
  */
 public function get_assignable_roles($otherusers = false)
 {
     if ($this->_assignableroles === null) {
         $this->_assignableroles = get_assignable_roles($this->context, ROLENAME_ALIAS, false);
         // verifies unassign access control too
     }
     if ($otherusers) {
         if (!is_array($this->_assignablerolesothers)) {
             $this->_assignablerolesothers = array();
             list($courseviewroles, $ignored) = get_roles_with_cap_in_context($this->context, 'moodle/course:view');
             foreach ($this->_assignableroles as $roleid => $role) {
                 if (isset($courseviewroles[$roleid])) {
                     $this->_assignablerolesothers[$roleid] = $role;
                 }
             }
         }
         return $this->_assignablerolesothers;
     } else {
         return $this->_assignableroles;
     }
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:26,代码来源:locallib.php

示例9: get_teachers

 /**
  * Returns a list of teachers by group
  * for sending email alerts to teachers
  * 
  * @return array the teacher array
  */
 protected function get_teachers()
 {
     global $CFG, $USER, $DB;
     $teachers = array();
     if (!empty($CFG->coursecontact)) {
         $coursecontactroles = explode(',', $CFG->coursecontact);
     } else {
         list($coursecontactroles, $trash) = get_roles_with_cap_in_context($this->get_context(), 'mod/simplecertificate:manage');
     }
     foreach ($coursecontactroles as $roleid) {
         $role = $DB->get_record('role', array('id' => $roleid));
         $roleid = (int) $roleid;
         if ($users = get_role_users($roleid, $this->context, true)) {
             foreach ($users as $teacher) {
                 if ($teacher->id == $USER->id) {
                     continue;
                     // do not send self
                 }
                 // do not send self
                 $manager = new stdClass();
                 $manager->user = $teacher;
                 $manager->username = fullname($teacher);
                 $teachers[$teacher->id] = $manager;
             }
         }
     }
     return $teachers;
 }
开发者ID:seducto,项目名称:moodle-mod_simplecertificate,代码行数:34,代码来源:locallib.php

示例10: xmldb_main_upgrade


//.........这里部分代码省略.........
            $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1');
        } else {
            if ($CFG->restrictmodulesfor === 'requested') {
                $courses = $DB->get_records_menu('course', array('restrictmodules' => 1), 'id', 'id, 1');
            } else {
                $courses = array();
            }
        }
        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }
        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');
        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }
        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60);
            // 1 minute per course should be fine.
            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }
            $context = context_course::instance($courseid);
            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }
            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }
                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }
            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - {$i}/{$coursecount}.");
        }
        if ($coursecount) {
            $transaction->allow_commit();
        }
        upgrade_main_savepoint(true, 2012031500.01);
    }
    if ($oldversion < 2012031500.02) {
        // Define field restrictmodules to be dropped from course
        $table = new xmldb_table('course');
        $field = new xmldb_field('restrictmodules');
        // Conditionally launch drop field requested
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        upgrade_main_savepoint(true, 2012031500.02);
    }
    if ($oldversion < 2012031500.03) {
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:67,代码来源:upgrade.php

示例11: backup

 /**
  * Takes the original course object as an argument, backs up the
  * course and returns a backupid which can be used for restoring the course.
  *
  * @param object $course Original course object
  * @param array $activityids all cm ids to backup
  * @param array $activityids all section ids to backup
  * @throws coding_exception Moodle coding_exception
  * @retun string backupid Backupid
  */
 private function backup($course, $activityids, $sectionids)
 {
     global $CFG, $DB, $USER;
     // MODE_IMPORT option is required to prevent it from zipping up the
     // result at the end. Unfortunately this breaks the system in some
     // other ways (see other comments).
     // NOTE: We cannot use MODE_SAMESITE here because that option will
     // zip the result and anyway, MODE_IMPORT already turns off the files.
     $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_IMPORT, $USER->id);
     // Setup custom logger that prints dots.
     $logger = new logger(\backup::LOG_INFO, false, true);
     self::$currentlogger = $logger;
     $logger->potential_dot();
     $bc->get_logger()->set_next($logger);
     $bc->set_progress(new progress());
     foreach ($bc->get_plan()->get_tasks() as $taskindex => $task) {
         $settings = $task->get_settings();
         foreach ($settings as $settingindex => $setting) {
             $setting->set_status(\backup_setting::NOT_LOCKED);
             // Modify the values of the intial backup settings.
             if ($taskindex == 0) {
                 if (isset($this->backupsettings[$setting->get_name()])) {
                     $setting->set_value($this->backupsettings[$setting->get_name()]);
                 }
             } else {
                 list($name, $id, $type) = $this->parse_backup_course_module($setting->get_name());
                 // Include user data on glossary if the role 'contributingstudent'
                 // does not have the capability mod/glossary:write on that glossary.
                 // This is so that we include course-team glossary data but not
                 // glossaries that are written by students.
                 if ($name === 'glossary' && $type === 'userinfo') {
                     // Find the contributing student role id. If there
                     // isn't one, use the student role id, for dev servers etc.
                     $roles = $DB->get_records_select('role', "shortname IN ('contributingstudent', 'student')", null, 'shortname', 'id');
                     if (!$roles) {
                         continue;
                     }
                     $roleid = reset($roles)->id;
                     // Get the list of roles which have the capability in the context
                     // of the glossary.
                     $context = \context_module::instance($id);
                     list($allowed, $forbidden) = get_roles_with_cap_in_context($context, 'mod/glossary:write');
                     // If student has this capability then the user data is false.
                     if (!empty($allowed[$roleid]) && empty($forbidden[$roleid])) {
                         $setting->set_value(false);
                     } else {
                         $setting->set_value(true);
                     }
                 }
                 // Ignone any sections not in subpage.
                 if ($name === 'section' && $type === 'included' && !in_array($id, $sectionids)) {
                     $setting->set_value(false);
                 }
                 // Ignone any activities not in subpage.
                 if ($name !== 'section' && $type === 'included' && !in_array($id, $activityids)) {
                     $setting->set_value(false);
                 }
             }
         }
     }
     $logger->potential_dot();
     $bc->save_controller();
     $backupid = $bc->get_backupid();
     $this->backupbasepath = $bc->get_plan()->get_basepath();
     $bc->execute_plan();
     $bc->destroy();
     return $backupid;
 }
开发者ID:ninelanterns,项目名称:moodle-mod_subpage,代码行数:78,代码来源:lib.php

示例12: emarking_send_notification

/**
 * Sends email to course manager, teacher and non-editingteacher,
 * when a printing order has been created
 *
 * @param unknown $exam            
 * @param unknown $course            
 * @param unknown $postsubject            
 * @param unknown $posttext            
 * @param unknown $posthtml            
 */
function emarking_send_notification($exam, $course, $postsubject, $posttext, $posthtml)
{
    global $USER, $CFG;
    $context = context_course::instance($course->id);
    $userstonotify = array();
    // Notify users that a new exam was sent. First, get all roles that have the capability in this context or higher
    $roles = get_roles_with_cap_in_context($context, 'mod/emarking:receivenotification');
    foreach ($roles[0] as $role) {
        // Get all users with any of the needed roles in the course context
        foreach (get_role_users($role, $context, true, 'u.id, u.username', null, true) as $usertonotify) {
            $userstonotify[$usertonotify->id] = $usertonotify;
        }
    }
    $forbidden = $roles[1];
    // Get the category context
    $contextcategory = context_coursecat::instance($course->category);
    // Now get all users that has any of the roles needed, no checking if they have roles forbidden as it is only
    // a notification
    foreach ($userstonotify as $user) {
        $thismessagehtml = $posthtml;
        // Downloading predominates over receiving notification
        if (has_capability('mod/emarking:downloadexam', $contextcategory, $user)) {
            $thismessagehtml .= '<p><a href="' . $CFG->wwwroot . '/mod/emarking/print/printorders.php?category=' . $course->category . '">' . get_string('printorders', 'mod_emarking') . '</a></p>';
        } else {
            if (has_capability('mod/emarking:receivenotification', $context, $user)) {
                $thismessagehtml .= '<p><a href="' . $CFG->wwwroot . '/mod/emarking/print/exams.php?course=' . $course->id . '">' . get_string('printorders', 'mod_emarking') . ' ' . $course->fullname . '</a></p>';
            }
        }
        $eventdata = new stdClass();
        $eventdata->component = 'mod_emarking';
        $eventdata->name = 'notification';
        $eventdata->userfrom = $USER;
        $eventdata->userto = $user->id;
        $eventdata->subject = $postsubject;
        $eventdata->fullmessage = $posttext;
        $eventdata->fullmessageformat = FORMAT_HTML;
        $eventdata->fullmessagehtml = $thismessagehtml;
        $eventdata->smallmessage = $postsubject;
        $eventdata->notification = 1;
        message_send($eventdata);
    }
}
开发者ID:eduagdo,项目名称:emarking,代码行数:52,代码来源:locallib.php

示例13: xmldb_main_upgrade


//.........这里部分代码省略.........
        // Main savepoint reached
        upgrade_main_savepoint(true, 2012030900.01);
    }
    if ($oldversion < 2012031500.01) {
        // Upgrade old course_allowed_modules data to be permission overrides.
        if ($CFG->restrictmodulesfor === 'all') {
            $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1');
        } else {
            if ($CFG->restrictmodulesfor === 'requested') {
                $courses = $DB->get_records_menu('course', array('retrictmodules' => 1), 'id', 'id, 1');
            } else {
                $courses = array();
            }
        }
        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }
        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');
        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }
        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60);
            // 1 minute per course should be fine.
            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }
            $context = context_course::instance($courseid);
            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }
            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }
                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }
            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - {$i}/{$coursecount}.");
        }
        if ($coursecount) {
            $transaction->allow_commit();
        }
        upgrade_main_savepoint(true, 2012031500.01);
    }
    if ($oldversion < 2012031500.02) {
        // Define field retrictmodules to be dropped from course
        $table = new xmldb_table('course');
        $field = new xmldb_field('restrictmodules');
        // Conditionally launch drop field requested
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        upgrade_main_savepoint(true, 2012031500.02);
    }
    if ($oldversion < 2012031500.03) {
        // Define table course_allowed_modules to be dropped
        $table = new xmldb_table('course_allowed_modules');
        // Conditionally launch drop table for course_allowed_modules
        if ($dbman->table_exists($table)) {
            $dbman->drop_table($table);
        }
        upgrade_main_savepoint(true, 2012031500.03);
    }
    if ($oldversion < 2012031500.04) {
        // Clean up the old admin settings.
        unset_config('restrictmodulesfor');
        unset_config('restrictbydefault');
        unset_config('defaultallowedmodules');
        upgrade_main_savepoint(true, 2012031500.04);
    }
    if ($oldversion < 2012032300.02) {
        // Migrate the old admin debug setting.
        if ($CFG->debug == 38911) {
            set_config('debug', DEBUG_DEVELOPER);
        } else {
            if ($CFG->debug == 6143) {
                set_config('debug', DEBUG_ALL);
            }
        }
        upgrade_main_savepoint(true, 2012032300.02);
    }
    return true;
}
开发者ID:robadobdob,项目名称:moodle,代码行数:101,代码来源:upgrade.php

示例14: xmldb_main_upgrade


//.........这里部分代码省略.........
            $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1');
        } else {
            if ($CFG->restrictmodulesfor === 'requested') {
                $courses = $DB->get_records_menu('course', array('retrictmodules' => 1), 'id', 'id, 1');
            } else {
                $courses = array();
            }
        }
        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }
        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');
        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }
        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60);
            // 1 minute per course should be fine.
            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }
            $context = context_course::instance($courseid);
            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }
            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }
                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }
            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - {$i}/{$coursecount}.");
        }
        if ($coursecount) {
            $transaction->allow_commit();
        }
        upgrade_main_savepoint(true, 2012031500.01);
    }
    if ($oldversion < 2012031500.02) {
        // Define field retrictmodules to be dropped from course
        $table = new xmldb_table('course');
        $field = new xmldb_field('restrictmodules');
        // Conditionally launch drop field requested
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        upgrade_main_savepoint(true, 2012031500.02);
    }
    if ($oldversion < 2012031500.03) {
开发者ID:nmicha,项目名称:moodle,代码行数:67,代码来源:upgrade.php

示例15: xmldb_main_upgrade


//.........这里部分代码省略.........
        }

        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }

        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');

        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }

        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60); // 1 minute per course should be fine.

            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules',
            array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }

            $context = context_course::instance($courseid);

            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }

            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }

                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }

            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - $i/$coursecount.");
        }

        if ($coursecount) {
            $transaction->allow_commit();
        }

        upgrade_main_savepoint(true, 2012031500.01);
    }

    if ($oldversion < 2012031500.02) {

        // Define field restrictmodules to be dropped from course
        $table = new xmldb_table('course');
        $field = new xmldb_field('restrictmodules');
开发者ID:ncsu-delta,项目名称:moodle,代码行数:67,代码来源:upgrade.php


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