Source for file published.php

Documentation is available at published.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 FOFFormFieldPublished extends JFormFieldList implements FOFFormField
  24. {
  25.     protected $static;
  26.  
  27.     protected $repeatable;
  28.  
  29.     /** @var   FOFTable  The item being rendered in a repeatable form field */
  30.     public $item;
  31.     
  32.     /** @var int A monotonically increasing number, denoting the row number in a repeatable view */
  33.     public $rowid;
  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.      * Method to get the field options.
  73.      *
  74.      * @since 2.0
  75.      *
  76.      * @return  array  The field option objects.
  77.      */
  78.     protected function getOptions()
  79.     {
  80.         $options parent::getOptions();
  81.  
  82.         if (!empty($options))
  83.         {
  84.             return $options;
  85.         }
  86.  
  87.         // If no custom options were defined let's figure out which ones of the
  88.         // defaults we shall use...
  89.  
  90.         $config array(
  91.             'published'         => 1,
  92.             'unpublished'     => 1,
  93.             'archived'         => 0,
  94.             'trash'             => 0,
  95.             'all'             => 0,
  96.         );
  97.  
  98.         $stack array();
  99.  
  100.         // We are no longer using jgrid.publishedOptions as it's returning
  101.         // untranslated strings, unsuitable for our purposes.
  102.  
  103.         if ($this->element['show_published'== 'false')
  104.         {
  105.             $stack[JHtml::_('select.option''1'JText::_('JPUBLISHED'));
  106.         }
  107.  
  108.         if ($this->element['show_unpublished'== 'false')
  109.         {
  110.             $stack[JHtml::_('select.option''0'JText::_('JUNPUBLISHED'));
  111.         }
  112.  
  113.         if ($this->element['show_archived'== 'true')
  114.         {
  115.             $stack[JHtml::_('select.option''2'JText::_('JARCHIVED'));
  116.         }
  117.  
  118.         if ($this->element['show_trash'== 'true')
  119.         {
  120.             $stack[JHtml::_('select.option''-2'JText::_('JTRASHED'));
  121.         }
  122.  
  123.         if ($this->element['show_all'== 'true')
  124.         {
  125.             $stack[JHtml::_('select.option''*'JText::_('JALL'));
  126.         }
  127.  
  128.         return $stack;
  129.     }
  130.  
  131.     /**
  132.      * Get the rendering of this field type for static display, e.g. in a single
  133.      * item view (typically a "read" task).
  134.      *
  135.      * @since 2.0
  136.      *
  137.      * @return  string  The field HTML
  138.      */
  139.     public function getStatic()
  140.     {
  141.         $class $this->element['class'' class="' . (string) $this->element['class''"' '';
  142.  
  143.         return '<span id="' $this->id . '" ' $class '>' .
  144.             htmlspecialchars(FOFFormFieldList::getOptionName($this->getOptions()$this->value)ENT_COMPAT'UTF-8'.
  145.             '</span>';
  146.     }
  147.  
  148.     /**
  149.      * Get the rendering of this field type for a repeatable (grid) display,
  150.      * e.g. in a view listing many item (typically a "browse" task)
  151.      *
  152.      * @since 2.0
  153.      *
  154.      * @return  string  The field HTML
  155.      */
  156.     public function getRepeatable()
  157.     {
  158.         if (!($this->item instanceof FOFTable))
  159.         {
  160.             throw new Exception(__CLASS__ . ' needs a FOFTable to act upon');
  161.         }
  162.  
  163.         // Initialise
  164.         $prefix '';
  165.         $checkbox 'cb';
  166.         $publish_up null;
  167.         $publish_down null;
  168.         $enabled true;
  169.  
  170.         // Get options
  171.         if ($this->element['prefix'])
  172.         {
  173.             $prefix = (string) $this->element['prefix'];
  174.         }
  175.  
  176.         if ($this->element['checkbox'])
  177.         {
  178.             $checkbox = (string) $this->element['checkbox'];
  179.         }
  180.  
  181.         if ($this->element['publish_up'])
  182.         {
  183.             $publish_up = (string) $this->element['publish_up'];
  184.         }
  185.  
  186.         if ($this->element['publish_down'])
  187.         {
  188.             $publish_down = (string) $this->element['publish_down'];
  189.         }
  190.  
  191.         // @todo Enforce ACL checks to determine if the field should be enabled or not
  192.         // Get the HTML
  193.         return JHTML::_('jgrid.published'$this->value$this->rowid$prefix$enabled$checkbox$publish_up$publish_down);
  194.     }
  195. }

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