.

History Class Reference
[Lib]

Keeps track of pages called. More...

List of all members.

Static Public Member Functions

static  clear ()
static  get ($index, $defaultpage=false)
  Retrieve page from history.
static  go_to ($index, $message= '', $defaultpage=false)
  Read last page from history and redirect to it.
static  push ($url)
  Put page into history.
static  remove ($url)
  Remove url from history.

Detailed Description

Keeps track of pages called.

Author:
Gerd Riesselmann

Definition at line 10 of file history.cls.php.


Member Function Documentation

static History::clear (  )  [static]

Definition at line 11 of file history.cls.php.

00011                                        {
00012                 Session::push('history', false);        
00013         }
static History::get ( index,
defaultpage = false  
) [static]

Retrieve page from history.

Parameters:
Integer  Index of page to retrieve, 0-based. Index counts back in time, so 0 is last, 1 is page before last etc
Mixed  Either Url or String: Default page to return if history is empty
Returns:
Url

Definition at line 69 of file history.cls.php.

00069                                                                  {
00070                 $val = ($defaultpage === false) ? Config::get_url(Config::URL_DEFAULT_PAGE) : $defaultpage;;
00071                 if (Session::is_started()) {
00072                         $index = Cast::int($index);
00073                         $arr = Session::peek('history');
00074                         
00075                         if ( is_array($arr) && ($index >= 0) && (count($arr) > $index) ) {
00076                                 $val = $arr[$index];
00077                         }
00078                 }
00079                 return self::make_url($val);
00080         }
static History::go_to ( index,
message = '',
defaultpage = false  
) [static]

Read last page from history and redirect to it.

If history is empty, $defaultpage is invoked (or current page, if empty)

Parameters:
Integer  Index of page to go to, 0-based. Index counts back in time, so 0 is last, 1 is page before last etc
String  Optional message to display on page redirected to
Mixed  Either Url or String: Default page to go to if history is empty

Definition at line 91 of file history.cls.php.

00091                                                                                   {
00092                 $url = self::get($index, $defaultpage);
00093                 if ($message instanceof Status) {
00094                         $message->persist();
00095                 }
00096                 else if (!empty($message)) {
00097                         $msg = new Message($message);
00098                         $msg->persist();
00099                 }
00100                 $url->redirect();
00101                 exit;
00102         }
static History::push ( url  )  [static]

Put page into history.

Definition at line 18 of file history.cls.php.

00018                                           {
00019                 if (Session::is_started()) {
00020                         $arr = Session::peek('history');
00021                         if (!is_array($arr)) {
00022                                 $arr = array();
00023                         }
00024                         array_unshift($arr, $url);
00025                         if (count($arr) > HISTORY_NUMBER_OF_ITEMS) {
00026                                 array_pop($arr);
00027                         }
00028                         Session::push('history', $arr);
00029                 }
00030         }
static History::remove ( url  )  [static]

Remove url from history.

Parameters:
string|Url  $url

Definition at line 37 of file history.cls.php.

00037                                             {
00038                 if (empty($url)) {
00039                         return;
00040                 }
00041                 if (Session::is_started()) {
00042                         $arr = Session::peek('history');
00043                         $new = array();
00044                         if (is_array($arr) && count($arr) > 0) {
00045                                 if (!$url instanceof Url) {
00046                                         $url = Url::create($url);
00047                                 }
00048                                 $compare = $url->build();
00049                                 while($cur = array_shift($arr)) {
00050                                         if (!$cur instanceof  Url) {
00051                                                 $cur = Url::create($cur);
00052                                         }
00053                                         if ($cur->build() !== $compare) {
00054                                                 $new[] = $cur;
00055                                         }
00056                                 }
00057                         }
00058                         Session::push('history', $new);
00059                 }               
00060         }

The documentation for this class was generated from the following file: