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


PHP has_all_capabilities函数代码示例

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


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

示例1: extend_course_navigation

 /**
  * Loads all of the course sections into the navigation
  *
  * @param global_navigation $navigation
  * @param navigation_node $node The course node within the navigation
  */
 public function extend_course_navigation($navigation, navigation_node $node)
 {
     // Display orphaned activities for the users who can see them.
     $context = context_course::instance($this->courseid);
     if (has_all_capabilities(array('moodle/course:viewhiddensections', 'moodle/course:viewhiddenactivities'), $context)) {
         $modinfo = get_fast_modinfo($this->courseid);
         if (!empty($modinfo->sections[1])) {
             $section1 = $modinfo->get_section_info(1);
             // Show orphaned activities.
             $orphanednode = $node->add(get_string('orphaned', 'format_singleactivity'), $this->get_view_url(1), navigation_node::TYPE_SECTION, null, $section1->id);
             $orphanednode->nodetype = navigation_node::NODETYPE_BRANCH;
             $orphanednode->add_class('orphaned');
             foreach ($modinfo->sections[1] as $cmid) {
                 $this->navigation_add_activity($orphanednode, $modinfo->cms[$cmid]);
             }
         }
     }
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:24,代码来源:lib.php

示例2: course_get_cm_edit_actions_reduced

/**
 * Returns the list of all editing actions that current user can perform on the module
 *
 * @param cm_info $mod The module to produce editing buttons for
 * @param int $indent The current indenting (default -1 means no move left-right actions)
 * @param int $sr The section to link back to (used for creating the links)
 * @return array array of action_link or pix_icon objects
 */
function course_get_cm_edit_actions_reduced(cm_info $mod, $indent = -1, $sr = null)
{
    global $COURSE, $SITE;
    static $str;
    $coursecontext = context_course::instance($mod->course);
    $modcontext = context_module::instance($mod->id);
    $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign');
    $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
    //No permission to edit anything.
    if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) {
        return array();
    }
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = get_strings(array('delete', 'move', 'moveright', 'moveleft', 'editsettings', 'duplicate', 'hide', 'show'), 'moodle');
        $str->assign = get_string('assignroles', 'role');
        $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone"));
        $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible"));
    }
    $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
    if ($sr !== null) {
        $baseurl->param('sr', $sr);
    }
    $actions = array();
    // Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php)
    // Note that restoring on front page is never allowed.
    if ($mod->course != SITEID && has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) {
        $actions['duplicate'] = new action_menu_link_secondary(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->duplicate, array('class' => 'editing_duplicate', 'data-action' => 'duplicate', 'data-sr' => $sr));
    }
    // Delete.
    if ($hasmanageactivities) {
        $actions['delete'] = new action_menu_link_secondary(new moodle_url($baseurl, array('delete' => $mod->id)), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->delete, array('class' => 'editing_delete', 'data-action' => 'delete'));
    }
    return $actions;
}
开发者ID:helenagarcia90,项目名称:moodle,代码行数:44,代码来源:lib.php

