[ 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_finder 6 * 7 * @copyright (C) 2016 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\Finder\Administrator\Field; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Form\Field\GroupedlistField; 15 use Joomla\CMS\HTML\HTMLHelper; 16 use Joomla\CMS\Language\Text; 17 use Joomla\Component\Finder\Administrator\Helper\LanguageHelper; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('JPATH_PLATFORM') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Supports a select grouped list of finder content map. 25 * 26 * @since 3.6.0 27 */ 28 class ContentmapField extends GroupedlistField 29 { 30 /** 31 * The form field type. 32 * 33 * @var string 34 * @since 3.6.0 35 */ 36 public $type = 'ContentMap'; 37 38 /** 39 * Method to get the list of content map options grouped by first level. 40 * 41 * @return array The field option objects as a nested array in groups. 42 * 43 * @since 3.6.0 44 */ 45 protected function getGroups() 46 { 47 $groups = array(); 48 49 // Get the database object and a new query object. 50 $db = $this->getDatabase(); 51 52 // Main query. 53 $query = $db->getQuery(true) 54 ->select($db->quoteName('a.title', 'text')) 55 ->select($db->quoteName('a.id', 'value')) 56 ->select($db->quoteName('a.parent_id')) 57 ->select($db->quoteName('a.level')) 58 ->from($db->quoteName('#__finder_taxonomy', 'a')) 59 ->where($db->quoteName('a.parent_id') . ' <> 0') 60 ->order('a.title ASC'); 61 62 $db->setQuery($query); 63 64 try { 65 $contentMap = $db->loadObjectList(); 66 } catch (\RuntimeException $e) { 67 return []; 68 } 69 70 // Build the grouped list array. 71 if ($contentMap) { 72 $parents = []; 73 74 foreach ($contentMap as $item) { 75 if (!isset($parents[$item->parent_id])) { 76 $parents[$item->parent_id] = []; 77 } 78 79 $parents[$item->parent_id][] = $item; 80 } 81 82 foreach ($parents[1] as $branch) { 83 $groups[$branch->text] = $this->prepareLevel($branch->value, $parents); 84 } 85 } 86 87 // Merge any additional groups in the XML definition. 88 $groups = array_merge(parent::getGroups(), $groups); 89 90 return $groups; 91 } 92 93 /** 94 * Indenting and translating options for the list 95 * 96 * @param int $parent Parent ID to process 97 * @param array $parents Array of arrays of items with parent IDs as keys 98 * 99 * @return array The indented list of entries for this branch 100 * 101 * @since 4.1.5 102 */ 103 private function prepareLevel($parent, $parents) 104 { 105 $lang = Factory::getLanguage(); 106 $entries = []; 107 108 foreach ($parents[$parent] as $item) { 109 $levelPrefix = str_repeat('- ', $item->level - 1); 110 111 if (trim($item->text, '*') === 'Language') { 112 $text = LanguageHelper::branchLanguageTitle($item->text); 113 } else { 114 $key = LanguageHelper::branchSingular($item->text); 115 $text = $lang->hasKey($key) ? Text::_($key) : $item->text; 116 } 117 118 $entries[] = HTMLHelper::_('select.option', $item->value, $levelPrefix . $text); 119 120 if (isset($parents[$item->value])) { 121 $entries = array_merge($entries, $this->prepareLevel($item->value, $parents)); 122 } 123 } 124 125 return $entries; 126 } 127 }
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 |