/** * Renders a non select field. * * @return string (X)HTML. */ protected function renderNonSelectField() { $o = ''; if (function_exists('advfrm_custom_field_default')) { $val = advfrm_custom_field_default($this->form, $this->field->getName(), null, isset($_POST['advfrm'])); } if (!isset($val)) { $val = isset($_POST[$this->name]) ? stsl($_POST[$this->name]) : $this->field->getDefaultValue(); } if ($this->field->getType() == 'textarea') { $cols = $this->field->getColumnCount() ? $this->field->getColumnCount() : 40; $rows = $this->field->getRowCount() ? $this->field->getRowCount() : 4; $o .= '<textarea id="' . $this->id . '" name="' . $this->name . '" cols="' . $cols . '" rows="' . $rows . '">' . XH_hsc($val) . '</textarea>'; } elseif ($this->field->getType() == 'output') { $o .= $val; } else { if ($this->field->getType() == 'date') { $this->initDatePicker(); } $size = $this->field->getType() == 'hidden' || $this->field->getSize() ? ' size="' . $this->field->getSize() . '"' : ''; $maxlen = in_array($this->field->getType(), array('hidden', 'file')) || !$this->field->getMaxLength() ? '' : ' maxlength="' . $this->field->getMaxLength() . '"'; if ($this->field->getType() == 'file' && $this->field->getMaxLength()) { $o .= tag('input type="hidden" name="MAX_FILE_SIZE" value="' . $this->field->getMaxLength() . '"'); } if ($this->field->getType() == 'file') { $value = ''; $accept = ' accept="' . XH_hsc($this->prefixFileExtensionList($val)) . '"'; } else { $value = ' value="' . XH_hsc($val) . '"'; $accept = ''; } $o .= tag('input type="' . $this->getInputElementType() . '" id="' . $this->id . '" name="' . $this->name . '"' . $value . $accept . $size . $maxlen); } return $o; }
public function testDefaultValue() { $crud = new LouisCRUD(); $field = new Field($crud, "product_name", "varchar(255)"); $this->assertEquals(null, $field->getDefaultValue()); $field->setDefaultValue(true); $this->assertEquals(true, $field->getDefaultValue()); $field->setDefaultValue(null); $this->assertEquals(null, $field->getDefaultValue()); $field->setDefaultValue(1999); $this->assertEquals(1999, $field->getDefaultValue()); $field->setDefaultValue(19.99); $this->assertEquals(19.99, $field->getDefaultValue()); $field->setDefaultValue("1999abc"); $this->assertEquals("1999abc", $field->getDefaultValue()); $field->setDefaultValue("中文字"); $this->assertEquals("中文字", $field->getDefaultValue()); }
/** * Change column from null to not null * @param Field $field */ public function changeFieldToNotNullable($field) { $result = PerfORMController::getConnection()->query('select * from %n where %n is null', $field->getModel()->getTableName(), $field->getName()); $pk = $field->getModel()->getPrimaryKey(); foreach ($result as $row) { if (!is_null($value = $field->getDefaultValue())) { } elseif (is_callable($field->getDefaultCallback())) { $value = call_user_func($field->getDefaultCallback(), $row); } else { throw new Exception("Unable to set default value for field '" . $field->getName() . "'"); } PerfORMController::getConnection()->query('update %n set %n = %' . $field->getType() . ' where %n = %i', $field->getModel()->getTableName(), $field->getName(), $value, $pk, $row->{$pk}); } PerfORMController::getBuilder()->changeFieldsNullable($field); $this->updateFieldSync($field); }