ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.arViewFields.php
Go to the documentation of this file.
1 <?php
2 include_once('./Services/ActiveRecord/Fields/class.arField.php');
3 include_once('./Services/ActiveRecord/Views/class.arViewField.php');
4 
13 {
14  const FIELD_CLASS = 'arViewField';
18  protected $fields = array();
22  protected $fields_for_display = null;
26  protected $active_record = null;
30  protected $txt_prefix = "";
34  protected $created_by_field = null;
38  protected $modified_by_field = null;
42  protected $creation_date_field = null;
46  protected $modification_date_field = null;
47 
48 
52  public function __construct(ActiveRecord $ar)
53  {
54  $this->active_record = $ar;
55  $this->generateFields();
56  }
57 
58 
62  protected function generateFields()
63  {
64  $fields = $this->active_record->getArFieldList()->getFields();
65  foreach ($fields as $standard_field) {
66  $current_class = get_called_class();
67  $field_class = $current_class::FIELD_CLASS;
71  $field = $field_class::castFromFieldToViewField($standard_field);
72  $this->addField($field);
73  }
74 
75  return true;
76  }
77 
78 
82  public function addField(arViewField $field)
83  {
84  $this->fields[$field->getName()] = $field;
85  }
86 
87 
91  public function getFields()
92  {
93  return $this->fields;
94  }
95 
96 
100  public function getPrimaryField()
101  {
102  return $this->getField(arFieldCache::getPrimaryFieldName($this->active_record));
103  }
104 
105 
109  public function sortFields()
110  {
111  uasort($this->fields, function (arViewField $field_a, arViewField $field_b) {
112  return $field_a->getPosition() > $field_b->getPosition();
113  });
114  }
115 
116 
120  public function getFieldsForDisplay()
121  {
122  if (!$this->fields_for_display && $this->getFields()) {
123  foreach ($this->getFields() as $field) {
127  if (($field->getVisible() || $field->getPrimary())) {
128  $this->fields_for_display[] = $field;
129  }
130  }
131  }
132 
134  }
135 
136 
142  public function getField($field_name)
143  {
144  return $this->fields[$field_name];
145  }
146 
147 
151  public function setTxtPrefix($txt_prefix)
152  {
153  $this->txt_prefix = $txt_prefix;
154  foreach ($this->getFields() as $field) {
155  $field->setTxtPrefix($txt_prefix);
156  }
157  }
158 
159 
163  public function getTxtPrefix()
164  {
165  return $this->txt_prefix;
166  }
167 
168 
173  {
174  $created_by_field->setIsCreatedByField(true);
175  $this->created_by_field = $created_by_field;
176  }
177 
178 
182  public function getCreatedByField()
183  {
184  if (!$this->created_by_field) {
185  foreach ($this->getFields() as $field) {
189  if ($field->getIsCreatedByField()) {
190  return $this->created_by_field = $field;
191  }
192  }
193  }
194 
196  }
197 
198 
203  {
204  $creation_date_field->setIsCreationDateField(true);
205  $this->creation_date_field = $creation_date_field;
206  }
207 
208 
212  public function getCreationDateField()
213  {
214  if (!$this->creation_date_field) {
215  foreach ($this->getFields() as $field) {
219  if ($field->getIsCreationDateField()) {
220  return $this->creation_date_field = $field;
221  }
222  }
223  }
224 
226  }
227 
228 
233  {
234  $modification_date_field->setIsModificationDateField(true);
235  $this->modification_date_field = $modification_date_field;
236  }
237 
238 
242  public function getModificationDateField()
243  {
244  if (!$this->modification_date_field) {
245  foreach ($this->getFields() as $field) {
249  if ($field->getIsModificationDateField()) {
250  return $this->modification_date_field = $field;
251  }
252  }
253  }
254 
256  }
257 
258 
263  {
264  $modified_by_field->setIsModifiedByField(true);
265  $this->modified_by_field = $modified_by_field;
266  }
267 
268 
272  public function getModifiedByField()
273  {
274  if (!$this->modified_by_field) {
275  foreach ($this->getFields() as $field) {
279  if ($field->getIsModifiedByField()) {
280  return $this->modified_by_field = $field;
281  }
282  }
283  }
284 
286  }
287 }
static getPrimaryFieldName(ActiveRecord $ar)
addField(arViewField $field)
setTxtPrefix($txt_prefix)
Class ActiveRecord.
setModifiedByField($modified_by_field)
getField($field_name)
GUI-Class arViewFields.
$errors fields
Definition: imgupload.php:51
setCreationDateField($creation_date_field)
setModificationDateField($modification_date_field)
Create styles array
The data for the language used.
GUI-Class arViewField.
__construct(ActiveRecord $ar)
setCreatedByField($created_by_field)