From 7fa1200b5e589a47884aa4d62630ce9099fccee1 Mon Sep 17 00:00:00 2001 From: wei <> Date: Tue, 30 Jan 2007 11:36:13 +0000 Subject: Add basic Scaffold view for Active Record --- .../Data/ActiveRecord/Scaffold/TScaffoldBase.php | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php (limited to 'framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php') diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php new file mode 100644 index 00000000..dc464245 --- /dev/null +++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php @@ -0,0 +1,113 @@ +_meta===null) + { + $finder = $this->getRecordFinder(); + $gateway = $finder->getRecordManager()->getRecordGateWay(); + $this->_meta = $gateway->getMetaData($finder); + } + return $this->_meta; + } + + protected function getRecordProperties($record) + { + $data = array(); + foreach($this->getTableMetaData()->getColumns() as $name=>$column) + $data[] = $record->{$name}; + return $data; + } + + public function getRecordObjectPk($record) + { + $pk = array(); + foreach($this->getTableMetaData()->getColumns() as $name=>$column) + { + if($column->getIsPrimaryKey()) + $data[] = $record->{$name}; + } + return $data; + } + + public function getRecordClass() + { + return $this->getViewState('RecordClass'); + } + + public function setRecordClass($value) + { + $this->setViewState('RecordClass', $value); + } + + public function copyFrom(TScaffoldBase $obj) + { + $this->_record = $obj->_record; + $this->_meta = $obj->_meta; + $this->setRecordClass($obj->getRecordClass()); + } + + protected function clearRecordObject() + { + $this->_record=null; + $this->_meta=null; + } + + public function getRecordObject($pk=null) + { + if($this->_record===null) + { + if($pk!==null) + $this->_record=$this->getRecordFinder()->findByPk($pk); + else + { + $class = $this->getRecordClass(); + if($class!==null) + $this->_record=Prado::createComponent($class); + else + throw new TConfigurationException('scaffold_invalid_record_class', $this->getID()); + } + } + return $this->_record; + } + + public function getRecordFinder() + { + return TActiveRecord::getRecordFinder(get_class($this->getRecordObject())); + } + + public function setRecordObject($value) + { + if($value instanceof TActiveRecord) + $this->_record=$value; + else + throw new TConfigurationException('scaffold_object_must_be_tactiverecord', $this->getID()); + } + + public function getDefaultStyle() + { + return $this->getViewState('DefaultStyle', 'style'); + } + + public function setDefaultStyle($value) + { + $this->setViewState('DefaultStyle', TPropertyValue::ensureString($value), 'style'); + } + + public function onPreRender($param) + { + parent::onPreRender($param); + $url = $this->publishAsset($this->getDefaultStyle().'.css'); + $cs = $this->getPage()->getClientScript(); + $cs->registerStyleSheetFile($url,$url); + } +} + +?> \ No newline at end of file -- cgit v1.2.3