Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2] [DRAFT] Global Delete Trash - New Feature #27429

Closed
wants to merge 11 commits into from
7 changes: 7 additions & 0 deletions administrator/components/com_menus/presets/alternate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
link="index.php?option=com_cache"
/>

<menuitem
title="MOD_MENU_EMPTY_TRASH"
type="component"
element="com_trash"
link="index.php?option=com_trash"
/>

<menuitem
title="MOD_MENU_SYSTEM_INFORMATION"
type="component"
Expand Down
9 changes: 9 additions & 0 deletions administrator/components/com_menus/presets/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
permission="core.manage;com_checkin"
ajax-badge="index.php?option=com_checkin&amp;task=getMenuBadgeData&amp;format=json"
/>

<menuitem
title="MOD_MENU_TRASH"
type="component"
element="com_trash"
link="index.php?option=com_trash"
permission="core.admin;com_trash"
ajax-badge="index.php?option=com_trash&amp;task=getMenuBadgeData&amp;format=json"
/>
</menuitem>

<menuitem
Expand Down
122 changes: 122 additions & 0 deletions administrator/components/com_trash/Controller/DisplayController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_trash
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
brianteeman marked this conversation as resolved.
Show resolved Hide resolved
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Trash\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Response\JsonResponse;

/**
* Trash Controller
*
* @since __DEPLOY_VERSION__
*/
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $default_view = 'trash';

/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe URL parameters and their variable types, for valid values see {@link \JFilterInput::clean()}.
*
* @return static A \JControllerLegacy object to support chaining.
*/
public function display($cachable = false, $urlparams = array())
{
return parent::display();
}

/**
* Trash a list of items.
*
* @return void
*/
public function trash()
{
// Check for request forgeries
$this->checkToken();

$ids = $this->input->get('cid', array(), 'array');

if (empty($ids))
{
$this->app->enqueueMessage(Text::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'), 'warning');
}
else
{
// Get the model.
/** @var \Joomla\Component\Trash\Administrator\Model\TrashModel $model */
$model = $this->getModel('Trash');

// Trash the items.
$this->setMessage(Text::plural('COM_TRASH_N_ITEMS_DELETED', $model->trash($ids)));
}

$this->setRedirect('index.php?option=com_trash');
}

/**
* Provide the data for a badge in a menu item via JSON
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function getMenuBadgeData()
{
if (!Factory::getUser()->authorise('core.admin', 'com_trash'))
{
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}

$model = $this->getModel('Trash');

$amount = (int) count($model->getItems());

echo new JsonResponse($amount);
}

/**
* Method to get the number of trashed items
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function getQuickiconContent()
{
if (!Factory::getUser()->authorise('core.admin', 'com_trash'))
{
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}

$model = $this->getModel('Trash');

$amount = (int) count($model->getItems());

$result = [];

$result['amount'] = $amount;
$result['sronly'] = Text::plural('COM_TRASH_N_QUICKICON_SRONLY', $amount);

echo new JsonResponse($result);
}
}
Loading