Select Git revision
Table.php 5.84 KiB
<?php
require_once('Zend.php');
Zend::loadInterface('Nmc_SingletonInterface');
Zend::loadClass('Zend_Db_Table');
abstract class Nmc_Db_Table
extends Zend_Db_Table
implements Nmc_SingletonInterface
{
public function _setup()
{
$selfInflection = new ReflectionObject($this);
$docBlock = Nmc_DocBlock::createFromString($selfInflection->getDocComment());
if (! $this->_name) {
if($docBlock->table) {
$this->_name = $docBlock->table;
} else {
$this->_name = DATABASE_TABLE_PREFIX . self::$_inflector->underscore(get_class($this));
}
}
if ($this->_primary == 'id') {
if($docBlock->primary) {
$this->_primary = $docBlock->primary;
}
}
parent::_setup();
}
/**
* find() - returns proper type of row
*
* @param mixed $val
* @return Nmc_Db_Table_Row
*/
public function find($val)
{
$row = parent::find($val);
if(!$row) {
return null;
}
$returnType = $this->getRowReturnType();
$config = array('db' => $this->getAdapter(),
'table' => $this,
'data' => $row->toArray());
return Nmc_Db_RowManager::getInstance()->getRow($returnType, $config);
}
/**
* findAll() returns rows with primary keys listed in the array
*
* @param array $valArray
* @return Nmc_Db_Table_Rowset
*/
public function findAll($valArray) {
if(!is_array($valArray) || count($valArray) == 0) {
return $this->fetchNewRowset();
}
$where = $this->_db->quoteInto($this->_primary . ' IN (?)', $valArray);
return $this->fetchAll($where);
}
/**
* fetchNew() - returns proper type of row