Skip to content

Commit

Permalink
Namespace com_categories
Browse files Browse the repository at this point in the history
  • Loading branch information
joomdonation committed May 6, 2017
1 parent a8d68c0 commit d43efb1
Show file tree
Hide file tree
Showing 16 changed files with 572 additions and 537 deletions.
132 changes: 132 additions & 0 deletions administrator/components/com_categories/Controller/Categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_categories
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Categories\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\Controller\Admin;
use Joomla\Utilities\ArrayHelper;

/**
* The Categories List Controller
*
* @since 1.6
*/
class Categories extends Admin
{
/**
* Proxy for getModel
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config The array of possible config values. Optional.
*
* @return \Joomla\Cms\Model\Model The model.
*
* @since 1.6
*/
public function getModel($name = 'Category', $prefix = 'Administrator', $config = array('ignore_request' => true))
{
return parent::getModel($name, $prefix, $config);
}

/**
* Rebuild the nested set tree.
*
* @return bool False on failure or error, true on success.
*
* @since 1.6
*/
public function rebuild()
{
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));

$extension = $this->input->get('extension');
$this->setRedirect(\JRoute::_('index.php?option=com_categories&view=categories&extension=' . $extension, false));

/** @var \Joomla\Component\Categories\Administrator\Model\Category $model */
$model = $this->getModel();

if ($model->rebuild())
{
// Rebuild succeeded.
$this->setMessage(\JText::_('COM_CATEGORIES_REBUILD_SUCCESS'));

return true;
}

// Rebuild failed.
$this->setMessage(\JText::_('COM_CATEGORIES_REBUILD_FAILURE'));

return false;
}

/**
* Deletes and returns correctly.
*
* @return void
*
* @since 3.1.2
*/
public function delete()
{
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));

// Get items to remove from the request.
$cid = $this->input->get('cid', array(), 'array');
$extension = $this->input->getCmd('extension', null);

if (!is_array($cid) || count($cid) < 1)
{
$this->app->enqueueMessage(\JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), 'warning');
}
else
{
// Get the model.
/** @var \Joomla\Component\Categories\Administrator\Model\Category $model */
$model = $this->getModel();

// Make sure the item ids are integers
$cid = ArrayHelper::toInteger($cid);

// Remove the items.
if ($model->delete($cid))
{
$this->setMessage(\JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
}
else
{
$this->setMessage($model->getError());
}
}

$this->setRedirect(\JRoute::_('index.php?option=' . $this->option . '&extension=' . $extension, false));
}

