Pop\Form\Fields::addFieldsFromTable PHP Метод

addFieldsFromTable() публичный Метод

Add form fields from a related database table. The $tableInfo parameter should be the returned array result from calling the static Pop\Db\Record method, Record::getTableInfo();
public addFieldsFromTable ( array $tableInfo, array $attribs = null, array $values = null, mixed $omit = null ) : Fields
$tableInfo array
$attribs array
$values array
$omit mixed
Результат Fields
    public function addFieldsFromTable(array $tableInfo, array $attribs = null, array $values = null, $omit = null)
    {
        if (!isset($tableInfo['tableName']) || !isset($tableInfo['primaryId']) || !isset($tableInfo['columns'])) {
            throw new Exception('Error: The table info parameter is not in the correct format. It should be a returned array value from the getTableInfo() method of the Record component.');
        }
        if (null !== $omit) {
            if (!is_array($omit)) {
                $omit = array($omit);
            }
        } else {
            $omit = array();
        }
        foreach ($tableInfo['columns'] as $key => $value) {
            if (!in_array($key, $omit)) {
                $fieldName = $key;
                $fieldValue = null;
                $fieldLabel = null;
                $required = $value['null'] ? false : true;
                $attributes = null;
                $marked = null;
                $validators = isset($values[$key]['validators']) ? $values[$key]['validators'] : null;
                $fieldType = stripos($key, 'password') !== false ? 'password' : (stripos($value['type'], 'text') !== false ? 'textarea' : 'text');
                if (null !== $values && isset($values[$key])) {
                    if (isset($values[$key]['type'])) {
                        $fieldType = $values[$key]['type'];
                    }
                    $fieldValue = isset($values[$key]['value']) ? $values[$key]['value'] : null;
                    if (!$_POST && !isset($_GET[$key])) {
                        $marked = isset($values[$key]['marked']) ? $values[$key]['marked'] : null;
                    }
                }
                if ($fieldType != 'hidden') {
                    $fieldLabel = ucwords(str_replace('_', ' ', $key)) . ':';
                } else {
                    if (null === $fieldValue && $required) {
                        $fieldValue = '0';
                    }
                }
                if (null !== $attribs) {
                    if (isset($attribs[$fieldType])) {
                        $attributes = $attribs[$fieldType];
                    }
                }
                if (stripos($key, 'email') !== false || stripos($key, 'e-mail') !== false || stripos($key, 'e_mail') !== false) {
                    $validators = new \Pop\Validator\Email();
                }
                $this->fields[$fieldName] = array('type' => $fieldType, 'label' => $fieldLabel, 'value' => $fieldValue, 'required' => $required, 'attributes' => $attributes, 'marked' => $marked, 'validators' => $validators);
            }
        }
        return $this;
    }