[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Association; 11 12 use Joomla\Utilities\ArrayHelper; 13 14 // phpcs:disable PSR1.Files.SideEffects 15 \defined('JPATH_PLATFORM') or die; 16 // phpcs:enable PSR1.Files.SideEffects 17 18 /** 19 * Association Extension Helper 20 * 21 * @since 3.7.0 22 */ 23 abstract class AssociationExtensionHelper implements AssociationExtensionInterface 24 { 25 /** 26 * The extension name 27 * 28 * @var array $extension 29 * 30 * @since 3.7.0 31 */ 32 protected $extension = 'com_??'; 33 34 /** 35 * Array of item types 36 * 37 * @var array $itemTypes 38 * 39 * @since 3.7.0 40 */ 41 protected $itemTypes = array(); 42 43 /** 44 * Has the extension association support 45 * 46 * @var boolean $associationsSupport 47 * 48 * @since 3.7.0 49 */ 50 protected $associationsSupport = false; 51 52 /** 53 * Checks if the extension supports associations 54 * 55 * @return boolean Supports the extension associations 56 * 57 * @since 3.7.0 58 */ 59 public function hasAssociationsSupport() 60 { 61 return $this->associationsSupport; 62 } 63 64 /** 65 * Get the item types 66 * 67 * @return array Array of item types 68 * 69 * @since 3.7.0 70 */ 71 public function getItemTypes() 72 { 73 return $this->itemTypes; 74 } 75 76 /** 77 * Get the associated items for an item 78 * 79 * @param string $typeName The item type 80 * @param int $itemId The id of item for which we need the associated items 81 * 82 * @return array 83 * 84 * @since 3.7.0 85 */ 86 public function getAssociationList($typeName, $itemId) 87 { 88 $items = array(); 89 90 $associations = $this->getAssociations($typeName, $itemId); 91 92 foreach ($associations as $key => $association) { 93 $items[$key] = ArrayHelper::fromObject($this->getItem($typeName, (int) $association->id), false); 94 } 95 96 return $items; 97 } 98 99 /** 100 * Get information about the type 101 * 102 * @param string $typeName The item type 103 * 104 * @return array Array of item types 105 * 106 * @since 3.7.0 107 */ 108 public function getType($typeName = '') 109 { 110 $fields = $this->getFieldsTemplate(); 111 $tables = array(); 112 $joins = array(); 113 $support = $this->getSupportTemplate(); 114 $title = ''; 115 116 return array( 117 'fields' => $fields, 118 'support' => $support, 119 'tables' => $tables, 120 'joins' => $joins, 121 'title' => $title 122 ); 123 } 124 125 /** 126 * Get information about the fields the type provides 127 * 128 * @param string $typeName The item type 129 * 130 * @return array Array of support information 131 * 132 * @since 3.7.0 133 */ 134 public function getTypeFields($typeName) 135 { 136 return $this->getTypeInformation($typeName, 'fields'); 137 } 138 139 /** 140 * Get information about the fields the type provides 141 * 142 * @param string $typeName The item type 143 * 144 * @return array Array of support information 145 * 146 * @since 3.7.0 147 */ 148 public function getTypeSupport($typeName) 149 { 150 return $this->getTypeInformation($typeName, 'support'); 151 } 152 153 /** 154 * Get information about the tables the type use 155 * 156 * @param string $typeName The item type 157 * 158 * @return array Array of support information 159 * 160 * @since 3.7.0 161 */ 162 public function getTypeTables($typeName) 163 { 164 return $this->getTypeInformation($typeName, 'tables'); 165 } 166 167 /** 168 * Get information about the table joins for the type 169 * 170 * @param string $typeName The item type 171 * 172 * @return array Array of support information 173 * 174 * @since 3.7.0 175 */ 176 public function getTypeJoins($typeName) 177 { 178 return $this->getTypeInformation($typeName, 'joins'); 179 } 180 181 /** 182 * Get the type title 183 * 184 * @param string $typeName The item type 185 * 186 * @return string The type title 187 * 188 * @since 3.7.0 189 */ 190 public function getTypeTitle($typeName) 191 { 192 $type = $this->getType($typeName); 193 194 if (!\array_key_exists('title', $type)) { 195 return ''; 196 } 197 198 return $type['title']; 199 } 200 201 /** 202 * Get information about the type 203 * 204 * @param string $typeName The item type 205 * @param string $part part of the information 206 * 207 * @return array Array of support information 208 * 209 * @since 3.7.0 210 */ 211 private function getTypeInformation($typeName, $part = 'support') 212 { 213 $type = $this->getType($typeName); 214 215 if (!\array_key_exists($part, $type)) { 216 return array(); 217 } 218 219 return $type[$part]; 220 } 221 222 /** 223 * Get a table field name for a type 224 * 225 * @param string $typeName The item type 226 * @param string $fieldName The item type 227 * 228 * @return string 229 * 230 * @since 3.7.0 231 */ 232 public function getTypeFieldName($typeName, $fieldName) 233 { 234 $fields = $this->getTypeFields($typeName); 235 236 if (!\array_key_exists($fieldName, $fields)) { 237 return ''; 238 } 239 240 $tmp = $fields[$fieldName]; 241 $pos = strpos($tmp, '.'); 242 243 if ($pos === false) { 244 return $tmp; 245 } 246 247 return substr($tmp, $pos + 1); 248 } 249 250 /** 251 * Get default values for support array 252 * 253 * @return array 254 * 255 * @since 3.7.0 256 */ 257 protected function getSupportTemplate() 258 { 259 return array( 260 'state' => false, 261 'acl' => false, 262 'checkout' => false 263 ); 264 } 265 266 /** 267 * Get default values for fields array 268 * 269 * @return array 270 * 271 * @since 3.7.0 272 */ 273 protected function getFieldsTemplate() 274 { 275 return array( 276 'id' => 'a.id', 277 'title' => 'a.title', 278 'alias' => 'a.alias', 279 'ordering' => 'a.ordering', 280 'menutype' => '', 281 'level' => '', 282 'catid' => 'a.catid', 283 'language' => 'a.language', 284 'access' => 'a.access', 285 'state' => 'a.state', 286 'created_user_id' => 'a.created_by', 287 'checked_out' => 'a.checked_out', 288 'checked_out_time' => 'a.checked_out_time' 289 ); 290 } 291 }
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 |