[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_categories 6 * 7 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Categories\Administrator\Helper; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Associations; 15 use Joomla\CMS\Table\Table; 16 use Joomla\Database\ParameterType; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Categories helper. 24 * 25 * @since 1.6 26 */ 27 class CategoriesHelper 28 { 29 /** 30 * Gets a list of associations for a given item. 31 * 32 * @param integer $pk Content item key. 33 * @param string $extension Optional extension name. 34 * 35 * @return array of associations. 36 */ 37 public static function getAssociations($pk, $extension = 'com_content') 38 { 39 $langAssociations = Associations::getAssociations($extension, '#__categories', 'com_categories.item', $pk, 'id', 'alias', ''); 40 $associations = array(); 41 $user = Factory::getUser(); 42 $groups = $user->getAuthorisedViewLevels(); 43 44 foreach ($langAssociations as $langAssociation) { 45 // Include only published categories with user access 46 $arrId = explode(':', $langAssociation->id); 47 $assocId = (int) $arrId[0]; 48 $db = Factory::getDbo(); 49 50 $query = $db->getQuery(true) 51 ->select($db->quoteName('published')) 52 ->from($db->quoteName('#__categories')) 53 ->whereIn($db->quoteName('access'), $groups) 54 ->where($db->quoteName('id') . ' = :associd') 55 ->bind(':associd', $assocId, ParameterType::INTEGER); 56 57 $result = (int) $db->setQuery($query)->loadResult(); 58 59 if ($result === 1) { 60 $associations[$langAssociation->language] = $langAssociation->id; 61 } 62 } 63 64 return $associations; 65 } 66 67 /** 68 * Check if Category ID exists otherwise assign to ROOT category. 69 * 70 * @param mixed $catid Name or ID of category. 71 * @param string $extension Extension that triggers this function 72 * 73 * @return integer $catid Category ID. 74 */ 75 public static function validateCategoryId($catid, $extension) 76 { 77 $categoryTable = Table::getInstance('CategoryTable', '\\Joomla\\Component\\Categories\\Administrator\\Table\\'); 78 79 $data = array(); 80 $data['id'] = $catid; 81 $data['extension'] = $extension; 82 83 if (!$categoryTable->load($data)) { 84 $catid = 0; 85 } 86 87 return (int) $catid; 88 } 89 90 /** 91 * Create new Category from within item view. 92 * 93 * @param array $data Array of data for new category. 94 * 95 * @return integer 96 */ 97 public static function createCategory($data) 98 { 99 $categoryModel = Factory::getApplication()->bootComponent('com_categories') 100 ->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]); 101 $categoryModel->save($data); 102 103 $catid = $categoryModel->getState('category.id'); 104 105 return $catid; 106 } 107 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |