Skip to content

Instantly share code, notes, and snippets.

@jlainezs
Created June 8, 2013 22:29
Show Gist options
  • Save jlainezs/5736842 to your computer and use it in GitHub Desktop.
Save jlainezs/5736842 to your computer and use it in GitHub Desktop.
Those Eclipse Juno code templates helps to prepare a basic skeleton for classes derived from JController and JModel classes.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
Eclipse Juno Joomla templates
=============================
Licensed under GNU/GPL 3.0
(C)2013 by Pep Lainez : jlainezs@econceptes.com
** Use at your own risk and under your responsability **
Those templates will write a basic skeleton for :
* JControllerAdmin (shortcut: joomla_cont_adm)
* JControllerForm (shortcut: joomla_cont_form)
* JModelAdmin (shortcut: joomla_model_adm)
* JModelList (shortcut: joomla_model_list)
Import into Eclipse using:
Window>Preferences
Select PHP>Editor>Templates and click Import button
Tested under Eclipse Juno
-->
<templates><template autoinsert="false" context="php" deleted="false" description="Descendant of JControllerAdmin" enabled="true" name="joomla_cont_adm">/**
* @package ${component}
* @subpackage ${subpackage}
* @author ${user} &lt;${email}&gt;
* @copyright ${year} ${holder}
* @license Licensed under GNU/GPL 3.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controlleradmin');
/**
* ${controllername} controller
*
* @since 1.0
*/
class ${component}Controller${controllername}
extends JControllerAdmin
{
/**
* Proxy for getModel.
*
* @param String $$name Model name
* @param String $$prefix Prefix to add to the model name
* @param Array $$options Model invocation options
*
* @return JModel
*
* @since 2.5
*/
public function getModel($$name = '${controllername}', $$prefix = '${component}Model', $$options = array())
{
$$model = parent::getModel($$name, $$prefix, array('ignore_request' =&gt; true));
return $$model;
}
}</template><template autoinsert="false" context="php" deleted="false" description="Descendant of JControllerForm" enabled="true" name="joomla_cont_form">/**
* @package ${component}
* @subpackage ${subpackage}
* @author ${user} &lt;${email}&gt;
* @copyright ${year} ${holder}
* @license Licensed under GNU/GPL 3.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controllerform');
/**
* ${controllername} controller
*
* @since 1.0
*/
class ${component}Controller${controllername}
extends JControllerForm
{
}</template><template autoinsert="false" context="php" deleted="false" description="Descendant of JModelAdmin" enabled="true" name="joomla_model_adm">/**
* @package ${component}
* @subpackage ${subpackage}
* @author ${user} &lt;${email}&gt;
* @copyright ${year} ${holder}
* @license Licensed under GNU/GPL 3.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
*
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.modeladmin');
/**
* ${model} Model
*
* @since 1.0
*/
class ${component}Model${model} extends JModelAdmin
{
/**
* Returns a reference to the a Table object, always creating it.
*
* @param String $$type The table type to instantiate
* @param String $$prefix A prefix for the table class name. Optional.
* @param Array $$config Configuration array for model. Optional.
*
* @return JTable A database object
*
* @since 2.5
*/
public function getTable($$type = '${model}', $$prefix = '${component}Table', $$config = array())
{
return JTable::getInstance($$type, $$prefix, $$config);
}
/**
* Get the record form.
*
* @param Array $$data Data for the form.
* @param Boolean $$loadData True if the form is to load its own data (default case), false if not.
*
* @return Mixed A JForm object on success, false on failure
*
* @since 2.5
*/
public function getForm($$data = array(), $$loadData = true)
{
// Get the form.
$$form = $$this-&gt;loadForm(
'com_${component}.${model}', '${model}',
array('control' =&gt; 'jform', 'load_data' =&gt; $$loadData)
);
if (empty($$form))
{
return false;
}
return $$form;
}
/**
* Get the data that should be injected in the form.
*
* @return mixed The data for the form.array
*
* @since 2.5
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$$data = JFactory::getApplication()-&gt;getUserState('com_${component}.edit.${model}.data', array());
if (empty($$data))
{
$$pk = JRequest::getInt('id', JRequest::getInt('id'));
$$data = $$this-&gt;getItem($$pk);
}
return $$data;
}
}</template><template autoinsert="false" context="php" deleted="false" description="Descendant of JModelList" enabled="true" name="joomla_model_list">/**
* @package ${component}
* @subpackage ${subpackage}
* @author ${user} &lt;${email}&gt;
* @copyright ${year} ${holder}
* @license Licensed under GNU/GPL 3.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
*
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.modellist');
/**
* ${model} Model
*
* @since 1.0
*/
class ${component}Model${model}
extends JModelList
{
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*/
public function getListQuery()
{
$$db = JFactory::getDBO();
$$query = $$db-&gt;getQuery(true);
$$query-&gt;select('${fields_list}');
$$query-&gt;from('${tables}');
if (JRequest::getString('filter', '') != '')
{
$$query-&gt;where(' (${field} like ' . $$db-&gt;quote('%' . JRequest::getString('filter') . '%') . ') ');
}
return $$query;
}
}</template></templates>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment