public function prepareFieldItem($fields)
{
if (is_array($fields)) {
foreach ($fields as $field) {
$this->prepareFieldItem($field);
}
} else {
/*TODO
if ($fields['needAccess'] && !Jarves::checkUrlAccess($fields['needAccess'])) {
$fields = null;
return;
}*/
if (substr($fields->getId(), 0, 2) != '__' && substr($fields->getId(), -2) != '__') {
switch ($fields->getType()) {
case 'predefined':
if (!$fields->getObject()) {
//&& !$this->getObject()) {
throw new \Exception(sprintf('Fields of type `predefined` need a `object` option. [%s]', json_encode($fields->toArray(), JSON_PRETTY_PRINT)));
// } else if (!$fields->getObject()) {
// $fields->setObject($this->getObject());
}
if (!$fields->getField()) {
//&& !$fields->getId()) {
throw new \Exception(sprintf('Fields of type `predefined` need a `field` option. [%s]', json_encode($fields->toArray(), JSON_PRETTY_PRINT)));
// } else if (!$fields->getField()) {
// $fields->setField($fields->getId());
}
$object = $this->objects->getDefinition($fields->getObject());
if (!$object) {
throw new \Exception(sprintf('Object `%s` does not exist [%s]', $fields->getObject(), json_encode($fields->toArray(), JSON_PRETTY_PRINT)));
}
$def = $object->getField($fields->getField());
if (!$def) {
$objectArray = $object->toArray();
$fields2 = $objectArray['fields'];
throw new \Exception(sprintf("Object `%s` does not have field `%s`. \n[%s]\n[%s]", $fields->getObject(), $fields->getField(), json_encode($fields->toArray(), JSON_PRETTY_PRINT), json_encode($fields2, JSON_PRETTY_PRINT)));
}
if ($def) {
$fields = $def;
}
break;
case 'select':
// if ($fields->getTable()) {
// $fields['tableItems'] = dbTableFetchAll($fields['table']);
// } else if ($fields['sql']) {
// $fields['tableItems'] = dbExFetchAll(str_replace('%pfx%', pfx, $fields['sql']));
// } else if ($fields['method']) {
// $nam = $fields['method'];
// if (method_exists($this, $nam)) {
// $fields['tableItems'] = $this->$nam($fields);
// }
// }
//
// if ($fields['modifier'] && !empty($fields['modifier']) &&
// method_exists($this, $fields['modifier'])
// ) {
// $fields['tableItems'] = $this->$fields['modifier']($fields['tableItems']);
// }
break;
}
$this->_fields[$fields->getId()] = $fields;
if ($fields->getType() && $fields->hasFieldType()) {
foreach ($fields->getFieldType()->getRequiredFields() as $fieldName) {
$this->_fields[$fieldName] = $this->getObjectDefinition()->getField($fieldName);
$this->prepareFieldItem($this->_fields[$fieldName]);
}
}
}
if (is_array($fields->getChildren())) {
$this->prepareFieldItem($fields->getChildren());
}
}
}