History.php
00001 <?php
00009 class Dsao_Controller_Action_Helper_History
00010 extends Zend_Controller_Action_Helper_Abstract
00011 {
00018 protected $_addToHistory = 0;
00019
00023 protected $_namespaceHistory = null;
00024
00030 public function getPreviousUri()
00031 {
00032
00033 if (null === $this->_namespaceHistory)
00034 {
00035 return null;
00036 }
00037
00038 return new Dsao_Uri_Http(end(array_keys($this->_namespaceHistory->entries)));
00039 }
00040
00046 public function init()
00047 {
00048
00049 if ($this->getActionController()->getUser()->isValid()
00050 && null === $this->_namespaceHistory)
00051 {
00052 $this->_namespaceHistory = new Zend_Session_Namespace('history');
00053
00054
00055 if (!isset($this->_namespaceHistory->entries))
00056 {
00057 $this->_namespaceHistory->entries = array();
00058 }
00059 }
00060 }
00061
00067 public function postDispatch()
00068 {
00069
00070
00071 if ($this->getActionController()->isXmlHttpRequest()
00072 || $this->getResponse()->isRedirect()
00073 || !$this->getActionController()->getUser()->isValid()
00074 || !$this->getRequest()->isDispatched())
00075 {
00076 return;
00077 }
00078
00079
00080 $label = null;
00081
00082
00083 $uri = null;
00084
00085
00086 $moduleControllerAction = array
00087 (
00088 $this->getRequest()->getModuleName(),
00089 $this->getRequest()->getControllerName(),
00090 $this->getRequest()->getActionName(),
00091 );
00092
00093 $label = implode('_', $moduleControllerAction);
00094
00095
00096 if (2 == $this->_addToHistory)
00097 {
00098
00099 unset($this->getActionController()->getUri()->token);
00100
00101
00102 $uri = $this->getActionController()->getUri()->getUriString();
00103 }
00104
00105 else
00106 {
00107 $uri = $this->getActionController()->getUri()->getUriString(false);
00108 }
00109
00110
00111
00112 if (null !== $label && isset($this->_namespaceHistory->entries[$label]))
00113 {
00114 unset($this->_namespaceHistory->entries[$label]);
00115 }
00116
00117
00118 if (!empty($this->_namespaceHistory->entries))
00119 {
00120 $history = array_reverse($this->_namespaceHistory->entries);
00121
00122
00123 $this->getActionController()->getView()
00124 ->assign_by_ref('historyEntries', $history);
00125 }
00126
00127
00128 if (!$this->_addToHistory)
00129 {
00130 return false;
00131 }
00132
00133
00134 $this->_namespaceHistory->entries[$label] = $uri;
00135
00136
00137 if (count($this->_namespaceHistory->entries) >
00138 $this->getActionController()->getConfig()->history->maxEntries)
00139 {
00140 array_shift($this->_namespaceHistory->entries);
00141 }
00142
00143 return true;
00144 }
00145
00154 public function setAddToHistory($add = true, $retainParameters = true)
00155 {
00156
00157 if ($add && $retainParameters)
00158 {
00159 $this->_addToHistory = 2;
00160 }
00161 else
00162 {
00163 $this->_addToHistory = (int) (bool) $add;
00164 }
00165
00166 return $this;
00167 }
00168 }