Source for file raw.php

Documentation is available at raw.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. /**
  12.  * FrameworkOnFramework raw output class. It works like an HTML view, but the
  13.  * output is bare HTML.
  14.  *
  15.  * @package  FrameworkOnFramework
  16.  * @since    2.1
  17.  */
  18. class FOFViewRaw extends FOFView
  19. {
  20.     /** @var array Data lists */
  21.     protected $lists = null;
  22.  
  23.     /** @var array Permissions map */
  24.     protected $perms = null;
  25.  
  26.     /**
  27.      * Class constructor
  28.      *
  29.      * @param   array  $config  Configuration parameters
  30.      */
  31.     public function __construct($config array())
  32.     {
  33.         // Make sure $config is an array
  34.         if (is_object($config))
  35.         {
  36.             $config = (array) $config;
  37.         }
  38.         elseif (!is_array($config))
  39.         {
  40.             $config array();
  41.         }
  42.  
  43.         parent::__construct($config);
  44.  
  45.         $this->config = $config;
  46.  
  47.         // Get the input
  48.         if (array_key_exists('input'$config))
  49.         {
  50.             if ($config['input'instanceof FOFInput)
  51.             {
  52.                 $this->input = $config['input'];
  53.             }
  54.             else
  55.             {
  56.                 $this->input = new FOFInput($config['input']);
  57.             }
  58.         }
  59.         else
  60.         {
  61.             $this->input = new FOFInput;
  62.         }
  63.  
  64.         $this->lists = new JObject;
  65.  
  66.         if (!FOFPlatform::getInstance()->isCli())
  67.         {
  68.             $platform FOFPlatform::getInstance();
  69.             $perms = (object) array(
  70.                     'create'     => $platform->authorise('core.create'$this->input->getCmd('option''com_foobar')),
  71.                     'edit'         => $platform->authorise('core.edit'$this->input->getCmd('option''com_foobar')),
  72.                     'editstate'     => $platform->authorise('core.edit.state'$this->input->getCmd('option''com_foobar')),
  73.                     'delete'     => $platform->authorise('core.delete'$this->input->getCmd('option''com_foobar')),
  74.             );
  75.             $this->assign('aclperms'$perms);
  76.             $this->perms = $perms;
  77.         }
  78.     }
  79.  
  80.     /**
  81.      * Displays the view
  82.      *
  83.      * @param   string  $tpl  The template to use
  84.      *
  85.      * @return  boolean|nullFalse if we can't render anything
  86.      */
  87.     public function display($tpl null)
  88.     {
  89.         // Get the task set in the model
  90.         $model $this->getModel();
  91.         $task $model->getState('task''browse');
  92.  
  93.         // Call the relevant method
  94.         $method_name 'on' ucfirst($task);
  95.  
  96.         if (method_exists($this$method_name))
  97.         {
  98.             $result $this->$method_name($tpl);
  99.         }
  100.         else
  101.         {
  102.             $result $this->onDisplay();
  103.         }
  104.  
  105.         if ($result === false)
  106.         {
  107.             return;
  108.         }
  109.  
  110.         // Show the view
  111.         if ($this->doPreRender)
  112.         {
  113.             $this->preRender();
  114.         }
  115.  
  116.         parent::display($tpl);
  117.  
  118.         if ($this->doPostRender)
  119.         {
  120.             $this->postRender();
  121.         }
  122.     }
  123.  
  124.     /**
  125.      * Last chance to output something before rendering the view template
  126.      *
  127.      * @return  void 
  128.      */
  129.     protected function preRender()
  130.     {
  131.     }
  132.  
  133.     /**
  134.      * Last chance to output something after rendering the view template and
  135.      * before returning to the caller
  136.      *
  137.      * @return  void 
  138.      */
  139.     protected function postRender()
  140.     {
  141.     }
  142.  
  143.     /**
  144.      * Executes before rendering the page for the Browse task.
  145.      *
  146.      * @param   string  $tpl  Subtemplate to use
  147.      *
  148.      * @return  boolean  Return true to allow rendering of the page
  149.      */
  150.     protected function onBrowse($tpl null)
  151.     {
  152.         // When in interactive browsing mode, save the state to the session
  153.         $this->getModel()->savestate(1);
  154.  
  155.         return $this->onDisplay($tpl);
  156.     }
  157.  
  158.     /**
  159.      * Executes before rendering a generic page, default to actions necessary
  160.      * for the Browse task.
  161.      *
  162.      * @param   string  $tpl  Subtemplate to use
  163.      *
  164.      * @return  boolean  Return true to allow rendering of the page
  165.      */
  166.     protected function onDisplay($tpl null)
  167.     {
  168.         $view $this->input->getCmd('view''cpanel');
  169.  
  170.         if (in_array($viewarray('cpanel''cpanels')))
  171.         {
  172.             return;
  173.         }
  174.  
  175.         // Load the model
  176.         $model $this->getModel();
  177.  
  178.         // ...ordering
  179.         $this->lists->set('order'$model->getState('filter_order''id''cmd'));
  180.         $this->lists->set('order_Dir'$model->getState('filter_order_Dir''DESC''cmd'));
  181.  
  182.         // Assign data to the view
  183.         $this->assign('items'$model->getItemList());
  184.         $this->assign('pagination'$model->getPagination());
  185.         $this->assignRef('lists'$this->lists);
  186.  
  187.         // Pass page params on frontend only
  188.         if (FOFPlatform::getInstance()->isFrontend())
  189.         {
  190.             $params JFactory::getApplication()->getParams();
  191.             $this->assignRef('params'$params);
  192.         }
  193.  
  194.         return true;
  195.     }
  196.  
  197.     /**
  198.      * Executes before rendering the page for the Add task.
  199.      *
  200.      * @param   string  $tpl  Subtemplate to use
  201.      *
  202.      * @return  boolean  Return true to allow rendering of the page
  203.      */
  204.     protected function onAdd($tpl null)
  205.     {
  206.         JRequest::setVar('hidemainmenu'true);
  207.         $model $this->getModel();
  208.         $this->assign('item'$model->getItem());
  209.  
  210.         return true;
  211.     }
  212.  
  213.     /**
  214.      * Executes before rendering the page for the Edit task.
  215.      *
  216.      * @param   string  $tpl  Subtemplate to use
  217.      *
  218.      * @return  boolean  Return true to allow rendering of the page
  219.      */
  220.     protected function onEdit($tpl null)
  221.     {
  222.         // An editor is an editor, no matter if the record is new or old :p
  223.  
  224.         return $this->onAdd();
  225.     }
  226.  
  227.     /**
  228.      * Executes before rendering the page for the Read task.
  229.      *
  230.      * @param   string  $tpl  Subtemplate to use
  231.      *
  232.      * @return  boolean  Return true to allow rendering of the page
  233.      */
  234.     protected function onRead($tpl null)
  235.     {
  236.         // All I need is to read the record
  237.  
  238.         return $this->onAdd();
  239.     }
  240.  
  241.     /**
  242.      * Determines if the current Joomla! version and your current table support
  243.      * AJAX-powered drag and drop reordering. If they do, it will set up the
  244.      * drag & drop reordering feature.
  245.      *
  246.      * @return  boolean|array False if not suported, a table with necessary
  247.      *                          information (saveOrder: should you enabled DnD
  248.      *                          reordering; orderingColumn: which column has the
  249.      *                          ordering information).
  250.      */
  251.     public function hasAjaxOrderingSupport()
  252.     {
  253.         if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''lt'))
  254.         {
  255.             return false;
  256.         }
  257.  
  258.         $model $this->getModel();
  259.  
  260.         if (!method_exists($model'getTable'))
  261.         {
  262.             return false;
  263.         }
  264.  
  265.         $table $this->getModel()->getTable();
  266.  
  267.         if (!method_exists($table'getColumnAlias'|| !method_exists($table'getTableFields'))
  268.         {
  269.             return false;
  270.         }
  271.  
  272.         $orderingColumn $table->getColumnAlias('ordering');
  273.         $fields $table->getTableFields();
  274.  
  275.         if (!array_key_exists($orderingColumn$fields))
  276.         {
  277.             return false;
  278.         }
  279.  
  280.         $listOrder $this->escape($model->getState('filter_order'null'cmd'));
  281.         $listDirn $this->escape($model->getState('filter_order_Dir''ASC''cmd'));
  282.         $saveOrder $listOrder == $orderingColumn;
  283.  
  284.         if ($saveOrder)
  285.         {
  286.             $saveOrderingUrl 'index.php?option=' $this->config['option''&view=' $this->config['view''&task=saveorder&format=json';
  287.             JHtml::_('sortablelist.sortable''itemsList''adminForm'strtolower($listDirn)$saveOrderingUrl);
  288.         }
  289.  
  290.         return array(
  291.             'saveOrder'         => $saveOrder,
  292.             'orderingColumn' => $orderingColumn
  293.         );
  294.     }
  295.  
  296.     /**
  297.      * Returns the internal list of useful variables to the benefit of
  298.      * FOFFormHeader fields.
  299.      *
  300.      * @return array 
  301.      *
  302.      * @since 2.0
  303.      */
  304.     public function getLists()
  305.     {
  306.         return $this->lists;
  307.     }
  308.  
  309.     /**
  310.      * Returns a reference to the permissions object of this view
  311.      *
  312.      * @return stdClass 
  313.      */
  314.     public function getPerms()
  315.     {
  316.         return $this->perms;
  317.     }
  318. }

Documentation generated on Tue, 19 Nov 2013 15:11:35 +0100 by phpDocumentor 1.4.3