Exemplo n.º 1
0
 /**
  * Defines the form.
  */
 public function definition()
 {
     $mform = $this->_form;
     $this->coursecat = $this->_customdata;
     $categorycontext = context_coursecat::instance($this->coursecat->id);
     $categoryname = $this->coursecat->get_formatted_name();
     // Check permissions, to see if it OK to give the option to delete
     // the contents, rather than move elsewhere.
     $candeletecontent = $this->coursecat->can_delete_full();
     // Get the list of categories we might be able to move to.
     $displaylist = $this->coursecat->move_content_targets_list();
     // Now build the options.
     $options = array();
     if ($displaylist) {
         $options[0] = get_string('movecontentstoanothercategory');
     }
     if ($candeletecontent) {
         $options[1] = get_string('deleteallcannotundo');
     }
     if (empty($options)) {
         print_error('youcannotdeletecategory', 'error', 'index.php', $categoryname);
     }
     // Now build the form.
     $mform->addElement('header', 'general', get_string('categorycurrentcontents', '', $categoryname));
     // Describe the contents of this category.
     $contents = '';
     if ($this->coursecat->has_children()) {
         $contents .= '<li>' . get_string('subcategories') . '</li>';
     }
     if ($this->coursecat->has_courses()) {
         $contents .= '<li>' . get_string('courses') . '</li>';
     }
     if (question_context_has_any_questions($categorycontext)) {
         $contents .= '<li>' . get_string('questionsinthequestionbank') . '</li>';
     }
     if (!empty($contents)) {
         $mform->addElement('static', 'emptymessage', get_string('thiscategorycontains'), html_writer::tag('ul', $contents));
     } else {
         $mform->addElement('static', 'emptymessage', '', get_string('deletecategoryempty'));
     }
     // Give the options for what to do.
     $mform->addElement('select', 'fulldelete', get_string('whattodo'), $options);
     if (count($options) == 1) {
         $optionkeys = array_keys($options);
         $option = reset($optionkeys);
         $mform->hardFreeze('fulldelete');
         $mform->setConstant('fulldelete', $option);
     }
     if ($displaylist) {
         $mform->addElement('select', 'newparent', get_string('movecategorycontentto'), $displaylist);
         if (in_array($this->coursecat->parent, $displaylist)) {
             $mform->setDefault('newparent', $this->coursecat->parent);
         }
         $mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
     }
     $mform->addElement('hidden', 'categoryid', $this->coursecat->id);
     $mform->setType('categoryid', PARAM_ALPHANUM);
     $mform->addElement('hidden', 'action', 'deletecategory');
     $mform->setType('action', PARAM_ALPHANUM);
     $mform->addElement('hidden', 'sure');
     // This gets set by default to ensure that if the user changes it manually we can detect it.
     $mform->setDefault('sure', md5(serialize($this->coursecat)));
     $mform->setType('sure', PARAM_ALPHANUM);
     $this->add_action_buttons(true, get_string('delete'));
 }