示例3: make_categories_list

 /**
  * This function returns a nice list representing category tree
  * for display or to use in a form <select> element
  *
  * List is cached for 10 minutes
  *
  * For example, if you have a tree of categories like:
  *   Miscellaneous (id = 1)
  *      Subcategory (id = 2)
  *         Sub-subcategory (id = 4)
  *   Other category (id = 3)
  * Then after calling this function you will have
  * array(1 => 'Miscellaneous',
  *       2 => 'Miscellaneous / Subcategory',
  *       4 => 'Miscellaneous / Subcategory / Sub-subcategory',
  *       3 => 'Other category');
  *
  * If you specify $requiredcapability, then only categories where the current
  * user has that capability will be added to $list.
  * If you only have $requiredcapability in a child category, not the parent,
  * then the child catgegory will still be included.
  *
  * If you specify the option $excludeid, then that category, and all its children,
  * are omitted from the tree. This is useful when you are doing something like
  * moving categories, where you do not want to allow people to move a category
  * to be the child of itself.
  *
  * See also {@link make_categories_options()}
  *
  * @param string/array $requiredcapability if given, only categories where the current
  *      user has this capability will be returned. Can also be an array of capabilities,
  *      in which case they are all required.
  * @param integer $excludeid Exclude this category and its children from the lists built.
  * @param string $separator string to use as a separator between parent and child category. Default ' / '
  * @return array of strings
  */
 public static function make_categories_list($requiredcapability = '', $excludeid = 0, $separator = ' / ')
 {
     global $DB;
     $coursecatcache = cache::make('core', 'coursecat');
     // Check if we cached the complete list of user-accessible category names ($baselist) or list of ids with requried cap ($thislist).
     $basecachekey = 'catlist';
     $baselist = $coursecatcache->get($basecachekey);
     if ($baselist !== false) {
         $baselist = false;
     }
     $thislist = false;
     if (!empty($requiredcapability)) {
         $requiredcapability = (array) $requiredcapability;
         $thiscachekey = 'catlist:' . serialize($requiredcapability);
         if ($baselist !== false && ($thislist = $coursecatcache->get($thiscachekey)) !== false) {
             $thislist = preg_split('|,|', $thislist, -1, PREG_SPLIT_NO_EMPTY);
         }
     } else {
         if ($baselist !== false) {
             $thislist = array_keys($baselist);
         }
     }
     if ($baselist === false) {
         // We don't have $baselist cached, retrieve it. Retrieve $thislist again in any case.
         $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT cc.id, cc.sortorder, cc.name, cc.visible, cc.parent, cc.path, {$ctxselect}\n                    FROM {course_categories} cc\n                    JOIN {context} ctx ON cc.id = ctx.instanceid AND ctx.contextlevel = :contextcoursecat\n                    ORDER BY cc.sortorder";
         $rs = $DB->get_recordset_sql($sql, array('contextcoursecat' => CONTEXT_COURSECAT));
         $baselist = array();
         $thislist = array();
         foreach ($rs as $record) {
             // If the category's parent is not visible to the user, it is not visible as well.
             if (!$record->parent || isset($baselist[$record->parent])) {
                 $context = context_coursecat::instance($record->id);
                 if (!$record->visible && !has_capability('moodle/category:viewhiddencategories', $context)) {
                     // No cap to view category, added to neither $baselist nor $thislist
                     continue;
                 }
                 $baselist[$record->id] = array('name' => format_string($record->name, true, array('context' => $context)), 'path' => $record->path);
                 if (!empty($requiredcapability) && !has_all_capabilities($requiredcapability, $context)) {
                     // No required capability, added to $baselist but not to $thislist.
                     continue;
                 }
                 $thislist[] = $record->id;
             }
         }
         $rs->close();
         $coursecatcache->set($basecachekey, $baselist);
         if (!empty($requiredcapability)) {
             $coursecatcache->set($thiscachekey, join(',', $thislist));
         }
     } else {
         if ($thislist === false) {
             // We have $baselist cached but not $thislist. Simplier query is used to retrieve.
             $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT ctx.instanceid id, {$ctxselect}\n                    FROM {context} ctx WHERE ctx.contextlevel = :contextcoursecat";
             $contexts = $DB->get_records_sql($sql, array('contextcoursecat' => CONTEXT_COURSECAT));
             $thislist = array();
             foreach (array_keys($baselist) as $id) {
                 context_helper::preload_from_record($contexts[$id]);
                 if (has_all_capabilities($requiredcapability, context_coursecat::instance($id))) {
                     $thislist[] = $id;
                 }
             }
             $coursecatcache->set($thiscachekey, join(',', $thislist));
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:coursecatlib.php

示例4: make_categories_manager_list

/**
 * @param $list
 * @param $parents
 * @param string $requiredcapability
 * @param int $excludeid
 * @param null $category
 * @param string $path
 * @return mixed
 */
function make_categories_manager_list(&$list, &$parents, $requiredcapability = '', $excludeid = 0, $category = null, $path = "")
{
    $requiredcapability = '';
    // Initialize the arrays if needed.
    if (!is_array($list)) {
        $list = array();
    }
    if (!is_array($parents)) {
        $parents = array();
    }
    if (empty($category)) {
        // Start at the top level.
        $category = new stdClass();
        $category->id = 0;
    } else {
        // This is the excluded category, don't include it.
        if ($excludeid > 0 && $excludeid == $category->id) {
            return;
        }
        $context = context_coursecat::instance($category->id);
        $categoryname = format_string($category->name, true, array('context' => $context));
        // Update $path.
        if ($path) {
            $path = $path . ' / ' . $categoryname;
        } else {
            $path = $categoryname;
        }
        // Add this category to $list, if the permissions check out.
        if (empty($requiredcapability)) {
            $list[$category->id] = $path;
        } else {
            $requiredcapability = (array) $requiredcapability;
            if (has_all_capabilities($requiredcapability, $context)) {
                $list[$category->id] = $path;
            }
        }
    }
    // Add all the children recursively, while updating the parents array.
    if ($categories = get_child_manager_categories($category->id)) {
        foreach ($categories as $cat) {
            if (!empty($category->id)) {
                if (isset($parents[$category->id])) {
                    $parents[$cat->id] = $parents[$category->id];
                }
                $parents[$cat->id][] = $category->id;
            }
            make_categories_manager_list($list, $parents, $requiredcapability, $excludeid, $cat, $path);
        }
    }
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:59,代码来源:locallib.php

示例5: search

    /**
     * Executes the search
     *
     * @global moodle_database $DB
     * @return int The number of results
     */
    final public function search() {
        global $DB;
        if (!is_null($this->results)) {
            return $this->results;
        }

        $this->results = array();
        $this->totalcount = 0;
        $contextlevel = $this->get_itemcontextlevel();
        list($sql, $params) = $this->get_searchsql();
        $blocksz = 5000;
        $offs = 0;
        // Get total number, to avoid some incorrect iterations
        $countsql = preg_replace('/ORDER BY.*/', '', $sql);
        $totalcourses = $DB->count_records_sql("SELECT COUNT(*) FROM ($countsql) sel", $params);
        // User to be checked is always the same (usually null, get it form first element)
        $firstcap = reset($this->requiredcapabilities);
        $userid = isset($firstcap['user']) ? $firstcap['user'] : null;
        // Extract caps to check, this saves us a bunch of iterations
        $requiredcaps = array();
        foreach ($this->requiredcapabilities as $cap) {
            $requiredcaps[] = $cap['capability'];
        }
        // Iterate while we have records and haven't reached $this->maxresults.
        while ($totalcourses > $offs and $this->totalcount < self::$MAXRESULTS) {
            $resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
            foreach ($resultset as $result) {
                context_instance_preload($result);
                $context = get_context_instance($contextlevel, $result->id);
                if (count($requiredcaps) > 0) {
                    if (!has_all_capabilities($requiredcaps, $context, $userid)) {
                        continue;
                    }
                }
                // Check if we are over the limit.
                if ($this->totalcount+1 > self::$MAXRESULTS) {
                    $this->hasmoreresults = true;
                    break;
                }
                // If not, then continue.
                $this->totalcount++;
                $this->results[$result->id] = $result;
            }
            $offs += $blocksz;
        }

        return $this->totalcount;
    }
开发者ID:ncsu-delta,项目名称:moodle,代码行数:54,代码来源:restore_ui_components.php

示例6: make_editing_buttons

/**
 * Produces the editing buttons for a module
 *
 * @global core_renderer $OUTPUT
 * @staticvar type $str
 * @param stdClass $mod The module to produce editing buttons for
 * @param bool $absolute_ignored ignored - all links are absolute
 * @param bool $moveselect If true a move seleciton process is used (default true)
 * @param int $indent The current indenting
 * @param int $section The section to link back to
 * @return string XHTML for the editing buttons
 */
function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent = -1, $section = -1)
{
    global $CFG, $OUTPUT;
    static $str;
    $coursecontext = get_context_instance(CONTEXT_COURSE, $mod->course);
    $modcontext = get_context_instance(CONTEXT_MODULE, $mod->id);
    $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign');
    $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
    // no permission to edit anything
    if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) {
        return false;
    }
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = new stdClass();
        $str->assign = get_string("assignroles", 'role');
        $str->delete = get_string("delete");
        $str->move = get_string("move");
        $str->moveup = get_string("moveup");
        $str->movedown = get_string("movedown");
        $str->moveright = get_string("moveright");
        $str->moveleft = get_string("moveleft");
        $str->update = get_string("update");
        $str->duplicate = get_string("duplicate");
        $str->hide = get_string("hide");
        $str->show = get_string("show");
        $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone"));
        $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible"));
        $str->forcedgroupsnone = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsnone"));
        $str->forcedgroupsseparate = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->forcedgroupsvisible = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsvisible"));
    }
    $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
    if ($section >= 0) {
        $baseurl->param('sr', $section);
    }
    $actions = array();
    // leftright
    if ($hasmanageactivities) {
        if (right_to_left()) {
            // Exchange arrows on RTL
            $rightarrow = 't/left';
            $leftarrow = 't/right';
        } else {
            $rightarrow = 't/right';
            $leftarrow = 't/left';
        }
        if ($indent > 0) {
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')), new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_moveleft', 'title' => $str->moveleft));
        }
        if ($indent >= 0) {
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')), new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_moveright', 'title' => $str->moveright));
        }
    }
    // move
    if ($hasmanageactivities) {
        if ($moveselect) {
            $actions[] = new action_link(new moodle_url($baseurl, array('copy' => $mod->id)), new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_move', 'title' => $str->move));
        } else {
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'move' => '-1')), new pix_icon('t/up', $str->moveup, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_moveup', 'title' => $str->moveup));
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'move' => '1')), new pix_icon('t/down', $str->movedown, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_movedown', 'title' => $str->movedown));
        }
    }
    // Update
    if ($hasmanageactivities) {
        $actions[] = new action_link(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_update', 'title' => $str->update));
    }
    // Duplicate (require both target import caps to be able to duplicate, see modduplicate.php)
    if (has_all_capabilities($dupecaps, $coursecontext)) {
        $actions[] = new action_link(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_duplicate', 'title' => $str->duplicate));
    }
    // Delete
    if ($hasmanageactivities) {
        $actions[] = new action_link(new moodle_url($baseurl, array('delete' => $mod->id)), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_delete', 'title' => $str->delete));
    }
    // hideshow
    if (has_capability('moodle/course:activityvisibility', $modcontext)) {
        if ($mod->visible) {
            $actions[] = new action_link(new moodle_url($baseurl, array('hide' => $mod->id)), new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_hide', 'title' => $str->hide));
        } else {
            $actions[] = new action_link(new moodle_url($baseurl, array('show' => $mod->id)), new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_show', 'title' => $str->show));
        }
    }
    // groupmode
    if ($hasmanageactivities and $mod->groupmode !== false) {
        if ($mod->groupmode == SEPARATEGROUPS) {
            $groupmode = 0;
//.........这里部分代码省略.........
开发者ID:numbas,项目名称:moodle,代码行数:101,代码来源:lib.php

示例7: add_grade_form_elements

 /**
  * Add elements to grade form.
  *
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @param array $params
  * @return void
  */
 public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params)
 {
     global $USER, $CFG;
     $settings = $this->get_instance();
     $rownum = $params['rownum'];
     $last = $params['last'];
     $useridlistid = $params['useridlistid'];
     $userid = $params['userid'];
     $attemptnumber = $params['attemptnumber'];
     if (!$userid) {
         $cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist');
         if (!($useridlist = $cache->get($this->get_course_module()->id . '_' . $useridlistid))) {
             $useridlist = $this->get_grading_userid_list();
             $cache->set($this->get_course_module()->id . '_' . $useridlistid, $useridlist);
         }
     } else {
         $useridlist = array($userid);
         $rownum = 0;
         $useridlistid = '';
     }
     $userid = $useridlist[$rownum];
     $grade = $this->get_user_grade($userid, false, $attemptnumber);
     $submission = null;
     if ($this->get_instance()->teamsubmission) {
         $submission = $this->get_group_submission($userid, 0, false, $attemptnumber);
     } else {
         $submission = $this->get_user_submission($userid, false, $attemptnumber);
     }
     // Add advanced grading.
     $gradingdisabled = $this->grading_disabled($userid);
     $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
     $mform->addElement('header', 'gradeheader', get_string('grade'));
     if ($gradinginstance) {
         $gradingelement = $mform->addElement('grading', 'advancedgrading', get_string('grade') . ':', array('gradinginstance' => $gradinginstance));
         if ($gradingdisabled) {
             $gradingelement->freeze();
         } else {
             $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
             $mform->setType('advancedgradinginstanceid', PARAM_INT);
         }
     } else {
         // Use simple direct grading.
         if ($this->get_instance()->grade > 0) {
             $name = get_string('gradeoutof', 'assign', $this->get_instance()->grade);
             if (!$gradingdisabled) {
                 $gradingelement = $mform->addElement('text', 'grade', $name);
                 $mform->addHelpButton('grade', 'gradeoutofhelp', 'assign');
                 $mform->setType('grade', PARAM_RAW);
             } else {
                 $mform->addElement('hidden', 'grade', $name);
                 $mform->hardFreeze('grade');
                 $mform->setType('grade', PARAM_RAW);
                 $strgradelocked = get_string('gradelocked', 'assign');
                 $mform->addElement('static', 'gradedisabled', $name, $strgradelocked);
                 $mform->addHelpButton('gradedisabled', 'gradeoutofhelp', 'assign');
             }
         } else {
             $grademenu = array(-1 => get_string("nograde")) + make_grades_menu($this->get_instance()->grade);
             if (count($grademenu) > 1) {
                 $gradingelement = $mform->addElement('select', 'grade', get_string('grade') . ':', $grademenu);
                 // The grade is already formatted with format_float so it needs to be converted back to an integer.
                 if (!empty($data->grade)) {
                     $data->grade = (int) unformat_float($data->grade);
                 }
                 $mform->setType('grade', PARAM_INT);
                 if ($gradingdisabled) {
                     $gradingelement->freeze();
                 }
             }
         }
     }
     $gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, $userid);
     if (!empty($CFG->enableoutcomes)) {
         foreach ($gradinginfo->outcomes as $index => $outcome) {
             $options = make_grades_menu(-$outcome->scaleid);
             if ($outcome->grades[$userid]->locked) {
                 $options[0] = get_string('nooutcome', 'grades');
                 $mform->addElement('static', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options[$outcome->grades[$userid]->grade]);
             } else {
                 $options[''] = get_string('nooutcome', 'grades');
                 $attributes = array('id' => 'menuoutcome_' . $index);
                 $mform->addElement('select', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options, $attributes);
                 $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT);
                 $mform->setDefault('outcome_' . $index . '[' . $userid . ']', $outcome->grades[$userid]->grade);
             }
         }
     }
     $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall');
     if (has_all_capabilities($capabilitylist, $this->get_course_context())) {
         $urlparams = array('id' => $this->get_course()->id);
         $url = new moodle_url('/grade/report/grader/index.php', $urlparams);
         $usergrade = '-';
//.........这里部分代码省略.........
开发者ID:covex-nn,项目名称:moodle,代码行数:101,代码来源:locallib.php

示例8: defined

// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Link to user roles management.
 *
 * @package    tool_cohortroles
 * @copyright  2015 Damyon Wiese
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
// This tool's required capabilities.
$capabilities = ['moodle/cohort:view', 'moodle/role:manage'];
// Check if the user has all of the required capabilities.
$context = context_system::instance();
$hasaccess = has_all_capabilities($capabilities, $context);
// Add this admin page only if the user has all of the required capabilities.
if ($hasaccess) {
    $str = get_string('managecohortroles', 'tool_cohortroles');
    $url = new moodle_url('/admin/tool/cohortroles/index.php');
    $ADMIN->add('roles', new admin_externalpage('toolcohortroles', $str, $url, $capabilities));
}
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:settings.php

示例9: course_get_cm_edit_actions

/**
 * Returns the list of all editing actions that current user can perform on the module
 *
 * @param cm_info $mod The module to produce editing buttons for
 * @param int $indent The current indenting (default -1 means no move left-right actions)
 * @param int $sr The section to link back to (used for creating the links)
 * @return array array of action_link or pix_icon objects
 */
function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null)
{
    global $COURSE, $SITE;
    static $str;
    $coursecontext = context_course::instance($mod->course);
    $modcontext = context_module::instance($mod->id);
    $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign');
    $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
    // No permission to edit anything.
    if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) {
        return array();
    }
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = get_strings(array('delete', 'move', 'moveright', 'moveleft', 'editsettings', 'duplicate', 'hide', 'show'), 'moodle');
        $str->assign = get_string('assignroles', 'role');
        $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone"));
        $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible"));
    }
    $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
    if ($sr !== null) {
        $baseurl->param('sr', $sr);
    }
    $actions = array();
    // Update.
    if ($hasmanageactivities) {
        $actions['update'] = new action_menu_link_secondary(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/edit', $str->editsettings, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->editsettings, array('class' => 'editing_update', 'data-action' => 'update'));
    }
    // Indent.
    if ($hasmanageactivities && $indent >= 0) {
        $indentlimits = new stdClass();
        $indentlimits->min = 0;
        $indentlimits->max = 16;
        if (right_to_left()) {
            // Exchange arrows on RTL
            $rightarrow = 't/left';
            $leftarrow = 't/right';
        } else {
            $rightarrow = 't/right';
            $leftarrow = 't/left';
        }
        if ($indent >= $indentlimits->max) {
            $enabledclass = 'hidden';
        } else {
            $enabledclass = '';
        }
        $actions['moveright'] = new action_menu_link_secondary(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')), new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->moveright, array('class' => 'editing_moveright ' . $enabledclass, 'data-action' => 'moveright', 'data-keepopen' => true));
        if ($indent <= $indentlimits->min) {
            $enabledclass = 'hidden';
        } else {
            $enabledclass = '';
        }
        $actions['moveleft'] = new action_menu_link_secondary(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')), new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->moveleft, array('class' => 'editing_moveleft ' . $enabledclass, 'data-action' => 'moveleft', 'data-keepopen' => true));
    }
    // Hide/Show.
    if (has_capability('moodle/course:activityvisibility', $modcontext)) {
        if ($mod->visible) {
            $actions['hide'] = new action_menu_link_secondary(new moodle_url($baseurl, array('hide' => $mod->id)), new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->hide, array('class' => 'editing_hide', 'data-action' => 'hide'));
        } else {
            $actions['show'] = new action_menu_link_secondary(new moodle_url($baseurl, array('show' => $mod->id)), new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->show, array('class' => 'editing_show', 'data-action' => 'show'));
        }
    }
    // Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php)
    // Note that restoring on front page is never allowed.
    if ($mod->course != SITEID && has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) {
        $actions['duplicate'] = new action_menu_link_secondary(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->duplicate, array('class' => 'editing_duplicate', 'data-action' => 'duplicate', 'data-sr' => $sr));
    }
    // Groupmode.
    if ($hasmanageactivities && !$mod->coursegroupmodeforce) {
        if (plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
            if ($mod->effectivegroupmode == SEPARATEGROUPS) {
                $nextgroupmode = VISIBLEGROUPS;
                $grouptitle = $str->groupsseparate;
                $actionname = 'groupsseparate';
                $groupimage = 'i/groups';
            } else {
                if ($mod->effectivegroupmode == VISIBLEGROUPS) {
                    $nextgroupmode = NOGROUPS;
                    $grouptitle = $str->groupsvisible;
                    $actionname = 'groupsvisible';
                    $groupimage = 'i/groupv';
                } else {
                    $nextgroupmode = SEPARATEGROUPS;
                    $grouptitle = $str->groupsnone;
                    $actionname = 'groupsnone';
                    $groupimage = 'i/groupn';
                }
            }
            $actions[$actionname] = new action_menu_link_primary(new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $nextgroupmode)), new pix_icon($groupimage, null, 'moodle', array('class' => 'iconsmall')), $grouptitle, array('class' => 'editing_' . $actionname, 'data-action' => $actionname, 'data-nextgroupmode' => $nextgroupmode, 'aria-live' => 'assertive'));
        } else {
            $actions['nogroupsupport'] = new action_menu_filler();
//.........这里部分代码省略.........
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:101,代码来源:lib.php

示例10: get_assignments

 /**
  * Returns an array of courses the user is enrolled in, and for each course all of the assignments that the user can
  * view within that course.
  *
  * @param array $courseids An optional array of course ids. If provided only assignments within the given course
  * will be returned. If the user is not enrolled in a given course a warning will be generated and returned.
  * @param array $capabilities An array of additional capability checks you wish to be made on the course context.
  * @return An array of courses and warnings.
  * @since  Moodle 2.4
  */
 public static function get_assignments($courseids = array(), $capabilities = array())
 {
     global $USER, $DB;
     $params = self::validate_parameters(self::get_assignments_parameters(), array('courseids' => $courseids, 'capabilities' => $capabilities));
     $warnings = array();
     $fields = 'sortorder,shortname,fullname,timemodified';
     $courses = enrol_get_users_courses($USER->id, true, $fields);
     // Used to test for ids that have been requested but can't be returned.
     if (count($params['courseids']) > 0) {
         foreach ($params['courseids'] as $courseid) {
             if (!in_array($courseid, array_keys($courses))) {
                 unset($courses[$courseid]);
                 $warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => '2', 'message' => 'User is not enrolled or does not have requested capability');
             }
         }
     }
     foreach ($courses as $id => $course) {
         if (count($params['courseids']) > 0 && !in_array($id, $params['courseids'])) {
             unset($courses[$id]);
         }
         $context = context_course::instance($id);
         try {
             self::validate_context($context);
         } catch (Exception $e) {
             unset($courses[$id]);
             $warnings[] = array('item' => 'course', 'itemid' => $id, 'warningcode' => '1', 'message' => 'No access rights in course context ' . $e->getMessage() . $e->getTraceAsString());
             continue;
         }
         if (count($params['capabilities']) > 0 && !has_all_capabilities($params['capabilities'], $context)) {
             unset($courses[$id]);
         }
     }
     $extrafields = 'm.id as assignmentid, ' . 'm.course, ' . 'm.nosubmissions, ' . 'm.submissiondrafts, ' . 'm.sendnotifications, ' . 'm.sendlatenotifications, ' . 'm.sendstudentnotifications, ' . 'm.duedate, ' . 'm.allowsubmissionsfromdate, ' . 'm.grade, ' . 'm.timemodified, ' . 'm.completionsubmit, ' . 'm.cutoffdate, ' . 'm.teamsubmission, ' . 'm.requireallteammemberssubmit, ' . 'm.teamsubmissiongroupingid, ' . 'm.blindmarking, ' . 'm.revealidentities, ' . 'm.attemptreopenmethod, ' . 'm.maxattempts, ' . 'm.markingworkflow, ' . 'm.markingallocation, ' . 'm.requiresubmissionstatement';
     $coursearray = array();
     foreach ($courses as $id => $course) {
         $assignmentarray = array();
         // Get a list of assignments for the course.
         if ($modules = get_coursemodules_in_course('assign', $courses[$id]->id, $extrafields)) {
             foreach ($modules as $module) {
                 $context = context_module::instance($module->id);
                 try {
                     self::validate_context($context);
                     require_capability('mod/assign:view', $context);
                 } catch (Exception $e) {
                     $warnings[] = array('item' => 'module', 'itemid' => $module->id, 'warningcode' => '1', 'message' => 'No access rights in module context');
                     continue;
                 }
                 $configrecords = $DB->get_recordset('assign_plugin_config', array('assignment' => $module->assignmentid));
                 $configarray = array();
                 foreach ($configrecords as $configrecord) {
                     $configarray[] = array('id' => $configrecord->id, 'assignment' => $configrecord->assignment, 'plugin' => $configrecord->plugin, 'subtype' => $configrecord->subtype, 'name' => $configrecord->name, 'value' => $configrecord->value);
                 }
                 $configrecords->close();
                 $assignmentarray[] = array('id' => $module->assignmentid, 'cmid' => $module->id, 'course' => $module->course, 'name' => $module->name, 'nosubmissions' => $module->nosubmissions, 'submissiondrafts' => $module->submissiondrafts, 'sendnotifications' => $module->sendnotifications, 'sendlatenotifications' => $module->sendlatenotifications, 'sendstudentnotifications' => $module->sendstudentnotifications, 'duedate' => $module->duedate, 'allowsubmissionsfromdate' => $module->allowsubmissionsfromdate, 'grade' => $module->grade, 'timemodified' => $module->timemodified, 'completionsubmit' => $module->completionsubmit, 'cutoffdate' => $module->cutoffdate, 'teamsubmission' => $module->teamsubmission, 'requireallteammemberssubmit' => $module->requireallteammemberssubmit, 'teamsubmissiongroupingid' => $module->teamsubmissiongroupingid, 'blindmarking' => $module->blindmarking, 'revealidentities' => $module->revealidentities, 'attemptreopenmethod' => $module->attemptreopenmethod, 'maxattempts' => $module->maxattempts, 'markingworkflow' => $module->markingworkflow, 'markingallocation' => $module->markingallocation, 'requiresubmissionstatement' => $module->requiresubmissionstatement, 'configs' => $configarray);
             }
         }
         $coursearray[] = array('id' => $courses[$id]->id, 'fullname' => $courses[$id]->fullname, 'shortname' => $courses[$id]->shortname, 'timemodified' => $courses[$id]->timemodified, 'assignments' => $assignmentarray);
     }
     $result = array('courses' => $coursearray, 'warnings' => $warnings);
     return $result;
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:71,代码来源:externallib.php

示例11: get_assignments

 /**
  * Returns an array of courses the user is enrolled, and for each course all of the assignments that the user can
  * view within that course.
  *
  * @param array $courseids An optional array of course ids. If provided only assignments within the given course
  * will be returned. If the user is not enrolled in or can't view a given course a warning will be generated and returned.
  * @param array $capabilities An array of additional capability checks you wish to be made on the course context.
  * @param bool $includenotenrolledcourses Wheter to return courses that the user can see even if is not enroled in.
  * This requires the parameter $courseids to not be empty.
  * @return An array of courses and warnings.
  * @since  Moodle 2.4
  */
 public static function get_assignments($courseids = array(), $capabilities = array(), $includenotenrolledcourses = false)
 {
     global $USER, $DB, $CFG;
     $params = self::validate_parameters(self::get_assignments_parameters(), array('courseids' => $courseids, 'capabilities' => $capabilities, 'includenotenrolledcourses' => $includenotenrolledcourses));
     $warnings = array();
     $courses = array();
     $fields = 'sortorder,shortname,fullname,timemodified';
     // If the courseids list is empty, we return only the courses where the user is enrolled in.
     if (empty($params['courseids'])) {
         $courses = enrol_get_users_courses($USER->id, true, $fields);
         $courseids = array_keys($courses);
     } else {
         if ($includenotenrolledcourses) {
             // In this case, we don't have to check here for enrolmnents. Maybe the user can see the course even if is not enrolled.
             $courseids = $params['courseids'];
         } else {
             // We need to check for enrolments.
             $mycourses = enrol_get_users_courses($USER->id, true, $fields);
             $mycourseids = array_keys($mycourses);
             foreach ($params['courseids'] as $courseid) {
                 if (!in_array($courseid, $mycourseids)) {
                     unset($courses[$courseid]);
                     $warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => '2', 'message' => 'User is not enrolled or does not have requested capability');
                 } else {
                     $courses[$courseid] = $mycourses[$courseid];
                 }
             }
             $courseids = array_keys($courses);
         }
     }
     foreach ($courseids as $cid) {
         try {
             $context = context_course::instance($cid);
             self::validate_context($context);
             // Check if this course was already loaded (by enrol_get_users_courses).
             if (!isset($courses[$cid])) {
                 $courses[$cid] = get_course($cid);
             }
             $courses[$cid]->contextid = $context->id;
         } catch (Exception $e) {
             unset($courses[$cid]);
             $warnings[] = array('item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context ' . $e->getMessage());
             continue;
         }
         if (count($params['capabilities']) > 0 && !has_all_capabilities($params['capabilities'], $context)) {
             unset($courses[$cid]);
         }
     }
     $extrafields = 'm.id as assignmentid, ' . 'm.course, ' . 'm.nosubmissions, ' . 'm.submissiondrafts, ' . 'm.sendnotifications, ' . 'm.sendlatenotifications, ' . 'm.sendstudentnotifications, ' . 'm.duedate, ' . 'm.allowsubmissionsfromdate, ' . 'm.grade, ' . 'm.timemodified, ' . 'm.completionsubmit, ' . 'm.cutoffdate, ' . 'm.teamsubmission, ' . 'm.requireallteammemberssubmit, ' . 'm.teamsubmissiongroupingid, ' . 'm.blindmarking, ' . 'm.revealidentities, ' . 'm.attemptreopenmethod, ' . 'm.maxattempts, ' . 'm.markingworkflow, ' . 'm.markingallocation, ' . 'm.requiresubmissionstatement, ' . 'm.preventsubmissionnotingroup, ' . 'm.intro, ' . 'm.introformat';
     $coursearray = array();
     foreach ($courses as $id => $course) {
         $assignmentarray = array();
         // Get a list of assignments for the course.
         if ($modules = get_coursemodules_in_course('assign', $courses[$id]->id, $extrafields)) {
             foreach ($modules as $module) {
                 $context = context_module::instance($module->id);
                 try {
                     self::validate_context($context);
                     require_capability('mod/assign:view', $context);
                 } catch (Exception $e) {
                     $warnings[] = array('item' => 'module', 'itemid' => $module->id, 'warningcode' => '1', 'message' => 'No access rights in module context');
                     continue;
                 }
                 $assign = new assign($context, null, null);
                 // Get configurations for only enabled plugins.
                 $plugins = $assign->get_submission_plugins();
                 $plugins = array_merge($plugins, $assign->get_feedback_plugins());
                 $configarray = array();
                 foreach ($plugins as $plugin) {
                     if ($plugin->is_enabled() && $plugin->is_visible()) {
                         $configrecords = $plugin->get_config_for_external();
                         foreach ($configrecords as $name => $value) {
                             $configarray[] = array('plugin' => $plugin->get_type(), 'subtype' => $plugin->get_subtype(), 'name' => $name, 'value' => $value);
                         }
                     }
                 }
                 $assignment = array('id' => $module->assignmentid, 'cmid' => $module->id, 'course' => $module->course, 'name' => $module->name, 'nosubmissions' => $module->nosubmissions, 'submissiondrafts' => $module->submissiondrafts, 'sendnotifications' => $module->sendnotifications, 'sendlatenotifications' => $module->sendlatenotifications, 'sendstudentnotifications' => $module->sendstudentnotifications, 'duedate' => $module->duedate, 'allowsubmissionsfromdate' => $module->allowsubmissionsfromdate, 'grade' => $module->grade, 'timemodified' => $module->timemodified, 'completionsubmit' => $module->completionsubmit, 'cutoffdate' => $module->cutoffdate, 'teamsubmission' => $module->teamsubmission, 'requireallteammemberssubmit' => $module->requireallteammemberssubmit, 'teamsubmissiongroupingid' => $module->teamsubmissiongroupingid, 'blindmarking' => $module->blindmarking, 'revealidentities' => $module->revealidentities, 'attemptreopenmethod' => $module->attemptreopenmethod, 'maxattempts' => $module->maxattempts, 'markingworkflow' => $module->markingworkflow, 'markingallocation' => $module->markingallocation, 'requiresubmissionstatement' => $module->requiresubmissionstatement, 'preventsubmissionnotingroup' => $module->preventsubmissionnotingroup, 'configs' => $configarray);
                 // Return or not intro and file attachments depending on the plugin settings.
                 if ($assign->show_intro()) {
                     list($assignment['intro'], $assignment['introformat']) = external_format_text($module->intro, $module->introformat, $context->id, 'mod_assign', 'intro', null);
                     $assignment['introfiles'] = external_util::get_area_files($context->id, 'mod_assign', 'intro', false, false);
                     $assignment['introattachments'] = external_util::get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
                 }
                 if ($module->requiresubmissionstatement) {
                     // Submission statement is required, return the submission statement value.
                     $adminconfig = get_config('assign');
                     list($assignment['submissionstatement'], $assignment['submissionstatementformat']) = external_format_text($adminconfig->submissionstatement, FORMAT_MOODLE, $context->id, 'mod_assign', '', 0);
                 }
//.........这里部分代码省略.........
开发者ID:janeklb,项目名称:moodle,代码行数:101,代码来源:externallib.php

示例12: course_section_cm


//.........这里部分代码省略.........
         }
         $assetrestrictions .= "<div class='text'>{$groupinfo}</div>";
     }
     // TODO - ask what this is...
     if (!empty($mod->groupingid) && $canmanagegroups) {
         // Grouping label.
         $groupings = groups_get_all_groupings($mod->course);
         $assetrestrictions .= "<div class='text text-danger'>" . format_string($groupings[$mod->groupingid]->name) . "</div>";
         // TBD - add a title to show this is the Grouping...
     }
     $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $mod->context);
     // If the module isn't available, or we are a teacher (can view hidden activities) then get availability
     // info.
     $availabilityinfo = '';
     if (!$mod->available || $canviewhidden) {
         $availabilityinfo = $this->course_section_cm_availability($mod, $displayoptions);
     }
     if ($availabilityinfo !== '') {
         $conditionalinfo = get_string('conditional', 'theme_snap');
         $assetrestrictions .= "<div class='text text-danger'>{$conditionalinfo}.{$availabilityinfo}</div>";
     }
     $assetrestrictions = "<div class='snap-restrictions-meta'>{$assetrestrictions}</div>";
     $assetmeta .= $assetcompletionmeta . $assetrestrictions;
     // Build output.
     $postcontent = '<div class="snap-asset-meta" data-cmid="' . $mod->id . '">' . $mod->afterlink . $assetmeta . '</div>';
     $output .= $assetlink . $contentpart . $postcontent;
     // Bail at this point if we aren't using a supported format. (Folder view is only partially supported).
     $supported = ['folderview', 'topics', 'weeks', 'site'];
     if (!in_array($COURSE->format, $supported)) {
         return parent::course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions) . $assetmeta;
     }
     // Build up edit actions.
     $actions = '';
     $actionsadvanced = array();
     $coursecontext = context_course::instance($mod->course);
     $modcontext = context_module::instance($mod->id);
     $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
     if (has_capability('moodle/course:update', $modcontext)) {
         $str = get_strings(array('delete', 'move', 'duplicate', 'hide', 'show', 'roles'), 'moodle');
         // TODO - add snap strings here.
         // Move, Edit, Delete.
         if (has_capability('moodle/course:manageactivities', $modcontext)) {
             $movealt = get_string('move', 'theme_snap', $mod->get_formatted_name());
             $moveicon = "<img title='{$movealt}' aria-hidden='true' class='svg-icon' src='" . $this->output->pix_url('move', 'theme') . "' />";
             $editalt = get_string('edit', 'theme_snap', $mod->get_formatted_name());
             $editicon = "<img title='{$editalt}' alt='{$editalt}' class='svg-icon' src='" . $this->output->pix_url('edit', 'theme') . "'/>";
             $actions .= "<input id='snap-move-mod-{$mod->id}' class='js-snap-asset-move sr-only' type='checkbox'><label class='snap-asset-move' for='snap-move-mod-{$mod->id}'><span class='sr-only'>{$movealt}</span>{$moveicon}</label>";
             $actions .= "<a class='snap-edit-asset' href='" . new moodle_url($baseurl, array('update' => $mod->id)) . "'>{$editicon}</a>";
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('delete' => $mod->id)) . "'>{$str->delete}</a>";
         }
         // Hide/Show.
         if (has_capability('moodle/course:activityvisibility', $modcontext)) {
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('hide' => $mod->id)) . "' class='editing_hide js_snap_hide'>{$str->hide}</a>";
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('show' => $mod->id)) . "' class='editing_show js_snap_show'>{$str->show}</a>";
             // AX click to change.
         }
         // Duplicate.
         $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
         if (has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2) && plugin_supports('mod', $mod->modname, 'duplicate', true)) {
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('duplicate' => $mod->id)) . "' class='js_snap_duplicate'>{$str->duplicate}</a>";
         }
         // Asign roles.
         if (has_capability('moodle/role:assign', $modcontext)) {
             $actionsadvanced[] = "<a href='" . new moodle_url('/admin/roles/assign.php', array('contextid' => $modcontext->id)) . "'>{$str->roles}</a>";
         }
         // Give local plugins a chance to add icons.
         $localplugins = array();
         foreach (get_plugin_list_with_function('local', 'extend_module_editing_buttons') as $function) {
             $localplugins = array_merge($localplugins, $function($mod));
         }
         // TODO - pld string is far too long....
         $locallinks = '';
         foreach ($localplugins as $localplugin) {
             $url = $localplugin->url;
             $text = $localplugin->text;
             $class = $localplugin->attributes['class'];
             $actionsadvanced[] = "<a href='{$url}' class='{$class}'>{$text}</a>";
         }
     }
     $advancedactions = '';
     if (!empty($actionsadvanced)) {
         $moreicon = "<img title='" . get_string('more', 'theme_snap') . "' alt='" . get_string('more', 'theme_snap') . "' class='svg-icon' src='" . $this->output->pix_url('more', 'theme') . "'/>";
         $advancedactions = "<div class='dropdown snap-edit-more-dropdown'>\n                      <a href='#' class='dropdown-toggle snap-edit-asset-more' data-toggle='dropdown' aria-expanded='false' aria-haspopup='true'>{$moreicon}</a>\n                      <ul class='dropdown-menu'>";
         foreach ($actionsadvanced as $action) {
             $advancedactions .= "<li>{$action}</li>";
         }
         $advancedactions .= "</ul></div>";
     }
     // Add actions menu.
     if ($actions) {
         $output .= "<div class='snap-asset-actions' role='region' aria-label='actions'>";
         $output .= $actions . $advancedactions;
         $output .= "</div>";
     }
     $output .= "</div>";
     // Close .activityinstance.
     $output .= "</div>";
     // Close .asset-wrapper.
     return $output;
 }
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:101,代码来源:course_renderer.php

