Item
[ class tree: Item ] [ index: Item ] [ all elements ]

Source for file PageController.php

Documentation is available at PageController.php

  1. <?php
  2. /**
  3.  * Formagic
  4.  *
  5.  * LICENCE
  6.  *
  7.  * This source file is subject to the new BSD license that is bundled
  8.  * with this package in the file LICENSE.txt.
  9.  * It is also available through the world-wide-web at
  10.  * http://formagic.weasle.de/licence.txt
  11.  * If you did not receive a copy of the license and are unable to
  12.  * obtain it through the world-wide-web, please send an email
  13.  * to licence@weasle.de so we can send you a copy immediately.
  14.  *
  15.  * @category    Formagic
  16.  * @package     Item
  17.  * @author      Florian Sonnenburg
  18.  * @copyright   Copyright (c) 2007 Florian Sonnenburg
  19.  * @license     http://formagic.weasle.de/licence.txt     New BSD License
  20.  */
  21.  
  22. /**
  23.  * Formagic_Item_PageController
  24.  *
  25.  * @category    Formagic
  26.  * @package     Item
  27.  * @author      Florian Sonnenburg
  28.  * @copyright   Copyright (c) 2007 Florian Sonnenburg
  29.  * @version     $Id: PageController.php 19 2007-08-22 22:02:47Z meweasle $
  30.  * @license     http://formagic.weasle.de/licence.txt     New BSD License
  31.  * @access      public
  32.  */
  33.  
  34.     /**
  35.      * Type of variable repository eg. for multi paged forms
  36.      * @var string 
  37.      */
  38.     private $_multipageStorage 'hidden';
  39.  
  40.     /**
  41.      * Page item has no own HTML representation
  42.      *
  43.      * @var boolean 
  44.      ***/
  45.     public $hasHtml = false;
  46.  
  47.     /**
  48.      * Page the user is coming from
  49.      *
  50.      * @var string 
  51.      ***/
  52.     private $_referringPage;
  53.  
  54.     /**
  55.      * Page user wants to be displayed
  56.      *
  57.      * @var string 
  58.      ***/
  59.     private $_requestedPage;
  60.  
  61.     /**
  62.      * True if hidden input has been saved to Formagic
  63.      *
  64.      * @var boolean 
  65.      ***/
  66.     private $_hiddenInputSet false;
  67.  
  68.     /**
  69.      * Tells if form is in validation process
  70.      *
  71.      * @var boolean 
  72.      ***/
  73.     private $_inValidation false;
  74.  
  75.  
  76.     /**
  77.      * Returns string with page item name or NULL if none detected
  78.      *
  79.      * Page submit item posts array with exactly one entry. The key of that
  80.      * entry is requested page name.
  81.      *
  82.      * getRequestedPage() returns NULL if form is being submitted without
  83.      * requesting another page or if there are no page items added to page
  84.      * controller
  85.      *
  86.      * @return mixed String or NULL
  87.      */
  88.     public function getRequestedPage()
  89.     {
  90.         if ($this->_requestedPage{
  91.             return $this->_requestedPage;
  92.         }
  93.  
  94.         $pSwitchValue $this->_caller->getValue(Formagic::PAGE_REQUEST_KEY);
  95.         if (isset($pSwitchValue)) {
  96.             $this->_requestedPage key($pSwitchValue);
  97.         elseif($this->_caller->isSubmitted()) {
  98.             return null;
  99.         else {
  100.             if (!count($this->_items)) {
  101.                 $this->_requestedPage null;
  102.             else {
  103.                 $firstItem reset($this->_items);
  104.                 $this->_requestedPage $firstItem->name;
  105.             }
  106.         }
  107.         return $this->_requestedPage;
  108.     }
  109.  
  110.     /**
  111.      * Returns name of page item that called currently requested page
  112.      *
  113.      * Referring page is NULL if form is in initial state
  114.      *
  115.      * @return string 
  116.      */
  117.     public function getReferringPage()
  118.     {
  119.         if ($this->_referringPage{
  120.             return $this->_referringPage;
  121.         }
  122.  
  123.         // set referring page from submit values
  124.         $pSwitchValue $this->_caller->getValue(Formagic::PAGE_TRACKING_KEY);
  125.         $this->_referringPage = isset($pSwitchValue)
  126.                 ? $pSwitchValue
  127.                 : null;
  128.  
  129.         return $this->_referringPage;
  130.     }
  131.  
  132.     /**
  133.      * Overwrites Formagic_Container::addItem()
  134.      *
  135.      * @param string $type 
  136.      * @param string $name 
  137.      * @param array $args 
  138.      * @return Formagic_Item 
  139.      */
  140.     public function addItem($type$name$args=null)
  141.     {
  142.         // avoid adding other than page items to be added
  143.         if ($type != 'page'{
  144.             throw new Formagic_Exception(__CLASS__ . ' can only items of type page added');
  145.         }
  146.  
  147.         // tag referring page
  148. //        if ($this->getReferringPage() == $name) {
  149. //            $args['referringPage'] = true;
  150. //        }
  151.  
  152.         return parent::addItem($type$name$args);
  153.     }
  154.  
  155.     /**
  156.      * Returns items of currently displayed page
  157.      *
  158.      * @return array 
  159.      */
  160.     public function &getItems()
  161.     {
  162.         if ($this->_inValidation{
  163.             $currentPage $this->getReferringPage();
  164.         else {
  165.             $currentPage $this->getRequestedPage();
  166.         }
  167.  
  168.         if (isset($this->_items[$currentPage])) {
  169.             $page $this->_items[$currentPage];
  170.             $res array($page->name => $page);
  171.         else {
  172.             $res array();
  173.         }
  174.         return $res;
  175.     }
  176.  
  177.     /**
  178.      * Implementation of preValidate handler
  179.      *
  180.      * Tags object to be in validation.
  181.      *
  182.      * @return boolean 
  183.      */
  184.     protected function _onPreValidate()
  185.     {
  186.         $this->_inValidation true;
  187.         return true;
  188.     }
  189.  
  190.     /**
  191.      * Implementation of postValidate handler
  192.      *
  193.      * Tags object to be out of validation. Averts form from beeing executed
  194.      * when any other page is requested.
  195.      *
  196.      * @return boolean 
  197.      */
  198.     protected function _onPostValidate()
  199.     {
  200.         $this->_inValidation false;
  201.  
  202.         // inhibit form execution if another page is requested
  203.         if ($this->_caller->getValue(Formagic::PAGE_REQUEST_KEY)) {
  204.             return false;
  205.         }
  206.         return true;
  207.     }
  208.  
  209.     /**
  210.      * Implementation of fetch handler
  211.      *
  212.      * @return void 
  213.      */
  214.     protected function _onFetch()
  215.     {
  216.         if ($this->_inValidation{
  217.             $currentPage $this->getReferringPage();
  218.         else {
  219.             $currentPage $this->getRequestedPage();
  220.         }
  221.  
  222.         if ($currentPage{
  223.             $this->_items[$currentPage]->_onFetch();
  224.         }
  225.  
  226.         // add hidden fields if there is a referring page
  227.         $referringPage $this->getReferringPage();
  228.         if ($referringPage{
  229.             $pageItem $this->_items[$referringPage];
  230.             foreach($pageItem->getItems(as $item{
  231.                 if ($item->isPostItem{
  232.                     $this->_caller->addItem('hidden'$item->name);
  233.                 }
  234.             }
  235.         }
  236.  
  237.         // add referring page tracker
  238.         if ($currentPage{
  239.             $this->_caller->addItem('hidden'Formagic::PAGE_TRACKING_KEY,
  240.                         array('constant' => $currentPage));
  241.         }
  242.     }
  243.  
  244. }

Documentation generated on Thu, 23 Aug 2007 00:29:45 +0200 by phpDocumentor 1.4.0