Item
[
class tree: Item
] [
index: Item
] [
all elements
]
README.txt
Todo List
Packages:
Formagic
Item
Renderer
Rule
Source for file PageController.php
Documentation is available at
PageController.php
<?php
/**
* Formagic
*
* LICENCE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at
* http://formagic.weasle.de/licence.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to licence@weasle.de so we can send you a copy immediately.
*
*
@category
Formagic
*
@package
Item
*
@author
Florian Sonnenburg
*
@copyright
Copyright (c) 2007 Florian Sonnenburg
*
@license
http://formagic.weasle.de/licence.txt New BSD License
*/
/**
* Formagic_Item_PageController
*
*
@category
Formagic
*
@package
Item
*
@author
Florian Sonnenburg
*
@copyright
Copyright (c) 2007 Florian Sonnenburg
*
@version
$Id: PageController.php 19 2007-08-22 22:02:47Z meweasle $
*
@license
http://formagic.weasle.de/licence.txt New BSD License
*
@access
public
*/
class
Formagic_Item_PageController
extends
Formagic_Item_Container
{
/**
* Type of variable repository eg. for multi paged forms
*
@var
string
*/
private
$_multipageStorage
=
'hidden'
;
/**
* Page item has no own HTML representation
*
*
@var
boolean
**
*/
public
$hasHtml
=
false
;
/**
* Page the user is coming from
*
*
@var
string
**
*/
private
$_referringPage
;
/**
* Page user wants to be displayed
*
*
@var
string
**
*/
private
$_requestedPage
;
/**
* True if hidden input has been saved to Formagic
*
*
@var
boolean
**
*/
private
$_hiddenInputSet
=
false
;
/**
* Tells if form is in validation process
*
*
@var
boolean
**
*/
private
$_inValidation
=
false
;
/**
* Returns string with page item name or NULL if none detected
*
* Page submit item posts array with exactly one entry. The key of that
* entry is requested page name.
*
* getRequestedPage() returns NULL if form is being submitted without
* requesting another page or if there are no page items added to page
* controller
*
*
@return
mixed
String or NULL
*/
public
function
getRequestedPage
(
)
{
if
(
$this
->
_requestedPage
)
{
return
$this
->
_requestedPage
;
}
$pSwitchValue
=
$this
->
_caller
->
getValue
(
Formagic
::
PAGE_REQUEST_KEY
)
;
if
(
isset
(
$pSwitchValue
))
{
$this
->
_requestedPage
=
key
(
$pSwitchValue
)
;
}
elseif
(
$this
->
_caller
->
isSubmitted
(
))
{
return
null
;
}
else
{
if
(
!
count
(
$this
->
_items
))
{
$this
->
_requestedPage
=
null
;
}
else
{
$firstItem
=
reset
(
$this
->
_items
)
;
$this
->
_requestedPage
=
$firstItem
->
name
;
}
}
return
$this
->
_requestedPage
;
}
/**
* Returns name of page item that called currently requested page
*
* Referring page is NULL if form is in initial state
*
*
@return
string
*/
public
function
getReferringPage
(
)
{
if
(
$this
->
_referringPage
)
{
return
$this
->
_referringPage
;
}
// set referring page from submit values
$pSwitchValue
=
$this
->
_caller
->
getValue
(
Formagic
::
PAGE_TRACKING_KEY
)
;
$this
->
_referringPage
= isset
(
$pSwitchValue
)
?
$pSwitchValue
:
null
;
return
$this
->
_referringPage
;
}
/**
* Overwrites Formagic_Container::addItem()
*
*
@param
string
$type
*
@param
string
$name
*
@param
array
$args
*
@return
Formagic_Item
*/
public
function
addItem
(
$type
,
$name
,
$args
=
null
)
{
// avoid adding other than page items to be added
if
(
$type
!=
'page'
)
{
throw
new
Formagic_Exception
(
__CLASS__ .
' can only items of type page added'
)
;
}
// tag referring page
// if ($this->getReferringPage() == $name) {
// $args['referringPage'] = true;
// }
return
parent
::
addItem
(
$type
,
$name
,
$args
)
;
}
/**
* Returns items of currently displayed page
*
*
@return
array
*/
public
function
&
getItems
(
)
{
if
(
$this
->
_inValidation
)
{
$currentPage
=
$this
->
getReferringPage
(
)
;
}
else
{
$currentPage
=
$this
->
getRequestedPage
(
)
;
}
if
(
isset
(
$this
->
_items
[
$currentPage
]
))
{
$page
=
$this
->
_items
[
$currentPage
]
;
$res
=
array
(
$page
->
name
=>
$page
)
;
}
else
{
$res
=
array
(
)
;
}
return
$res
;
}
/**
* Implementation of preValidate handler
*
* Tags object to be in validation.
*
*
@return
boolean
*/
protected
function
_onPreValidate
(
)
{
$this
->
_inValidation
=
true
;
return
true
;
}
/**
* Implementation of postValidate handler
*
* Tags object to be out of validation. Averts form from beeing executed
* when any other page is requested.
*
*
@return
boolean
*/
protected
function
_onPostValidate
(
)
{
$this
->
_inValidation
=
false
;
// inhibit form execution if another page is requested
if
(
$this
->
_caller
->
getValue
(
Formagic
::
PAGE_REQUEST_KEY
))
{
return
false
;
}
return
true
;
}
/**
* Implementation of fetch handler
*
*
@return
void
*/
protected
function
_onFetch
(
)
{
if
(
$this
->
_inValidation
)
{
$currentPage
=
$this
->
getReferringPage
(
)
;
}
else
{
$currentPage
=
$this
->
getRequestedPage
(
)
;
}
if
(
$currentPage
)
{
$this
->
_items
[
$currentPage
]
->
_onFetch
(
)
;
}
// add hidden fields if there is a referring page
$referringPage
=
$this
->
getReferringPage
(
)
;
if
(
$referringPage
)
{
$pageItem
=
$this
->
_items
[
$referringPage
]
;
foreach
(
$pageItem
->
getItems
(
)
as
$item
)
{
if
(
$item
->
isPostItem
)
{
$this
->
_caller
->
addItem
(
'hidden'
,
$item
->
name
)
;
}
}
}
// add referring page tracker
if
(
$currentPage
)
{
$this
->
_caller
->
addItem
(
'hidden'
,
Formagic
::
PAGE_TRACKING_KEY
,
array
(
'constant'
=>
$currentPage
))
;
}
}
}
Documentation generated on Thu, 23 Aug 2007 00:29:45 +0200 by
phpDocumentor 1.4.0