mirror of
https://github.com/joomla-extensions/weblinks.git
synced 2024-12-26 18:10:11 +00:00
Clean up code
This commit is contained in:
parent
8d714ace8d
commit
9107b7e1de
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
use Joomla\CMS\Extension\ExtensionHelper;
|
|
||||||
use Joomla\CMS\Factory;
|
use Joomla\CMS\Factory;
|
||||||
use Joomla\CMS\Filesystem\File;
|
use Joomla\CMS\Filesystem\File;
|
||||||
use Joomla\CMS\Filesystem\Folder;
|
use Joomla\CMS\Filesystem\Folder;
|
||||||
@ -93,8 +92,8 @@ class Com_WeblinksInstallerScript
|
|||||||
public function install($parent)
|
public function install($parent)
|
||||||
{
|
{
|
||||||
// Initialize a new category
|
// Initialize a new category
|
||||||
/** @type JTableCategory $category */
|
/** @type Joomla\CMS\Table\Category $category */
|
||||||
$category = Table::getInstance('Category');
|
$category = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
|
||||||
|
|
||||||
// Check if the Uncategorised category exists before adding it
|
// Check if the Uncategorised category exists before adding it
|
||||||
if (!$category->load(array('extension' => 'com_weblinks', 'title' => 'Uncategorised')))
|
if (!$category->load(array('extension' => 'com_weblinks', 'title' => 'Uncategorised')))
|
||||||
|
@ -44,19 +44,23 @@ return new class implements ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
$container->set(AssociationExtensionInterface::class, new AssociationsHelper);
|
$container->set(AssociationExtensionInterface::class, new AssociationsHelper);
|
||||||
|
|
||||||
$container->registerServiceProvider(new CategoryFactory('\\Joomla\\Component\\Weblinks'));
|
$componentNamespace = '\\Joomla\\Component\\Weblinks';
|
||||||
$container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Weblinks'));
|
|
||||||
$container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Weblinks'));
|
$container->registerServiceProvider(new CategoryFactory($componentNamespace));
|
||||||
$container->registerServiceProvider(new RouterFactory('\\Joomla\\Component\\Weblinks'));
|
$container->registerServiceProvider(new MVCFactory($componentNamespace));
|
||||||
|
$container->registerServiceProvider(new ComponentDispatcherFactory($componentNamespace));
|
||||||
|
$container->registerServiceProvider(new RouterFactory($componentNamespace));
|
||||||
|
|
||||||
$container->set(
|
$container->set(
|
||||||
ComponentInterface::class,
|
ComponentInterface::class,
|
||||||
function (Container $container) {
|
function (Container $container) {
|
||||||
$component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class));
|
$component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class));
|
||||||
|
|
||||||
$component->setRegistry($container->get(Registry::class));
|
$component->setRegistry($container->get(Registry::class));
|
||||||
$component->setMVCFactory($container->get(MVCFactoryInterface::class));
|
$component->setMVCFactory($container->get(MVCFactoryInterface::class));
|
||||||
$component->setCategoryFactory($container->get(CategoryFactoryInterface::class));
|
$component->setCategoryFactory($container->get(CategoryFactoryInterface::class));
|
||||||
$component->setRouterFactory($container->get(RouterFactoryInterface::class));
|
|
||||||
$component->setAssociationExtension($container->get(AssociationExtensionInterface::class));
|
$component->setAssociationExtension($container->get(AssociationExtensionInterface::class));
|
||||||
|
$component->setRouterFactory($container->get(RouterFactoryInterface::class));
|
||||||
|
|
||||||
return $component;
|
return $component;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ class WeblinkController extends FormController
|
|||||||
$this->checkToken();
|
$this->checkToken();
|
||||||
|
|
||||||
// Set the model
|
// Set the model
|
||||||
$model = $this->getModel('Weblink', '', array());
|
$model = $this->getModel('Weblink', 'Administrator', array());
|
||||||
|
|
||||||
// Preset the redirect
|
// Preset the redirect
|
||||||
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false));
|
$this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false));
|
||||||
|
@ -128,7 +128,7 @@ class AssociationsHelper extends AssociationExtensionHelper
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'category':
|
case 'category':
|
||||||
$table = Table::getInstance('Category');
|
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,20 @@ class CategoryModel extends ListModel
|
|||||||
*/
|
*/
|
||||||
protected $_item = null;
|
protected $_item = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Category left of this one
|
||||||
|
*
|
||||||
|
* @var CategoryNode|null
|
||||||
|
*/
|
||||||
|
protected $_leftsibling = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Category right right of this one
|
||||||
|
*
|
||||||
|
* @var CategoryNode|null
|
||||||
|
*/
|
||||||
|
protected $_rightsibling = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of child-categories
|
* Array of child-categories
|
||||||
*
|
*
|
||||||
@ -114,7 +128,7 @@ class CategoryModel extends ListModel
|
|||||||
$viewLevels = Factory::getApplication()->getIdentity()->getAuthorisedViewLevels();
|
$viewLevels = Factory::getApplication()->getIdentity()->getAuthorisedViewLevels();
|
||||||
|
|
||||||
// Create a new query object.
|
// Create a new query object.
|
||||||
$db = $this->getDbo();
|
$db = $this->getDbo();
|
||||||
$query = $db->getQuery(true);
|
$query = $db->getQuery(true);
|
||||||
|
|
||||||
// Select required fields from the categories.
|
// Select required fields from the categories.
|
||||||
@ -174,7 +188,7 @@ class CategoryModel extends ListModel
|
|||||||
if ($this->getState('filter.publish_date'))
|
if ($this->getState('filter.publish_date'))
|
||||||
{
|
{
|
||||||
$nullDate = $db->getNullDate();
|
$nullDate = $db->getNullDate();
|
||||||
$nowDate = Factory::getDate()->toSql();
|
$nowDate = Factory::getDate()->toSql();
|
||||||
$query->where('(a.publish_up = :publishUpNullDate OR a.publish_up <= :publishUpNowDate)')
|
$query->where('(a.publish_up = :publishUpNullDate OR a.publish_up <= :publishUpNowDate)')
|
||||||
->where('(a.publish_down = :publishDownNullDate OR a.publish_down >= :publishDownNowDate)')
|
->where('(a.publish_down = :publishDownNullDate OR a.publish_down >= :publishDownNowDate)')
|
||||||
->bind(':publishUpNullDate', $nullDate)
|
->bind(':publishUpNullDate', $nullDate)
|
||||||
@ -231,7 +245,7 @@ class CategoryModel extends ListModel
|
|||||||
*/
|
*/
|
||||||
protected function populateState($ordering = null, $direction = null)
|
protected function populateState($ordering = null, $direction = null)
|
||||||
{
|
{
|
||||||
$app = Factory::getApplication();
|
$app = Factory::getApplication();
|
||||||
$params = ComponentHelper::getParams('com_weblinks');
|
$params = ComponentHelper::getParams('com_weblinks');
|
||||||
|
|
||||||
// List state information
|
// List state information
|
||||||
@ -304,17 +318,17 @@ class CategoryModel extends ListModel
|
|||||||
$params = new Registry;
|
$params = new Registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array();
|
$options = array();
|
||||||
$options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|
$options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|
||||||
|| $params->get('show_empty_categories', 0);
|
|| $params->get('show_empty_categories', 0);
|
||||||
|
|
||||||
$categories = Categories::getInstance('Weblinks', $options);
|
$categories = Categories::getInstance('Weblinks', $options);
|
||||||
$this->_item = $categories->get($this->getState('category.id', 'root'));
|
$this->_item = $categories->get($this->getState('category.id', 'root'));
|
||||||
|
|
||||||
if (is_object($this->_item))
|
if (is_object($this->_item))
|
||||||
{
|
{
|
||||||
$this->_children = $this->_item->getChildren();
|
$this->_children = $this->_item->getChildren();
|
||||||
$this->_parent = false;
|
$this->_parent = false;
|
||||||
|
|
||||||
if ($this->_item->getParent())
|
if ($this->_item->getParent())
|
||||||
{
|
{
|
||||||
@ -322,12 +336,12 @@ class CategoryModel extends ListModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->_rightsibling = $this->_item->getSibling();
|
$this->_rightsibling = $this->_item->getSibling();
|
||||||
$this->_leftsibling = $this->_item->getSibling(false);
|
$this->_leftsibling = $this->_item->getSibling(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->_children = false;
|
$this->_children = false;
|
||||||
$this->_parent = false;
|
$this->_parent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,8 +423,8 @@ class CategoryModel extends ListModel
|
|||||||
|
|
||||||
if ($hitcount)
|
if ($hitcount)
|
||||||
{
|
{
|
||||||
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
|
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
|
||||||
$table = Table::getInstance('Category', 'JTable');
|
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
|
||||||
$table->load($pk);
|
$table->load($pk);
|
||||||
$table->hit($pk);
|
$table->hit($pk);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user