/**
* Check in of one or more records.
*
* Overrides \JControllerAdmin::checkin to redirect to URL with extension.
*
* @return boolean True on success
*
* @since 3.6.0
*/
public function checkin()
{
// Process parent checkin method.
$result = parent::checkin();

// Override the redirect Uri.
$redirectUri = 'index.php?option=' . $this->option . '&view=' . $this->view_list . '&extension=' . $this->input->get('extension', '', 'CMD');
$this->setRedirect(\JRoute::_($redirectUri, false), $this->message, $this->messageType);

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Categories\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\Mvc\Factory\MvcFactoryInterface;
use Joomla\CMS\Controller\Form;
use Joomla\CMS\Model\Model;
use Joomla\Registry\Registry;

/**
* The Category Controller
*
* @since 1.6
*/
class CategoriesControllerCategory extends JControllerForm
class Category extends Form
{
/**
* The extension for which the categories apply.
Expand All @@ -29,16 +33,18 @@ class CategoriesControllerCategory extends JControllerForm
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param array $config An optional associative array of configuration settings.
* @param MvcFactoryInterface $factory The factory.
* @param CMSApplication $app The JApplication for the dispatcher
* @param \JInput $input Input
*
* @since 1.6
* @see JControllerLegacy
* @see \JControllerLegacy
*/
public function __construct($config = array())
public function __construct($config = array(), MvcFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config);
parent::__construct($config, $factory, $app, $input);

// Guess the JText message prefix. Defaults to the option.
if (empty($this->extension))
{
$this->extension = $this->input->get('extension', 'com_content');
Expand All @@ -56,7 +62,7 @@ public function __construct($config = array())
*/
protected function allowAdd($data = array())
{
$user = JFactory::getUser();
$user = \JFactory::getUser();

return ($user->authorise('core.create', $this->extension) || count($user->getAuthorisedCategories($this->extension, 'core.create')));
}
Expand All @@ -74,7 +80,7 @@ protected function allowAdd($data = array())
protected function allowEdit($data = array(), $key = 'parent_id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$user = JFactory::getUser();
$user = \JFactory::getUser();

// Check "edit" permission on record asset (explicit or inherited)
if ($user->authorise('core.edit', $this->extension . '.category.' . $recordId))
Expand Down Expand Up @@ -116,10 +122,10 @@ protected function allowEdit($data = array(), $key = 'parent_id')
*/
public function batch($model = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));

// Set the model
/** @var CategoriesModelCategory $model */
/** @var \Joomla\Component\Categories\Administrator\Model\Category $model */
$model = $this->getModel('Category');

// Preset the redirect
Expand Down Expand Up @@ -164,14 +170,14 @@ protected function getRedirectToListAppend()
/**
* 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.
* @param \Joomla\Cms\Model\Model $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 3.1
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
protected function postSaveHook(Model $model, $validData = array())
{
$item = $model->getItem();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Categories\Administrator\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\Mvc\Factory\MvcFactoryInterface;
use Joomla\CMS\Controller\Controller as BaseController;
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;

/**
* Categories view class for the Category package.
*
* @since 1.6
*/
class CategoriesController extends JControllerLegacy
class Controller extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'categories';

/**
* The extension for which the categories apply.
*
Expand All @@ -27,16 +40,18 @@ class CategoriesController extends JControllerLegacy
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param array $config An optional associative array of configuration settings.
* @param MvcFactoryInterface $factory The factory.
* @param CMSApplication $app The JApplication for the dispatcher
* @param \JInput $input Input
*
* @see JControllerLegacy
* @since 1.6
* @since 3.0
*/
public function __construct($config = array())
public function __construct($config = array(), MvcFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config);
parent::__construct($config, $factory, $app, $input);

// Guess the JText message prefix. Defaults to the option.
// Guess the \JText message prefix. Defaults to the option.
if (empty($this->extension))
{
$this->extension = $this->input->get('extension', 'com_content');
Expand All @@ -47,16 +62,16 @@ public function __construct($config = array())
* 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()}.
* @param array $urlparams An array of safe URL parameters and their variable types, for valid values see {@link \JFilterInput::clean()}.
*
* @return CategoriesController This object to support chaining.
* @return static This object to support chaining.
*
* @since 1.5
*/
public function display($cachable = false, $urlparams = array())
{
// Get the document object.
$document = JFactory::getDocument();
$document = \JFactory::getDocument();

// Set the default view name and format from the Request.
$vName = $this->input->get('view', 'categories');
Expand All @@ -68,8 +83,8 @@ public function display($cachable = false, $urlparams = array())
if ($vName == 'category' && $lName == 'edit' && !$this->checkEditId('com_categories.edit.category', $id))
{
// Somehow the person just went to the form - we don't allow that.
$this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_categories&view=categories&extension=' . $this->extension, false));
$this->setMessage(\JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
$this->setRedirect(\JRoute::_('index.php?option=com_categories&view=categories&extension=' . $this->extension, false));

return false;
}
Expand All @@ -78,7 +93,7 @@ public function display($cachable = false, $urlparams = array())
if ($view = $this->getView($vName, $vFormat))
{
// Get the model for the view.
$model = $this->getModel($vName, 'CategoriesModel', array('name' => $vName . '.' . substr($this->extension, 4)));
$model = $this->getModel($vName, 'Administrator', array('name' => $vName . '.' . substr($this->extension, 4)));

// Push the model into the view (as default).
$view->setModel($model, true);
Expand All @@ -88,8 +103,6 @@ public function display($cachable = false, $urlparams = array())
$view->document = $document;

// Load the submenu.
JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');

CategoriesHelper::addSubmenu($model->getState('filter.extension'));
$view->display();
}
Expand Down

0 comments on commit d43efb1

Please sign in to comment.