Source for file style.php
Documentation is available at style.php
* @package Joomla.Administrator
* @subpackage com_templates
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla.Administrator
* @subpackage com_templates
* @var string The help screen key for the module.
protected $helpKey =
'JHELP_EXTENSIONS_TEMPLATE_MANAGER_STYLES_EDIT';
* @var string The help screen base URL for the module.
private $_cache =
array();
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
$pk =
$app->input->getInt('id');
* @param array &$pks An array of item ids.
* @return boolean Returns true on success, false on failure.
// Iterate the items to delete each one.
if (!$user->authorise('core.delete', 'com_templates'))
throw
new Exception(JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
// You should not delete a default style
JError::raiseWarning(SOME_ERROR_NUMBER, Jtext::_('COM_TEMPLATES_STYLE_CANNOT_DELETE_DEFAULT_STYLE'));
if (!$table->delete($pk))
* Method to duplicate styles.
* @param array &$pks An array of primary key IDs.
* @return boolean True if successful.
if (!$user->authorise('core.create', 'com_templates'))
throw
new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
if ($table->load($pk, true))
// Reset the id to create a new record.
// Reset the home (don't want dupes of that field).
if (!$table->check() ||
!$table->store())
throw
new Exception($table->getError());
throw
new Exception($table->getError());
* Method to change the title.
* @param integer $category_id The id of the category.
* @param string $alias The alias.
* @param string $title The title.
* @return string New title.
while ($table->load(array('title' =>
$title)))
* Method to get the record form.
* @param array $data An optional array of data for the form to interogate.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return JForm A JForm object on success, false on failure
public function getForm($data =
array(), $loadData =
true)
// The folder and element vars are passed when saving the form.
$clientId =
$item->client_id;
$template =
$item->template;
// These variables are used to add data from the plugin XML files.
$this->setState('item.client_id', $clientId);
$this->setState('item.template', $template);
$form =
$this->loadForm('com_templates.style', 'style', array('control' =>
'jform', 'load_data' =>
$loadData));
// Modify the form based on access controls.
// Disable fields for display.
$form->setFieldAttribute('home', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('home', 'filter', 'unset');
* Method to get the data that should be injected in the form.
* @return mixed The data for the form.
// Check the session for previously entered form data.
* Method to get a single record.
* @param integer $pk The id of the primary key.
* @return mixed Object on success, false on failure.
public function getItem($pk =
null)
$pk =
(!empty($pk)) ?
$pk : (int)
$this->getState('style.id');
if (!isset
($this->_cache[$pk]))
// Attempt to load the row.
$return =
$table->load($pk);
// Check for a table object error.
if ($return ===
false &&
$table->getError())
// Convert to the JObject before adding other data.
$properties =
$table->getProperties(1);
// Convert the params field to an array.
$registry->loadString($table->params);
$this->_cache[$pk]->params =
$registry->toArray();
$path =
JPath::clean($client->path.
'/templates/'.
$table->template.
'/templateDetails.xml');
$this->_cache[$pk]->xml =
null;
return $this->_cache[$pk];
* Returns a reference to the a Table object, always creating it.
* @param type $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
public function getTable($type =
'Style', $prefix =
'TemplatesTable', $config =
array())
* @param object $form A form object.
* @param mixed $data The data expected for the form.
* @param string $group TODO
* @throws Exception if there is an error in the form event.
protected function preprocessForm(JForm $form, $data, $group =
'content')
$clientId =
$this->getState('item.client_id');
$template =
$this->getState('item.template');
if (!$form->loadFile('style_'.
$client->name, true))
throw
new Exception(JText::_('JERROR_LOADFILE_FAILED'));
$formFile =
JPath::clean($client->path.
'/templates/'.
$template.
'/templateDetails.xml');
// Load the core and/or local language file(s).
$lang->load('tpl_'.
$template, $client->path, null, false, true)
||
$lang->load('tpl_'.
$template, $client->path.
'/templates/'.
$template, null, false, true);
// Get the template form.
if (!$form->loadFile($formFile, false, '//config'))
throw
new Exception(JText::_('JERROR_LOADFILE_FAILED'));
// Disable home field if it is default style
||
((is_object($data) && isset
($data->home) &&
$data->home ==
'1')))
$form->setFieldAttribute('home', 'readonly', 'true');
// Attempt to load the xml file.
throw
new Exception(JText::_('JERROR_LOADFILE_FAILED'));
// Get the help data from the XML file if present.
$help =
$xml->xpath('/extension/help');
$helpKey =
trim((string)
$help[0]['key']);
$helpURL =
trim((string)
$help[0]['url']);
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
* Method to save the form data.
* @param array $data The form data.
* @return boolean True on success.
public function save($data)
// Detect disabled extension
if ($extension->load(array('enabled' =>
0, 'type' =>
'template', 'element' =>
$data['template'], 'client_id' =>
$data['client_id'])))
$this->setError(JText::_('COM_TEMPLATES_ERROR_SAVE_DISABLED_TEMPLATE'));
$pk =
(!empty($data['id'])) ?
$data['id'] : (int)
$this->getState('style.id');
// Include the extension plugins for the save events.
// Load the row if saving an existing record.
if ($app->input->get('task') ==
'save2copy')
if (!$table->bind($data))
// Prepare the row for saving
// Trigger the onExtensionBeforeSave event.
$result =
$dispatcher->trigger('onExtensionBeforeSave', array('com_templates.style', &$table, $isNew));
if ($user->authorise('core.edit', 'com_menus') &&
$table->client_id ==
0)
if (!empty($data['assigned']) &&
is_array($data['assigned']))
// Update the mapping for menu items that this style IS assigned to.
$query =
$db->getQuery(true)
->set('template_style_id = ' . (int)
$table->id)
->where('id IN (' .
implode(',', $data['assigned']) .
')')
->where('template_style_id != ' . (int)
$table->id)
->where('checked_out IN (0,' . (int)
$user->id .
')');
$n +=
$db->getAffectedRows();
// Remove style mappings for menu items this style is NOT assigned to.
// If unassigned then all existing maps will be removed.
$query =
$db->getQuery(true)
->set('template_style_id = 0');
if (!empty($data['assigned']))
$query->where('id NOT IN (' .
implode(',', $data['assigned']) .
')');
$query->where('template_style_id = ' . (int)
$table->id)
->where('checked_out IN (0,' . (int)
$user->id .
')');
$n +=
$db->getAffectedRows();
$app->enQueueMessage(JText::plural('COM_TEMPLATES_MENU_CHANGED', $n));
// Trigger the onExtensionAfterSave event.
$dispatcher->trigger('onExtensionAfterSave', array('com_templates.style', &$table, $isNew));
$this->setState('style.id', $table->id);
* Method to set a template style as home.
* @param integer $id The primary key ID for the style.
* @return boolean True if successful.
if (!$user->authorise('core.edit.state', 'com_templates'))
throw
new Exception(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
if (!$style->load((int)
$id))
throw
new Exception(JText::_('COM_TEMPLATES_ERROR_STYLE_NOT_FOUND'));
// Detect disabled extension
if ($extension->load(array('enabled' =>
0, 'type' =>
'template', 'element' =>
$style->template, 'client_id' =>
$style->client_id)))
throw
new Exception(JText::_('COM_TEMPLATES_ERROR_SAVE_DISABLED_TEMPLATE'));
// Reset the home fields for the client_id.
'UPDATE #__template_styles' .
' WHERE client_id = ' . (int)
$style->client_id .
// Set the new home style.
'UPDATE #__template_styles' .
' WHERE id = ' . (int)
$id
* Method to unset a template style as default for a language.
* @param integer $id The primary key ID for the style.
* @return boolean True if successful.
if (!$user->authorise('core.edit.state', 'com_templates'))
throw
new Exception(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
'SELECT client_id, home' .
' FROM #__template_styles' .
' WHERE id = ' . (int)
$id
$style =
$db->loadObject();
throw
new Exception(JText::_('COM_TEMPLATES_ERROR_STYLE_NOT_FOUND'));
elseif ($style->home ==
'1')
throw
new Exception(JText::_('COM_TEMPLATES_ERROR_CANNOT_UNSET_DEFAULT_STYLE'));
// Set the new home style.
'UPDATE #__template_styles' .
' WHERE id = ' . (int)
$id
* Get the necessary data to load an item help screen.
* @return object An object with key, url, and local properties for loading the item help screen.
return (object)
array('key' =>
$this->helpKey, 'url' =>
$this->helpURL);
* Custom clean cache method
* @param string $group The cache group
* @param integer $client_id The ID of the client
protected function cleanCache($group =
null, $client_id =
0)
parent::cleanCache('com_templates');
parent::cleanCache('_system');
Documentation generated on Tue, 19 Nov 2013 15:14:40 +0100 by phpDocumentor 1.4.3