/** * Renderers the actions for individual category list items. * * @param coursecat $category * @param array $actions * @return string */ public function category_listitem_actions(coursecat $category, array $actions = null) { if ($actions === null) { $actions = \core_course\management\helper::get_category_listitem_actions($category); } $menu = new action_menu(); $menu->attributes['class'] .= ' category-item-actions item-actions'; $hasitems = false; foreach ($actions as $key => $action) { $hasitems = true; $menu->add(new action_menu_link($action['url'], $action['icon'], $action['string'], in_array($key, array('show', 'hide', 'moveup', 'movedown')), array('data-action' => $key, 'class' => 'action-' . $key))); } if (!$hasitems) { return ''; } return $this->render($menu); }
/** * Tests the fetching of actions for a category. */ public function test_get_category_listitem_actions() { global $PAGE; $this->resetAfterTest(true); $PAGE->set_url(new moodle_url('/course/management.php')); $generator = $this->getDataGenerator(); $category = $generator->create_category(); $context = context_system::instance(); list($user, $roleid) = $this->get_user_objects($generator, $context->id); course_capability_assignment::allow(array(self::CATEGORY_MANAGE, self::CATEGORY_VIEWHIDDEN, 'moodle/role:assign', 'moodle/cohort:view', 'moodle/filter:manage'), $roleid, $context->id); $actions = \core_course\management\helper::get_category_listitem_actions($category); $this->assertInternalType('array', $actions); $this->assertArrayHasKey('edit', $actions); $this->assertArrayHasKey('hide', $actions); $this->assertArrayHasKey('show', $actions); $this->assertArrayHasKey('moveup', $actions); $this->assertArrayHasKey('movedown', $actions); $this->assertArrayHasKey('delete', $actions); $this->assertArrayHasKey('assignroles', $actions); $this->assertArrayHasKey('permissions', $actions); $this->assertArrayHasKey('cohorts', $actions); $this->assertArrayHasKey('filters', $actions); }