Backend\Modules\FormBuilder\Engine\Api::entriesGetById PHP Метод

entriesGetById() публичный статический Метод

Get a single entry
public static entriesGetById ( integer $id ) : array
$id integer The id of the entry.
Результат array
    public static function entriesGetById($id)
    {
        if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('GET')) {
            // redefine
            $id = (int) $id;
            $entries = (array) BackendModel::getContainer()->get('database')->getRecords('SELECT i.*, f.*, UNIX_TIMESTAMP(i.sent_on) AS sent_on
                 FROM forms_data AS i
                 INNER JOIN forms_data_fields AS f ON i.id = f.data_id
                 WHERE i.id = ?', array($id));
            // any entries?
            if (empty($entries)) {
                return BaseAPI::output(BaseAPI::ERROR, array('message' => 'Not found.'));
            }
            $return = array('entry' => null);
            $data = array();
            foreach ($entries as $row) {
                if (!isset($data['id'])) {
                    $data = $row;
                }
                $data['fields'][$row['label']] = unserialize($row['value']);
            }
            $fields = (array) BackendModel::getContainer()->get('database')->getRecords('SELECT i.type, i.settings
                 FROM forms_fields AS i
                 WHERE i.form_id = ?', array($data['form_id']));
            $fieldTypes = array();
            foreach ($fields as $row) {
                $row['settings'] = unserialize($row['settings']);
                if (isset($row['settings']['label'])) {
                    $fieldTypes[$row['settings']['label']] = $row['type'];
                }
            }
            // set attributes
            $return['entry']['@attributes']['form_id'] = $data['form_id'];
            $return['entry']['id'] = $data['id'];
            $return['entry']['sent_on'] = date('c', $data['sent_on']);
            foreach ($data['fields'] as $key => $value) {
                $return['entry']['fields'][] = array('field' => array('name' => $key, 'value' => $value, 'guessed_type' => isset($fieldTypes[$key]) ? $fieldTypes[$key] : 'textbox'));
            }
            return $return;
        }
    }