[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_finder/helpers/indexer/ -> adapter.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Administrator
   4   * @subpackage  com_finder
   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('_JEXEC') or die;
  11  
  12  // Register dependent classes.
  13  JLoader::register('FinderIndexer', dirname(__FILE__) . '/indexer.php');
  14  JLoader::register('FinderIndexerHelper', dirname(__FILE__) . '/helper.php');
  15  JLoader::register('FinderIndexerResult', dirname(__FILE__) . '/result.php');
  16  JLoader::register('FinderIndexerTaxonomy', dirname(__FILE__) . '/taxonomy.php');
  17  
  18  /**
  19   * Prototype adapter class for the Finder indexer package.
  20   *
  21   * @package     Joomla.Administrator
  22   * @subpackage  com_finder
  23   * @since       2.5
  24   */
  25  abstract class FinderIndexerAdapter extends JPlugin
  26  {
  27      /**
  28       * The context is somewhat arbitrary but it must be unique or there will be
  29       * conflicts when managing plugin/indexer state. A good best practice is to
  30       * use the plugin name suffix as the context. For example, if the plugin is
  31       * named 'plgFinderContent', the context could be 'Content'.
  32       *
  33       * @var    string
  34       * @since  2.5
  35       */
  36      protected $context;
  37  
  38      /**
  39       * The extension name.
  40       *
  41       * @var    string
  42       * @since  2.5
  43       */
  44      protected $extension;
  45  
  46      /**
  47       * The sublayout to use when rendering the results.
  48       *
  49       * @var    string
  50       * @since  2.5
  51       */
  52      protected $layout;
  53  
  54      /**
  55       * The mime type of the content the adapter indexes.
  56       *
  57       * @var    string
  58       * @since  2.5
  59       */
  60      protected $mime;
  61  
  62      /**
  63       * The access level of an item before save.
  64       *
  65       * @var    integer
  66       * @since  2.5
  67       */
  68      protected $old_access;
  69  
  70      /**
  71       * The access level of a category before save.
  72       *
  73       * @var    integer
  74       * @since  2.5
  75       */
  76      protected $old_cataccess;
  77  
  78      /**
  79       * The type of content the adapter indexes.
  80       *
  81       * @var    string
  82       * @since  2.5
  83       */
  84      protected $type_title;
  85  
  86      /**
  87       * The type id of the content.
  88       *
  89       * @var    integer
  90       * @since  2.5
  91       */
  92      protected $type_id;
  93  
  94      /**
  95       * The database object.
  96       *
  97       * @var    object
  98       * @since  2.5
  99       */
 100      protected $db;
 101  
 102      /**
 103       * The table name.
 104       *
 105       * @var    string
 106       * @since  2.5
 107       */
 108      protected $table;
 109  
 110      /**
 111       * The field the published state is stored in.
 112       *
 113       * @var    string
 114       * @since  2.5
 115       */
 116      protected $state_field = 'state';
 117  
 118      /**
 119       * Method to instantiate the indexer adapter.
 120       *
 121       * @param   object  &$subject  The object to observe.
 122       * @param   array   $config    An array that holds the plugin configuration.
 123       *
 124       * @since   2.5
 125       */
 126  	public function __construct(&$subject, $config)
 127      {
 128          // Get the database object.
 129          $this->db = JFactory::getDBO();
 130  
 131          // Call the parent constructor.
 132          parent::__construct($subject, $config);
 133  
 134          // Get the type id.
 135          $this->type_id = $this->getTypeId();
 136  
 137          // Add the content type if it doesn't exist and is set.
 138          if (empty($this->type_id) && !empty($this->type_title))
 139          {
 140              $this->type_id = FinderIndexerHelper::addContentType($this->type_title, $this->mime);
 141          }
 142  
 143          // Check for a layout override.
 144          if ($this->params->get('layout'))
 145          {
 146              $this->layout = $this->params->get('layout');
 147          }
 148      }
 149  
 150      /**
 151       * Method to get the adapter state and push it into the indexer.
 152       *
 153       * @return  boolean  True on success.
 154       *
 155       * @since   2.5
 156       * @throws    Exception on error.
 157       */
 158  	public function onStartIndex()
 159      {
 160          JLog::add('FinderIndexerAdapter::onStartIndex', JLog::INFO);
 161  
 162          // Get the indexer state.
 163          $iState = FinderIndexer::getState();
 164  
 165          // Get the number of content items.
 166          $total = (int) $this->getContentCount();
 167  
 168          // Add the content count to the total number of items.
 169          $iState->totalItems += $total;
 170  
 171          // Populate the indexer state information for the adapter.
 172          $iState->pluginState[$this->context]['total'] = $total;
 173          $iState->pluginState[$this->context]['offset'] = 0;
 174  
 175          // Set the indexer state.
 176          FinderIndexer::setState($iState);
 177      }
 178  
 179      /**
 180       * Method to prepare for the indexer to be run. This method will often
 181       * be used to include dependencies and things of that nature.
 182       *
 183       * @return  boolean  True on success.
 184       *
 185       * @since   2.5
 186       * @throws  Exception on error.
 187       */
 188  	public function onBeforeIndex()
 189      {
 190          JLog::add('FinderIndexerAdapter::onBeforeIndex', JLog::INFO);
 191  
 192          // Get the indexer and adapter state.
 193          $iState = FinderIndexer::getState();
 194          $aState = $iState->pluginState[$this->context];
 195  
 196          // Check the progress of the indexer and the adapter.
 197          if ($iState->batchOffset == $iState->batchSize || $aState['offset'] == $aState['total'])
 198          {
 199              return true;
 200          }
 201  
 202          // Run the setup method.
 203          return $this->setup();
 204      }
 205  
 206      /**
 207       * Method to index a batch of content items. This method can be called by
 208       * the indexer many times throughout the indexing process depending on how
 209       * much content is available for indexing. It is important to track the
 210       * progress correctly so we can display it to the user.
 211       *
 212       * @return  boolean  True on success.
 213       *
 214       * @since   2.5
 215       * @throws  Exception on error.
 216       */
 217  	public function onBuildIndex()
 218      {
 219          JLog::add('FinderIndexerAdapter::onBuildIndex', JLog::INFO);
 220  
 221          // Get the indexer and adapter state.
 222          $iState = FinderIndexer::getState();
 223          $aState = $iState->pluginState[$this->context];
 224  
 225          // Check the progress of the indexer and the adapter.
 226          if ($iState->batchOffset == $iState->batchSize || $aState['offset'] == $aState['total'])
 227          {
 228              return true;
 229          }
 230  
 231          // Get the batch offset and size.
 232          $offset = (int) $aState['offset'];
 233          $limit = (int) ($iState->batchSize - $iState->batchOffset);
 234  
 235          // Get the content items to index.
 236          $items = $this->getItems($offset, $limit);
 237  
 238          // Iterate through the items and index them.
 239          for ($i = 0, $n = count($items); $i < $n; $i++)
 240          {
 241              // Index the item.
 242              $this->index($items[$i]);
 243  
 244              // Adjust the offsets.
 245              $offset++;
 246              $iState->batchOffset++;
 247              $iState->totalItems--;
 248          }
 249  
 250          // Update the indexer state.
 251          $aState['offset'] = $offset;
 252          $iState->pluginState[$this->context] = $aState;
 253          FinderIndexer::setState($iState);
 254  
 255          return true;
 256      }
 257  
 258      /**
 259       * Method to change the value of a content item's property in the links
 260       * table. This is used to synchronize published and access states that
 261       * are changed when not editing an item directly.
 262       *
 263       * @param   string   $id        The ID of the item to change.
 264       * @param   string   $property  The property that is being changed.
 265       * @param   integer  $value     The new value of that property.
 266       *
 267       * @return  boolean  True on success.
 268       *
 269       * @since   2.5
 270       * @throws    Exception on database error.
 271       */
 272  	protected function change($id, $property, $value)
 273      {
 274          JLog::add('FinderIndexerAdapter::change', JLog::INFO);
 275  
 276          // Check for a property we know how to handle.
 277          if ($property !== 'state' && $property !== 'access')
 278          {
 279              return true;
 280          }
 281  
 282          // Get the url for the content id.
 283          $item = $this->db->quote($this->getUrl($id, $this->extension, $this->layout));
 284  
 285          // Update the content items.
 286          $query = $this->db->getQuery(true);
 287          $query->update($this->db->quoteName('#__finder_links'));
 288          $query->set($this->db->quoteName($property) . ' = ' . (int) $value);
 289          $query->where($this->db->quoteName('url') . ' = ' . $item);
 290          $this->db->setQuery($query);
 291          $this->db->query();
 292  
 293          // Check for a database error.
 294          if ($this->db->getErrorNum())
 295          {
 296              // Throw database error exception.
 297              throw new Exception($this->db->getErrorMsg(), 500);
 298          }
 299  
 300          return true;
 301      }
 302  
 303      /**
 304       * Method to index an item.
 305       *
 306       * @param   FinderIndexerResult  $item  The item to index as a FinderIndexerResult object.
 307       *
 308       * @return  boolean  True on success.
 309       *
 310       * @since   2.5
 311       * @throws  Exception on database error.
 312       */
 313      abstract protected function index(FinderIndexerResult $item);
 314  
 315      /**
 316       * Method to reindex an item.
 317       *
 318       * @param   integer  $id  The ID of the item to reindex.
 319       *
 320       * @return  boolean  True on success.
 321       *
 322       * @since   2.5
 323       * @throws  Exception on database error.
 324       */
 325  	protected function reindex($id)
 326      {
 327          // Run the setup method.
 328          $this->setup();
 329  
 330          // Get the item.
 331          $item = $this->getItem($id);
 332  
 333          // Index the item.
 334          $this->index($item);
 335      }
 336  
 337      /**
 338       * Method to remove an item from the index.
 339       *
 340       * @param   string  $id  The ID of the item to remove.
 341       *
 342       * @return  boolean  True on success.
 343       *
 344       * @since   2.5
 345       * @throws  Exception on database error.
 346       */
 347  	protected function remove($id)
 348      {
 349          JLog::add('FinderIndexerAdapter::remove', JLog::INFO);
 350  
 351          // Get the item's URL
 352          $url = $this->db->quote($this->getUrl($id, $this->extension, $this->layout));
 353  
 354          // Get the link ids for the content items.
 355          $query = $this->db->getQuery(true);
 356          $query->select($this->db->quoteName('link_id'));
 357          $query->from($this->db->quoteName('#__finder_links'));
 358          $query->where($this->db->quoteName('url') . ' = ' . $url);
 359          $this->db->setQuery($query);
 360          $items = $this->db->loadColumn();
 361  
 362          // Check for a database error.
 363          if ($this->db->getErrorNum())
 364          {
 365              // Throw database error exception.
 366              throw new Exception($this->db->getErrorMsg(), 500);
 367          }
 368  
 369          // Check the items.
 370          if (empty($items))
 371          {
 372              return true;
 373          }
 374  
 375          // Remove the items.
 376          foreach ($items as $item)
 377          {
 378              FinderIndexer::remove($item);
 379          }
 380  
 381          return true;
 382      }
 383  
 384      /**
 385       * Method to setup the adapter before indexing.
 386       *
 387       * @return  boolean  True on success, false on failure.
 388       *
 389       * @since   2.5
 390       * @throws  Exception on database error.
 391       */
 392      abstract protected function setup();
 393  
 394      /**
 395       * Method to update index data on category access level changes
 396       *
 397       * @param   JTable  $row  A JTable object
 398       *
 399       * @return  void
 400       *
 401       * @since   2.5
 402       */
 403  	protected function categoryAccessChange($row)
 404      {
 405          $sql = clone($this->getStateQuery());
 406          $sql->where('c.id = ' . (int) $row->id);
 407  
 408          // Get the access level.
 409          $this->db->setQuery($sql);
 410          $items = $this->db->loadObjectList();
 411  
 412          // Adjust the access level for each item within the category.
 413          foreach ($items as $item)
 414          {
 415              // Set the access level.
 416              $temp = max($item->access, $row->access);
 417  
 418              // Update the item.
 419              $this->change((int) $item->id, 'access', $temp);
 420  
 421              // Reindex the item
 422              $this->reindex($row->id);
 423          }
 424      }
 425  
 426      /**
 427       * Method to update index data on category access level changes
 428       *
 429       * @param   array    $pks    A list of primary key ids of the content that has changed state.
 430       * @param   integer  $value  The value of the state that the content has been changed to.
 431       *
 432       * @return  void
 433       *
 434       * @since   2.5
 435       */
 436  	protected function categoryStateChange($pks, $value)
 437      {
 438          // The item's published state is tied to the category
 439          // published state so we need to look up all published states
 440          // before we change anything.
 441          foreach ($pks as $pk)
 442          {
 443              $sql = clone($this->getStateQuery());
 444              $sql->where('c.id = ' . (int) $pk);
 445  
 446              // Get the published states.
 447              $this->db->setQuery($sql);
 448              $items = $this->db->loadObjectList();
 449  
 450              // Adjust the state for each item within the category.
 451              foreach ($items as $item)
 452              {
 453                  // Translate the state.
 454                  $temp = $this->translateState($item->state, $value);
 455  
 456                  // Update the item.
 457                  $this->change($item->id, 'state', $temp);
 458  
 459                  // Reindex the item
 460                  $this->reindex($item->id);
 461              }
 462          }
 463      }
 464  
 465      /**
 466       * Method to check the existing access level for categories
 467       *
 468       * @param   JTable  $row  A JTable object
 469       *
 470       * @return  void
 471       *
 472       * @since   2.5
 473       */
 474  	protected function checkCategoryAccess($row)
 475      {
 476          $query = $this->db->getQuery(true);
 477          $query->select($this->db->quoteName('access'));
 478          $query->from($this->db->quoteName('#__categories'));
 479          $query->where($this->db->quoteName('id') . ' = ' . (int)$row->id);
 480          $this->db->setQuery($query);
 481  
 482          // Store the access level to determine if it changes
 483          $this->old_cataccess = $this->db->loadResult();
 484      }
 485  
 486      /**
 487       * Method to check the existing access level for items
 488       *
 489       * @param   JTable  $row  A JTable object
 490       *
 491       * @return  void
 492       *
 493       * @since   2.5
 494       */
 495  	protected function checkItemAccess($row)
 496      {
 497          $query = $this->db->getQuery(true);
 498          $query->select($this->db->quoteName('access'));
 499          $query->from($this->db->quoteName($this->table));
 500          $query->where($this->db->quoteName('id') . ' = ' . (int)$row->id);
 501          $this->db->setQuery($query);
 502  
 503          // Store the access level to determine if it changes
 504          $this->old_access = $this->db->loadResult();
 505      }
 506  
 507      /**
 508       * Method to get the number of content items available to index.
 509       *
 510       * @return  integer  The number of content items available to index.
 511       *
 512       * @since   2.5
 513       * @throws  Exception on database error.
 514       */
 515  	protected function getContentCount()
 516      {
 517          JLog::add('FinderIndexerAdapter::getContentCount', JLog::INFO);
 518  
 519          $return = 0;
 520  
 521          // Get the list query.
 522          $sql = $this->getListQuery();
 523  
 524          // Check if the query is valid.
 525          if (empty($sql))
 526          {
 527              return $return;
 528          }
 529  
 530          // Tweak the SQL query to make the total lookup faster.
 531          if ($sql instanceof JDatabaseQuery)
 532          {
 533              $sql = clone($sql);
 534              $sql->clear('select');
 535              $sql->select('COUNT(*)');
 536              $sql->clear('order');
 537          }
 538  
 539          // Get the total number of content items to index.
 540          $this->db->setQuery($sql);
 541          $return = (int) $this->db->loadResult();
 542  
 543          // Check for a database error.
 544          if ($this->db->getErrorNum())
 545          {
 546              // Throw database error exception.
 547              throw new Exception($this->db->getErrorMsg(), 500);
 548          }
 549  
 550          return $return;
 551      }
 552  
 553      /**
 554       * Method to get a content item to index.
 555       *
 556       * @param   integer  $id  The id of the content item.
 557       *
 558       * @return  FinderIndexerResult  A FinderIndexerResult object.
 559       *
 560       * @since   2.5
 561       * @throws  Exception on database error.
 562       */
 563  	protected function getItem($id)
 564      {
 565          JLog::add('FinderIndexerAdapter::getItem', JLog::INFO);
 566  
 567          // Get the list query and add the extra WHERE clause.
 568          $sql = $this->getListQuery();
 569          $sql->where('a.' . $this->db->quoteName('id') . ' = ' . (int) $id);
 570  
 571          // Get the item to index.
 572          $this->db->setQuery($sql);
 573          $row = $this->db->loadAssoc();
 574  
 575          // Check for a database error.
 576          if ($this->db->getErrorNum())
 577          {
 578              // Throw database error exception.
 579              throw new Exception($this->db->getErrorMsg(), 500);
 580          }
 581  
 582          // Convert the item to a result object.
 583          $item = JArrayHelper::toObject($row, 'FinderIndexerResult');
 584  
 585          // Set the item type.
 586          $item->type_id = $this->type_id;
 587  
 588          // Set the item layout.
 589          $item->layout = $this->layout;
 590  
 591          return $item;
 592      }
 593  
 594      /**
 595       * Method to get a list of content items to index.
 596       *
 597       * @param   integer         $offset  The list offset.
 598       * @param   integer         $limit   The list limit.
 599       * @param   JDatabaseQuery  $sql     A JDatabaseQuery object. [optional]
 600       *
 601       * @return  array  An array of FinderIndexerResult objects.
 602       *
 603       * @since   2.5
 604       * @throws  Exception on database error.
 605       */
 606  	protected function getItems($offset, $limit, $sql = null)
 607      {
 608          JLog::add('FinderIndexerAdapter::getItems', JLog::INFO);
 609  
 610          $items = array();
 611  
 612          // Get the content items to index.
 613          $this->db->setQuery($this->getListQuery($sql), $offset, $limit);
 614          $rows = $this->db->loadAssocList();
 615  
 616          // Check for a database error.
 617          if ($this->db->getErrorNum())
 618          {
 619              // Throw database error exception.
 620              throw new Exception($this->db->getErrorMsg(), 500);
 621          }
 622  
 623          // Convert the items to result objects.
 624          foreach ($rows as $row)
 625          {
 626              // Convert the item to a result object.
 627              $item = JArrayHelper::toObject($row, 'FinderIndexerResult');
 628  
 629              // Set the item type.
 630              $item->type_id = $this->type_id;
 631  
 632              // Set the mime type.
 633              $item->mime = $this->mime;
 634  
 635              // Set the item layout.
 636              $item->layout = $this->layout;
 637  
 638              // Set the extension if present
 639              if (isset($row->extension))
 640              {
 641                  $item->extension = $row->extension;
 642              }
 643  
 644              // Add the item to the stack.
 645              $items[] = $item;
 646          }
 647  
 648          return $items;
 649      }
 650  
 651      /**
 652       * Method to get the SQL query used to retrieve the list of content items.
 653       *
 654       * @param   mixed  $sql  A JDatabaseQuery object. [optional]
 655       *
 656       * @return  JDatabaseQuery  A database object.
 657       *
 658       * @since   2.5
 659       */
 660  	protected function getListQuery($sql = null)
 661      {
 662          JLog::add('FinderIndexerAdapter::getListQuery', JLog::INFO);
 663  
 664          // Check if we can use the supplied SQL query.
 665          $sql = is_a($sql, 'JDatabaseQuery') ? $sql : $this->db->getQuery(true);
 666  
 667          return $sql;
 668      }
 669  
 670      /**
 671       * Method to get the plugin type
 672       *
 673       * @param   integer  $id  The plugin ID
 674       *
 675       * @return  string  The plugin type
 676       *
 677       * @since   2.5
 678       */
 679  	protected function getPluginType($id)
 680      {
 681          // Prepare the query
 682          $query = $this->db->getQuery(true);
 683          $query->select($this->db->quoteName('element'));
 684          $query->from($this->db->quoteName('#__extensions'));
 685          $query->where($this->db->quoteName('extension_id') . ' = ' . (int) $id);
 686          $this->db->setQuery($query);
 687          $type = $this->db->loadResult();
 688  
 689          return $type;
 690      }
 691  
 692      /**
 693       * Method to get a SQL query to load the published and access states for
 694       * an article and category.
 695       *
 696       * @return  JDatabaseQuery  A database object.
 697       *
 698       * @since   2.5
 699       */
 700  	protected function getStateQuery()
 701      {
 702          $sql = $this->db->getQuery(true);
 703          // Item ID
 704          $sql->select('a.id');
 705          // Item and category published state
 706          $sql->select('a.' . $this->state_field . ' AS state, c.published AS cat_state');
 707          // Item and category access levels
 708          $sql->select('a.access, c.access AS cat_access');
 709          $sql->from($this->table . ' AS a');
 710          $sql->join('LEFT', '#__categories AS c ON c.id = a.catid');
 711  
 712          return $sql;
 713      }
 714  
 715      /**
 716       * Method to get the query clause for getting items to update by time.
 717       *
 718       * @param   string  $time  The modified timestamp.
 719       *
 720       * @return  JDatabaseQuery  A database object.
 721       *
 722       * @since   2.5
 723       */
 724  	protected function getUpdateQueryByTime($time)
 725      {
 726          JLog::add('FinderIndexerAdapter::getUpdateQueryByTime', JLog::INFO);
 727  
 728          // Build an SQL query based on the modified time.
 729          $sql = $this->db->getQuery(true);
 730          $sql->where('a.' . $this->db->quoteName('modified') . ' >= ' . $this->db->quote($time));
 731  
 732          return $sql;
 733      }
 734  
 735      /**
 736       * Method to get the query clause for getting items to update by id.
 737       *
 738       * @param   array  $ids  The ids to load.
 739       *
 740       * @return  JDatabaseQuery  A database object.
 741       *
 742       * @since   2.5
 743       */
 744  	protected function getUpdateQueryByIds($ids)
 745      {
 746          JLog::add('FinderIndexerAdapter::getUpdateQueryByIds', JLog::INFO);
 747  
 748          // Build an SQL query based on the item ids.
 749          $sql = $this->db->getQuery(true);
 750          $sql->where('a.' . $this->db->quoteName('id') . ' IN(' . implode(',', $ids) . ')');
 751  
 752          return $sql;
 753      }
 754  
 755      /**
 756       * Method to get the type id for the adapter content.
 757       *
 758       * @return  integer  The numeric type id for the content.
 759       *
 760       * @since   2.5
 761       * @throws  Exception on database error.
 762       */
 763  	protected function getTypeId()
 764      {
 765          JLog::add('FinderIndexerAdapter::getTypeId', JLog::INFO);
 766  
 767          // Get the type id from the database.
 768          $query = $this->db->getQuery(true);
 769          $query->select($this->db->quoteName('id'));
 770          $query->from($this->db->quoteName('#__finder_types'));
 771          $query->where($this->db->quoteName('title') . ' = ' . $this->db->quote($this->type_title));
 772          $this->db->setQuery($query);
 773          $result = (int) $this->db->loadResult();
 774  
 775          // Check for a database error.
 776          if ($this->db->getErrorNum())
 777          {
 778              // Throw database error exception.
 779              throw new Exception($this->db->getErrorMsg(), 500);
 780          }
 781  
 782          return $result;
 783      }
 784  
 785      /**
 786       * Method to get the URL for the item. The URL is how we look up the link
 787       * in the Finder index.
 788       *
 789       * @param   integer  $id         The id of the item.
 790       * @param   string   $extension  The extension the category is in.
 791       * @param   string   $view       The view for the URL.
 792       *
 793       * @return  string  The URL of the item.
 794       *
 795       * @since   2.5
 796       */
 797  	protected function getURL($id, $extension, $view)
 798      {
 799          return 'index.php?option=' . $extension . '&view=' . $view . '&id=' . $id;
 800      }
 801  
 802      /**
 803       * Method to get the page title of any menu item that is linked to the
 804       * content item, if it exists and is set.
 805       *
 806       * @param   string  $url  The url of the item.
 807       *
 808       * @return  mixed  The title on success, null if not found.
 809       *
 810       * @since   2.5
 811       * @throws  Exception on database error.
 812       */
 813  	protected function getItemMenuTitle($url)
 814      {
 815          JLog::add('FinderIndexerAdapter::getItemMenuTitle', JLog::INFO);
 816  
 817          $return = null;
 818  
 819          // Set variables
 820          $user = JFactory::getUser();
 821          $groups = implode(',', $user->getAuthorisedViewLevels());
 822  
 823          // Build a query to get the menu params.
 824          $sql = $this->db->getQuery(true);
 825          $sql->select($this->db->quoteName('params'));
 826          $sql->from($this->db->quoteName('#__menu'));
 827          $sql->where($this->db->quoteName('link') . ' = ' . $this->db->quote($url));
 828          $sql->where($this->db->quoteName('published') . ' = 1');
 829          $sql->where($this->db->quoteName('access') . ' IN (' . $groups . ')');
 830  
 831          // Get the menu params from the database.
 832          $this->db->setQuery($sql);
 833          $params = $this->db->loadResult();
 834  
 835          // Check for a database error.
 836          if ($this->db->getErrorNum())
 837          {
 838              // Throw database error exception.
 839              throw new Exception($this->db->getErrorMsg(), 500);
 840          }
 841  
 842          // Check the results.
 843          if (empty($params))
 844          {
 845              return $return;
 846          }
 847  
 848          // Instantiate the params.
 849          $params = json_decode($params);
 850  
 851          // Get the page title if it is set.
 852          if ($params->page_title)
 853          {
 854              $return = $params->page_title;
 855          }
 856  
 857          return $return;
 858      }
 859  
 860      /**
 861       * Method to update index data on access level changes
 862       *
 863       * @param   JTable  $row  A JTable object
 864       *
 865       * @return  void
 866       *
 867       * @since   2.5
 868       */
 869  	protected function itemAccessChange($row)
 870      {
 871          $sql = clone($this->getStateQuery());
 872          $sql->where('a.id = ' . (int) $row->id);
 873  
 874          // Get the access level.
 875          $this->db->setQuery($sql);
 876          $item = $this->db->loadObject();
 877  
 878          // Set the access level.
 879          $temp = max($row->access, $item->cat_access);
 880  
 881          // Update the item.
 882          $this->change((int) $row->id, 'access', $temp);
 883      }
 884  
 885      /**
 886       * Method to update index data on published state changes
 887       *
 888       * @param   array    $pks    A list of primary key ids of the content that has changed state.
 889       * @param   integer  $value  The value of the state that the content has been changed to.
 890       *
 891       * @return  void
 892       *
 893       * @since   2.5
 894       */
 895  	protected function itemStateChange($pks, $value)
 896      {
 897          // The item's published state is tied to the category
 898          // published state so we need to look up all published states
 899          // before we change anything.
 900          foreach ($pks as $pk)
 901          {
 902              $sql = clone($this->getStateQuery());
 903              $sql->where('a.id = ' . (int) $pk);
 904  
 905              // Get the published states.
 906              $this->db->setQuery($sql);
 907              $item = $this->db->loadObject();
 908  
 909              // Translate the state.
 910              $temp = $this->translateState($value, $item->cat_state);
 911  
 912              // Update the item.
 913              $this->change($pk, 'state', $temp);
 914  
 915              // Reindex the item
 916              $this->reindex($pk);
 917          }
 918      }
 919  
 920      /**
 921       * Method to update index data when a plugin is disabled
 922       *
 923       * @param   array  $pks  A list of primary key ids of the content that has changed state.
 924       *
 925       * @return  void
 926       *
 927       * @since   2.5
 928       */
 929  	protected function pluginDisable($pks)
 930      {
 931          // Since multiple plugins may be disabled at a time, we need to check first
 932          // that we're handling the appropriate one for the context
 933          foreach ($pks as $pk)
 934          {
 935              if ($this->getPluginType($pk) == strtolower($this->context))
 936              {
 937                  // Get all of the items to unindex them
 938                  $sql = clone($this->getStateQuery());
 939                  $this->db->setQuery($sql);
 940                  $items = $this->db->loadColumn();
 941  
 942                  // Remove each item
 943                  foreach ($items as $item)
 944                  {
 945                      $this->remove($item);
 946                  }
 947              }
 948          }
 949      }
 950  
 951      /**
 952       * Method to translate the native content states into states that the
 953       * indexer can use.
 954       *
 955       * @param   integer  $item      The item state.
 956       * @param   integer  $category  The category state. [optional]
 957       *
 958       * @return  integer  The translated indexer state.
 959       *
 960       * @since   2.5
 961       */
 962  	protected function translateState($item, $category = null)
 963      {
 964          // If category is present, factor in its states as well
 965          if ($category !== null)
 966          {
 967              if ($category == 0)
 968              {
 969                  $item = 0;
 970              }
 971          }
 972  
 973          // Translate the state
 974          switch ($item)
 975          {
 976              // Published and archived items only should return a published state
 977              case 1;
 978              case 2:
 979                  return 1;
 980  
 981              // All other states should return a unpublished state
 982              default:
 983              case 0:
 984                  return 0;
 985          }
 986      }
 987  }


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