1 <?php
  2   3   4   5   6   7   8 
  9 
 10 defined('FOF_INCLUDED') or die;
 11 
 12 JFormHelper::loadFieldClass('accesslevel');
 13 
 14  15  16  17  18  19  20 
 21 class FOFFormFieldAccesslevel extends JFormFieldAccessLevel implements FOFFormField
 22 {
 23     protected $static;
 24 
 25     protected $repeatable;
 26 
 27     
 28     public $rowid;
 29 
 30     
 31     public $item;
 32 
 33      34  35  36  37  38  39  40  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  71  72  73  74  75  76 
 77     public function getStatic()
 78     {
 79         $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
 80 
 81         $params = $this->getOptions();
 82 
 83         $db    = FOFPlatform::getInstance()->getDbo();
 84         $query = $db->getQuery(true);
 85 
 86         $query->select('a.id AS value, a.title AS text');
 87         $query->from('#__viewlevels AS a');
 88         $query->group('a.id, a.title, a.ordering');
 89         $query->order('a.ordering ASC');
 90         $query->order($query->qn('title') . ' ASC');
 91 
 92         
 93         $db->setQuery($query);
 94         $options = $db->loadObjectList();
 95 
 96         
 97         if (is_array($params))
 98         {
 99             $options = array_merge($params, $options);
100         }
101 
102         
103         elseif ($params)
104         {
105             array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
106         }
107 
108         return '<span id="' . $this->id . '" ' . $class . '>' .
109             htmlspecialchars(FOFFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
110             '</span>';
111     }
112 
113     114 115 116 117 118 119 120 
121     public function getRepeatable()
122     {
123         $class = $this->element['class'] ? (string) $this->element['class'] : '';
124 
125         $params = $this->getOptions();
126 
127         $db    = FOFPlatform::getInstance()->getDbo();
128         $query = $db->getQuery(true);
129 
130         $query->select('a.id AS value, a.title AS text');
131         $query->from('#__viewlevels AS a');
132         $query->group('a.id, a.title, a.ordering');
133         $query->order('a.ordering ASC');
134         $query->order($query->qn('title') . ' ASC');
135 
136         
137         $db->setQuery($query);
138         $options = $db->loadObjectList();
139 
140         
141         if (is_array($params))
142         {
143             $options = array_merge($params, $options);
144         }
145 
146         
147         elseif ($params)
148         {
149             array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
150         }
151 
152         return '<span class="' . $this->id . ' ' . $class . '">' .
153             htmlspecialchars(FOFFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
154             '</span>';
155     }
156 }
157