I pasted in the Model and View classes for the list view based on the 2.5 Joomla Programming book with comments stripped out and generic names. In the view.html.php file there is a line:
Code:
JToolBarHelper::deleteList('', 'myitems.delete','JTOOLBAR_EMPTY_TRASH');
Which adds the delete functionality without a need to create a method. You'll notice in the model there is no reference to a delete method and there doesn't need to be one as it is part of the core.
Code:
$bar = JToolBar::getInstance('toolbar');
$bar->appendButton('Link', 'export', 'COM_MYEXAMPLE_TOOLBAR_CUSTOMDELETE',
'index.php?option=com_joomprosubs&task=myitems.mydelete');
This line would add your custom functionality for deleting to the toolbar icons.
ModelList is correct for the list view, but it looks like you are missing some methods. On a side note, ModelAdmin is the extended Joomla class for the single or detailed view and has its own set of methods you need to call.
A big thing to remember is that 2.5 depreciated a LOT of 1.5 functionality which shored up security and cleaned up the core. A result of this maturing of the code base was many of the shortcuts developers used to insert hand rolled classes and code snippets no longer work.
You have to think of 2.5 as an all or nothing approach, and in your defense; Joomla's online tutorials for 2.5 dwarf in detail and scope to the new Joomla Programming book. Which I might add is the ONLY reason I am able to integrate into Joomla 2.5.
MODELCode:
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class MyExampleModelMyItems extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id', 'a.id',
'title', 'a.title',
'alias', 'a.alias',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'catid', 'a.catid', 'category_title',
'published', 'a.published',
'access', 'a.access', 'access_level',
'created', 'a.created',
'created_by', 'a.created_by',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'group_title', 'g.title',
'duration', 'a.duration'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
$app = JFactory::getApplication('administrator');
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$accessId = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', null, 'int');
$this->setState('filter.access', $accessId);
$published = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_published', '', 'string');
$this->setState('filter.state', $published);
$categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id', '');
$this->setState('filter.category_id', $categoryId);
$params = JComponentHelper::getParams('com_joomprosubs');
$this->setState('params', $params);
parent::populateState('a.title', 'asc');
}
protected function getStoreId($id = '')
{
// Compile the store id.
$id.= ':' . $this->getState('filter.search');
$id.= ':' . $this->getState('filter.access');
$id.= ':' . $this->getState('filter.state');
$id.= ':' . $this->getState('filter.category_id');
return parent::getStoreId($id);
}
protected function getListQuery()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('a.*');
$query->from($db->quoteName('#__joompro_subscriptions').' AS a');
$query->select('uc.name AS editor');
$query->join('LEFT', $db->quoteName('#__users').' AS uc ON uc.id=a.checked_out');
$query->select('g.title AS group_title');
$query->join('LEFT', $db->quoteName('#__usergroups').' AS g ON a.group_id = g.id');
$query->select('c.title AS category_title');
$query->join('LEFT', $db->quoteName('#__categories').' AS c ON c.id = a.catid');
if ($access = $this->getState('filter.access')) {
$query->where('a.access = '.(int) $access);
}
$published = $this->getState('filter.state');
if (is_numeric($published)) {
$query->where('a.published = '.(int) $published);
} else if ($published === '') {
$query->where('(a.published IN (0, 1))');
}
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId)) {
$query->where('a.catid = '.(int) $categoryId);
}
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$query->where('a.id = '.(int) substr($search, 3));
} else {
$search = $db->Quote('%'.$db->getEscaped($search, true).'%');
$query->where('(a.title LIKE '.$search.' OR a.alias LIKE '.$search.')');
}
}
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
$query->order($db->getEscaped($orderCol.' '.$orderDirn));
return $query;
}
}
VIEW.HTML.PHPCode:
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
class MyExampleViewMyItems extends JView
{
protected $items;
protected $pagination;
protected $state;
/**
* Display the view
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->addToolbar();
parent::display($tpl);
}
protected function addToolbar()
{
JLoader::register('MyExampleHelper', JPATH_COMPONENT.'/helpers/myexample.php');
$state = $this->get('State');
$canDo = MyExampleHelper::getActions($state->get('filter.category_id'));
$user = JFactory::getUser();
JToolBarHelper::title(JText::_('COM_MYEXAMPLE_MANAGER_MYITEMS'), 'icon.png');
if ($canDo->get('core.create')) {
JToolBarHelper::addNew('myitem.add','JTOOLBAR_NEW');
}
if ($canDo->get('core.edit')) {
JToolBarHelper::editList('myitem.edit','JTOOLBAR_EDIT');
}
// Add export toolbar
$bar = JToolBar::getInstance('toolbar');
$bar->appendButton('Link', 'export', 'COM_MYEXAMPLE_TOOLBAR_CUSTOMDELETE',
'index.php?option=com_joomprosubs&task=myitems.mydelete');
if ($canDo->get('core.edit.state')) {
JToolBarHelper::divider();
JToolBarHelper::publish('myitems.publish', 'JTOOLBAR_PUBLISH', true);
JToolBarHelper::unpublish('myitems.unpublish', 'JTOOLBAR_UNPUBLISH', true);
JToolBarHelper::divider();
JToolBarHelper::archiveList('myitems.archive');
JToolBarHelper::checkin('myitems.checkin');
}
if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) {
JToolBarHelper::deleteList('', 'myitems.delete','JTOOLBAR_EMPTY_TRASH');
JToolBarHelper::divider();
} else if ($canDo->get('core.edit.state')) {
JToolBarHelper::trash('myitems.trash','JTOOLBAR_TRASH');
JToolBarHelper::divider();
}
if ($canDo->get('core.admin')) {
JToolBarHelper::preferences('com_myexample');
JToolBarHelper::divider();
}
JToolBarHelper::help('', '', JText::_('COM_MYEXAMPLE_MYITEMS_HELP_LINK'));
}
}
I inserted this code snippet because it is VERY important to proper integration. There is a lot of navigation and management features which depend on database items having this foundation. When I write an extension, I always use this as the base for the table and add columns and fields needed for what I'm writing. Without these additional fields, integration won't work properly.
Again, if possible, spend the $30 bucks on the book which lays everything out for you!
http://www.amazon.com/Joomla-Programmin ... 013278081X<b>SQL</b>
Code:
CREATE TABLE IF NOT EXISTS `#__myitems` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatic incrementing key field',
`catid` int(11) NOT NULL DEFAULT '0' COMMENT 'Foreign key to #__categories table',
`title` varchar(250) NOT NULL DEFAULT '' COMMENT 'Title of Subscription',
`alias` varchar(255) NOT NULL DEFAULT '' COMMENT 'Alias value, used for SEF URLs',
`description` text NOT NULL COMMENT 'Description (will be edited using editor)',
`group_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Foreign key to #__groups table',
`duration` int(11) NOT NULL DEFAULT '0' COMMENT 'Number for days that subscription lasts',
`published` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Published state (1=published, 0=unpublished, -2=trashed)',
`checked_out` int(11) NOT NULL DEFAULT '0',
`checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`access` int(11) NOT NULL DEFAULT '1' COMMENT 'Used to control access to subscriptions',
`params` text NOT NULL COMMENT 'For possible future use to add item-level parameters (JSON string format)',
`language` char(7) NOT NULL DEFAULT '' COMMENT 'For possible future use to add language switching',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Foreign key to #__users table for user who created this item',
`created_by_alias` varchar(255) NOT NULL DEFAULT '',
`modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Foreign key to #__users table for user who modified this item',
`publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date to start publishing this item',
`publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date to stop publishing this item',
PRIMARY KEY (`id`),
KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`),
KEY `idx_published` (`published`),
KEY `idx_catid` (`catid`),
KEY `idx_createdby` (`created_by`),
KEY `idx_language` (`language`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;