+++ /dev/null
-<?php
-
-class IPF_Form_DB_Date extends IPF_Form_DB{
- public $type = 'date';
- function formField($def, $form_field='IPF_Form_Field_Date'){
- return parent::formField($def, $form_field);
- }
-}
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Datetime extends IPF_Form_DB{
- public $type = 'datetime';
- function formField($def, $form_field='IPF_Form_Field_Datetime'){
- return parent::formField($def, $form_field);
- }
-}
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Decimal extends IPF_Form_DB
-{
- function formField($def, $form_field='IPF_Form_Field_Float')
- {
- $def['widget_attrs'] = array('style' => 'width:140px;');
- return parent::formField($def, $form_field);
- }
-}
-
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Double extends IPF_Form_DB
-{
- function formField($def, $form_field='IPF_Form_Field_Float')
- {
- $def['widget_attrs'] = array('style' => 'width:140px;');
- return parent::formField($def, $form_field);
- }
-}
-
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Email extends IPF_Form_DB
-{
- public $type = 'varchar';
- public $extra = array('size' => 200);
-
- function formField($def, $form_field='IPF_Form_Field_Email')
- {
- return parent::formField($def, $form_field);
- }
-}
-
+++ /dev/null
-<?php
-
-class IPF_Form_DB_File extends IPF_Form_DB
-{
- function formField($def, $form_field='IPF_Form_Field_File')
- {
- $field = parent::formField($def, $form_field);
- $field->uploadTo = @$this->extra['uploadTo'];
- return $field;
- }
-}
-
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Html extends IPF_Form_DB{
- function formField($def, $form_field='IPF_Form_Field_Html'){
- return parent::formField($def, $form_field);
- }
-}
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Image extends IPF_Form_DB_File
-{
- function formField($def, $form_field='IPF_Form_Field_Image')
- {
- return parent::formField($def, $form_field);
- }
-}
-
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Integer extends IPF_Form_DB
-{
- function formField($def, $form_field='IPF_Form_Field_Integer')
- {
- $def['widget_attrs'] = array('style' => 'width:140px;');
- return parent::formField($def, $form_field);
- }
-}
-
+++ /dev/null
-<?php
-
-class IPF_Form_DB_String extends IPF_Form_DB
-{
- public $type = 'varchar';
-}
+++ /dev/null
-<?php
-
-class IPF_Form_DB_Timestamp extends IPF_Form_DB{
- public $type = 'datetime';
- function formField($def, $form_field='IPF_Form_Field_Datetime'){
- return parent::formField($def, $form_field);
- }
-}
if ($name == $this->model->getTable()->getIdentifier())
return;
- $defaults = array(
- 'blank' => true,
- 'help_text' => '',
+ $required = isset($col['notblank']) && $col['notblank'];
+ $label = isset($col['verbose']) ? $col['verbose'] : IPF_Utils::humanTitle($name);
+
+ $params = array(
+ 'required' => $required,
'editable' => true,
- 'verbose' => isset($col['verbose']) ? $col['verbose'] : $name,
+ 'label' => $label,
+ 'help_text' => '',
);
- $type = $col['type'];
-
- if (isset($col['notblank'])) {
- if ($col['notblank'])
- $defaults['blank'] = false;
- else
- $defaults['blank'] = true;
+ switch ($col['type']) {
+ case 'string':
+ if (isset($col['length']))
+ $params['max_length'] = (int)($col['length']);
+
+ if (isset($col['uploadTo']))
+ $params['uploadTo'] = $col['uploadTo'];
+
+ if (isset($col['email']) && $col['email']) { $form_field = new IPF_Form_Field_Email($params); }
+ elseif (isset($col['file']) && $col['file']) { $form_field = new IPF_Form_Field_File($params); }
+ elseif (isset($col['image']) && $col['image']) { $form_field = new IPF_Form_Field_Image($params); }
+ elseif (isset($col['html']) && $col['html']) { $form_field = new IPF_Form_Field_Html($params); }
+ else { $form_field = new IPF_Form_Field_Varchar($params); }
+
+ break;
+ case 'boolean':
+ $form_field = new IPF_Form_Field_Boolean($params);
+ break;
+ case 'integer':
+ $params['widget_attrs'] = array('style' => 'width:140px;');
+ $form_field = new IPF_Form_Field_Integer($params);
+ break;
+ case 'double':
+ case 'decimal':
+ $params['widget_attrs'] = array('style' => 'width:140px;');
+ $form_field = new IPF_Form_Field_Float($params);
+ break;
+ case 'date':
+ $form_field = new IPF_Form_Field_Date($params);
+ break;
+ case 'datetime':
+ case 'timestamp':
+ $form_field = new IPF_Form_Field_Datetime($params);
+ break;
+ default:
+ throw new IPF_Exception_Form(__('Unsupported column type \''.$col['type'].'\'.'));
}
- if (isset($col['length']))
- $defaults['max_length'] = (int)($col['length']);
-
- if (isset($col['email']))
- $type = 'email';
-
- if (isset($col['file']))
- $type = 'file';
-
- if (isset($col['image']))
- $type = 'image';
-
- if (isset($col['html']))
- $type = 'html';
-
- $cn = 'IPF_Form_DB_'.ucfirst($type);
-
- $db_field = new $cn('', $name, $col);
- $form_field = $db_field->formField($defaults);
if ($form_field !== null)
$this->fields[$name] = $form_field;
}