public
anonymous / Example1.php
Last active

  • Download Gist
Example1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
// Zend Framework Workaround
require_once('ZFWA\Db\Table\Row\Abstract.php');
require_once('ZFWA\Db\Table\Select\ColumnsWithoutFrom.php');
// That Table we want to start from
require_once('ThatTable.php');
// init Table
$ThatTable = new ThatTable();
// fetch Rowset/Row
$ThatRowset = $ThatTable->find(1);
$ThatRow = $ThatRowset->current();
// select Intersection Columns
$select = $ThatTable->selectIntersectionColumns('status');
// fetch ManyToMany with Intersection Columns
$FarRows = $ThatRow->findManyToManyRowset('ThatToFarTable', 'FarTable', null, null, $select);
ZFWA\Db\Table\Row\Abstract.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?php
/**
* @see Zend_Db_Table_Row_Abstract
*/
require_once 'Zend/Db/Table/Row/Abstract.php';
 
/**
* @category ZFWA
* @package ZFWA_Db
* @subpackage Table
*
* @author Christoph Roensch
*/
abstract class ZFWA_Db_Table_Row_Abstract extends Zend_Db_Table_Row_Abstract
{
/**
* Select columns of the intersection table used in findManyToManyRowset
*
* part of the fix to revert the changes in ZF-3709
*
* @param array|string|Zend_Db_Expr $cols The columns to select.
*/
public function selectIntersectionColumns($cols = '*')
{
if( is_array($cols) )
{
foreach( $cols as &$col )
{
$col = 'i.'.$col;
}
}
elseif ( is_string($cols) )
{
$cols = 'i.'.$cols;
}
$table = $this->getTable();
/**
* @see ZFWA_Db_Table_Select_ColumnsWithoutFrom
*/
require_once 'ZFWA/Db/Table/Select/ColumnsWithoutFrom.php';
$select = new ZFWA_Db_Table_Select_ColumnsWithoutFrom($table);
return $select->columns($cols);
}
}
ZFWA\Db\Table\Select\ColumnsWithoutFrom.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?php
/**
* Class for SQL SELECT query manipulation for the Zend_Db_Table_Row component.
*
* allows to use columns before specifying a FROM clause
* part of the fix to revert the changes in ZF-3709
*
* @see ZFWA_Db_Table_Row_Abstract::selectIntersectionColumns()
*
* @category ZFWA
* @package ZFWA_Db
* @subpackage Table
*
* @author Christoph Roensch
*/
class ZFWA_Db_Table_Select_ColumnsWithoutFrom extends Zend_Db_Table_Select
{
/**
* Specifies columns even if they are not used in the FROM clause.
*
* The parameter can be a single string or Zend_Db_Expr object,
* or else an array of strings or Zend_Db_Expr objects.
*
* @param array|string|Zend_Db_Expr $cols The columns to select from this table.
* @param string $correlationName Correlation name of target table. OPTIONAL
* @return ZFWA_Db_Table_Select This ZFWA_Db_Table_Select object.
*/
public function columns($cols = '*', $correlationName = null)
{
$this->_tableCols($correlationName, $cols);
return $this;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.