Done !
| Server IP : 46.105.57.169 / Your IP : 216.73.216.67 Web Server : Apache System : Linux webm002.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : verseaumee ( 152031) PHP Version : 8.5.7 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/verseaumee/zenit/administrator/components/com_categories/src/Helper/ |
Upload File : |
<?php
/**
* @package Joomla.Administrator
* @subpackage com_categories
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Categories\Administrator\Helper;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
/**
* Categories helper.
*
* @since 1.6
*/
class CategoriesHelper
{
/**
* Gets a list of associations for a given item.
*
* @param integer $pk Content item key.
* @param string $extension Optional extension name.
*
* @return array of associations.
*/
public static function getAssociations($pk, $extension = 'com_content')
{
$langAssociations = Associations::getAssociations($extension, '#__categories', 'com_categories.item', $pk, 'id', 'alias', '');
$associations = array();
$user = Factory::getUser();
$groups = $user->getAuthorisedViewLevels();
foreach ($langAssociations as $langAssociation)
{
// Include only published categories with user access
$arrId = explode(':', $langAssociation->id);
$assocId = (int) $arrId[0];
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('published'))
->from($db->quoteName('#__categories'))
->whereIn($db->quoteName('access'), $groups)
->where($db->quoteName('id') . ' = :associd')
->bind(':associd', $assocId, ParameterType::INTEGER);
$result = (int) $db->setQuery($query)->loadResult();
if ($result === 1)
{
$associations[$langAssociation->language] = $langAssociation->id;
}
}
return $associations;
}
/**
* Check if Category ID exists otherwise assign to ROOT category.
*
* @param mixed $catid Name or ID of category.
* @param string $extension Extension that triggers this function
*
* @return integer $catid Category ID.
*/
public static function validateCategoryId($catid, $extension)
{
$categoryTable = Table::getInstance('CategoryTable', '\\Joomla\\Component\\Categories\\Administrator\\Table\\');
$data = array();
$data['id'] = $catid;
$data['extension'] = $extension;
if (!$categoryTable->load($data))
{
$catid = 0;
}
return (int) $catid;
}
/**
* Create new Category from within item view.
*
* @param array $data Array of data for new category.
*
* @return integer
*/
public static function createCategory($data)
{
$categoryModel = Factory::getApplication()->bootComponent('com_categories')
->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]);
$categoryModel->save($data);
$catid = $categoryModel->getState('category.id');
return $catid;
}
}