public function action_index() { if (!$this->user->can('Admin_Item_Index')) { throw HTTP_Exception::factory('403', 'Permission denied to view admin item index'); } $types = ORM::factory('Item_Type')->find_all(); $this->view = new View_Admin_Item_Index(); $this->_nav('items', 'index'); $this->view->item_types = $types->as_array(); $commands = Item::list_commands(); $input_c = array(); $menu_c = array(array('name' => 'General', 'commands' => array()), array('name' => 'Pet', 'commands' => array())); $def_c = array(); foreach ($commands as $cmd) { $name = str_replace(DIRECTORY_SEPARATOR, '_', $cmd); $class = 'Item_Command_' . $name; $command = new $class(); if ($command->is_default() == FALSE) { $struct = explode('_', $name); $admin = $command->build_admin($name); $input_c[] = array('title' => $admin['title'], 'fields' => $admin['fields']); $def_c[] = array('name' => $name, 'multiple' => $admin['multiple'], 'pets' => $admin['pets'], 'search' => $admin['search'], 'only' => !$command->allow_more); $loc = in_array($struct[0], array('General', 'User')) ? 0 : 1; $menu_c[$loc]['commands'][] = array('name' => $struct[1], 'cmd' => $name); } } $this->view->input_commands = $input_c; $this->view->menu_commands = $menu_c; $this->view->command_definitions = $def_c; $this->view->image = Kohana::$config->load('items.image'); }
/** * A list of item commands * @return array */ public function commands() { $commands = Item::list_commands(); $list_c = array(); foreach ($commands as $cmd) { $name = str_replace(Kohana::include_paths(), '', $cmd); $name = str_replace(array('\\', '/'), '_', $name); $value = 'Item_Command_' . $name; $command = new $value(); if ($command->is_default() == FALSE) { $list_c[] = array('name' => str_replace('_', ' - ', $name), 'value' => $value); } } return $list_c; }