Source for file weblink.php
Documentation is available at weblink.php
* @package Joomla.Administrator
* @subpackage com_weblinks
* @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_weblinks
* The type alias for this content type.
* The prefix to use with controller messages.
* Method to test whether a record can be deleted.
* @param object $record A record object.
* @return boolean True if allowed to delete the record. Defaults to the permission for the component.
if ($record->state != -
2)
return $user->authorise('core.delete', 'com_weblinks.category.'.(int)
$record->catid);
return parent::canDelete($record);
* Method to test whether a record can be deleted.
* @param object $record A record object.
* @return boolean True if allowed to change the state of the record. Defaults to the permission for the component.
if (!empty($record->catid))
return $user->authorise('core.edit.state', 'com_weblinks.category.'.(int)
$record->catid);
return parent::canEditState($record);
* Method to get a table object, load it if necessary.
* @param string $type The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
* @return JTable A JTable object
public function getTable($type =
'Weblink', $prefix =
'WeblinksTable', $config =
array())
* Abstract method for getting the form from the model.
* @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
public function getForm($data =
array(), $loadData =
true)
$form =
$this->loadForm('com_weblinks.weblink', 'weblink', array('control' =>
'jform', 'load_data' =>
$loadData));
// Determine correct permissions to check.
// Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit');
// New record. Can only create in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.create');
// Modify the form based on access controls.
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('state', 'disabled', 'true');
$form->setFieldAttribute('publish_up', 'disabled', 'true');
$form->setFieldAttribute('publish_down', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('state', 'filter', 'unset');
$form->setFieldAttribute('publish_up', 'filter', 'unset');
$form->setFieldAttribute('publish_down', 'filter', 'unset');
* Method to get the data that should be injected in the form.
* @return array The default data is an empty array.
// Check the session for previously entered form data.
// Prime some default values.
$data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int'));
* 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)
if ($item =
parent::getItem($pk))
// Convert the metadata field to an array.
$registry->loadString($item->metadata);
$item->metadata =
$registry->toArray();
// Convert the images field to an array.
$registry->loadString($item->images);
$item->images =
$registry->toArray();
$item->tags->getTagIds($item->id, 'com_weblinks.weblink');
$item->metadata['tags'] =
$item->tags;
* Prepare and sanitise the table data prior to saving.
* @param JTable $table A reference to a JTable object.
if (empty($table->alias))
// Set ordering to the last item if not set
if (empty($table->ordering))
$db->setQuery('SELECT MAX(ordering) FROM #__weblinks');
$max =
$db->loadResult();
$table->ordering =
$max +
1;
$table->modified =
$date->toSql();
$table->modified_by =
$user->get('id');
// Increment the weblink version number.
* A protected method to get a set of ordering conditions.
* @param JTable $table A JTable object.
* @return array An array of conditions to add to ordering queries.
$condition[] =
'catid = ' . (int)
$table->catid;
* Method to save the form data.
* @param array $data The form data.
* @return boolean True on success.
public function save($data)
// Alter the title for save as copy
if ($app->input->get('task') ==
'save2copy')
list
($name, $alias) =
$this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
return parent::save($data);
* Method to change the title & alias.
* @param integer $category_id The id of the parent.
* @param string $alias The alias.
* @param string $name The title.
* @return array Contains the modified title and alias.
// Alter the title & alias
while ($table->load(array('alias' =>
$alias, 'catid' =>
$category_id)))
if ($name ==
$table->title)
return array($name, $alias);
Documentation generated on Tue, 19 Nov 2013 15:18:29 +0100 by phpDocumentor 1.4.3