2006-05-30 12:42:10 +04:00
|
|
|
<?php
|
|
|
|
class Doctrine_Form implements Iterator {
|
|
|
|
protected $record;
|
|
|
|
protected $elements = array();
|
|
|
|
protected $columns;
|
|
|
|
protected $current;
|
|
|
|
protected $keys;
|
|
|
|
protected $index;
|
|
|
|
protected $count;
|
|
|
|
public function __construct(Doctrine_Record $record) {
|
|
|
|
$this->record = $record;
|
|
|
|
$this->columns = $record->getTable()->getColumns();
|
|
|
|
$this->keys = array_keys($this->columns);
|
|
|
|
$this->index = 0;
|
|
|
|
$this->count = count($this->keys);
|
|
|
|
}
|
|
|
|
public function current() {
|
|
|
|
$i = $this->index;
|
|
|
|
$column = $this->keys[$i];
|
|
|
|
|
|
|
|
$definitions = $this->columns[$column];
|
|
|
|
|
|
|
|
$e = explode("|",$definitions[2]);
|
2006-06-20 01:31:22 +04:00
|
|
|
|
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
$enum = false;
|
2006-06-20 01:31:22 +04:00
|
|
|
|
|
|
|
if($definitions[0] == "enum")
|
|
|
|
$enum = $this->record->getTable()->getEnumValues($column);
|
|
|
|
|
2006-05-30 12:42:10 +04:00
|
|
|
$length = $definitions[1];
|
|
|
|
if( ! in_array("autoincrement",$e) && ! in_array("protected",$e)) {
|
|
|
|
if($enum) {
|
|
|
|
$elements[$column] = "<select name='data[$column]'>\n";
|
|
|
|
foreach($enum as $k => $v) {
|
2006-06-20 01:31:22 +04:00
|
|
|
if($this->record->get($column) == $v) {
|
2006-05-30 12:42:10 +04:00
|
|
|
$str = 'selected';
|
|
|
|
} else
|
|
|
|
$str = '';
|
|
|
|
|
2006-06-20 01:31:22 +04:00
|
|
|
$elements[$column] .= " <option value='$v' $str>$v</option>\n";
|
2006-05-30 12:42:10 +04:00
|
|
|
}
|
|
|
|
$elements[$column] .= "</select>\n";
|
|
|
|
} else {
|
|
|
|
if($length <= 255) {
|
|
|
|
$elements[$column] = "<input name='data[$column]' type='text' value='".$this->record->get($column)."' maxlength=$length \>\n";
|
2006-06-12 12:44:08 +04:00
|
|
|
} elseif($length <= 4000) {
|
2006-05-30 12:42:10 +04:00
|
|
|
$elements[$column] = "<textarea name='data[$column]' cols=40 rows=10>".$this->record->get($column)."</textarea>\n";
|
2006-06-12 12:44:08 +04:00
|
|
|
} else {
|
|
|
|
$elements[$column] = "<textarea name='data[$column]' cols=60 rows=25>".$this->record->get($column)."</textarea>\n";
|
2006-05-30 12:42:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $elements[$column];
|
|
|
|
} else {
|
|
|
|
$this->index++;
|
|
|
|
|
|
|
|
if($this->index < $this->count)
|
|
|
|
return self::current();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function key() {
|
|
|
|
$i = $this->index;
|
|
|
|
return $this->keys[$i];
|
|
|
|
}
|
|
|
|
public function next() {
|
|
|
|
$this->index++;
|
|
|
|
}
|
|
|
|
public function rewind() {
|
|
|
|
$this->index = 0;
|
|
|
|
}
|
|
|
|
public function valid() {
|
|
|
|
if($this->index >= $this->count)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|