Exemplo n.º 1
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;
 }