I wanted a way to quickly review my K2 attachments, so I created and installed the necessary files as shown in the attached images. 1) administrator/components/com_k2/controllers/attachments.php getModel('attachments'); $model->remove(); } } 2) administrator/components/com_k2/models/attachments.php getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); $limitstart = $mainframe->getUserStateFromRequest($option.$view.'.limitstart', 'limitstart', 0, 'int'); $filter_order = $mainframe->getUserStateFromRequest($option.$view.'filter_order', 'filter_order', 'id', 'cmd'); $filter_order_Dir = $mainframe->getUserStateFromRequest($option.$view.'filter_order_Dir', 'filter_order_Dir', 'DESC', 'word'); // $filter_state = $mainframe->getUserStateFromRequest($option.$view.'filter_state', 'filter_state', -1, 'int'); $search = $mainframe->getUserStateFromRequest($option.$view.'search', 'search', '', 'string'); $search = JString::strtolower($search); $query = "SELECT * FROM #__k2_attachments WHERE id>0"; if ($search) { $query .= " AND LOWER( filename ) LIKE ".$db->Quote('%'.$search.'%'); } if (!$filter_order) { $filter_order = "filename"; } $query .= " ORDER BY {$filter_order} {$filter_order_Dir}"; $db->setQuery($query, $limitstart, $limit); $rows = $db->loadObjectList(); return $rows; } function getTotal() { global $mainframe; $option = JRequest::getCmd('option'); $view = JRequest::getCmd('view'); $db = & JFactory::getDBO(); $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); $limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart', 'limitstart', 0, 'int'); $filter_state = $mainframe->getUserStateFromRequest($option.$view.'filter_state', 'filter_state', 1, 'int'); $search = $mainframe->getUserStateFromRequest($option.$view.'search', 'search', '', 'string'); $search = JString::strtolower($search); $query = "SELECT COUNT(*) FROM #__k2_attachments WHERE id>0"; if ($filter_state > -1) { $query .= " AND published={$filter_state}"; } if ($search) { $query .= " AND LOWER( filename ) LIKE ".$db->Quote('%'.$search.'%'); } $db->setQuery($query); $total = $db->loadresult(); return $total; } function remove() { global $mainframe; $db = & JFactory::getDBO(); $cid = JRequest::getVar('cid'); $row = & JTable::getInstance('K2Attachment', 'Table'); foreach ($cid as $id) { $row->load($id); $row->delete($id); } $cache = & JFactory::getCache('com_k2'); $cache->clean(); $mainframe->redirect('index.php?option=com_k2&view=attachments', JText::_('Delete Completed')); } } 3) administrator/components/com_k2/views/attachments/tmpl/default.php
rows as $row) : $row->checked_out=0; $checked = JHTML::_('grid.checkedout', $row, $i ); ?> ">
# lists['order_Dir'], @$this->lists['order'] ); ?> lists['order_Dir'], @$this->lists['order'] ); ?> lists['order_Dir'], @$this->lists['order'] ); ?> lists['order_Dir'], @$this->lists['order'] ); ?> lists['order_Dir'], @$this->lists['order'] ); ?> lists['order_Dir'], @$this->lists['order'] ); ?>
itemID;?> filename;?> title;?> titleAttribute;?> hits;?> id; ?>
page->getListFooter(); ?>
4) administrator/components/com_k2/views/attachments/view.html.php getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); $limitstart = $mainframe->getUserStateFromRequest($option.$view.'.limitstart', 'limitstart', 0, 'int'); $filter_order = $mainframe->getUserStateFromRequest($option.$view.'filter_order', 'filter_order', 'id', 'cmd'); $filter_order_Dir = $mainframe->getUserStateFromRequest($option.$view.'filter_order_Dir', 'filter_order_Dir', 'DESC', 'word'); // $filter_state = $mainframe->getUserStateFromRequest($option.$view.'filter_state', 'filter_state', -1, 'int'); $search = $mainframe->getUserStateFromRequest($option.$view.'search', 'search', '', 'string'); $search = JString::strtolower($search); $model = & $this->getModel(); $attachments = $model->getData(); for ($i=0; $ilink = JRoute::_('index.php?option=com_k2&view=item&cid='.$attachments[$i]->itemID); } $this->assignRef('rows', $attachments); $total = $model->getTotal(); jimport('joomla.html.pagination'); $pageNav = new JPagination($total, $limitstart, $limit); $this->assignRef('page', $pageNav); $lists = array (); $lists['search'] = $search; $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; $this->assignRef('lists', $lists); JToolBarHelper::title(JText::_('Attachments')); JToolBarHelper::deleteList(JText::_('Are you sure you want to delete selected attachments?'), 'remove', JText::_('Delete')); $toolbar=&JToolBar::getInstance('toolbar'); JToolBarHelper::preferences('com_k2', '500', '600'); JSubMenuHelper::addEntry(JText::_('Dashboard'), 'index.php?option=com_k2'); JSubMenuHelper::addEntry(JText::_('Items'), 'index.php?option=com_k2&view=items'); JSubMenuHelper::addEntry(JText::_('Categories'), 'index.php?option=com_k2&view=categories'); JSubMenuHelper::addEntry(JText::_('Tags'), 'index.php?option=com_k2&view=tags'); JSubMenuHelper::addEntry(JText::_('Comments'), 'index.php?option=com_k2&view=comments'); JSubMenuHelper::addEntry(JText::_('Attachments'), 'index.php?option=com_k2&view=attachments', true); if ($user->gid > 23) { JSubMenuHelper::addEntry(JText::_('Users'), 'index.php?option=com_k2&view=users'); JSubMenuHelper::addEntry(JText::_('User Groups'), 'index.php?option=com_k2&view=userGroups'); JSubMenuHelper::addEntry(JText::_('Extra Fields'), 'index.php?option=com_k2&view=extraFields'); JSubMenuHelper::addEntry(JText::_('Extra Field Groups'), 'index.php?option=com_k2&view=extraFieldsGroups'); JSubMenuHelper::addEntry(JText::_('Information'), 'index.php?option=com_k2&view=info'); } parent::display($tpl); } } 5) administrator/components/com_k2/views/cpanel/view.html.php Add this at line 40: $sumOfAttachments = $model->countAttachmentDownloads(); $this->assignRef('sumOfAttachments',$sumOfAttachments); And Add this at line 76: JSubMenuHelper::addEntry(JText::_('Attachments'), 'index.php?option=com_k2&view=attachments'); 6) administrator/components/com_k2/views/cpanel/tmpl/default.php Add this at line 102:
7) administrator/components/com_k2/models/cpanel.php Add these functions around line 85: function countAttachments(){ global $mainframe; $db = & JFactory::getDBO(); $query = "SELECT COUNT(*) FROM #__k2_attachments"; $db->setQuery($query); $result = $db->loadResult(); return $result; } function countAttachmentDownloads(){ global $mainframe; $db = & JFactory::getDBO(); $query = "SELECT Sum(hits) FROM #__k2_attachments"; $db->setQuery($query); $result = $db->loadResult(); return $result; } 8) Add the following to all of the other view.html.php files JSubMenuHelper::addEntry(JText::_('Attachments'), 'index.php?option=com_k2&view=attachments'); I am not happy with the layout of all of these files, a Joomla construct issue. We should be able to create a Plugin (com_k2) and ALL of the files for com_k2 are located under com_k2, We should be able to create a Plugin under com_k2 (Attachments) and ALL of the files for attachments are located under it. The CakePHP framework has gone a long way towards the deployment of this type of MVC framework. I don't like having to copy and past a menu item into several files! I don't like having to hack several non Attachments files located in the Controllers, Models, Views. Shouldn't the structure be Plug-In com_k2 Controllers, Models, Views, etc. etc. etc. and not Controllers, com_k2, etc., etc., etc. ; Models, com_k2 , etc., etc., etc.; Views, com_k2 , etc., etc., etc.? I'm just saying! Wayne