[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage Finder.Contacts 6 * 7 * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 10 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 11 */ 12 13 use Joomla\CMS\Categories\Categories; 14 use Joomla\CMS\Component\ComponentHelper; 15 use Joomla\CMS\Table\Table; 16 use Joomla\Component\Contact\Site\Helper\RouteHelper; 17 use Joomla\Component\Finder\Administrator\Indexer\Adapter; 18 use Joomla\Component\Finder\Administrator\Indexer\Helper; 19 use Joomla\Component\Finder\Administrator\Indexer\Indexer; 20 use Joomla\Component\Finder\Administrator\Indexer\Result; 21 use Joomla\Database\DatabaseQuery; 22 use Joomla\Registry\Registry; 23 24 // phpcs:disable PSR1.Files.SideEffects 25 \defined('_JEXEC') or die; 26 // phpcs:enable PSR1.Files.SideEffects 27 28 /** 29 * Finder adapter for Joomla Contacts. 30 * 31 * @since 2.5 32 */ 33 class PlgFinderContacts extends Adapter 34 { 35 /** 36 * The plugin identifier. 37 * 38 * @var string 39 * @since 2.5 40 */ 41 protected $context = 'Contacts'; 42 43 /** 44 * The extension name. 45 * 46 * @var string 47 * @since 2.5 48 */ 49 protected $extension = 'com_contact'; 50 51 /** 52 * The sublayout to use when rendering the results. 53 * 54 * @var string 55 * @since 2.5 56 */ 57 protected $layout = 'contact'; 58 59 /** 60 * The type of content that the adapter indexes. 61 * 62 * @var string 63 * @since 2.5 64 */ 65 protected $type_title = 'Contact'; 66 67 /** 68 * The table name. 69 * 70 * @var string 71 * @since 2.5 72 */ 73 protected $table = '#__contact_details'; 74 75 /** 76 * The field the published state is stored in. 77 * 78 * @var string 79 * @since 2.5 80 */ 81 protected $state_field = 'published'; 82 83 /** 84 * Load the language file on instantiation. 85 * 86 * @var boolean 87 * @since 3.1 88 */ 89 protected $autoloadLanguage = true; 90 91 /** 92 * Method to update the item link information when the item category is 93 * changed. This is fired when the item category is published or unpublished 94 * from the list view. 95 * 96 * @param string $extension The extension whose category has been updated. 97 * @param array $pks A list of primary key ids of the content that has changed state. 98 * @param integer $value The value of the state that the content has been changed to. 99 * 100 * @return void 101 * 102 * @since 2.5 103 */ 104 public function onFinderCategoryChangeState($extension, $pks, $value) 105 { 106 // Make sure we're handling com_contact categories 107 if ($extension === 'com_contact') { 108 $this->categoryStateChange($pks, $value); 109 } 110 } 111 112 /** 113 * Method to remove the link information for items that have been deleted. 114 * 115 * This event will fire when contacts are deleted and when an indexed item is deleted. 116 * 117 * @param string $context The context of the action being performed. 118 * @param Table $table A Table object containing the record to be deleted 119 * 120 * @return void 121 * 122 * @since 2.5 123 * @throws Exception on database error. 124 */ 125 public function onFinderAfterDelete($context, $table): void 126 { 127 if ($context === 'com_contact.contact') { 128 $id = $table->id; 129 } elseif ($context === 'com_finder.index') { 130 $id = $table->link_id; 131 } else { 132 return; 133 } 134 135 // Remove the items. 136 $this->remove($id); 137 } 138 139 /** 140 * Method to determine if the access level of an item changed. 141 * 142 * @param string $context The context of the content passed to the plugin. 143 * @param Table $row A Table object 144 * @param boolean $isNew If the content has just been created 145 * 146 * @return void 147 * 148 * @since 2.5 149 * @throws Exception on database error. 150 */ 151 public function onFinderAfterSave($context, $row, $isNew): void 152 { 153 // We only want to handle contacts here 154 if ($context === 'com_contact.contact') { 155 // Check if the access levels are different 156 if (!$isNew && $this->old_access != $row->access) { 157 // Process the change. 158 $this->itemAccessChange($row); 159 } 160 161 // Reindex the item 162 $this->reindex($row->id); 163 } 164 165 // Check for access changes in the category 166 if ($context === 'com_categories.category') { 167 // Check if the access levels are different 168 if (!$isNew && $this->old_cataccess != $row->access) { 169 $this->categoryAccessChange($row); 170 } 171 } 172 } 173 174 /** 175 * Method to reindex the link information for an item that has been saved. 176 * This event is fired before the data is actually saved so we are going 177 * to queue the item to be indexed later. 178 * 179 * @param string $context The context of the content passed to the plugin. 180 * @param Table $row A Table object 181 * @param boolean $isNew If the content is just about to be created 182 * 183 * @return boolean True on success. 184 * 185 * @since 2.5 186 * @throws Exception on database error. 187 */ 188 public function onFinderBeforeSave($context, $row, $isNew) 189 { 190 // We only want to handle contacts here 191 if ($context === 'com_contact.contact') { 192 // Query the database for the old access level if the item isn't new 193 if (!$isNew) { 194 $this->checkItemAccess($row); 195 } 196 } 197 198 // Check for access levels from the category 199 if ($context === 'com_categories.category') { 200 // Query the database for the old access level if the item isn't new 201 if (!$isNew) { 202 $this->checkCategoryAccess($row); 203 } 204 } 205 206 return true; 207 } 208 209 /** 210 * Method to update the link information for items that have been changed 211 * from outside the edit screen. This is fired when the item is published, 212 * unpublished, archived, or unarchived from the list view. 213 * 214 * @param string $context The context for the content passed to the plugin. 215 * @param array $pks A list of primary key ids of the content that has changed state. 216 * @param integer $value The value of the state that the content has been changed to. 217 * 218 * @return void 219 * 220 * @since 2.5 221 */ 222 public function onFinderChangeState($context, $pks, $value) 223 { 224 // We only want to handle contacts here 225 if ($context === 'com_contact.contact') { 226 $this->itemStateChange($pks, $value); 227 } 228 229 // Handle when the plugin is disabled 230 if ($context === 'com_plugins.plugin' && $value === 0) { 231 $this->pluginDisable($pks); 232 } 233 } 234 235 /** 236 * Method to index an item. The item must be a Result object. 237 * 238 * @param Result $item The item to index as a Result object. 239 * 240 * @return void 241 * 242 * @since 2.5 243 * @throws Exception on database error. 244 */ 245 protected function index(Result $item) 246 { 247 // Check if the extension is enabled 248 if (ComponentHelper::isEnabled($this->extension) === false) { 249 return; 250 } 251 252 $item->setLanguage(); 253 254 // Initialize the item parameters. 255 $item->params = new Registry($item->params); 256 257 // Create a URL as identifier to recognise items again. 258 $item->url = $this->getUrl($item->id, $this->extension, $this->layout); 259 260 // Build the necessary route and path information. 261 $item->route = RouteHelper::getContactRoute($item->slug, $item->catslug, $item->language); 262 263 // Get the menu title if it exists. 264 $title = $this->getItemMenuTitle($item->url); 265 266 // Adjust the title if necessary. 267 if (!empty($title) && $this->params->get('use_menu_title', true)) { 268 $item->title = $title; 269 } 270 271 /* 272 * Add the metadata processing instructions based on the contact 273 * configuration parameters. 274 */ 275 276 // Handle the contact position. 277 if ($item->params->get('show_position', true)) { 278 $item->addInstruction(Indexer::META_CONTEXT, 'position'); 279 } 280 281 // Handle the contact street address. 282 if ($item->params->get('show_street_address', true)) { 283 $item->addInstruction(Indexer::META_CONTEXT, 'address'); 284 } 285 286 // Handle the contact city. 287 if ($item->params->get('show_suburb', true)) { 288 $item->addInstruction(Indexer::META_CONTEXT, 'city'); 289 } 290 291 // Handle the contact region. 292 if ($item->params->get('show_state', true)) { 293 $item->addInstruction(Indexer::META_CONTEXT, 'region'); 294 } 295 296 // Handle the contact country. 297 if ($item->params->get('show_country', true)) { 298 $item->addInstruction(Indexer::META_CONTEXT, 'country'); 299 } 300 301 // Handle the contact zip code. 302 if ($item->params->get('show_postcode', true)) { 303 $item->addInstruction(Indexer::META_CONTEXT, 'zip'); 304 } 305 306 // Handle the contact telephone number. 307 if ($item->params->get('show_telephone', true)) { 308 $item->addInstruction(Indexer::META_CONTEXT, 'telephone'); 309 } 310 311 // Handle the contact fax number. 312 if ($item->params->get('show_fax', true)) { 313 $item->addInstruction(Indexer::META_CONTEXT, 'fax'); 314 } 315 316 // Handle the contact email address. 317 if ($item->params->get('show_email', true)) { 318 $item->addInstruction(Indexer::META_CONTEXT, 'email'); 319 } 320 321 // Handle the contact mobile number. 322 if ($item->params->get('show_mobile', true)) { 323 $item->addInstruction(Indexer::META_CONTEXT, 'mobile'); 324 } 325 326 // Handle the contact webpage. 327 if ($item->params->get('show_webpage', true)) { 328 $item->addInstruction(Indexer::META_CONTEXT, 'webpage'); 329 } 330 331 // Handle the contact user name. 332 $item->addInstruction(Indexer::META_CONTEXT, 'user'); 333 334 // Add the type taxonomy data. 335 $item->addTaxonomy('Type', 'Contact'); 336 337 // Add the category taxonomy data. 338 $categories = Categories::getInstance('com_contact', ['published' => false, 'access' => false]); 339 $category = $categories->get($item->catid); 340 341 // Category does not exist, stop here 342 if (!$category) { 343 return; 344 } 345 346 $item->addNestedTaxonomy('Category', $category, $this->translateState($category->published), $category->access, $category->language); 347 348 // Add the language taxonomy data. 349 $item->addTaxonomy('Language', $item->language); 350 351 // Add the region taxonomy data. 352 if (!empty($item->region) && $this->params->get('tax_add_region', true)) { 353 $item->addTaxonomy('Region', $item->region); 354 } 355 356 // Add the country taxonomy data. 357 if (!empty($item->country) && $this->params->get('tax_add_country', true)) { 358 $item->addTaxonomy('Country', $item->country); 359 } 360 361 // Get content extras. 362 Helper::getContentExtras($item); 363 364 // Index the item. 365 $this->indexer->index($item); 366 } 367 368 /** 369 * Method to setup the indexer to be run. 370 * 371 * @return boolean True on success. 372 * 373 * @since 2.5 374 */ 375 protected function setup() 376 { 377 return true; 378 } 379 380 /** 381 * Method to get the SQL query used to retrieve the list of content items. 382 * 383 * @param mixed $query A DatabaseQuery object or null. 384 * 385 * @return DatabaseQuery A database object. 386 * 387 * @since 2.5 388 */ 389 protected function getListQuery($query = null) 390 { 391 $db = $this->db; 392 393 // Check if we can use the supplied SQL query. 394 $query = $query instanceof DatabaseQuery ? $query : $db->getQuery(true) 395 ->select('a.id, a.name AS title, a.alias, a.con_position AS position, a.address, a.created AS start_date') 396 ->select('a.created_by_alias, a.modified, a.modified_by') 397 ->select('a.metakey, a.metadesc, a.metadata, a.language') 398 ->select('a.sortname1, a.sortname2, a.sortname3') 399 ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date') 400 ->select('a.suburb AS city, a.state AS region, a.country, a.postcode AS zip') 401 ->select('a.telephone, a.fax, a.misc AS summary, a.email_to AS email, a.mobile') 402 ->select('a.webpage, a.access, a.published AS state, a.ordering, a.params, a.catid') 403 ->select('c.title AS category, c.published AS cat_state, c.access AS cat_access'); 404 405 // Handle the alias CASE WHEN portion of the query 406 $case_when_item_alias = ' CASE WHEN '; 407 $case_when_item_alias .= $query->charLength('a.alias', '!=', '0'); 408 $case_when_item_alias .= ' THEN '; 409 $a_id = $query->castAsChar('a.id'); 410 $case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':'); 411 $case_when_item_alias .= ' ELSE '; 412 $case_when_item_alias .= $a_id . ' END as slug'; 413 $query->select($case_when_item_alias); 414 415 $case_when_category_alias = ' CASE WHEN '; 416 $case_when_category_alias .= $query->charLength('c.alias', '!=', '0'); 417 $case_when_category_alias .= ' THEN '; 418 $c_id = $query->castAsChar('c.id'); 419 $case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':'); 420 $case_when_category_alias .= ' ELSE '; 421 $case_when_category_alias .= $c_id . ' END as catslug'; 422 $query->select($case_when_category_alias) 423 424 ->select('u.name') 425 ->from('#__contact_details AS a') 426 ->join('LEFT', '#__categories AS c ON c.id = a.catid') 427 ->join('LEFT', '#__users AS u ON u.id = a.user_id'); 428 429 return $query; 430 } 431 }
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 |