1 <?php
2 /**
3 * @package FrameworkOnFramework
4 * @subpackage form
5 * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE.txt
7 */
8
9 // Protect from unauthorized access
10 defined('FOF_INCLUDED') or die;
11
12 JFormHelper::loadFieldClass('cachehandler');
13
14 /**
15 * Form Field class for FOF
16 * Joomla! cache handlers
17 *
18 * @package FrameworkOnFramework
19 * @since 2.0
20 */
21 class FOFFormFieldCachehandler extends JFormFieldCacheHandler implements FOFFormField
22 {
23 protected $static;
24
25 protected $repeatable;
26
27 /** @var FOFTable The item being rendered in a repeatable form field */
28 public $item;
29
30 /** @var int A monotonically increasing number, denoting the row number in a repeatable view */
31 public $rowid;
32
33 /**
34 * Method to get certain otherwise inaccessible properties from the form field object.
35 *
36 * @param string $name The property name for which to the the value.
37 *
38 * @return mixed The property value or null.
39 *
40 * @since 2.0
41 */
42 public function __get($name)
43 {
44 switch ($name)
45 {
46 case 'static':
47 if (empty($this->static))
48 {
49 $this->static = $this->getStatic();
50 }
51
52 return $this->static;
53 break;
54
55 case 'repeatable':
56 if (empty($this->repeatable))
57 {
58 $this->repeatable = $this->getRepeatable();
59 }
60
61 return $this->repeatable;
62 break;
63
64 default:
65 return parent::__get($name);
66 }
67 }
68
69 /**
70 * Get the rendering of this field type for static display, e.g. in a single
71 * item view (typically a "read" task).
72 *
73 * @since 2.0
74 *
75 * @return string The field HTML
76 */
77 public function getStatic()
78 {
79 $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
80
81 return '<span id="' . $this->id . '" ' . $class . '>' .
82 htmlspecialchars(FOFFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
83 '</span>';
84 }
85
86 /**
87 * Get the rendering of this field type for a repeatable (grid) display,
88 * e.g. in a view listing many item (typically a "browse" task)
89 *
90 * @since 2.0
91 *
92 * @return string The field HTML
93 */
94 public function getRepeatable()
95 {
96 $class = $this->element['class'] ? (string) $this->element['class'] : '';
97
98 return '<span class="' . $this->id . ' ' . $class . '">' .
99 htmlspecialchars(FOFFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
100 '</span>';
101 }
102 }
103