本文整理汇总了PHP中can_edit_in_category函数的典型用法代码示例。如果您正苦于以下问题:PHP can_edit_in_category函数的具体用法?PHP can_edit_in_category怎么用?PHP can_edit_in_category使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了can_edit_in_category函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_category_settings
/**
* Loads category specific settings in the navigation
*
* @return navigation_node
*/
protected function load_category_settings()
{
global $CFG;
// We can land here while being in the context of a block, in which case we
// should get the parent context which should be the category one. See self::initialise().
if ($this->context->contextlevel == CONTEXT_BLOCK) {
$catcontext = $this->context->get_parent_context();
} else {
$catcontext = $this->context;
}
// Let's make sure that we always have the right context when getting here.
if ($catcontext->contextlevel != CONTEXT_COURSECAT) {
throw new coding_exception('Unexpected context while loading category settings.');
}
$categorynode = $this->add($catcontext->get_context_name(), null, null, null, 'categorysettings');
$categorynode->nodetype = navigation_node::NODETYPE_BRANCH;
$categorynode->force_open();
if (can_edit_in_category($catcontext->instanceid)) {
$url = new moodle_url('/course/management.php', array('categoryid' => $catcontext->instanceid));
$editstring = get_string('managecategorythis');
$categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
}
if (has_capability('moodle/category:manage', $catcontext)) {
$editurl = new moodle_url('/course/editcategory.php', array('id' => $catcontext->instanceid));
$categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', ''));
$addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $catcontext->instanceid));
$categorynode->add(get_string('addsubcategory'), $addsubcaturl, self::TYPE_SETTING, null, 'addsubcat', new pix_icon('i/withsubcat', ''));
}
// Assign local roles
$assignableroles = get_assignable_roles($catcontext);
if (!empty($assignableroles)) {
$assignurl = new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', ''));
}
// Override roles
if (has_capability('moodle/role:review', $catcontext) or count(get_overridable_roles($catcontext)) > 0) {
$url = new moodle_url('/' . $CFG->admin . '/roles/permissions.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING, null, 'permissions', new pix_icon('i/permissions', ''));
}
// Check role permissions
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $catcontext)) {
$url = new moodle_url('/' . $CFG->admin . '/roles/check.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', ''));
}
// Cohorts
if (has_any_capability(array('moodle/cohort:view', 'moodle/cohort:manage'), $catcontext)) {
$categorynode->add(get_string('cohorts', 'cohort'), new moodle_url('/cohort/index.php', array('contextid' => $catcontext->id)), self::TYPE_SETTING, null, 'cohort', new pix_icon('i/cohort', ''));
}
// Manage filters
if (has_capability('moodle/filter:manage', $catcontext) && count(filter_get_available_in_context($catcontext)) > 0) {
$url = new moodle_url('/filter/manage.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filters', new pix_icon('i/filter', ''));
}
// Restore.
if (has_capability('moodle/restore:restorecourse', $catcontext)) {
$url = new moodle_url('/backup/restorefile.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('restorecourse', 'admin'), $url, self::TYPE_SETTING, null, 'restorecourse', new pix_icon('i/restore', ''));
}
// Let plugins hook into category settings navigation.
$pluginsfunction = get_plugins_with_function('extend_navigation_category_settings', 'lib.php');
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($categorynode, $catcontext);
}
}
return $categorynode;
}
示例2: optional_param
require_once "../config.php";
require_once "lib.php";
$categoryedit = optional_param('categoryedit', -1, PARAM_BOOL);
$delete = optional_param('delete', 0, PARAM_INT);
$hide = optional_param('hide', 0, PARAM_INT);
$show = optional_param('show', 0, PARAM_INT);
$move = optional_param('move', 0, PARAM_INT);
$moveto = optional_param('moveto', -1, PARAM_INT);
$moveup = optional_param('moveup', 0, PARAM_INT);
$movedown = optional_param('movedown', 0, PARAM_INT);
$site = get_site();
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$PAGE->set_url('/course/index.php');
$PAGE->set_context($systemcontext);
$PAGE->set_pagelayout('admin');
if (can_edit_in_category()) {
if ($categoryedit !== -1) {
$USER->editing = $categoryedit;
}
require_login();
$adminediting = $PAGE->user_is_editing();
} else {
if ($CFG->forcelogin) {
require_login();
}
$adminediting = false;
}
$stradministration = get_string('administration');
$strcategories = 'Materias';
$strcategory = 'Materia';
$strcourses = get_string('courses');
示例3: update_category_button
/**
* Prints the turn editing on/off button on course/index.php or course/category.php.
*
* @param integer $categoryid The id of the category we are showing, or 0 for system context.
* @return string HTML of the editing button, or empty string, if this user is not allowed
* to see it.
*/
function update_category_button($categoryid = 0)
{
global $CFG, $PAGE, $OUTPUT;
// Check permissions.
if (!can_edit_in_category($categoryid)) {
return '';
}
// Work out the appropriate action.
if ($PAGE->user_is_editing()) {
$label = get_string('turneditingoff');
$edit = 'off';
} else {
$label = get_string('turneditingon');
$edit = 'on';
}
// Generate the button HTML.
$options = array('categoryedit' => $edit, 'sesskey' => sesskey());
if ($categoryid) {
$options['id'] = $categoryid;
$page = 'category.php';
} else {
$page = 'index.php';
}
return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
}
示例4: print_error
if ($movecourse->category != $id) {
print_error('coursedoesnotbelongtocategory');
}
$DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id' => $movecourse->id));
$DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id' => $swapcourse->id));
}
}
}
// End of editing stuff
// Print headings
$numcategories = $DB->count_records('course_categories');
$stradministration = get_string('administration');
$strcategories = get_string('categories');
$strcategory = get_string('category');
$strcourses = get_string('courses');
if ($editingon && can_edit_in_category()) {
// Integrate into the admin tree only if the user can edit categories at the top level,
// otherwise the admin block does not appear to this user, and you get an error.
require_once $CFG->libdir . '/adminlib.php';
admin_externalpage_setup('coursemgmt', '', $urlparams, $CFG->wwwroot . '/course/category.php');
$PAGE->set_context($context);
// Ensure that we are actually showing blocks etc for the cat context
$settingsnode = $PAGE->settingsnav->find_active_node();
if ($settingsnode) {
$settingsnode->make_inactive();
$settingsnode->force_open();
$PAGE->navbar->add($settingsnode->text, $settingsnode->action);
}
echo $OUTPUT->header();
} else {
$PAGE->set_title("{$site->shortname}: {$category->name}");
示例5: update_category_button
/**
* Prints the turn editing on/off button on course/index.php or course/category.php.
*
* @deprecated since 2.5
*
* @param integer $categoryid The id of the category we are showing, or 0 for system context.
* @return string HTML of the editing button, or empty string, if this user is not allowed
* to see it.
*/
function update_category_button($categoryid = 0)
{
global $CFG, $PAGE, $OUTPUT;
debugging('Function update_category_button() is deprecated. Pages to view ' . 'and edit courses are now separate and no longer depend on editing mode.', DEBUG_DEVELOPER);
// Check permissions.
if (!can_edit_in_category($categoryid)) {
return '';
}
// Work out the appropriate action.
if ($PAGE->user_is_editing()) {
$label = get_string('turneditingoff');
$edit = 'off';
} else {
$label = get_string('turneditingon');
$edit = 'on';
}
// Generate the button HTML.
$options = array('categoryedit' => $edit, 'sesskey' => sesskey());
if ($categoryid) {
$options['id'] = $categoryid;
$page = 'category.php';
} else {
$page = 'index.php';
}
return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
}
示例6: course_category
/**
* Renders HTML to display particular course category - list of it's subcategories and courses
*
* Invoked from /course/index.php
*
* @param int|stdClass|coursecat $category
*/
public function course_category($category)
{
global $CFG;
require_once $CFG->libdir . '/coursecatlib.php';
$coursecat = coursecat::get(is_object($category) ? $category->id : $category);
$site = get_site();
$output = '';
if (can_edit_in_category($coursecat->id)) {
// Add 'Manage' button if user has permissions to edit this category.
$managebutton = $this->single_button(new moodle_url('/course/management.php', array('categoryid' => $coursecat->id)), get_string('managecourses'), 'get');
$this->page->set_button($managebutton);
}
if (!$coursecat->id) {
if (coursecat::count_all() == 1) {
// There exists only one category in the system, do not display link to it
$coursecat = coursecat::get_default();
$strfulllistofcourses = get_string('fulllistofcourses');
$this->page->set_title("{$site->shortname}: {$strfulllistofcourses}");
} else {
$strcategories = get_string('categories');
$this->page->set_title("{$site->shortname}: {$strcategories}");
}
} else {
$this->page->set_title("{$site->shortname}: " . $coursecat->get_formatted_name());
// Print the category selector
$output .= html_writer::start_tag('div', array('class' => 'categorypicker'));
$select = new single_select(new moodle_url('/course/index.php'), 'categoryid', coursecat::make_categories_list(), $coursecat->id, null, 'switchcategory');
$select->set_label(get_string('categories') . ':');
$output .= $this->render($select);
$output .= html_writer::end_tag('div');
// .categorypicker
}
// Print current category description
$chelper = new coursecat_helper();
if ($description = $chelper->get_category_formatted_description($coursecat)) {
$output .= $this->box($description, array('class' => 'generalbox info'));
}
// Prepare parameters for courses and categories lists in the tree
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO)->set_attributes(array('class' => 'category-browse category-browse-' . $coursecat->id));
$coursedisplayoptions = array();
$catdisplayoptions = array();
$browse = optional_param('browse', null, PARAM_ALPHA);
$perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$baseurl = new moodle_url('/course/index.php');
if ($coursecat->id) {
$baseurl->param('categoryid', $coursecat->id);
}
if ($perpage != $CFG->coursesperpage) {
$baseurl->param('perpage', $perpage);
}
$coursedisplayoptions['limit'] = $perpage;
$catdisplayoptions['limit'] = $perpage;
if ($browse === 'courses' || !$coursecat->has_children()) {
$coursedisplayoptions['offset'] = $page * $perpage;
$coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses'));
$catdisplayoptions['nodisplay'] = true;
$catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories'));
$catdisplayoptions['viewmoretext'] = new lang_string('viewallsubcategories');
} else {
if ($browse === 'categories' || !$coursecat->has_courses()) {
$coursedisplayoptions['nodisplay'] = true;
$catdisplayoptions['offset'] = $page * $perpage;
$catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories'));
$coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses'));
$coursedisplayoptions['viewmoretext'] = new lang_string('viewallcourses');
} else {
// we have a category that has both subcategories and courses, display pagination separately
$coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1));
$catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1));
}
}
$chelper->set_courses_display_options($coursedisplayoptions)->set_categories_display_options($catdisplayoptions);
// Add course search form.
$output .= $this->course_search_form();
// Display course category tree.
$output .= $this->coursecat_tree($chelper, $coursecat);
// Add action buttons
$output .= $this->container_start('buttons');
$context = get_category_or_system_context($coursecat->id);
if (has_capability('moodle/course:create', $context)) {
// Print link to create a new course, for the 1st available category.
if ($coursecat->id) {
$url = new moodle_url('/course/edit.php', array('category' => $coursecat->id, 'returnto' => 'category'));
} else {
$url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat'));
}
$output .= $this->single_button($url, get_string('addnewcourse'), 'get');
}
ob_start();
if (coursecat::count_all() == 1) {
print_course_request_buttons(context_system::instance());
} else {
//.........这里部分代码省略.........
示例7: count
if ($i >= $firstcourse && $i <= $lastcourse) {
$courses[$course->id] = $course;
}
$i++;
}
}
$totalcount = count($courselist);
} else {
if (!empty($searchterm)) {
// Donot do search for empty search request.
$courses = get_courses_search($searchterms, "fullname ASC", $page, $perpage, $totalcount);
}
}
$searchform = '';
// Turn editing should be visible if user have system or category level capability
if (!empty($courses) && (can_edit_in_category() || !empty($usercatlist))) {
if ($PAGE->user_is_editing()) {
$string = new lang_string("turneditingoff");
$edit = "off";
} else {
$string = new lang_string("turneditingon");
$edit = "on";
}
$params = array_merge($urlparams, array('sesskey' => sesskey(), 'edit' => $edit));
$aurl = new moodle_url("{$CFG->wwwroot}/course/search.php", $params);
$searchform = $OUTPUT->single_button($aurl, $string, 'get');
} else {
$searchform = print_course_search($search, true, "navbar");
}
$PAGE->navbar->add($strcourses, new moodle_url('/course/index.php'));
$PAGE->navbar->add($strsearch, new moodle_url('/course/search.php'));
示例8: load_category_settings
/**
* Loads category specific settings in the navigation
*
* @return navigation_node
*/
protected function load_category_settings()
{
global $CFG;
$categorynode = $this->add($this->context->get_context_name(), null, null, null, 'categorysettings');
$categorynode->force_open();
if (can_edit_in_category($this->context->instanceid)) {
$url = new moodle_url('/course/management.php', array('categoryid' => $this->context->instanceid));
$editstring = get_string('managecategorythis');
$categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
}
if (has_capability('moodle/category:manage', $this->context)) {
$editurl = new moodle_url('/course/editcategory.php', array('id' => $this->context->instanceid));
$categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', ''));
$addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $this->context->instanceid));
$categorynode->add(get_string('addsubcategory'), $addsubcaturl, self::TYPE_SETTING, null, 'addsubcat', new pix_icon('i/withsubcat', ''));
}
// Assign local roles
if (has_capability('moodle/role:assign', $this->context)) {
$assignurl = new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', ''));
}
// Override roles
if (has_capability('moodle/role:review', $this->context) or count(get_overridable_roles($this->context)) > 0) {
$url = new moodle_url('/' . $CFG->admin . '/roles/permissions.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING, null, 'permissions', new pix_icon('i/permissions', ''));
}
// Check role permissions
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $this->context)) {
$url = new moodle_url('/' . $CFG->admin . '/roles/check.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', ''));
}
// Cohorts
if (has_any_capability(array('moodle/cohort:view', 'moodle/cohort:manage'), $this->context)) {
$categorynode->add(get_string('cohorts', 'cohort'), new moodle_url('/cohort/index.php', array('contextid' => $this->context->id)), self::TYPE_SETTING, null, 'cohort', new pix_icon('i/cohort', ''));
}
// Manage filters
if (has_capability('moodle/filter:manage', $this->context) && count(filter_get_available_in_context($this->context)) > 0) {
$url = new moodle_url('/filter/manage.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filters', new pix_icon('i/filter', ''));
}
return $categorynode;
}
示例9: lang_string
$strsearch = new lang_string("search");
$strsearchresults = new lang_string("searchresults");
$strnovalidcourses = new lang_string('novalidcourses');
$PAGE->navbar->add($strcourses, new moodle_url('/course/index.php'));
$PAGE->navbar->add($strsearch, new moodle_url('/course/search.php'));
if (!empty($search)) {
$PAGE->navbar->add(s($search));
}
if (empty($searchcriteria)) {
// no search criteria specified, print page with just search form
$PAGE->set_title("{$site->fullname} : {$strsearch}");
} else {
// this is search results page
$PAGE->set_title("{$site->fullname} : {$strsearchresults}");
// Link to manage search results should be visible if user have system or category level capability
if (can_edit_in_category() || !empty($usercatlist)) {
$aurl = new moodle_url('/course/management.php', $searchcriteria);
$searchform = $OUTPUT->single_button($aurl, get_string('managecourses'), 'get');
} else {
$searchform = $courserenderer->course_search_form($search, 'navbar');
}
$PAGE->set_button($searchform);
// Trigger event, courses searched.
$eventparams = array('context' => $PAGE->context, 'other' => array('query' => $search));
$event = \core\event\courses_searched::create($eventparams);
$event->trigger();
}
$PAGE->set_heading($site->fullname);
echo $OUTPUT->header();
echo $courserenderer->search_courses($searchcriteria);
echo $OUTPUT->footer();