- md5
- a2e25fde648fa58ca76f1af96eacc910
- sha1
- 20168874fa02c57b144238ad6b2427291ab50d16
- sha256
- 15e6255c51be16eb1e27cf9133f8e8047afa97b59282d787b8e5227acbea4f29
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
<?php
/**
* @version $Id: banner.php 21148 2011-04-14 17:30:08Z ian $
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access.
defined('_JEXEC') or die;
jimport('joomla.application.component.modeladmin');
/**
* Banner model.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class BannersModelBanner extends JModelAdmin
{
/**
* @var string The prefix to use with controller messages.
* @since 1.6
*/
protected $text_prefix = 'COM_BANNERS_BANNER';
/**
* Method to test whether a record can be deleted.
*
* @param object A record object.
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
* @since 1.6
*/
protected function canDelete($record)
{
if (!empty($record->id)) {
if ($record->state != -2) {
return ;
}
$user = JFactory::getUser();
if (!empty($record->catid)) {
return $user->authorise('core.delete', 'com_banners.category.'.(int) $record->catid);
}
else {
return parent::canDelete($record);
}
}
}
/**
* Method to test whether a record can have its state changed.
*
* @param object A record object.
* @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
* @since 1.6
*/
protected function canEditState($record)
{
$user = JFactory::getUser();
// Check against the category.
if (!empty($record->catid)) {
return $user->authorise('core.edit.state', 'com_banners.category.'.(int) $record->catid);
}
// Default to component settings if category not known.
else {
return parent::canEditState($record);
}
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
* @since 1.6
*/
public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to 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 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_banners.banner', 'banner', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
// Determine correct permissions to check.
if ($this->getState('banner.id')) {
// Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit');
} else {
// New record. Can only create in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.create');
}
// Modify the form based on access controls.
if (!$this->canEditState((object) $data)) {
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('publish_up', 'disabled', 'true');
$form->setFieldAttribute('publish_down', 'disabled', 'true');
$form->setFieldAttribute('state', 'disabled', 'true');
$form->setFieldAttribute('sticky', '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('publish_up', 'filter', 'unset');
$form->setFieldAttribute('publish_down', 'filter', 'unset');
$form->setFieldAttribute('state', 'filter', 'unset');
$form->setFieldAttribute('sticky', 'filter', 'unset');
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
* @since 1.6
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_banners.edit.banner.data', array());
if (empty($data)) {
$data = $this->getItem();
// Prime some default values.
if ($this->getState('banner.id') == 0) {
$app = JFactory::getApplication();
$data->set('catid', JRequest::getInt('catid', $app->getUserState('com_banners.banners.filter.category_id')));
}
}
return $data;
}
/**
* Method to stick records.
*
* @param array The ids of the items to publish.
* @param int The value of the published state
*
* @return boolean True on success.
*/
function stick(&$pks, $value = 1)
{
// Initialise variables.
$user = JFactory::getUser();
$table = $this->getTable();
$pks = (array) $pks;
// Access checks.
foreach ($pks as $i => $pk) {
if ($table->load($pk)) {
if (!$this->canEditState($table)) {
// Prune items that you can't change.
unset($pks[$i]);
JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
}
}
}
// Attempt to change the state of the records.
if (!$table->stick($pks, $value, $user->get('id'))) {
$this->setError($table->getError());
return false;
}
return true;
}
/**
* A protected method to get a set of ordering conditions.
*
* @param object A record object.
* @return array An array of conditions to add to add to ordering queries.
* @since 1.6
*/
protected function getReorderConditions($table)
{
$condition = array();
$condition[] = 'catid = '. (int) $table->catid;
$condition[] = 'state >= 0';
return $condition;
}
}
The same content is in 5 releases, Joomla 1.6.2 to 1.6.6. See them all, or every version of this file.