Skip to content

Commit

Permalink
Merge pull request #29 from mbabker/batch
Browse files Browse the repository at this point in the history
[#27221] Improvements for batch processing
  • Loading branch information
chdemko committed Jan 3, 2012
2 parents 65e09a2 + 29e68be commit a0c6adf
Show file tree
Hide file tree
Showing 54 changed files with 3,191 additions and 1,177 deletions.
83 changes: 59 additions & 24 deletions administrator/components/com_banners/controllers/banner.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
/**
* @version $Id$
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla.Administrator
* @subpackage com_banners
*
* @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
Expand All @@ -13,25 +15,26 @@
/**
* Banner controller class.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class BannersControllerBanner extends JControllerForm
{
/**
* @var string The prefix to use with controller messages.
* @since 1.6
* @var string The prefix to use with controller messages.
* @since 1.6
*/
protected $text_prefix = 'COM_BANNERS_BANNER';

/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
* @param array $data An array of input data.
*
* @return boolean
*
* @return boolean
* @since 1.6
* @since 1.6
*/
protected function allowAdd($data = array())
{
Expand All @@ -40,27 +43,32 @@ protected function allowAdd($data = array())
$categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int');
$allow = null;

if ($categoryId) {
if ($categoryId)
{
// If the category has been passed in the URL check it.
$allow = $user->authorise('core.create', $this->option.'.category.'.$categoryId);
$allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId);
}

if ($allow === null) {
// In the absense of better information, revert to the component permissions.
if ($allow === null)
{
// In the absence of better information, revert to the component permissions.
return parent::allowAdd($data);
} else {
}
else
{
return $allow;
}
}

/**
* 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.
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
* @since 1.6
* @return boolean
*
* @since 1.6
*/
protected function allowEdit($data = array(), $key = 'id')
{
Expand All @@ -69,16 +77,43 @@ protected function allowEdit($data = array(), $key = 'id')
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$categoryId = 0;

if ($recordId) {
if ($recordId)
{
$categoryId = (int) $this->getModel()->getItem($recordId)->catid;
}

if ($categoryId) {
if ($categoryId)
{
// The category has been set. Check the category permissions.
return $user->authorise('core.edit', $this->option.'.category.'.$categoryId);
} else {
return $user->authorise('core.edit', $this->option . '.category.' . $categoryId);
}
else
{
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
}

/**
* Method to run batch operations.
*
* @param string $model The model
*
* @return boolean True on success.
*
* @since 2.5
*/
public function batch($model = null)
{
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

// Set the model
$model = $this->getModel('Banner', '', array());

// Preset the redirect
$this->setRedirect(JRoute::_('index.php?option=com_banners&view=banners' . $this->getRedirectToListAppend(), false));

return parent::batch($model);
}

}
72 changes: 72 additions & 0 deletions administrator/components/com_banners/helpers/html/banner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_banners
*
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_BASE') or die;

/**
* Banner HTML class.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 2.5
*/
abstract class JHtmlBanner
{
/**
* Display a batch widget for the client selector.
*
* @return string The necessary HTML for the widget.
*
* @since 2.5
*/
public static function clients()
{
// Create the batch selector to change the client on a selection list.
$lines = array(
'<label id="batch-client-lbl" for="batch-client" class="hasTip" title="'.JText::_('COM_BANNERS_BATCH_CLIENT_LABEL').'::'.JText::_('COM_BANNERS_BATCH_CLIENT_LABEL_DESC').'">',
JText::_('COM_BANNERS_BATCH_CLIENT_LABEL'),
'</label>',
'<select name="batch[client_id]" class="inputbox" id="batch-client-id">',
'<option value="">'.JText::_('COM_BANNERS_BATCH_CLIENT_NOCHANGE').'</option>',
'<option value="0">'.JText::_('COM_BANNERS_NO_CLIENT').'</option>',
JHtml::_('select.options', self::clientlist(), 'value', 'text'),
'</select>'
);

return implode("\n", $lines);
}

/**
* Method to get the field options.
*
* @return array The field option objects.
* @since 1.6
*/
public static function clientlist()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->select('id As value, name As text');
$query->from('#__banner_clients AS a');
$query->order('a.name');

// Get the options.
$db->setQuery($query);

$options = $db->loadObjectList();

// Check for a database error.
if ($db->getErrorNum()) {
JError::raiseWarning(500, $db->getErrorMsg());
}

return $options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
Loading

0 comments on commit a0c6adf

Please sign in to comment.