MDL-42629 course: fixed up create category management actions
authorSam Hemelryk <sam@moodle.com>
Thu, 31 Oct 2013 06:21:54 +0000 (14:21 +0800)
committerSam Hemelryk <sam@moodle.com>
Tue, 5 Nov 2013 01:49:13 +0000 (09:49 +0800)
course/classes/management/helper.php
course/classes/management_renderer.php
lang/en/moodle.php

index ce02da9..3fc3086 100644 (file)
@@ -208,6 +208,14 @@ class helper {
             );
         }
 
+        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(
index f54e445..2ceb4b9 100644 (file)
@@ -257,39 +257,17 @@ class core_course_management_renderer extends plugin_renderer_base {
      */
     public function category_listing_actions(coursecat $category = null) {
         $actions = array();
-        $createtoplevel = coursecat::can_create_top_level_category();
-        $createsubcategory = $category && $category->can_create_subcategory();
+
+        $cancreatecategory = $category && $category->can_create_subcategory();
+        $cancreatecategory = $cancreatecategory || coursecat::can_create_top_level_category();
         if ($category === null) {
             $category = coursecat::get(0);
         }
 
         $hasitems = false;
-        if ($createtoplevel) {
-            $hasitems = true;
-            $menu = new action_menu;
-            if ($createtoplevel) {
-                $url = new moodle_url('/course/editcategory.php', array('parent' => 0));
-                $menu->add(new action_menu_link_secondary(
-                    $url,
-                    null,
-                    get_string('toplevelcategory')
-                ));
-            }
-            if ($createsubcategory) {
-                $url = new moodle_url('/course/editcategory.php', array('parent' => $category->id));
-                $attributes = array(
-                    'title' => get_string('createsubcategoryof', 'moodle', $category->get_formatted_name())
-                );
-                $menu->add(new action_menu_link_secondary(
-                    $url,
-                    null,
-                    get_string('subcategory'),
-                    $attributes
-                ));
-            }
-            $menu->actiontext = get_string('createnew');
-            $menu->actionicon = new pix_icon('t/contextmenu', ' ', 'moodle', array('class' => 'iconsmall', 'title' => ''));
-            $actions[] = $this->render($menu);
+        if ($cancreatecategory) {
+            $url = new moodle_url('/course/editcategory.php', array('parent' => $category->id));
+            $actions[] = html_writer::link($url, get_string('createnewcategory'));
         }
         if (coursecat::can_approve_course_requests()) {
             $actions[] = html_writer::link(new moodle_url('/course/pending.php'), get_string('coursespending'));
index 938a58b..e805453 100644 (file)
@@ -377,6 +377,8 @@ $string['createaccount'] = 'Create my new account';
 $string['createcategory'] = 'Create category';
 $string['createfolder'] = 'Create a folder in {$a}';
 $string['createnew'] = 'Create new';
+$string['createnewcategory'] = 'Create new category';
+$string['createnewsubcategory'] = 'Create new subcategory';
 $string['createsubcategoryof'] = 'Create subcategory of {$a}';
 $string['createuserandpass'] = 'Choose your username and password';
 $string['createuser'] = 'Create user';