Source for file form.php

Documentation is available at form.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  view
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. // Protect from unauthorized access
  9. defined('_JEXEC'or die;
  10.  
  11. JLoader::import('joomla.application.component.view');
  12.  
  13. /**
  14.  * FrameworkOnFramework Form class. It preferrably renders an XML view template
  15.  * instead of a traditional PHP-based view template.
  16.  *
  17.  * @package  FrameworkOnFramework
  18.  * @since    2.0
  19.  */
  20. class FOFViewForm extends FOFViewHtml
  21. {
  22.     /** @var FOFForm The form to render */
  23.     protected $form;
  24.  
  25.     /**
  26.      * Displays the view
  27.      *
  28.      * @param   string  $tpl  The template to use
  29.      *
  30.      * @return  boolean|nullFalse if we can't render anything
  31.      */
  32.     public function display($tpl null)
  33.     {
  34.         $model $this->getModel();
  35.  
  36.         // Get the form
  37.         $this->form = $this->getModel()->getForm();
  38.         $this->form->setModel($model);
  39.         $this->form->setView($this);
  40.  
  41.         // Get the task set in the model
  42.         $task $model->getState('task''browse');
  43.  
  44.         // Call the relevant method
  45.         $method_name 'on' ucfirst($task);
  46.  
  47.         if (method_exists($this$method_name))
  48.         {
  49.             $result $this->$method_name($tpl);
  50.         }
  51.         else
  52.         {
  53.             $result $this->onDisplay();
  54.         }
  55.  
  56.         // Bail out if we're told not to render anything
  57.  
  58.         if ($result === false)
  59.         {
  60.             return;
  61.         }
  62.  
  63.         // Show the view
  64.         // -- Output HTML before the view template
  65.         $this->preRender();
  66.  
  67.         // -- Try to load a view template; if not exists render the form directly
  68.         $basePath FOFPlatform::getInstance()->isBackend('admin:' 'site:';
  69.         $basePath .= $this->config['option''/';
  70.         $basePath .= $this->config['view''/';
  71.         $path $basePath $this->getLayout();
  72.  
  73.         if ($tpl)
  74.         {
  75.             $path .= '_' $tpl;
  76.         }
  77.  
  78.         $viewTemplate $this->loadAnyTemplate($path);
  79.  
  80.         // If there was no template file found, display the form
  81.         if ($viewTemplate instanceof Exception)
  82.         {
  83.             $viewTemplate $this->getRenderedForm();
  84.         }
  85.  
  86.         // -- Output the view template
  87.         echo $viewTemplate;
  88.  
  89.         // -- Output HTML after the view template
  90.         $this->postRender();
  91.     }
  92.  
  93.     /**
  94.      * Returns the HTML rendering of the FOFForm attached to this view. Very
  95.      * useful for customising a form page without having to meticulously hand-
  96.      * code the entire form.
  97.      *
  98.      * @return  string  The HTML of the rendered form
  99.      */
  100.     public function getRenderedForm()
  101.     {
  102.         $html '';
  103.         $renderer $this->getRenderer();
  104.  
  105.         if ($renderer instanceof FOFRenderAbstract)
  106.         {
  107.             // Load CSS and Javascript files defined in the form
  108.             $this->form->loadCSSFiles();
  109.             $this->form->loadJSFiles();
  110.  
  111.             // Get the form's HTML
  112.             $html $renderer->renderForm($this->form$this->getModel()$this->input);
  113.         }
  114.  
  115.         return $html;
  116.     }
  117.  
  118.     /**
  119.      * The event which runs when we are displaying the Add page
  120.      *
  121.      * @param   string  $tpl  The view sub-template to use
  122.      *
  123.      * @return  boolean  True to allow display of the view
  124.      */
  125.     protected function onAdd($tpl null)
  126.     {
  127.         // Hide the main menu
  128.         JRequest::setVar('hidemainmenu'true);
  129.  
  130.         // Get the model
  131.         $model $this->getModel();
  132.  
  133.         // Assign the item and form to the view
  134.         $this->assign('item'$model->getItem());
  135.         $this->assign('form'$this->form);
  136.  
  137.         return true;
  138.     }
  139. }

Documentation generated on Tue, 19 Nov 2013 15:03:29 +0100 by phpDocumentor 1.4.3