Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
contenthistory.php
Aller à la documentation de ce fichier.
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  */
21 {
22  /**
23  * Helper object for storing and deleting version history information associated with this table observer
24  *
25  * @var JHelperContenthistory
26  * @since 3.2
27  */
29 
30  /**
31  * The pattern for this table's TypeAlias
32  *
33  * @var string
34  * @since 3.2
35  */
36  protected $typeAliasPattern = null;
37 
38  /**
39  * Not public, so marking private and deprecated, but needed internally in parseTypeAlias for
40  * PHP < 5.4.0 as it's not passing context $this to closure function.
41  *
42  * @var JTableObserverContenthistory
43  * @since 3.2
44  * @deprecated Never use this
45  * @private
46  */
48 
49  /**
50  * Creates the associated observer instance and attaches it to the $observableObject
51  * Creates the associated content history helper class instance
52  * $typeAlias can be of the form "{variableName}.type", automatically replacing {variableName} with table-instance variables variableName
53  *
54  * @param JObservableInterface $observableObject The subject object to be observed
55  * @param array $params ( 'typeAlias' => $typeAlias )
56  *
57  * @return JTableObserverContenthistory
58  *
59  * @since 3.2
60  */
61  public static function createObserver(JObservableInterface $observableObject, $params = array())
62  {
63  $typeAlias = $params['typeAlias'];
64 
65  $observer = new self($observableObject);
66 
67  $observer->contenthistoryHelper = new JHelperContenthistory($typeAlias);
68  $observer->typeAliasPattern = $typeAlias;
69 
70  return $observer;
71  }
72 
73  /**
74  * Post-processor for $table->store($updateNulls)
75  *
76  * @param boolean &$result The result of the load
77  *
78  * @return void
79  *
80  * @since 3.2
81  */
82  public function onAfterStore(&$result)
83  {
84  if ($result)
85  {
86  $this->parseTypeAlias();
87  $aliasParts = explode('.', $this->contenthistoryHelper->typeAlias);
88 
89  if (JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
90  {
91  $this->contenthistoryHelper->store($this->table);
92  }
93  }
94  }
95 
96  /**
97  * Pre-processor for $table->delete($pk)
98  *
99  * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used.
100  *
101  * @return void
102  *
103  * @since 3.2
104  * @throws UnexpectedValueException
105  */
106  public function onBeforeDelete($pk)
107  {
108  $this->parseTypeAlias();
109  $aliasParts = explode('.', $this->contenthistoryHelper->typeAlias);
110 
111  if (JComponentHelper::getParams($aliasParts[0])->get('save_history', 0))
112  {
113  $this->parseTypeAlias();
114  $this->contenthistoryHelper->deleteHistory($this->table);
115  }
116  }
117 
118  /**
119  * Internal method
120  * Parses a TypeAlias of the form "{variableName}.type", replacing {variableName} with table-instance variables variableName
121  * Storing result into $this->contenthistoryHelper->typeAlias
122  *
123  * @return void
124  *
125  * @since 3.2
126  */
127  protected function parseTypeAlias()
128  {
129  // Needed for PHP < 5.4.0 as it's not passing context $this to closure function
130  static::$_myTableForPregreplaceOnly = $this->table;
131 
132  $this->contenthistoryHelper->typeAlias = preg_replace_callback('/{([^}]+)}/',
133  function($matches)
134  {
136  },
137  $this->typeAliasPattern
138  );
139  }
140 }