diff options
author | wei <> | 2007-02-12 12:46:11 +0000 |
---|---|---|
committer | wei <> | 2007-02-12 12:46:11 +0000 |
commit | fd4b8d9f45d1707035021bc19b8d5bc17ede66ce (patch) | |
tree | 093b8b3f92d4d6421f19a6d1e7c8211817f3d51d /framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php | |
parent | f4c525abc3d4d3f3eecf1019770936e4ca39fd62 (diff) |
Add IBM DB2 driver for active record.
Diffstat (limited to 'framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php')
-rw-r--r-- | framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php | 115 |
1 files changed, 100 insertions, 15 deletions
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 @@ <?php
-
+/**
+ * TScaffoldBase class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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 <weizho[at]gmail[dot]com>
+ * @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);
}
}
|