summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
diff options
context:
space:
mode:
authorwei <>2007-01-30 11:36:13 +0000
committerwei <>2007-01-30 11:36:13 +0000
commit7fa1200b5e589a47884aa4d62630ce9099fccee1 (patch)
tree739e307440b4fccf3125ab11719dc09fccefed41 /framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
parentfcb45e6479d4c13084c8033e543e0c1fdeead8e5 (diff)
Add basic Scaffold view for Active Record
Diffstat (limited to 'framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php')
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php119
1 files changed, 119 insertions, 0 deletions
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
new file mode 100644
index 00000000..28fc8fb9
--- /dev/null
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php
@@ -0,0 +1,119 @@
+<?php
+
+Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase');
+Prado::using('System.Data.ActiveRecord.Scaffold.InputBuilder.TScaffoldInputBase');
+
+class TScaffoldEditView extends TScaffoldBase
+{
+ private static $_builders=array();
+
+ public function onLoad($param)
+ {
+ $this->initializeEditForm();
+ }
+
+ public function setRecordPk($value)
+ {
+ $this->clearRecordObject();
+ $val = TPropertyValue::ensureArray($value);
+ $this->setViewState('PK', count($val) > 0 ? $val : null);
+ }
+
+ public function getRecordPk()
+ {
+ return $this->getViewState('PK');
+ }
+
+ protected function getCurrentRecord()
+ {
+ return $this->getRecordObject($this->getRecordPk());
+ }
+
+ public function initializeEditForm()
+ {
+ $this->getCurrentRecord();
+ $columns = $this->getTableMetaData()->getColumns();
+ $this->_repeater->setDataSource($columns);
+ $this->_repeater->dataBind();
+ }
+
+ public function repeaterItemCreated($sender, $param)
+ {
+ $type = $param->getItem()->getItemType();
+ if($type==TListItemType::Item || $type==TListItemType::AlternatingItem)
+ {
+ $item = $param->getItem();
+ $column = $item->getDataItem();
+ if($column===null)
+ return;
+
+ $record = $this->getCurrentRecord();
+ $builder = $this->getScaffoldInputBuilder($record);
+ $builder->createScaffoldInput($this, $item, $column, $record);
+ }
+ }
+
+ public function bubbleEvent($sender, $param)
+ {
+ switch(strtolower($param->getCommandName()))
+ {
+ case 'save':
+ if($this->getPage()->getIsValid())
+ return $this->doSave() === true ? false : true;
+ return true;
+ case 'clear':
+ $this->setRecordPk(null);
+ $this->initializeEditForm();
+ return false;
+ default:
+ return false;
+ }
+ }
+
+ protected function doSave()
+ {
+ $record = $this->getCurrentRecord();
+ $table = $this->getTableMetaData();
+ $builder = $this->getScaffoldInputBuilder($record);
+ foreach($this->_repeater->getItems() as $item)
+ {
+ $column = $table->getColumn($item->getCustomData());
+ $builder->loadScaffoldInput($this, $item, $column, $record);
+ }
+ $record->save();
+ return true;
+ }
+
+ public function getSaveButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_save');
+ }
+
+ public function getClearButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_clear');
+ }
+
+ public function getCancelButton()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('_cancel');
+ }
+
+ protected function getScaffoldInputBuilder($record)
+ {
+ $class = get_class($record);
+ if(!isset(self::$_builders[$class]))
+ self::$_builders[$class] = TScaffoldInputBase::createInputBuilder($record);
+ return self::$_builders[$class];
+ }
+
+ public function getValidationGroup()
+ {
+ return 'group_'.$this->getUniqueID();
+ }
+}
+
+?> \ No newline at end of file