示例13: search

 /**
  * Executes the search
  *
  * @global moodle_database $DB
  * @return int The number of results
  */
 public final function search()
 {
     global $DB;
     if (!is_null($this->results)) {
         return $this->results;
     }
     $this->results = array();
     $this->totalcount = 0;
     $contextlevel = $this->get_itemcontextlevel();
     list($sql, $params) = $this->get_searchsql();
     // Get total number, to avoid some incorrect iterations.
     $countsql = preg_replace('/ORDER BY.*/', '', $sql);
     $totalcourses = $DB->count_records_sql("SELECT COUNT(*) FROM ({$countsql}) sel", $params);
     if ($totalcourses > 0) {
         // User to be checked is always the same (usually null, get it from first element).
         $firstcap = reset($this->requiredcapabilities);
         $userid = isset($firstcap['user']) ? $firstcap['user'] : null;
         // Extract caps to check, this saves us a bunch of iterations.
         $requiredcaps = array();
         foreach ($this->requiredcapabilities as $cap) {
             $requiredcaps[] = $cap['capability'];
         }
         // Iterate while we have records and haven't reached $this->maxresults.
         $resultset = $DB->get_recordset_sql($sql, $params);
         foreach ($resultset as $result) {
             context_helper::preload_from_record($result);
             $classname = context_helper::get_class_for_level($contextlevel);
             $context = $classname::instance($result->id);
             if (count($requiredcaps) > 0) {
                 if (!has_all_capabilities($requiredcaps, $context, $userid)) {
                     continue;
                 }
             }
             // Check if we are over the limit.
             if ($this->totalcount + 1 > $this->maxresults) {
                 $this->hasmoreresults = true;
                 break;
             }
             // If not, then continue.
             $this->totalcount++;
             $this->results[$result->id] = $result;
         }
         $resultset->close();
     }
     return $this->totalcount;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:52,代码来源:restore_ui_components.php

示例14: make_editing_buttons


//.........这里部分代码省略.........
        $str->moveleft = get_string("moveleft");
        $str->update = get_string("update");
        $str->duplicate = get_string("duplicate");
        $str->hide = get_string("hide");
        $str->show = get_string("show");
        $str->clicktochange = get_string("clicktochange");
        $str->forcedmode = get_string("forcedmode");
        $str->groupsnone = get_string("groupsnone");
        $str->groupsseparate = get_string("groupsseparate");
        $str->groupsvisible = get_string("groupsvisible");
        $sesskey = sesskey();
    }
    if ($section >= 0) {
        $section = '&amp;sr=' . $section;
        // Section return
    } else {
        $section = '';
    }
    if ($absolute) {
        $path = $CFG->wwwroot . '/course';
    } else {
        $path = '.';
    }
    if (has_capability('moodle/course:activityvisibility', $modcontext)) {
        if ($mod->visible) {
            $hideshow = '<a class="editing_hide" title="' . $str->hide . '" href="' . $path . '/mod.php?hide=' . $mod->id . '&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/hide') . '" class="iconsmall" ' . ' alt="' . $str->hide . '" /></a>' . "\n";
        } else {
            $hideshow = '<a class="editing_show" title="' . $str->show . '" href="' . $path . '/mod.php?show=' . $mod->id . '&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/show') . '" class="iconsmall" ' . ' alt="' . $str->show . '" /></a>' . "\n";
        }
    } else {
        $hideshow = '';
    }
    if ($mod->groupmode !== false) {
        if ($mod->groupmode == SEPARATEGROUPS) {
            $grouptitle = $str->groupsseparate;
            $groupclass = 'editing_groupsseparate';
            $groupimage = $OUTPUT->pix_url('t/groups') . '';
            $grouplink = $path . '/mod.php?id=' . $mod->id . '&amp;groupmode=0&amp;sesskey=' . $sesskey;
        } else {
            if ($mod->groupmode == VISIBLEGROUPS) {
                $grouptitle = $str->groupsvisible;
                $groupclass = 'editing_groupsvisible';
                $groupimage = $OUTPUT->pix_url('t/groupv') . '';
                $grouplink = $path . '/mod.php?id=' . $mod->id . '&amp;groupmode=1&amp;sesskey=' . $sesskey;
            } else {
                $grouptitle = $str->groupsnone;
                $groupclass = 'editing_groupsnone';
                $groupimage = $OUTPUT->pix_url('t/groupn') . '';
                $grouplink = $path . '/mod.php?id=' . $mod->id . '&amp;groupmode=2&amp;sesskey=' . $sesskey;
            }
        }
        if ($mod->groupmodelink) {
            $groupmode = '<a class="' . $groupclass . '" title="' . $grouptitle . ' (' . $str->clicktochange . ')" href="' . $grouplink . '">' . '<img src="' . $groupimage . '" class="iconsmall" ' . 'alt="' . $grouptitle . '" /></a>';
        } else {
            $groupmode = '<img title="' . $grouptitle . ' (' . $str->forcedmode . ')" ' . ' src="' . $groupimage . '" class="iconsmall" ' . 'alt="' . $grouptitle . '" />';
        }
    } else {
        $groupmode = "";
    }
    if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
        if ($moveselect) {
            $move = '<a class="editing_move" title="' . $str->move . '" href="' . $path . '/mod.php?copy=' . $mod->id . '&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" ' . ' alt="' . $str->move . '" /></a>' . "\n";
        } else {
            $move = '<a class="editing_moveup" title="' . $str->moveup . '" href="' . $path . '/mod.php?id=' . $mod->id . '&amp;move=-1&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/up') . '" class="iconsmall" ' . ' alt="' . $str->moveup . '" /></a>' . "\n" . '<a class="editing_movedown" title="' . $str->movedown . '" href="' . $path . '/mod.php?id=' . $mod->id . '&amp;move=1&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/down') . '" class="iconsmall" ' . ' alt="' . $str->movedown . '" /></a>' . "\n";
        }
    } else {
        $move = '';
    }
    $leftright = '';
    if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
        if (right_to_left()) {
            // Exchange arrows on RTL
            $rightarrow = 't/left';
            $leftarrow = 't/right';
        } else {
            $rightarrow = 't/right';
            $leftarrow = 't/left';
        }
        if ($indent > 0) {
            $leftright .= '<a class="editing_moveleft" title="' . $str->moveleft . '" href="' . $path . '/mod.php?id=' . $mod->id . '&amp;indent=-1&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url($leftarrow) . '" class="iconsmall" ' . ' alt="' . $str->moveleft . '" /></a>' . "\n";
        }
        if ($indent >= 0) {
            $leftright .= '<a class="editing_moveright" title="' . $str->moveright . '" href="' . $path . '/mod.php?id=' . $mod->id . '&amp;indent=1&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url($rightarrow) . '" class="iconsmall" ' . ' alt="' . $str->moveright . '" /></a>' . "\n";
        }
    }
    if (has_capability('moodle/course:managegroups', $modcontext)) {
        $context = get_context_instance(CONTEXT_MODULE, $mod->id);
        $assign = '<a class="editing_assign" title="' . $str->assign . '" href="' . $CFG->wwwroot . '/' . $CFG->admin . '/roles/assign.php?contextid=' . $context->id . '"><img src="' . $OUTPUT->pix_url('i/roles') . '" alt="' . $str->assign . '" class="iconsmall"/></a>';
    } else {
        $assign = '';
    }
    // Duplicate (require both target import caps to be able to duplicate, see modduplicate.php)
    $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
    if (has_all_capabilities($dupecaps, get_context_instance(CONTEXT_COURSE, $mod->course))) {
        $duplicatemodule = '<a class="editing_duplicate" title="' . $str->duplicate . '" href="' . $path . '/mod.php?duplicate=' . $mod->id . '&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/copy') . '" class="iconsmall" ' . ' alt="' . $str->duplicate . '" /></a>' . "\n";
    } else {
        $duplicatemodule = '';
    }
    return '<span class="commands">' . "\n" . $leftright . $move . '<a class="editing_update" title="' . $str->update . '" href="' . $path . '/mod.php?update=' . $mod->id . '&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" ' . ' alt="' . $str->update . '" /></a>' . "\n" . $duplicatemodule . '<a class="editing_delete" title="' . $str->delete . '" href="' . $path . '/mod.php?delete=' . $mod->id . '&amp;sesskey=' . $sesskey . $section . '"><img' . ' src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" ' . ' alt="' . $str->delete . '" /></a>' . "\n" . $hideshow . $groupmode . "\n" . $assign . '</span>';
}
开发者ID:hatone,项目名称:moodle,代码行数:101,代码来源:lib.php

