[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/plugins/finder/contacts/ -> contacts.php (source)

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


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1