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     // Falls History nicht vorhanden
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     // Falls Benutzer gültig und History noch nicht initialisiert
00049     if ($this->getActionController()->getUser()->isValid()
00050       && null === $this->_namespaceHistory)
00051     {
00052       $this->_namespaceHistory = new Zend_Session_Namespace('history');
00053 
00054       // Falls Array mit History-Einträgen noch nicht vorhanden
00055       if (!isset($this->_namespaceHistory->entries))
00056       {
00057         $this->_namespaceHistory->entries = array();
00058       }
00059     }
00060   }
00061 
00067   public function postDispatch()
00068   {
00069     // Falls Ajax-Anfrage, Weiterleitung aktiviert, Benutzer nicht
00070     // angemeldet oder noch Aktionen ausgeführt werden sollen, abbrechen
00071     if ($this->getActionController()->isXmlHttpRequest()
00072         || $this->getResponse()->isRedirect()
00073         || !$this->getActionController()->getUser()->isValid()
00074         || !$this->getRequest()->isDispatched())
00075     {
00076       return;
00077     }
00078 
00079     // string, Message-ID für die Beschriftung des Links
00080     $label = null;
00081 
00082     // string, URI der zur aktuellen Seite
00083     $uri = null;
00084 
00085     // array, Array aus aufgerufenem Modul, Controller und Aktion
00086     $moduleControllerAction = array
00087       (
00088         $this->getRequest()->getModuleName(),
00089         $this->getRequest()->getControllerName(),
00090         $this->getRequest()->getActionName(),
00091       );
00092 
00093     $label = implode('_', $moduleControllerAction);
00094 
00095     // Falls Parameter des Aufrufs beibehalten werden sollen
00096     if (2 == $this->_addToHistory)
00097     {
00098       // Token entfernen
00099       unset($this->getActionController()->getUri()->token);
00100 
00101       // String
00102       $uri = $this->getActionController()->getUri()->getUriString();
00103     }
00104     // Ansonsten Link aus aktuellem Modul, Controller und Aktion aufbauen
00105     else
00106     {
00107       $uri = $this->getActionController()->getUri()->getUriString(false);
00108     }
00109 
00110     // Falls ein Eintrag mit der gleichen Beschreibung existiert, diesen
00111     // löschen
00112     if (null !== $label && isset($this->_namespaceHistory->entries[$label]))
00113     {
00114       unset($this->_namespaceHistory->entries[$label]);
00115     }
00116 
00117     // Falls History vorhanden
00118     if (!empty($this->_namespaceHistory->entries))
00119     {
00120       $history = array_reverse($this->_namespaceHistory->entries);
00121 
00122       // History-Einträge an Smarty übergeben
00123       $this->getActionController()->getView()
00124         ->assign_by_ref('historyEntries', $history);
00125     }
00126 
00127     // Falls Seite nicht zur History hinzugefügt werden soll, abbrechen
00128     if (!$this->_addToHistory)
00129     {
00130       return false;
00131     }
00132 
00133     // Eintrag hinzufügen
00134     $this->_namespaceHistory->entries[$label] = $uri;
00135 
00136     // Falls maximale Anzahl Einträge erreicht ist, ersten Eintrag entfernen
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     // Falls Seite hinzugefügt, und Parameter behalten werden sollen
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 }

Erzeugt am Fri Sep 18 19:04:11 2009 für DSA online - Morgendaemmerung von  doxygen 1.5.7.1