示例15: make_editing_buttons

/**
 * Produces the editing buttons for a module
 *
 * @global core_renderer $OUTPUT
 * @staticvar type $str
 * @param stdClass $mod The module to produce editing buttons for
 * @param bool $absolute_ignored ignored - all links are absolute
 * @param bool $moveselect If true a move seleciton process is used (default true)
 * @param int $indent The current indenting
 * @param int $section The section to link back to
 * @return string XHTML for the editing buttons
 */
function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent = -1, $section = null)
{
    global $CFG, $OUTPUT, $COURSE;
    static $str;
    $coursecontext = context_course::instance($mod->course);
    $modcontext = context_module::instance($mod->id);
    $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign');
    $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
    // no permission to edit anything
    if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) {
        return false;
    }
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = new stdClass();
        $str->assign = get_string("assignroles", 'role');
        $str->delete = get_string("delete");
        $str->move = get_string("move");
        $str->moveup = get_string("moveup");
        $str->movedown = get_string("movedown");
        $str->moveright = get_string("moveright");
        $str->moveleft = get_string("moveleft");
        $str->update = get_string("update");
        $str->duplicate = get_string("duplicate");
        $str->hide = get_string("hide");
        $str->show = get_string("show");
        $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone"));
        $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible"));
        $str->forcedgroupsnone = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsnone"));
        $str->forcedgroupsseparate = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->forcedgroupsvisible = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsvisible"));
        $str->edittitle = get_string('edittitle', 'moodle');
    }
    $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
    if ($section !== null) {
        $baseurl->param('sr', $section);
    }
    $actions = array();
    // AJAX edit title
    if ($mod->modname !== 'label' && $hasmanageactivities && course_ajax_enabled($COURSE)) {
        $actions[] = new action_link(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/editstring', $str->edittitle, 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => '')), null, array('class' => 'editing_title', 'title' => $str->edittitle));
    }
    // leftright
    if ($hasmanageactivities) {
        if (right_to_left()) {
            // Exchange arrows on RTL
            $rightarrow = 't/left';
            $leftarrow = 't/right';
        } else {
            $rightarrow = 't/right';
            $leftarrow = 't/left';
        }
        if ($indent > 0) {
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')), new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_moveleft', 'title' => $str->moveleft));
        }
        if ($indent >= 0) {
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')), new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_moveright', 'title' => $str->moveright));
        }
    }
    // move
    if ($hasmanageactivities) {
        if ($moveselect) {
            $actions[] = new action_link(new moodle_url($baseurl, array('copy' => $mod->id)), new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_move', 'title' => $str->move));
        } else {
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'move' => '-1')), new pix_icon('t/up', $str->moveup, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_moveup', 'title' => $str->moveup));
            $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'move' => '1')), new pix_icon('t/down', $str->movedown, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_movedown', 'title' => $str->movedown));
        }
    }
    // Update
    if ($hasmanageactivities) {
        $actions[] = new action_link(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_update', 'title' => $str->update));
    }
    // Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php)
    if (has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) {
        $actions[] = new action_link(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_duplicate', 'title' => $str->duplicate));
    }
    // Delete
    if ($hasmanageactivities) {
        $actions[] = new action_link(new moodle_url($baseurl, array('delete' => $mod->id)), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_delete', 'title' => $str->delete));
    }
    // hideshow
    if (has_capability('moodle/course:activityvisibility', $modcontext)) {
        if ($mod->visible) {
            $actions[] = new action_link(new moodle_url($baseurl, array('hide' => $mod->id)), new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_hide', 'title' => $str->hide));
        } else {
            $actions[] = new action_link(new moodle_url($baseurl, array('show' => $mod->id)), new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_show', 'title' => $str->show));
        }
//.........这里部分代码省略.........
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:lib.php


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