Source for file views.php

Documentation is available at views.php

  1. <?php
  2. /**
  3.  *  @package     FrameworkOnFramework
  4.  *  @subpackage  config
  5.  *  @copyright   Copyright (c)2010-2012 Nicholas K. Dionysopoulos
  6.  *  @license     GNU General Public License version 2, or later
  7.  */
  8.  
  9. defined('FOF_INCLUDED'or die();
  10.  
  11. /**
  12.  * Configuration parser for the view-specific settings
  13.  *
  14.  * @package  FrameworkOnFramework
  15.  * @since    2.1
  16.  */
  17. class FOFConfigDomainViews implements FOFConfigDomainInterface
  18. {
  19.     /**
  20.      * Parse the XML data, adding them to the $ret array
  21.      *
  22.      * @param   SimpleXMLElement  $xml   The XML data of the component's configuration area
  23.      * @param   array             &$ret  The parsed data, in the form of a hash array
  24.      *
  25.      * @return  void 
  26.      */
  27.     public function parseDomain(SimpleXMLElement $xmlarray &$ret)
  28.     {
  29.         // Initialise
  30.         $ret['views'array();
  31.  
  32.         // Parse view configuration
  33.         $viewData $xml->xpath('view');
  34.  
  35.         // Sanity check
  36.  
  37.         if (empty($viewData))
  38.         {
  39.             return;
  40.         }
  41.  
  42.         foreach ($viewData as $aView)
  43.         {
  44.             $key = (string) $aView['name'];
  45.  
  46.             // Parse ACL options
  47.             $ret['views'][$key]['acl'array();
  48.             $aclData $aView->xpath('acl/task');
  49.  
  50.             if (!empty($aclData))
  51.             {
  52.                 foreach ($aclData as $acl)
  53.                 {
  54.                     $k = (string) $acl['name'];
  55.                     $ret['views'][$key]['acl'][$k= (string) $acl;
  56.                 }
  57.             }
  58.  
  59.             // Parse taskmap
  60.             $ret['views'][$key]['taskmap'array();
  61.             $taskmapData $aView->xpath('taskmap/task');
  62.  
  63.             if (!empty($taskmapData))
  64.             {
  65.                 foreach ($taskmapData as $map)
  66.                 {
  67.                     $k = (string) $map['name'];
  68.                     $ret['views'][$key]['taskmap'][$k= (string) $map;
  69.                 }
  70.             }
  71.  
  72.             // Parse controller configuration
  73.             $ret['views'][$key]['config'array();
  74.             $optionData $aView->xpath('config/option');
  75.  
  76.             if (!empty($optionData))
  77.             {
  78.                 foreach ($optionData as $option)
  79.                 {
  80.                     $k = (string) $option['name'];
  81.                     $ret['views'][$key]['config'][$k= (string) $option;
  82.                 }
  83.             }
  84.  
  85.             // Parse the toolbar
  86.             $ret['views'][$key]['toolbar'array();
  87.             $toolBar $aView->xpath('toolbar');
  88.  
  89.             if (!empty($toolBar))
  90.             {
  91.                 $toolbarAttributes $toolBar[0]->attributes();
  92.  
  93.                 // If a toolbar title is specified, create a title element.
  94.                 if (isset($toolbarAttributes['title']))
  95.                 {
  96.                     $ret['views'][$key]['toolbar']['title'array(
  97.                         'value' => (string) $toolbarAttributes['title']
  98.                     );
  99.                 }
  100.  
  101.                 // Parse the toolbar buttons data
  102.                 $toolbarData $aView->xpath('toolbar/button');
  103.  
  104.                 if (!empty($toolbarData))
  105.                 {
  106.                     foreach ($toolbarData as $button)
  107.                     {
  108.                         $k = (string) $button['type'];
  109.                         $ret['views'][$key]['toolbar'][$kcurrent($button->attributes());
  110.                         $ret['views'][$key]['toolbar'][$k]['value'= (string) $button;
  111.                     }
  112.                 }
  113.             }
  114.         }
  115.     }
  116.  
  117.     /**
  118.      * Return a configuration variable
  119.      *
  120.      * @param   string  &$configuration  Configuration variables (hashed array)
  121.      * @param   string  $var             The variable we want to fetch
  122.      * @param   mixed   $default         Default value
  123.      *
  124.      * @return  mixed  The variable's value
  125.      */
  126.     public function get(&$configuration$var$default)
  127.     {
  128.         $parts explode('.'$var);
  129.  
  130.         $view $parts[0];
  131.         $method 'get' ucfirst($parts[1]);
  132.  
  133.         if (!method_exists($this$method))
  134.         {
  135.             return $default;
  136.         }
  137.  
  138.         array_shift($parts);
  139.         array_shift($parts);
  140.  
  141.         $ret $this->$method($view$configuration$parts$default);
  142.  
  143.         return $ret;
  144.     }
  145.  
  146.     /**
  147.      * Internal function to return the task map for a view
  148.      *
  149.      * @param   string  $view            The view for which we will be fetching a task map
  150.      * @param   array   &$configuration  The configuration parameters hash array
  151.      * @param   array   $params          Extra options (not used)
  152.      * @param   array   $default         ßDefault task map; empty array if not provided
  153.      *
  154.      * @return  array  The task map as a hash array in the format task => method
  155.      */
  156.     protected function getTaskmap($view&$configuration$params$default array())
  157.     {
  158.         $taskmap array();
  159.  
  160.         if (isset($configuration['views']['*']&& isset($configuration['views']['*']['taskmap']))
  161.         {
  162.             $taskmap $configuration['views']['*']['taskmap'];
  163.         }
  164.  
  165.         if (isset($configuration['views'][$view]&& isset($configuration['views'][$view]['taskmap']))
  166.         {
  167.             $taskmap array_merge($taskmap$configuration['views'][$view]['taskmap']);
  168.         }
  169.  
  170.         if (empty($taskmap))
  171.         {
  172.             return $default;
  173.         }
  174.  
  175.         return $taskmap;
  176.     }
  177.  
  178.     /**
  179.      * Internal method to return the ACL mapping (privilege required to access
  180.      * a specific task) for the given view's tasks
  181.      *
  182.      * @param   string  $view            The view for which we will be fetching a task map
  183.      * @param   array   &$configuration  The configuration parameters hash array
  184.      * @param   array   $params          Extra options; key 0 defines the task we want to fetch
  185.      * @param   string  $default         Default ACL option; empty (no ACL check) if not defined
  186.      *
  187.      * @return  string  The privilege required to access this view
  188.      */
  189.     protected function getAcl($view&$configuration$params$default '')
  190.     {
  191.         $aclmap array();
  192.  
  193.         if (isset($configuration['views']['*']&& isset($configuration['views']['*']['acl']))
  194.         {
  195.             $aclmap $configuration['views']['*']['acl'];
  196.         }
  197.  
  198.         if (isset($configuration['views'][$view]&& isset($configuration['views'][$view]['acl']))
  199.         {
  200.             $aclmap array_merge($aclmap$configuration['views'][$view]['acl']);
  201.         }
  202.  
  203.         $acl $default;
  204.  
  205.         if (isset($aclmap['*']))
  206.         {
  207.             $acl $aclmap['*'];
  208.         }
  209.  
  210.         if (isset($aclmap[$params[0]]))
  211.         {
  212.             $acl $aclmap[$params[0]];
  213.         }
  214.  
  215.         return $acl;
  216.     }
  217.  
  218.     /**
  219.      * Internal method to return the a configuration option for the view. These
  220.      * are equivalent to $config array options passed to the Controller
  221.      *
  222.      * @param   string  $view            The view for which we will be fetching a task map
  223.      * @param   array   &$configuration  The configuration parameters hash array
  224.      * @param   array   $params          Extra options; key 0 defines the option variable we want to fetch
  225.      * @param   mixed   $default         Default option; null if not defined
  226.      *
  227.      * @return  string  The setting for the requested option
  228.      */
  229.     protected function getConfig($view&$configuration$params$default null)
  230.     {
  231.         $ret $default;
  232.  
  233.         if (isset($configuration['views']['*'])
  234.             && isset($configuration['views']['*']['config'])
  235.             && isset($configuration['views']['*']['config'][$params[0]]))
  236.         {
  237.             $ret $configuration['views']['*']['config'][$params[0]];
  238.         }
  239.  
  240.         if (isset($configuration['views'][$view])
  241.             && isset($configuration['views'][$view]['config'])
  242.             && isset($configuration['views'][$view]['config'][$params[0]]))
  243.         {
  244.             $ret $configuration['views'][$view]['config'][$params[0]];
  245.         }
  246.  
  247.         return $ret;
  248.     }
  249.  
  250.     /**
  251.      * Internal method to return the toolbar infos.
  252.      *
  253.      * @param   string  $view            The view for which we will be fetching buttons
  254.      * @param   array   &$configuration  The configuration parameters hash array
  255.      * @param   array   $params          Extra options
  256.      * @param   string  $default         Default option
  257.      *
  258.      * @return  string  The toolbar data for this view
  259.      */
  260.     protected function getToolbar($view&$configuration$params$default '')
  261.     {
  262.         $toolbar array();
  263.  
  264.         if (isset($configuration['views']['*']&& isset($configuration['views']['*']['toolbar']))
  265.         {
  266.             $toolbar $configuration['views']['*']['toolbar'];
  267.         }
  268.  
  269.         if (isset($configuration['views'][$view]&& isset($configuration['views'][$view]['toolbar']))
  270.         {
  271.             $toolbar array_merge($toolbar$configuration['views'][$view]['toolbar']);
  272.         }
  273.  
  274.         if (empty($toolbar))
  275.         {
  276.             return $default;
  277.         }
  278.  
  279.         return $toolbar;
  280.     }
  281. }

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