[ 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_contact 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\Contact\Administrator\Helper; 12 13 use Joomla\CMS\Association\AssociationExtensionHelper; 14 use Joomla\CMS\Language\Associations; 15 use Joomla\CMS\Table\Table; 16 use Joomla\Component\Contact\Site\Helper\AssociationHelper; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Content associations helper. 24 * 25 * @since 3.7.0 26 */ 27 class AssociationsHelper extends AssociationExtensionHelper 28 { 29 /** 30 * The extension name 31 * 32 * @var array $extension 33 * 34 * @since 3.7.0 35 */ 36 protected $extension = 'com_contact'; 37 38 /** 39 * Array of item types 40 * 41 * @var array $itemTypes 42 * 43 * @since 3.7.0 44 */ 45 protected $itemTypes = array('contact', 'category'); 46 47 /** 48 * Has the extension association support 49 * 50 * @var boolean $associationsSupport 51 * 52 * @since 3.7.0 53 */ 54 protected $associationsSupport = true; 55 56 /** 57 * Method to get the associations for a given item. 58 * 59 * @param integer $id Id of the item 60 * @param string $view Name of the view 61 * 62 * @return array Array of associations for the item 63 * 64 * @since 4.0.0 65 */ 66 public function getAssociationsForItem($id = 0, $view = null) 67 { 68 return AssociationHelper::getAssociations($id, $view); 69 } 70 71 /** 72 * Get the associated items for an item 73 * 74 * @param string $typeName The item type 75 * @param int $id The id of item for which we need the associated items 76 * 77 * @return array 78 * 79 * @since 3.7.0 80 */ 81 public function getAssociations($typeName, $id) 82 { 83 $type = $this->getType($typeName); 84 85 $context = $this->extension . '.item'; 86 $catidField = 'catid'; 87 88 if ($typeName === 'category') { 89 $context = 'com_categories.item'; 90 $catidField = ''; 91 } 92 93 // Get the associations. 94 $associations = Associations::getAssociations( 95 $this->extension, 96 $type['tables']['a'], 97 $context, 98 $id, 99 'id', 100 'alias', 101 $catidField 102 ); 103 104 return $associations; 105 } 106 107 /** 108 * Get item information 109 * 110 * @param string $typeName The item type 111 * @param int $id The id of item for which we need the associated items 112 * 113 * @return Table|null 114 * 115 * @since 3.7.0 116 */ 117 public function getItem($typeName, $id) 118 { 119 if (empty($id)) { 120 return null; 121 } 122 123 $table = null; 124 125 switch ($typeName) { 126 case 'contact': 127 $table = Table::getInstance('ContactTable', 'Joomla\\Component\\Contact\\Administrator\\Table\\'); 128 break; 129 130 case 'category': 131 $table = Table::getInstance('Category'); 132 break; 133 } 134 135 if (empty($table)) { 136 return null; 137 } 138 139 $table->load($id); 140 141 return $table; 142 } 143 144 /** 145 * Get information about the type 146 * 147 * @param string $typeName The item type 148 * 149 * @return array Array of item types 150 * 151 * @since 3.7.0 152 */ 153 public function getType($typeName = '') 154 { 155 $fields = $this->getFieldsTemplate(); 156 $tables = array(); 157 $joins = array(); 158 $support = $this->getSupportTemplate(); 159 $title = ''; 160 161 if (in_array($typeName, $this->itemTypes)) { 162 switch ($typeName) { 163 case 'contact': 164 $fields['title'] = 'a.name'; 165 $fields['state'] = 'a.published'; 166 167 $support['state'] = true; 168 $support['acl'] = true; 169 $support['checkout'] = true; 170 $support['category'] = true; 171 $support['save2copy'] = true; 172 173 $tables = array( 174 'a' => '#__contact_details' 175 ); 176 177 $title = 'contact'; 178 break; 179 180 case 'category': 181 $fields['created_user_id'] = 'a.created_user_id'; 182 $fields['ordering'] = 'a.lft'; 183 $fields['level'] = 'a.level'; 184 $fields['catid'] = ''; 185 $fields['state'] = 'a.published'; 186 187 $support['state'] = true; 188 $support['acl'] = true; 189 $support['checkout'] = true; 190 $support['level'] = true; 191 192 $tables = array( 193 'a' => '#__categories' 194 ); 195 196 $title = 'category'; 197 break; 198 } 199 } 200 201 return array( 202 'fields' => $fields, 203 'support' => $support, 204 'tables' => $tables, 205 'joins' => $joins, 206 'title' => $title 207 ); 208 } 209 }
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 |