From fd4b8d9f45d1707035021bc19b8d5bc17ede66ce Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 12 Feb 2007 12:46:11 +0000 Subject: Add IBM DB2 driver for active record. --- .../Data/ActiveRecord/Scaffold/TScaffoldBase.php | 115 ++++++++++++++++++--- 1 file changed, 100 insertions(+), 15 deletions(-) (limited to 'framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php') diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php index dc464245..b55ceedc 100644 --- a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php +++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php @@ -1,12 +1,49 @@ + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2007 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Data.ActiveRecord.Scaffold + */ + +/** + * Include the base Active Record class. + */ Prado::using('System.Data.ActiveRecord.TActiveRecord'); +/** + * Base class for Active Record scaffold views. + * + * Provides common properties for all scaffold views (such as, TScaffoldListView, + * TScaffoldEditView, TScaffoldListView and TScaffoldView). + * + * During the OnPrRender stage the default css style file (filename style.css) + * is published and registered. To override the default style, provide your own stylesheet + * file explicitly. + * + * @author Wei Zhuo + * @version $Id$ + * @package System.Data.ActiveRecord.Scaffold + * @since 3.1 + */ abstract class TScaffoldBase extends TTemplateControl { + /** + * @var TActiveRecord record instance (may be new or retrieved from db) + */ private $_record; + /** + * @var TDbMetaData table/view information. + */ private $_meta; + /** + * @return TDbMetaData table/view information + */ protected function getTableMetaData() { if($this->_meta===null) @@ -18,7 +55,11 @@ abstract class TScaffoldBase extends TTemplateControl return $this->_meta; } - protected function getRecordProperties($record) + /** + * @param TActiveRecord record instance + * @return array record property values + */ + protected function getRecordPropertyValues($record) { $data = array(); foreach($this->getTableMetaData()->getColumns() as $name=>$column) @@ -26,7 +67,11 @@ abstract class TScaffoldBase extends TTemplateControl return $data; } - public function getRecordObjectPk($record) + /** + * @param TActiveRecord record instance + * @return array record primary key values. + */ + protected function getRecordPkValues($record) { $pk = array(); foreach($this->getTableMetaData()->getColumns() as $name=>$column) @@ -37,76 +82,116 @@ abstract class TScaffoldBase extends TTemplateControl return $data; } + /** + * Name of the Active Record class to be viewed or scaffolded. + * @return string Active Record class name. + */ public function getRecordClass() { return $this->getViewState('RecordClass'); } + /** + * Name of the Active Record class to be viewed or scaffolded. + * @param string Active Record class name. + */ public function setRecordClass($value) { $this->setViewState('RecordClass', $value); } - public function copyFrom(TScaffoldBase $obj) + /** + * Copy the view details from another scaffold view instance. + * @param TScaffoldBase scaffold view. + */ + protected function copyFrom(TScaffoldBase $obj) { $this->_record = $obj->_record; $this->_meta = $obj->_meta; $this->setRecordClass($obj->getRecordClass()); } + /** + * Unset the current record instance and table information. + */ protected function clearRecordObject() { $this->_record=null; $this->_meta=null; } - public function getRecordObject($pk=null) + /** + * Gets the current Active Record instance. Creates new instance if the + * primary key value is null otherwise the record is fetched from the db. + * @param array primary key value + * @return TActiveRecord record instance + */ + protected function getRecordObject($pk=null) { if($this->_record===null) { if($pk!==null) + { $this->_record=$this->getRecordFinder()->findByPk($pk); + if($this->_record===null) + throw new TConfigurationException('scaffold_invalid_record_pk', + $this->getRecordClass(), $pk); + } else { $class = $this->getRecordClass(); if($class!==null) $this->_record=Prado::createComponent($class); else - throw new TConfigurationException('scaffold_invalid_record_class', $this->getID()); + { + throw new TConfigurationException('scaffold_invalid_record_class', + $this->getRecordClass(),$this->getID()); + } } } return $this->_record; } - public function getRecordFinder() + /** + * @param TActiveRecord Active Record instance. + */ + protected function setRecordObject(TActiveRecord $value) { - return TActiveRecord::getRecordFinder(get_class($this->getRecordObject())); + $this->_record=$value; } - public function setRecordObject($value) + /** + * @return TActiveRecord Active Record finder instance + */ + protected function getRecordFinder() { - if($value instanceof TActiveRecord) - $this->_record=$value; - else - throw new TConfigurationException('scaffold_object_must_be_tactiverecord', $this->getID()); + return TActiveRecord::getRecordFinder($this->getRecordClass()); } + /** + * @return string default scaffold stylesheet name + */ public function getDefaultStyle() { return $this->getViewState('DefaultStyle', 'style'); } + /** + * @param string default scaffold stylesheet name + */ public function setDefaultStyle($value) { $this->setViewState('DefaultStyle', TPropertyValue::ensureString($value), 'style'); } + /** + * Publish the default stylesheet file. + */ public function onPreRender($param) { parent::onPreRender($param); $url = $this->publishAsset($this->getDefaultStyle().'.css'); - $cs = $this->getPage()->getClientScript(); - $cs->registerStyleSheetFile($url,$url); + $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url); } } -- cgit v1.2.3