Skip to content

Instantly share code, notes, and snippets.

@eddieajau
Created January 27, 2013 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eddieajau/4651383 to your computer and use it in GitHub Desktop.
Save eddieajau/4651383 to your computer and use it in GitHub Desktop.
Eclipse snippet category for general purpose Joomla 2.5/3 Component snippets. Includes: * PHP File Header * XML Installation File (Component) * INI File Header * Master Component File * Master Controller * Basic View * Basic Model * Basic View with Toolbar * Basic Controller Display Override * Basic Component Helper * Basic config.xml * Basic ac…
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<snippets>
<category filters="*" id="category_1275479375591" initial_state="1" label="Joomla Components" largeicon="" smallicon="">
<description><![CDATA[Snippets that support the general needs for any Joomla component.]]></description>
<item category="category_1275479375591" class="" editorclass="" id="item_1275479460203" label="PHP File Header" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[The standard header for a PHP file.]]></description>
<content><![CDATA[<?php
/**
* @version $Id$
* @package ${PACKAGE}
* @subpackage ${SUBPACKAGE}
* @copyright Copyright ${COPYRIGHT}. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
// No direct access
defined('_JEXEC') or die;
]]></content>
<variable default="" id="name_1" name="PACKAGE">
<description><![CDATA[The API package.]]></description>
</variable>
<variable default="" id="name_2" name="SUBPACKAGE">
<description><![CDATA[The API subpackage.]]></description>
</variable>
<variable default="2011 New Life in IT Pty Ltd" id="name_3" name="COPYRIGHT">
<description><![CDATA[The copyright statement.]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275479635542" label="XML Installation File (Component)" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[A basic XML manifest for a component.]]></description>
<content><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<!-- $Id$ -->
<extension type="component" version="1.6.0" method="upgrade">
<name>COM_${NAME}</name>
<author>Andrew Eddie</author>
<creationDate>${DATE}</creationDate>
<copyright>Copyright ${COPYRIGHT}. All rights reserved. </copyright>
<license>GNU General Public License version 2 or later.</license>
<authorEmail>${EMAIL}</authorEmail>
<authorUrl>${URL}</authorUrl>
<version>${VERSION}</version>
<description>COM_${NAME}_XML_DESCRIPTION</description>
<administration>
<files>
<filename>index.html</filename>
<filename>${NAME}.php</filename>
</files>
<menu>COM_${NAME}</menu>
</administration>
</extension>
]]></content>
<variable default="" id="name_1" name="NAME">
<description><![CDATA[The lower case name of the component (without com_).]]></description>
</variable>
<variable default="" id="name_2" name="DATE">
<description><![CDATA[The deployment date of the component.]]></description>
</variable>
<variable default="2011 New Life in IT Pty Ltd" id="name_3" name="COPYRIGHT">
<description><![CDATA[The copyright statement.]]></description>
</variable>
<variable default="andrew.eddie@newlifeinit.com" id="name_4" name="EMAIL">
<description><![CDATA[The author email.]]></description>
</variable>
<variable default="www.newlifeinit.com" id="name_5" name="URL">
<description><![CDATA[The author web site.]]></description>
</variable>
<variable default="1.0" id="name_6" name="VERSION">
<description><![CDATA[The component version.]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275479391879" label="INI File Header" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[The standard header for an INI language file.]]></description>
<content><![CDATA[; $Id$
; Copyright 2010 New Life in IT Pty Ltd. All rights reserved.
; License GNU General Public License version 2 or later.
; Note : All ini files need to be saved as UTF-8 - No BOM
]]></content>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275909113860" label="Master Component File" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[This snippet provides the access check for the component, then instantiates the controller and executes the task in the request.]]></description>
<content><![CDATA[// Access check.
if (!JFactory::getUser()->authorise('core.manage', 'com_${NAME}')) {
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
}
// Include dependencies
jimport('joomla.application.component.controller');
$controller = JController::getInstance('${NAME}');
$controller->execute(JRequest::getVar('task'));
$controller->redirect();]]></content>
<variable default="" id="name_1" name="NAME">
<description><![CDATA[The lower case name of the component (without com_).]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275909640352" label="Master Controller" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[The master display controller for the component.]]></description>
<content><![CDATA[jimport('joomla.application.component.controller');
/**
* ${NAME} Component Controller
*
* @package ${PACKAGE}
* @subpackage ${SUBPACKAGE}
* @since ${SINCE}
*/
class ${NAME}Controller extends JController
{
}]]></content>
<variable default="" id="name_1" name="PACKAGE">
<description><![CDATA[The API package.]]></description>
</variable>
<variable default="" id="name_2" name="SUBPACKAGE">
<description><![CDATA[The API subpackage.]]></description>
</variable>
<variable default="" id="name_3" name="NAME">
<description><![CDATA[The proper case name of the component (without com_).]]></description>
</variable>
<variable default="1.0" id="name_4" name="SINCE">
<description><![CDATA[The version this feature was added.]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275909822586" label="Basic View" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[A basic view for a component.]]></description>
<content><![CDATA[jimport('joomla.application.component.view');
/**
* ${VIEW} view.
*
* @package ${PACKAGE}
* @subpackage ${SUBPACKAGE}
* @since ${SINCE}
*/
class ${NAME}View${VIEW} extends JView
{
}]]></content>
<variable default="" id="name_1" name="PACKAGE">
<description><![CDATA[The API package.]]></description>
</variable>
<variable default="" id="name_2" name="SUBPACKAGE">
<description><![CDATA[The API subpackage.]]></description>
</variable>
<variable default="" id="name_3" name="NAME">
<description><![CDATA[The proper case name of the component (without com_).]]></description>
</variable>
<variable default="" id="name_4" name="VIEW">
<description><![CDATA[The proper case name of the view.]]></description>
</variable>
<variable default="1.0" id="name_5" name="SINCE">
<description><![CDATA[The version this feature was added.]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275909964972" label="Basic Model" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[A basic model for a component.]]></description>
<content><![CDATA[jimport('joomla.application.component.model');
/**
* ${MODEL} model.
*
* @package ${PACKAGE}
* @subpackage ${SUBPACKAGE}
* @since ${SINCE}
*/
class ${NAME}Model${MODEL} extends JModel
{
}]]></content>
<variable default="" id="name_1" name="PACKAGE">
<description><![CDATA[The API package.]]></description>
</variable>
<variable default="" id="name_2" name="SUBPACKAGE">
<description><![CDATA[The API subpackage.]]></description>
</variable>
<variable default="" id="name_3" name="NAME">
<description><![CDATA[The proper case name of the component.]]></description>
</variable>
<variable default="" id="name_4" name="MODEL">
<description><![CDATA[The proper case name of the model.]]></description>
</variable>
<variable default="1.0" id="name_5" name="SINCE">
<description><![CDATA[The version this feature was added.]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275992666831" label="Basic View with Toolbar" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[This snippet adds a simple override to the display method for a view, and adds a toolbar method to display the title of the view and test whether the Options button can be added.]]></description>
<content><![CDATA[ /**
* Override the display method for the view.
*
* @return void
* @since ${SINCE}
*/
public function display()
{
$this->addToolbar();
parent::display();
}
/**
* Add the page title and toolbar.
*
* @return void
* @since ${SINCE}
*/
protected function addToolbar()
{
$canDo = ${NAME}Helper::getActions();
// Add the view title.
JToolBarHelper::title(JText::_('COM_${NAME}_${VIEW}_TITLE'));
// Check if the Options button can be added.
if ($canDo->get('core.admin')) {
JToolBarHelper::preferences('${OPTION}');
}
}]]></content>
<variable default="" id="name_1" name="NAME">
<description><![CDATA[The proper case name of the component (without COM_).]]></description>
</variable>
<variable default="" id="name_2" name="VIEW">
<description><![CDATA[The upper case name of the view.]]></description>
</variable>
<variable default="1.0" id="name_3" name="SINCE">
<description><![CDATA[The version this feature was added.]]></description>
</variable>
<variable default="" id="name_4" name="OPTION">
<description><![CDATA[The lower case option for the component (with com_).]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275994786665" label="Basic Controller Display Override" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[This snippet adds a basic display method override to the controller to load the component helper.]]></description>
<content><![CDATA[ /**
* Override the display method for the controller.
*
* @return void
* @since ${SINCE}
*/
function display()
{
// Load the component helper.
require_once JPATH_COMPONENT.'/helpers/${NAME}.php';
// Display the view.
parent::display();
}]]></content>
<variable default="1.0" id="name_1" name="SINCE">
<description><![CDATA[The version this feature was added.]]></description>
</variable>
<variable default="" id="name_2" name="NAME">
<description><![CDATA[The lower case name of the component (without com_).]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275993353265" label="Basic Component Helper" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[This snippet adds the basic component helper class.]]></description>
<content><![CDATA[/**
* ${NAME} display helper.
*
* @package ${PACKAGE}
* @subpackage ${SUBPACKAGE}
* @since ${SINCE}
*/
class ${NAME}Helper
{
/**
* Gets a list of the actions that can be performed.
*
* @return JObject
* @since 1.6
*/
public static function getActions()
{
$user = JFactory::getUser();
$result = new JObject;
$actions = array(
'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.state', 'core.delete'
);
foreach ($actions as $action) {
$result->set($action, $user->authorise($action, '${OPTION}'));
}
return $result;
}
}]]></content>
<variable default="" id="name_1" name="PACKAGE">
<description><![CDATA[The API package.]]></description>
</variable>
<variable default="" id="name_2" name="SUBPACKAGE">
<description><![CDATA[The API subpackage.]]></description>
</variable>
<variable default="1.0" id="name_3" name="SINCE">
<description><![CDATA[The version this feature was added.]]></description>
</variable>
<variable default="" id="name_4" name="NAME">
<description><![CDATA[The propercase name of the component (without com_).]]></description>
</variable>
<variable default="" id="name_5" name="OPTION">
<description><![CDATA[The lowercase option for the component (with com_).]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275994131378" label="Basic config.xml" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[This is a basic component config.xml that has sufficient information to support the component permissions.]]></description>
<content><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<!-- $Id$ -->
<config>
<fieldset
name="permissions"
label="JCONFIG_PERMISSIONS_LABEL"
description="JCONFIG_PERMISSIONS_DESC"
>
<field
name="rules"
type="rules"
label="JCONFIG_PERMISSIONS_LABEL"
class="inputbox"
filter="rules"
component="${OPTION}"
section="component" />
</fieldset>
</config>]]></content>
<variable default="" id="name_1" name="OPTION">
<description><![CDATA[The lower case option for the component (with com_).]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1275994266858" label="Basic access.xml" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[This is a basic component access.xml that has sufficient information to support the component permissions.]]></description>
<content><![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<!-- $Id$ -->
<access component="${OPTION}">
<section name="component">
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
<action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDIT_STATE" description="JACTION_EDIT_STATE_COMPONENT_DESC" />
</section>
</access>]]></content>
<variable default="" id="name_1" name="OPTION">
<description><![CDATA[The lower case option for the component (with com_).]]></description>
</variable>
</item>
<item category="category_1275479375591" class="" editorclass="" id="item_1276476050476" label="Basic Table Class" largeicon="" smallicon="" snippetProvider="org.eclipse.wst.common.snippets.ui.TextSnippetProvider">
<description><![CDATA[This snippet adds a basic table class. You would add custom bind, check, store, et al methods to suit your data model.]]></description>
<content><![CDATA[jimport('joomla.database.table');
/**
* ${TABLE} table.
*
* @package ${PACKAGE}
* @subpackage ${SUBPACKAGE}
* @since ${SINCE}
*/
class ${NAME}Table${TABLE} extends JTable
{
/**
* Constructor.
*
* @param JDatabase $db A database connector object.
*
* @return ${NAME}Table${TABLE}
* @since ${SINCE}
*/
public function __construct($db)
{
parent::__construct('#__${DBTABLE}', '${PRIMARYKEY}', $db);
}
/**
* Overloaded bind function to pre-process the params.
*
* @param array $array The input array to bind.
* @param string $ignore A list of fields to ignore in the binding.
*
* @return null|string null is operation was satisfactory, otherwise returns an error
* @see JTable:bind
* @since ${SINCE}
*/
public function bind($array, $ignore = '')
{
if (isset($array['params']) && is_array($array['params'])) {
$registry = new JRegistry();
$registry->loadArray($array['params']);
$array['params'] = (string) $registry;
}
return parent::bind($array, $ignore);
}
/**
* Overloaded check method to ensure data integrity.
*
* @return boolean True on success.
* @since ${SINCE}
*/
public function check()
{
// Check for valid name.
if (trim($this->title) === '') {
$this->setError(JText::_('COM_${NAME}_ERROR_${TABLE}_TITLE'));
return false;
}
return true;
}
/**
* Overload the store method for the Weblinks table.
*
* @param boolean $updateNulls Toggle whether null values should be updated.
*
* @return boolean True on success, false on failure.
* @since ${SINCE}
*/
public function store($updateNulls = false)
{
// Initialiase variables.
$date = JFactory::getDate()->toMySQL();
$userId = JFactory::getUser()->get('id');
if (empty($this->id)) {
// New record.
$this->created_time = $date;
$this->created_user_id = $userId;
}
else {
// Existing record.
$this->modified_time = $date;
$this->modified_user_id = $userId;
}
// Attempt to store the data.
return parent::store($updateNulls);
}
}]]></content>
<variable default="" id="name_1" name="PACKAGE">
<description><![CDATA[The API package.]]></description>
</variable>
<variable default="" id="name_2" name="SUBPACKAGE">
<description><![CDATA[The API subpackage.]]></description>
</variable>
<variable default="1.0" id="name_3" name="SINCE">
<description><![CDATA[The version this feature was added.]]></description>
</variable>
<variable default="" id="name_4" name="NAME">
<description><![CDATA[The proper case name of the component (without com_).]]></description>
</variable>
<variable default="" id="name_5" name="TABLE">
<description><![CDATA[The proper case name of the table. Usually singular form.]]></description>
</variable>
<variable default="" id="name_6" name="DBTABLE">
<description><![CDATA[The name of the actual database table (without prefix). Usually plural form.]]></description>
</variable>
<variable default="id" id="name_7" name="PRIMARYKEY">
<description><![CDATA[The name of the primary key field in the database table.]]></description>
</variable>
</item>
</category>
</snippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment