Skip to content
Snippets Groups Projects
Commit 64f1a73d authored by Tim Steiner's avatar Tim Steiner
Browse files

Updates for ZF-0.9.3 Compatibility

DB_Table_Row_DataType added
Support for Linking Tables in DB_Table_Relation_HasMany
parent 134c4e7a
Branches
No related tags found
No related merge requests found
Showing
with 174 additions and 77 deletions
<?php
require_once('Zend.php');
Zend_Loader::loadClass('Nmc_Auth_Exception');
interface Nmc_Auth_Interface
......
<?php
require_once 'Zend.php';
require_once 'Nmc/Auth/Interface.php';
class Nmc_Auth_Ldap implements Nmc_Auth_Interface
......@@ -26,5 +25,3 @@ class Nmc_Auth_Ldap implements Nmc_Auth_Interface
return true;
}
}
?>
\ No newline at end of file
<?php
require_once 'Zend.php';
require_once 'Nmc/Auth/Interface.php';
class Nmc_Auth_Multi implements Nmc_Auth_Interface
......@@ -55,5 +54,3 @@ class Nmc_Auth_Multi implements Nmc_Auth_Interface
return true;
}
}
?>
\ No newline at end of file
<?php
require_once('Zend.php');
require_once 'Nmc/Auth/Interface.php';
class Nmc_Auth_Mysql implements Nmc_Auth_Interface
......@@ -15,12 +14,12 @@ class Nmc_Auth_Mysql implements Nmc_Auth_Interface
public function login( $user_name, $password )
{
$db = $this->table->getAdapter();
$where = $db->quoteInto('user_name=?', $user_name)
$where = $db->quoteInto('userName=?', $user_name)
. ' AND '
. $db->quoteInto('password=?', md5($password));
$data = $this->table->fetchAll($where);
if( count( $data->toArray() ) == 0 ) {
throw new Nmc_Auth_Exception( 'MySQL: user_name or password incorrect.');
throw new Nmc_Auth_Exception( 'MySQL: userName or password incorrect.');
}
return true;
......
......@@ -11,7 +11,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
require_once 'Nmc/SingletonInterface.php';
/**
......
......@@ -12,7 +12,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
/**
* Nmc_Db_SessionHandler - Use a Db Table as your session handler
......
<?php
require_once('Zend.php');
require_once 'Nmc/SingletonInterface.php';
Zend_Loader::loadClass('Zend_Db_Table');
......
<?php
require_once('Zend.php');
Zend_Loader::loadClass('Zend_Db_Table_Row');
abstract class Nmc_Db_Table_AclRow extends Zend_Db_Table_Row
......
<?php
require_once 'Nmc/Db/Table/DataType/Interface.php';
class Nmc_Db_Table_DataType_Date implements Nmc_Db_Table_DataType_Interface
{
/**
* Stores the date object
*
* @var Zend_Date
*/
protected $_dateObject = null;
public function setColumnData($columnData)
{
if ($columnData) {
$this->_dateObject = new Zend_Date($columnData);
}
}
public function setObject($object)
{
if (is_null($object)) {
$this->_dateObject = null;
return;
}
if(!$object instanceof Zend_Date) {
throw new Nmc_Exception('Attempt to set wrong data type');
}
$this->_dateObject = $object;
}
public function getColumnData()
{
if ($this->_dateObject) {
return $this->_dateObject->getTimestamp();
}
return null;
}
public function getObject()
{
return $this->_dateObject;
}
}
\ No newline at end of file
<?php
interface Nmc_Db_Table_DataType_Interface
{
public function setColumnData($columnData);
public function setObject($object);
public function getColumnData();
public function getObject();
}
<?php
require_once('Zend.php');
require_once 'Nmc/Db/Table/Relation/Interface.php';
/**
......
......@@ -12,8 +12,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
/**
* Nmc_Db_Table_Relation_Extend - A one to one relation where one table extends another
*
......
......@@ -12,8 +12,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
/**
* Nmc_Db_Table_Relation_HasMany - A relation where one row is the parent of many others
*
......@@ -45,6 +43,17 @@ class Nmc_Db_Table_Relation_HasMany extends Nmc_Db_Table_Relation_Abstract
protected $_attributeName;
protected $_saveChildRows = true;
/**
* The linking table, if one is used
*
* @var Nmc_Db_Table
*/
protected $_linkingTable;
protected $_linkingForeignKeyName;
/**
* The set of rows belonging to this relation
*
......@@ -71,12 +80,44 @@ class Nmc_Db_Table_Relation_HasMany extends Nmc_Db_Table_Relation_Abstract
$this->_attributeName = $attributeName;
}
/**
* If the rows are related via a linking table, use this function to tell
* the parent table how to use the linking table.
*
* @param Nmc_Db_Table $linkingTable
* @param unknown_type $foreignKeyName
*/
public function setLinkingTable(Nmc_Db_Table $linkingTable, $foreignKeyName)
{
$this->_linkingTable = $linkingTable;
$this->_linkingForeignKeyName = $foreignKeyName;
}
public function setSaveChildRows($value = true)
{
$this->_saveChildRows = $value;
}
public function register()
{
$db = $this->_childTable->getAdapter();
if ($this->_linkingTable) {
$where = $db->quoteInto($this->_foreignKeyName . ' = ?', $this->_row->getPrimaryKey());
$linkingRowset = $this->_linkingTable->fetchAll($where);
$keys = array();
foreach($linkingRowset as $row) {
$keys[] = $row->{$this->_linkingForeignKeyName};
}
$this->_rowset = $this->_childTable->find($keys);
} else {
$where = $db->quoteInto($this->_foreignKeyName . ' = ?', $this->_row->getPrimaryKey());
$this->_rowset = $this->_childTable->fetchAll($where);
}
}
public function onPostGet($name)
{
......@@ -102,8 +143,51 @@ class Nmc_Db_Table_Relation_HasMany extends Nmc_Db_Table_Relation_Abstract
public function onPostSave()
{
if (!$this->_saveChildRows) {
return;
}
$db = $this->_childTable->getAdapter();
if ($this->_linkingTable) {
$keys = array(-1);
foreach($this->_rowset as $row) {
$keys[] = $row->getPrimaryKey();
}
$where = array();
$where[] = $db->quoteInto($this->_foreignKeyName . ' = ?', $this->_row->getPrimaryKey());
$where[] = $db->quoteInto($this->_linkingForeignKeyName . ' IN(?)', $keys);
$where = implode(' AND ', $where);
$selectedRows = $this->_linkingTable->fetchAll($where);
$where = $db->quoteInto(
$this->_foreignKeyName . ' = ?', $this->_row->getPrimaryKey()
);
$currentRows = $this->_linkingTable->fetchAll($where);
$removedRows = $currentRows->getRowsNotInCommonWith($selectedRows);
foreach ($removedRows as $removedRow) {
$removedRow->delete();
}
foreach ($this->_rowset as $row) {
$row->save();
$where = array();
$where[] = $db->quoteInto($this->_foreignKeyName . ' = ?', $this->_row->getPrimaryKey());
$where[] = $db->quoteInto($this->_linkingForeignKeyName . ' = ?', $row->getPrimaryKey());
$where = implode(' AND ', $where);
$linkingRow = $this->_linkingTable->fetchAll($where);
if ($linkingRow->count() == 0) {
$linkingRow = $this->_linkingTable->fetchNew();
$linkingRow->{$this->_foreignKeyName} = $this->_row->getPrimaryKey();
$linkingRow->{$this->_linkingForeignKeyName} = $row->getPrimaryKey();
$linkingRow->save();
}
}
} else {
$selectedRows = $this->_rowset;
$where = $this->_childTable->getAdapter()->quoteInto(
$where = $db->quoteInto(
$this->_foreignKeyName . ' = ?', $this->_row->getPrimaryKey()
);
$currentRows = $this->_childTable->fetchAll($where);
......@@ -119,42 +203,8 @@ class Nmc_Db_Table_Relation_HasMany extends Nmc_Db_Table_Relation_Abstract
$selectedRow->$foreignKeyName = $this->_row->getPrimaryKey();
$selectedRow->save();
}
/*
$newRows = array();
foreach($this->_rowset as $row) {
$row->{$this->_foreignKeyName} = $this->_row->getPrimaryKey();
$newRows[] = $row;
}
$where = $this->_childTable->getAdapter()->quoteInto($this->_foreignKeyName . ' = ?', $this->_row->getPrimaryKey());
$currentRows = $this->_childTable->fetchAll($where);
foreach($currentRows as $currentRow) {
$keepRow = false;
foreach($newRows as $key => $newRow) {
if($currentRow->equalTo($newRow)) {
$keepRow = true;
if($currentRow !== $newRow) {
unset($newRows[$key]);
}
}
}
if(!$keepRow) {
$currentRow->delete();
}
}
foreach($newRows as $newRow) {
$newRow->save();
}
*/
}
public function onPostClone(Nmc_Db_Table_Row $newParentRow)
{
......
......@@ -12,8 +12,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
/**
* Nmc_Db_Table_Relation_HasOne - A relation where one row is the parent of a single other row
*
......
......@@ -37,6 +37,8 @@ class Nmc_Db_Table_Row extends Zend_Db_Table_Row
protected $_relations = array();
protected $_dataTypes = array();
protected $_uuid;
public function __construct($config = array())
......@@ -181,6 +183,9 @@ class Nmc_Db_Table_Row extends Zend_Db_Table_Row
protected function _get($name)
{
if (array_key_exists($name, $this->_dataTypes)) {
return $this->_dataTypes[$name]->getObject();
}
return parent::__get($name);
}
......@@ -219,6 +224,9 @@ class Nmc_Db_Table_Row extends Zend_Db_Table_Row
protected function _set($name, $value)
{
if (array_key_exists($name, $this->_dataTypes)) {
return $this->_dataTypes[$name]->setObject($value);
}
return parent::__set($name, $value);
}
......@@ -275,6 +283,9 @@ class Nmc_Db_Table_Row extends Zend_Db_Table_Row
protected function _save()
{
foreach ($this->_dataTypes as $columnName => $columnType) {
$this->_data[$columnName] = $columnType->getColumnData();
}
parent::save();
}
......@@ -289,6 +300,15 @@ class Nmc_Db_Table_Row extends Zend_Db_Table_Row
$this->_relations[] = $relation;
}
protected function _registerColumnDataType($columnName, Nmc_Db_Table_DataType_Interface $dataType)
{
if(!array_key_exists($columnName, $this->_data)) {
throw new Nmc_Exception('Column does not exist');
}
$this->_dataTypes[$columnName] = $dataType;
$dataType->setColumnData($this->_data[$columnName]);
}
/**
* Duplicates record in database and sets current record to
* the duplicated record.
......
......@@ -11,8 +11,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
/**
* Objects implementing the equalTo interface supply the equalTo() function
* This function is used to do custom equality comparisons.
......@@ -29,5 +27,3 @@ interface Nmc_EqualToInterface {
public function equalTo($object);
}
?>
\ No newline at end of file
<?php
require_once('Zend.php');
Zend_Loader::loadClass('Zend_Filter');
Zend_Loader::loadClass('Nmc_Math_OrderedPair');
Zend_Loader::loadClass('Nmc_Image_Exception');
......
<?php
require_once('Zend.php');
Zend_Loader::loadClass('Zend_Filter');
Zend_Loader::loadClass('Nmc_Math_OrderedPair');
Zend_Loader::loadClass('Nmc_Image_Exception');
......
......@@ -11,8 +11,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
/**
* Color Class
*
......
......@@ -12,7 +12,6 @@
* @since File available since Release 0.0.1
*/
require_once('Zend.php');
Zend_Loader::loadClass('Nmc_Image');
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment