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 // Protect from unauthorized access
9 defined('FOF_INCLUDED') or die;
10
11 /**
12 * Form Field class for FOF
13 * Renders the checkbox in browse views which allows you to select rows
14 *
15 * @package FrameworkOnFramework
16 * @since 2.0
17 */
18 class FOFFormFieldSelectrow extends JFormField implements FOFFormField
19 {
20 protected $static;
21
22 protected $repeatable;
23
24 /** @var FOFTable The item being rendered in a repeatable form field */
25 public $item;
26
27 /** @var int A monotonically increasing number, denoting the row number in a repeatable view */
28 public $rowid;
29
30 /**
31 * Method to get certain otherwise inaccessible properties from the form field object.
32 *
33 * @param string $name The property name for which to the the value.
34 *
35 * @return mixed The property value or null.
36 *
37 * @since 2.0
38 */
39 public function __get($name)
40 {
41 switch ($name)
42 {
43 case 'static':
44 if (empty($this->static))
45 {
46 $this->static = $this->getStatic();
47 }
48
49 return $this->static;
50 break;
51
52 case 'repeatable':
53 if (empty($this->repeatable))
54 {
55 $this->repeatable = $this->getRepeatable();
56 }
57
58 return $this->repeatable;
59 break;
60
61 default:
62 return parent::__get($name);
63 }
64 }
65
66 /**
67 * Method to get the field input markup for this field type.
68 *
69 * @since 2.0
70 *
71 * @return string The field input markup.
72 */
73 protected function getInput()
74 {
75 throw new Exception(__CLASS__ . ' cannot be used in input forms');
76 }
77
78 /**
79 * Get the rendering of this field type for static display, e.g. in a single
80 * item view (typically a "read" task).
81 *
82 * @since 2.0
83 *
84 * @return string The field HTML
85 */
86 public function getStatic()
87 {
88 throw new Exception(__CLASS__ . ' cannot be used in single item display forms');
89 }
90
91 /**
92 * Get the rendering of this field type for a repeatable (grid) display,
93 * e.g. in a view listing many item (typically a "browse" task)
94 *
95 * @since 2.0
96 *
97 * @return string The field HTML
98 */
99 public function getRepeatable()
100 {
101 if (!($this->item instanceof FOFTable))
102 {
103 throw new Exception(__CLASS__ . ' needs a FOFTable to act upon');
104 }
105
106 // Is this record checked out?
107 $checked_out = false;
108 $locked_by_field = $this->item->getColumnAlias('locked_by');
109 $myId = JFactory::getUser()->get('id', 0);
110
111 if (property_exists($this->item, $locked_by_field))
112 {
113 $locked_by = $this->item->$locked_by_field;
114 $checked_out = ($locked_by != 0 && $locked_by != $myId);
115 }
116
117 // Get the key id for this record
118 $key_field = $this->item->getKeyName();
119 $key_id = $this->item->$key_field;
120
121 // Get the HTML
122 return JHTML::_('grid.id', $this->rowid, $key_id, $checked_out);
123 }
124 }
125