public function grab(array &$param_pool = NULL) { // remove placeholder elements unset($this->dsParamINCLUDEDELEMENTS); // fill with all included elements if none are set if (is_null(REST_Entries::getDatasourceParam('included_elements'))) { // get all fields in this section $fields = FieldManager::fetchFieldsSchema(REST_Entries::getSectionId()); // add them to the data source foreach ($fields as $field) { $this->dsParamINCLUDEDELEMENTS[] = $field['element_name']; } // also add pagination $this->dsParamINCLUDEDELEMENTS[] = 'system:pagination'; } else { $this->dsParamINCLUDEDELEMENTS = explode(',', REST_Entries::getDatasourceParam('included_elements')); } // fill the other parameters if (!is_null(REST_Entries::getDatasourceParam('limit'))) { $this->dsParamLIMIT = REST_Entries::getDatasourceParam('limit'); } if (!is_null(REST_Entries::getDatasourceParam('page'))) { $this->dsParamSTARTPAGE = REST_Entries::getDatasourceParam('page'); } if (!is_null(REST_Entries::getDatasourceParam('sort'))) { $this->dsParamSORT = REST_Entries::getDatasourceParam('sort'); } if (!is_null(REST_Entries::getDatasourceParam('order'))) { $this->dsParamORDER = REST_Entries::getDatasourceParam('order'); } // Do grouping if (!is_null(REST_Entries::getDatasourceParam('groupby'))) { $field_id = FieldManager::fetchFieldIDFromElementName(REST_Entries::getDatasourceParam('groupby'), REST_Entries::getSectionId()); if ($field_id) { $this->dsParamGROUP = $field_id; } } // if API is calling a known entry, filter on System ID only if (!is_null(REST_Entries::getEntryId())) { $this->dsParamFILTERS['id'] = REST_Entries::getEntryId(); } elseif (REST_Entries::getDatasourceParam('filters')) { foreach (REST_Entries::getDatasourceParam('filters') as $field_handle => $filter_value) { $filter_value = rawurldecode($filter_value); $field_id = FieldManager::fetchFieldIDFromElementName($field_handle, REST_Entries::getSectionId()); if (is_numeric($field_id)) { $this->dsParamFILTERS[$field_id] = $filter_value; } } } return $this->execute($param_pool); }
/** * Returns the Schema of this section which includes all this sections * fields and their settings. * * @return array */ public function fetchFieldsSchema() { return FieldManager::fetchFieldsSchema($this->get('id')); }
protected function buildEntryArray($entry, $sectionId) { $data = array(); if ($entry != null) { $schema = \FieldManager::fetchFieldsSchema($sectionId); foreach ($schema as $field) { $data[$field['element_name']] = $entry->getData($field['id']); } } $data['id'] = $entry->get('id'); return $data; }
/** * Checks field data foreach Entry. * * @param $input * * @return array */ private function sectionsCheckFields($input) { $output = $input; foreach ($output as $handle => &$section) { // skip done sections if ($section['done'] === true) { continue; } $schema = FieldManager::fetchFieldsSchema($section['id']); if (!is_array($schema) || empty($schema)) { continue; } foreach ($section['entries'] as &$entry) { // skip done entries if ($entry['done'] === true) { continue; } $errors = array(); $entry_status = __ENTRY_OK__; $ignore_missing_fields = $entry['action'] === SE_Permissions::ACTION_EDIT; foreach ($schema as $field_info) { $field_id = $field_info['id']; $field_name = $field_info['element_name']; $has_data = isset($entry['fields'][$field_name]); if ($ignore_missing_fields && !$has_data) { continue; } // errors were injected by other events. Don't ask ... just use it ;) if (is_array($entry['fields'][$field_name]) && isset($entry['fields'][$field_name]['__error'])) { $error_code = $entry['fields'][$field_name]['__error']['code']; $error_msg = $entry['fields'][$field_name]['__error']['message']; $entry['orig_fields'][$field_name] = $entry['fields'][$field_name]['__value']; $entry['fields'][$field_name] = $entry['fields'][$field_name]['__value']; } else { /** @var $field Field */ $field = FieldManager::fetch($field_id); $field_data = $has_data ? $entry['fields'][$field_name] : null; $error_code = $field->checkPostFieldData($field_data, $error_msg, $entry['entry']->get('id')); } if ($error_code != Field::__OK__) { $entry_status = __ENTRY_FIELD_ERROR__; $errors[$field_id]['code'] = $error_code; $errors[$field_id]['message'] = $error_msg; } } if ($entry_status !== __ENTRY_OK__) { $this->error = true; $entry['done'] = true; $this->resultEntry($entry['res_entry'], 'error'); $this->resultFields($entry['res_fields'], $entry['fields'], $errors); } } } return $output; }