Source for file article.php
Documentation is available at article.php
* @subpackage com_content
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @subpackage com_content
* The URL view item variable.
* The URL view list variable.
* Method to add a new record.
* @return mixed True if the record can be added, a error object if not.
// Redirect to the return page.
* Method override to check if you can add a new record.
* @param array $data An array of input data.
protected function allowAdd($data =
array())
// If the category has been passed in the data or URL check it.
$allow =
$user->authorise('core.create', 'com_content.category.'.
$categoryId);
// In the absense of better information, revert to the component permissions.
* Method override to check if you can edit an existing record.
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key; default is id.
protected function allowEdit($data =
array(), $key =
'id')
$recordId = (int) isset
($data[$key]) ?
$data[$key] :
0;
$userId =
$user->get('id');
$asset =
'com_content.article.' .
$recordId;
// Check general edit permission first.
if ($user->authorise('core.edit', $asset))
// First test if the permission is available.
if ($user->authorise('core.edit.own', $asset))
// Now test the owner is the user.
$ownerId = (int) isset
($data['created_by']) ?
$data['created_by'] :
0;
if (empty($ownerId) &&
$recordId)
// Need to do a lookup from the model.
$record =
$this->getModel()->getItem($recordId);
$ownerId =
$record->created_by;
// If the owner matches 'me' then do the test.
// Since there is no asset tracking, revert to the component permissions.
* Method to cancel an edit.
* @param string $key The name of the primary key of the URL variable.
* @return boolean True if access level checks pass, false otherwise.
public function cancel($key =
'a_id')
// Redirect to the return page.
* Method to edit an existing record.
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key
* (sometimes required to avoid router collisions).
* @return boolean True if access level check and checkout passes, false otherwise.
public function edit($key =
null, $urlVar =
'a_id')
$result =
parent::edit($key, $urlVar);
* Method to get a model object, loading it if required.
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
* @return object The model.
public function getModel($name =
'form', $prefix =
'', $config =
array('ignore_request' =>
true))
$model =
parent::getModel($name, $prefix, $config);
* Gets the URL arguments to append to an item redirect.
* @param integer $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the id.
* @return string The arguments to append to the redirect URL.
// Need to override the parent method completely.
$tmpl =
$this->input->get('tmpl');
// $layout = $this->input->get('layout', 'edit');
$append .=
'&tmpl='.
$tmpl;
// TODO This is a bandaid, not a long term solution.
// $append .= '&layout=' . $layout;
$append .=
'&layout=edit';
$append .=
'&'.
$urlVar.
'='.
$recordId;
$itemId =
$this->input->getInt('Itemid');
$catId =
$this->input->getInt('catid', null, 'get');
$append .=
'&Itemid='.
$itemId;
$append .=
'&catid='.
$catId;
* If a "return" variable has been passed in the request
* @return string The return URL.
$return =
$this->input->get('return', null, 'base64');
* Function that allows child controller access to model data after the data has been saved.
* @param JModelLegacy $model The data model object.
* @param array $validData The validated data.
protected function postSaveHook(JModelLegacy $model, $validData =
array())
* Method to save a record.
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
* @return boolean True if successful, false otherwise.
public function save($key =
null, $urlVar =
'a_id')
$result =
parent::save($key, $urlVar);
// If ok, redirect to the return page.
// Check for request forgeries.
$user_rating =
$this->input->getInt('user_rating', -
1);
$url =
$this->input->getString('url', '');
$id =
$this->input->getInt('id', 0);
if ($model->storeVote($id, $user_rating))
Documentation generated on Tue, 19 Nov 2013 14:53:54 +0100 by phpDocumentor 1.4.3