Source for file actions.php

Documentation is available at actions.php

  1. <?php
  2. /**
  3.  * @package    FrameworkOnFramework
  4.  * @subpackage form
  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. if (!class_exists('JFormFieldList'))
  12. {
  13.     require_once JPATH_LIBRARIES '/joomla/form/fields/list.php';
  14. }
  15.  
  16. /**
  17.  * Form Field class for FOF
  18.  * Supports a generic list of options.
  19.  *
  20.  * @package  FrameworkOnFramework
  21.  * @since    2.0
  22.  */
  23. class FOFFormFieldActions extends JFormFieldList implements FOFFormField
  24. {
  25.     protected $static;
  26.  
  27.     protected $repeatable;
  28.  
  29.     /** @var int A monotonically increasing number, denoting the row number in a repeatable view */
  30.     public $rowid;
  31.     
  32.     /** @var   FOFTable  The item being rendered in a repeatable form field */
  33.     public $item;
  34.  
  35.     /**
  36.      * Method to get certain otherwise inaccessible properties from the form field object.
  37.      *
  38.      * @param   string  $name  The property name for which to the the value.
  39.      *
  40.      * @return  mixed  The property value or null.
  41.      *
  42.      * @since   2.0
  43.      */
  44.     public function __get($name)
  45.     {
  46.         switch ($name)
  47.         {
  48.             case 'static':
  49.                 if (empty($this->static))
  50.                 {
  51.                     $this->static = $this->getStatic();
  52.                 }
  53.  
  54.                 return $this->static;
  55.                 break;
  56.  
  57.             case 'repeatable':
  58.                 if (empty($this->repeatable))
  59.                 {
  60.                     $this->repeatable = $this->getRepeatable();
  61.                 }
  62.  
  63.                 return $this->static;
  64.                 break;
  65.  
  66.             default:
  67.                 return parent::__get($name);
  68.         }
  69.     }
  70.  
  71.     /**
  72.      * Get the field configuration
  73.      *
  74.      * @return  array 
  75.      */
  76.     protected function getConfig()
  77.     {
  78.         // If no custom options were defined let's figure out which ones of the
  79.         // defaults we shall use...
  80.         $config array(
  81.             'published'         => 1,
  82.             'unpublished'     => 1,
  83.             'archived'         => 0,
  84.             'trash'             => 0,
  85.             'all'             => 0,
  86.         );
  87.  
  88.         $stack array();
  89.  
  90.         if (isset($this->element['show_published']))
  91.         {
  92.             $config['published'FOFStringUtils::toBool($this->element['show_published']);
  93.         }
  94.  
  95.         if (isset($this->element['show_unpublished']))
  96.         {
  97.             $config['unpublished'FOFStringUtils::toBool($this->element['show_unpublished']);
  98.         }
  99.  
  100.         if (isset($this->element['show_archived']))
  101.         {
  102.             $config['archived'FOFStringUtils::toBool($this->element['show_archived']);
  103.         }
  104.  
  105.         if (isset($this->element['show_trash']))
  106.         {
  107.             $config['trash'FOFStringUtils::toBool($this->element['show_trash']);
  108.         }
  109.  
  110.         if (isset($this->element['show_all']))
  111.         {
  112.             $config['all'FOFStringUtils::toBool($this->element['show_all']);
  113.         }
  114.  
  115.         return $config;
  116.     }
  117.  
  118.     /**
  119.      * Method to get the field options.
  120.      *
  121.      * @since 2.0
  122.      *
  123.      * @return  array  The field option objects.
  124.      */
  125.     protected function getOptions()
  126.     {
  127.         return null;
  128.     }
  129.  
  130.     /**
  131.      * Method to get a
  132.      *
  133.      * @param   string  $enabledFieldName  Name of the enabled/published field
  134.      *
  135.      * @return  FOFFormFieldPublished  Field
  136.      */
  137.     protected function getPublishedField($enabledFieldName)
  138.     {
  139.         $attributes array(
  140.             'name' => $enabledFieldName,
  141.             'type' => 'published',
  142.         );
  143.  
  144.         if ($this->element['publish_up'])
  145.         {
  146.             $attributes['publish_up'= (string) $this->element['publish_up'];
  147.         }
  148.  
  149.         if ($this->element['publish_down'])
  150.         {
  151.             $attributes['publish_down'= (string) $this->element['publish_down'];
  152.         }
  153.  
  154.         foreach ($attributes as $name => $value)
  155.         {
  156.             if (!is_null($value))
  157.             {
  158.                 $renderedAttributes[$name '="' $value '"';
  159.             }
  160.         }
  161.  
  162.         $publishedXml new SimpleXMLElement('<field ' implode(' '$renderedAttributes' />');
  163.  
  164.         $publishedField new FOFFormFieldPublished($this->form);
  165.  
  166.         // Pass required objects to the field
  167.         $publishedField->item $this->item;
  168.         $publishedField->rowid $this->rowid;
  169.         $publishedField->setup($publishedXml$this->item->{$enabledFieldName});
  170.  
  171.         return $publishedField;
  172.     }
  173.  
  174.     /**
  175.      * Get the rendering of this field type for static display, e.g. in a single
  176.      * item view (typically a "read" task).
  177.      *
  178.      * @since 2.0
  179.      *
  180.      * @return  string  The field HTML
  181.      */
  182.     public function getStatic()
  183.     {
  184.         throw new Exception(__CLASS__ . ' cannot be used in single item display forms');
  185.     }
  186.  
  187.     /**
  188.      * Get the rendering of this field type for a repeatable (grid) display,
  189.      * e.g. in a view listing many item (typically a "browse" task)
  190.      *
  191.      * @since 2.0
  192.      *
  193.      * @return  string  The field HTML
  194.      */
  195.     public function getRepeatable()
  196.     {
  197.         if (!($this->item instanceof FOFTable))
  198.         {
  199.             throw new Exception(__CLASS__ . ' needs a FOFTable to act upon');
  200.         }
  201.  
  202.         $config $this->getConfig();
  203.  
  204.         // Initialise
  205.         $prefix       '';
  206.         $checkbox     'cb';
  207.         $publish_up   null;
  208.         $publish_down null;
  209.         $enabled      true;
  210.  
  211.         $html '<div class="btn-group">';
  212.  
  213.         // Render a published field
  214.         if ($publishedFieldName $this->item->getColumnAlias('enabled'))
  215.         {
  216.             if ($config['published'|| $config['unpublished'])
  217.             {
  218.                 // Generate a FOFFormFieldPublished field
  219.                 $publishedField $this->getPublishedField($publishedFieldName);
  220.  
  221.                 // Render the publish button
  222.                 $html .= $publishedField->getRepeatable();
  223.             }
  224.  
  225.             if ($config['archived'])
  226.             {
  227.                 $archived    $this->item->{$publishedFieldName== true false;
  228.  
  229.                 // Create dropdown items
  230.                 $action $archived 'unarchive' 'archive';
  231.                 JHtml::_('actionsdropdown.' $action'cb' $this->rowid$prefix);
  232.             }
  233.  
  234.             if ($config['trash'])
  235.             {
  236.                 $trashed    $this->item->{$publishedFieldName== -true false;
  237.  
  238.                 $action $trashed 'untrash' 'trash';
  239.                 JHtml::_('actionsdropdown.' $action'cb' $this->rowid$prefix);
  240.             }
  241.  
  242.             // Render dropdown list
  243.             if ($config['archived'|| $config['trash'])
  244.             {
  245.                 $html .= JHtml::_('actionsdropdown.render'$this->item->title);
  246.             }
  247.         }
  248.  
  249.         $html .= '</div>';
  250.  
  251.         return $html;
  252.     }
  253. }

Documentation generated on Tue, 19 Nov 2013 14:53:20 +0100 by phpDocumentor 1.4.3