Exemplo n.º 2
0
 /**
  * Returns an array of actions that can be performed upon a category being shown in a list.
  *
  * @param \coursecat $category
  * @return array
  */
 public static function get_category_listitem_actions(\coursecat $category)
 {
     global $PAGE;
     $baseurl = new \moodle_url('/course/management.php', array('categoryid' => $category->id, 'sesskey' => \sesskey()));
     $actions = array();
     // Edit.
     if ($category->can_edit()) {
         $actions['edit'] = array('url' => new \moodle_url('/course/editcategory.php', array('id' => $category->id)), 'icon' => new \pix_icon('t/edit', new \lang_string('edit')), 'string' => new \lang_string('edit'));
     }
     // Show/Hide.
     if ($category->can_change_visibility()) {
         // We always show both icons and then just toggle the display of the invalid option with CSS.
         $actions['hide'] = array('url' => new \moodle_url($baseurl, array('action' => 'hidecategory')), 'icon' => new \pix_icon('t/hide', new \lang_string('hide')), 'string' => new \lang_string('hide'));
         $actions['show'] = array('url' => new \moodle_url($baseurl, array('action' => 'showcategory')), 'icon' => new \pix_icon('t/show', new \lang_string('show')), 'string' => new \lang_string('show'));
     }
     // Move up/down.
     if ($category->can_change_sortorder()) {
         $actions['moveup'] = array('url' => new \moodle_url($baseurl, array('action' => 'movecategoryup')), 'icon' => new \pix_icon('t/up', new \lang_string('up')), 'string' => new \lang_string('up'));
         $actions['movedown'] = array('url' => new \moodle_url($baseurl, array('action' => 'movecategorydown')), 'icon' => new \pix_icon('t/down', new \lang_string('down')), 'string' => new \lang_string('down'));
     }
     if ($category->can_create_subcategory()) {
         $actions['createnewsubcategory'] = array('url' => new \moodle_url('/course/editcategory.php', array('parent' => $category->id)), 'icon' => new \pix_icon('i/withsubcat', new \lang_string('createnewsubcategory')), 'string' => new \lang_string('createnewsubcategory'));
     }
     // Resort.
     if ($category->can_resort_subcategories() && $category->has_children()) {
         $actions['resortbyname'] = array('url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'name')), 'icon' => new \pix_icon('t/sort', new \lang_string('sort')), 'string' => new \lang_string('resortsubcategoriesby', 'moodle', get_string('categoryname')));
         $actions['resortbynamedesc'] = array('url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'namedesc')), 'icon' => new \pix_icon('t/sort', new \lang_string('sort')), 'string' => new \lang_string('resortsubcategoriesbyreverse', 'moodle', get_string('categoryname')));
         $actions['resortbyidnumber'] = array('url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'idnumber')), 'icon' => new \pix_icon('t/sort', new \lang_string('sort')), 'string' => new \lang_string('resortsubcategoriesby', 'moodle', get_string('idnumbercoursecategory')));
         $actions['resortbyidnumberdesc'] = array('url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'idnumberdesc')), 'icon' => new \pix_icon('t/sort', new \lang_string('sort')), 'string' => new \lang_string('resortsubcategoriesbyreverse', 'moodle', get_string('idnumbercoursecategory')));
     }
     // Delete.
     if ($category->can_delete_full()) {
         $actions['delete'] = array('url' => new \moodle_url($baseurl, array('action' => 'deletecategory')), 'icon' => new \pix_icon('t/delete', new \lang_string('delete')), 'string' => new \lang_string('delete'));
     }
     // Assign roles.
     if ($category->can_review_roles()) {
         $actions['assignroles'] = array('url' => new \moodle_url('/admin/roles/assign.php', array('contextid' => $category->get_context()->id, 'returnurl' => $PAGE->url->out_as_local_url(false))), 'icon' => new \pix_icon('t/assignroles', new \lang_string('assignroles', 'role')), 'string' => new \lang_string('assignroles', 'role'));
     }
     // Permissions.
     if ($category->can_review_permissions()) {
         $actions['permissions'] = array('url' => new \moodle_url('/admin/roles/permissions.php', array('contextid' => $category->get_context()->id, 'returnurl' => $PAGE->url->out_as_local_url(false))), 'icon' => new \pix_icon('i/permissions', new \lang_string('permissions', 'role')), 'string' => new \lang_string('permissions', 'role'));
     }
     // Check permissions.
     if ($category->can_review_permissions()) {
         $actions['checkroles'] = array('url' => new \moodle_url('/admin/roles/check.php', array('contextid' => $category->get_context()->id, 'returnurl' => $PAGE->url->out_as_local_url(false))), 'icon' => new \pix_icon('i/checkpermissions', new \lang_string('checkpermissions', 'role')), 'string' => new \lang_string('checkpermissions', 'role'));
     }
     // Cohorts.
     if ($category->can_review_cohorts()) {
         $actions['cohorts'] = array('url' => new \moodle_url('/cohort/index.php', array('contextid' => $category->get_context()->id)), 'icon' => new \pix_icon('t/cohort', new \lang_string('cohorts', 'cohort')), 'string' => new \lang_string('cohorts', 'cohort'));
     }
     // Filters.
     if ($category->can_review_filters()) {
         $actions['filters'] = array('url' => new \moodle_url('/filter/manage.php', array('contextid' => $category->get_context()->id, 'return' => 'management')), 'icon' => new \pix_icon('i/filter', new \lang_string('filters', 'admin')), 'string' => new \lang_string('filters', 'admin'));
     }
     if ($category->can_restore_courses_into()) {
         $actions['restore'] = array('url' => new \moodle_url('/backup/restorefile.php', array('contextid' => $category->get_context()->id)), 'icon' => new \pix_icon('i/restore', new \lang_string('restorecourse', 'admin')), 'string' => new \lang_string('restorecourse', 'admin'));
     }
     return $actions;
 }