Frontend\Modules\FormBuilder\Engine\Model::getFields PHP Method

getFields() public static method

Get all fields of a form.
public static getFields ( integer $id ) : array
$id integer The id of the form wherefore we fetch the fields.
return array
    public static function getFields($id)
    {
        // get fields
        $fields = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.id, i.type, i.settings
             FROM forms_fields AS i
             WHERE i.form_id = ?
             ORDER BY i.sequence ASC', (int) $id, 'id');
        if (empty($fields)) {
            return false;
        }
        // create an array with an equal amount of questionmarks as ids provided
        $idPlaceHolders = array_fill(0, count($fields), '?');
        // get field validations, each field can have multiple 'type' validations
        $fieldValidations = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.field_id, i.type, i.parameter, i.error_message
             FROM forms_fields_validation AS i
             WHERE i.field_id IN (' . implode(', ', $idPlaceHolders) . ')', array_keys($fields));
        // loop fields to add extra parameters
        foreach ($fields as &$field) {
            // unserialize
            if ($field['settings'] !== null) {
                $field['settings'] = unserialize($field['settings']);
            }
            // init validations
            $field['validations'] = array();
        }
        // we need to loop because one field can have multiple 'type' validations
        foreach ($fieldValidations as $fieldValidation) {
            // add validation type to our field
            $fields[$fieldValidation['field_id']]['validations'][$fieldValidation['type']] = $fieldValidation;
        }
        return $fields;
    }