Exemplo n.º 1
0
 public function findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule = null, $matchRefRule = null, Zend_Db_Table_Select $select = null)
 {
     // Possível Informação de Chaves
     if (is_string($intersectionTable) && is_string($matchTable) && !isset($callerRefRule, $matchRefRule)) {
         $needle1 = $intersectionTable;
         $mapper1 = $this->getTable()->info(Zend_Db_Table::DEPENDENT_TABLES);
         // Busca por Chave como Referência
         if (array_key_exists($needle1, $mapper1)) {
             // Chave Encontrada
             // Construindo Tabela Intermediária
             $intersection = $this->_getTableFromString($mapper1[$needle1]);
             $needle2 = $matchTable;
             $mapper2 = $intersection->info(Zend_Db_Table::REFERENCE_MAP);
             // Busca por Chave como Referência
             if (array_key_exists($needle2, $mapper2)) {
                 // Chave Encontrada
                 // Transformando a Pesquisa
                 $intersectionTable = $mapper1[$needle1];
                 // Tabela Real = Mapeamento
                 $matchTable = $mapper2[$needle2]['refTableClass'];
                 // Intersecção Real = Mapeamento
             }
         }
     }
     return parent::findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule, $matchRefRule, $select);
 }
Exemplo n.º 2
0
 /**
  * @param  string|Zend_Db_Table_Abstract  $matchTable
  * @param  string|Zend_Db_Table_Abstract  $intersectionTable
  * @param  string                         OPTIONAL $callerRefRule
  * @param  string                         OPTIONAL $matchRefRule
  * @param  Zend_Db_Table_Select           OPTIONAL $select
  * @return Zend_Db_Table_Rowset_Abstract Query result from $matchTable
  * @throws Zend_Db_Table_Row_Exception If $matchTable or $intersectionTable is not a table class or is not loadable.
  */
 public function findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule = null, $matchRefRule = null, Zend_Db_Table_Select $select = null)
 {
     if (is_string($matchTable)) {
         $matchTable = System_Locator_TableLocator::getInstance()->get($matchTable);
     }
     if (is_string($intersectionTable)) {
         $intersectionTable = System_Locator_TableLocator::getInstance()->get($intersectionTable);
     }
     return parent::findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule, $matchRefRule, $select);
 }
 /**
  * Constructor
  *
  * @param Zend_Db_Table_Row_Abstract $row
  * @param string|Zend_Db_Table_Abstract $matchTableName
  * @param string|Zend_Db_Table_Abstract $junctionTableName
  * @param string $matchRefRule
  * @throws Zend_Db_Table_Rowset_Exception
  */
 public function __construct(Zend_Db_Table_Row_Abstract $row, $matchTableName, $junctionTableName, $matchRefRule = null)
 {
     $this->_matchRowset = $row->findManyToManyRowset($matchTableName, $junctionTableName);
     $this->_junctionRowset = $row->findDependentRowset($junctionTableName);
     if (count($this->_matchRowset) != count($this->_junctionRowset)) {
         throw new Zend_Db_Table_Rowset_Exception('Mismatch in values returned in the matching rowset and the junction rowset');
     }
     // set count
     $this->_count = count($this->_matchRowset);
     // prepare junction rowset index (to ensure order)
     $junctionData = $this->_junctionRowset->toArray();
     // will get raw data, no iteration
     // get name of column to key off of
     /* @var $t Zend_Db_Table */
     $junctionTable = new $junctionTableName();
     $this->_referenceMap = $junctionTable->getReference($matchTableName, $matchRefRule);
     foreach ($junctionData as $index => $data) {
         $this->_junctionRowsetIndex[$index] = $data[$this->_referenceMap['columns'][0]];
         // @todo: identify use case with compound key
     }
 }