Source for file contenthistory.php

Documentation is available at contenthistory.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Table
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Table class supporting modified pre-order tree traversal behavior.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Table
  17.  * @link        http://docs.joomla.org/JTableObserver
  18.  * @since       3.2
  19.  */
  20. {
  21.     /**
  22.      * Helper object for storing and deleting version history information associated with this table observer
  23.      *
  24.      * @var    JHelperContenthistory 
  25.      * @since  3.2
  26.      */
  27.     protected $contenthistoryHelper;
  28.  
  29.     /**
  30.      * The pattern for this table's TypeAlias
  31.      *
  32.      * @var    string 
  33.      * @since  3.2
  34.      */
  35.     protected $typeAliasPattern = null;
  36.  
  37.     /**
  38.      * Not public, so marking private and deprecated, but needed internally in parseTypeAlias for
  39.      * PHP < 5.4.0 as it's not passing context $this to closure function.
  40.      *
  41.      * @var         JTableObserverContenthistory 
  42.      * @since       3.2
  43.      * @deprecated  Never use this
  44.      * @private
  45.      */
  46.     public static $_myTableForPregreplaceOnly;
  47.  
  48.     /**
  49.      * Creates the associated observer instance and attaches it to the $observableObject
  50.      * Creates the associated content history helper class instance
  51.      * $typeAlias can be of the form "{variableName}.type", automatically replacing {variableName} with table-instance variables variableName
  52.      *
  53.      * @param   JObservableInterface  $observableObject  The subject object to be observed
  54.      * @param   array                 $params            ( 'typeAlias' => $typeAlias )
  55.      *
  56.      * @return  JTableObserverContenthistory 
  57.      *
  58.      * @since   3.2
  59.      */
  60.     public static function createObserver(JObservableInterface $observableObject$params array())
  61.     {
  62.         $typeAlias $params['typeAlias'];
  63.  
  64.         $observer new self($observableObject);
  65.  
  66.         $observer->contenthistoryHelper new JHelperContenthistory($typeAlias);
  67.         $observer->typeAliasPattern $typeAlias;
  68.  
  69.         return $observer;
  70.     }
  71.  
  72.     /**
  73.      * Post-processor for $table->store($updateNulls)
  74.      *
  75.      * @param   boolean  &$result  The result of the load
  76.      *
  77.      * @return  void 
  78.      *
  79.      * @since   3.2
  80.      */
  81.     public function onAfterStore(&$result)
  82.     {
  83.         if ($result)
  84.         {
  85.             $this->parseTypeAlias();
  86.             $aliasParts explode('.'$this->contenthistoryHelper->typeAlias);
  87.  
  88.             if (JComponentHelper::getParams($aliasParts[0])->get('save_history'0))
  89.             {
  90.                 $this->contenthistoryHelper->store($this->table);
  91.             }
  92.         }
  93.     }
  94.  
  95.     /**
  96.      * Pre-processor for $table->delete($pk)
  97.      *
  98.      * @param   mixed  $pk  An optional primary key value to delete.  If not set the instance property value is used.
  99.      *
  100.      * @return  void 
  101.      *
  102.      * @since   3.2
  103.      * @throws  UnexpectedValueException
  104.      */
  105.     public function onBeforeDelete($pk)
  106.     {
  107.         $this->parseTypeAlias();
  108.         $aliasParts explode('.'$this->contenthistoryHelper->typeAlias);
  109.  
  110.         if (JComponentHelper::getParams($aliasParts[0])->get('save_history'0))
  111.         {
  112.             $this->parseTypeAlias();
  113.             $this->contenthistoryHelper->deleteHistory($this->table);
  114.         }
  115.     }
  116.  
  117.     /**
  118.      * Internal method
  119.      * Parses a TypeAlias of the form "{variableName}.type", replacing {variableName} with table-instance variables variableName
  120.      * Storing result into $this->contenthistoryHelper->typeAlias
  121.      *
  122.      * @return  void 
  123.      *
  124.      * @since   3.2
  125.      */
  126.     protected function parseTypeAlias()
  127.     {
  128.         // Needed for PHP < 5.4.0 as it's not passing context $this to closure function
  129.         static::$_myTableForPregreplaceOnly $this->table;
  130.  
  131.         $this->contenthistoryHelper->typeAlias preg_replace_callback('/{([^}]+)}/',
  132.             function($matches)
  133.             {
  134.                 return JTableObserverContenthistory::$_myTableForPregreplaceOnly->{$matches[1]};
  135.             },
  136.             $this->typeAliasPattern
  137.         );
  138.     }
  139. }

Documentation generated on Tue, 19 Nov 2013 14:56:59 +0100 by phpDocumentor 1.4.3