From 1633b07f1dc5cddaacb6c025951f1456b924bbb6 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 17 Jul 2007 20:59:09 +0000 Subject: [PATCH] --- lib/Doctrine/Record.php | 36 +++++++++++++++++++++++++++++++++++- lib/Doctrine/Search.php | 13 ++++++++++--- lib/Doctrine/Table.php | 24 ++++++++++++++++-------- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 50bf8f412..8b5a7e6df 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1370,7 +1370,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count } public function revert($version) { - $data = $this->_table->getAuditLog()->getVersion($this, $version); + $data = $this->_table + ->getTemplate('Doctrine_Template_Versionable') + ->getAuditLog() + ->getVersion($this, $version); $this->_data = $data[0]; } @@ -1387,6 +1390,37 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $tpl->setTableDefinition(); return $this; } + + public function actAs($tpl, $options = array()) + { + + if ( ! is_object($tpl)) { + if (class_exists($tpl)) { + $tpl = new $tpl($options); + } else { + $className = 'Doctrine_Template_' . ucwords(strtolower($tpl)); + + if ( ! class_exists($className)) { + throw new Doctrine_Record_Exception("Couldn't load plugin."); + } + + $tpl = new $className($options); + } + } + + if ( ! ($tpl instanceof Doctrine_Template)) { + throw new Doctrine_Record_Exception('Loaded plugin class is not an istance of Doctrine_Template.'); + } + $className = get_class($tpl); + + $this->_table->addTemplate($className, $tpl); + + $tpl->setTable($this->_table); + $tpl->setUp(); + $tpl->setTableDefinition(); + + return $this; + } /** * used to delete node from tree - MUST BE USE TO DELETE RECORD IF TABLE ACTS AS TREE * diff --git a/lib/Doctrine/Search.php b/lib/Doctrine/Search.php index cfd04dbab..7b4f88fe5 100644 --- a/lib/Doctrine/Search.php +++ b/lib/Doctrine/Search.php @@ -33,6 +33,7 @@ class Doctrine_Search { protected $_options = array('generateFiles' => true); + public function __construct(array $options) { @@ -98,12 +99,17 @@ class Doctrine_Search $columns = array('keyword' => array('type' => 'string', 'length' => 200, - 'notnull' => true), + 'notnull' => true, + 'primary' => true, + ), 'field' => array('type' => 'string', 'length' => 50, - 'notnull' => true), + 'notnull' => true, + 'primary' => true), 'position' => array('type' => 'integer', - 'length' => 8)); + 'length' => 8, + 'primary' => true, + )); $id = $table->getIdentifier(); @@ -120,6 +126,7 @@ class Doctrine_Search $col = strtolower($name . '_' . $column); + $def['primary'] = true; $fk[$col] = $def; } diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index e5f9f48d9..2efe2ae3c 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -154,9 +154,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable */ protected $_parser; /** - * @var Doctrine_AuditLog $_auditLog + * @var array $_templates an array containing all templates attached to this table */ - protected $_auditLog; + protected $_templates; + + /** * the constructor * @throws Doctrine_Connection_Exception if there are no opened connections @@ -1238,13 +1240,19 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable public function isTree() { return ( ! is_null($this->options['treeImpl'])) ? true : false; } - public function getAuditLog() + + public function getTemplate($template) { - if ( ! isset($this->_auditLog)) { - $this->_auditLog = new Doctrine_AuditLog($this); - } - - return $this->_auditLog; + if ( ! isset($this->_templates[$template])) { + throw new Doctrine_Table_Exception('Template ' . $template . ' not loaded'); + } + + return $this->_templates[$template]; + } + + public function addTemplate($template, Doctrine_Template $impl) + { + $this->_templates[$template] = $impl; } /** * returns a string representation of this object