protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/courses.php';
     $state = $this->get('State');
     $canDo = CoursesHelper::getActions($state->get('filter.category_id'));
     $user = JFactory::getUser();
     JToolBarHelper::title(JText::_('COM_COURSES_MANAGER_COURSES'), 'courses');
     //if (count($user->getAuthorisedCategories('com_courses', 'core.create')) > 0) {
     JToolBarHelper::addNew('course.add');
     //}
     if ($canDo->get('core.edit')) {
         JToolBarHelper::editList('course.edit');
     }
     if ($canDo->get('core.edit.state')) {
         JToolBarHelper::divider();
         JToolBarHelper::publish('courses.publish', 'JTOOLBAR_PUBLISH', true);
         JToolBarHelper::unpublish('courses.unpublish', 'JTOOLBAR_UNPUBLISH', true);
         JToolBarHelper::divider();
         JToolBarHelper::archiveList('courses.archive');
         JToolBarHelper::checkin('courses.checkin');
     }
     if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) {
         JToolBarHelper::deleteList('', 'courses.delete', 'JTOOLBAR_EMPTY_TRASH');
         JToolBarHelper::divider();
     } elseif ($canDo->get('core.edit.state')) {
         JToolBarHelper::trash('courses.trash');
         JToolBarHelper::divider();
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::preferences('com_courses');
         JToolBarHelper::divider();
     }
     JToolBarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS');
     // TODO
 }
 protected function addToolbar()
 {
     JRequest::setVar('hidemainmenu', true);
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $isNew = $this->item->id == 0;
     $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
     // Since we don't track these assets at the item level, use the category id.
     $canDo = CoursesHelper::getActions($this->item->catid, 0);
     JToolBarHelper::title(JText::_('COM_COURSES_MANAGER_COURSE'), 'courses-categories');
     // If not checked out, can save the item.
     if (!$checkedOut && ($canDo->get('core.edit') || count($user->getAuthorisedCategories('com_courses', 'core.create')))) {
         JToolBarHelper::apply('course.apply');
         JToolBarHelper::save('course.save');
     }
     if (!$checkedOut && count($user->getAuthorisedCategories('com_courses', 'core.create'))) {
         JToolBarHelper::save2new('course.save2new');
     }
     // If an existing item, can save to a copy.
     if (!$isNew && count($user->getAuthorisedCategories('com_courses', 'core.create')) > 0) {
         JToolBarHelper::save2copy('course.save2copy');
     }
     if (empty($this->item->id)) {
         JToolBarHelper::cancel('course.cancel');
     } else {
         JToolBarHelper::cancel('course.cancel', 'JTOOLBAR_CLOSE');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_COURSES_LINKS_EDIT');
 }
 /**
  * Method to display a view.
  *
  * @param	boolean			$cachable	If true, the view output will be cached
  * @param	array			$urlparams	An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  *
  * @return	JController		This object to support chaining.
  * @since	1.5
  */
 public function display($cachable = false, $urlparams = false)
 {
     require_once JPATH_COMPONENT . '/helpers/courses.php';
     // Load the submenu.
     CoursesHelper::addSubmenu(JRequest::getCmd('view', 'courses'));
     $view = JRequest::getCmd('view', 'courses');
     $layout = JRequest::getCmd('layout', 'default');
     $id = JRequest::getInt('id');
     // Check for edit form.
     if ($view == 'course' && $layout == 'edit' && !$this->checkEditId('com_courses.edit.course', $id)) {
         // Somehow the person just went to the form - we don't allow that.
         $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
         $this->setMessage($this->getError(), 'error');
         $this->setRedirect(JRoute::_('index.php?option=com_courses&view=courses', false));
         return false;
     }
     parent::display();
     return $this;
 }