Ejemplo n.º 1
0
	/**
	 * <p>Holt alle vom übergebenen Model abhängigen Werte.</p>
	 * @param Dkplus_Model_Interface $model
	 * @param scalar $modelValue
	 * @param Dkplus_Model_Criteria_Interface $crit
	 * @return Dkplus_Model_Rowset_Interface
	 */
	public function fetchDependent(Dkplus_Model_Interface $model, $modelValue, $crit = null){
		$modelClass = get_class($model);
		
		if(
			$this->_hasOneToManyReference($modelClass)
		){	
			if(
				is_null($crit)
			){
				$crit = new Dkplus_Model_Criteria();
				$crit->andWhere($this->_getReference($modelClass), $modelValue);
			}
			elseif(
				$crit->getWhereConnector() == Dkplus_Model_Criteria::WHERE_AND
			){
				$crit->andWhere($this->_getReference($modelClass), $modelValue);
			}
			else{
				$crit2 = new Dkplus_Model_Criteria();
				$crit2->andWhere($this->_getReference($modelClass), $modelValue);				
				$exec = new Dkplus_Model_Criteria_Executor();
				$exec->setAlias($this->_alias)
					->setArray($this->_getData())
					->setCriteria($crit2);
				$data = $exec->execute();
				
				$exec = new Dkplus_Model_Criteria_Executor();
				$exec->setAlias($this->_alias)
					->setArray($data)
					->setCriteria($crit);
				$data = $exec->execute();
								
				return new $this->_rowsetClass($this, $data);
			}
			return $this->fetchRowset($crit);
		}
		
		/**
		 * @see Dkplus_Model_Exception
		 */
		//require-once 'Dkplus/Model/Exception.php';
		throw new Dkplus_Model_Exception('There is no Relation to '.$modelClass);
	}
Ejemplo n.º 2
0
 /**
  * <p>Holt alle vom übergebenen Model abhängigen Werte.</p>
  * @param Dkplus_Model_Interface $model
  * @param scalar $modelValue
  * @param Dkplus_Model_Criteria_Interface $crit
  * @return Dkplus_Model_Rowset_Interface
  */
 public function fetchDependent(Dkplus_Model_Interface $model, $modelValue, $crit = null)
 {
     $modelClass = get_class($model);
     if ($this->_hasOneToManyReference($modelClass)) {
         if (is_null($crit)) {
             $crit = new Dkplus_Model_Criteria();
             $crit->andWhere($this->_getReference($modelClass), $modelValue);
         } elseif ($crit->getWhereConnector() == Dkplus_Model_Criteria::WHERE_AND) {
             $crit->andWhere($this->_getReference($modelClass), $modelValue);
         } else {
             $select = $this->_critToQuery($crit);
             $select->where($this->_getReference($modelClass) . ' = ?', $modelValue);
             return $this->_fetchRowsetBySelect($select);
         }
         return $this->fetchRowset($crit);
     }
     if ($this->_hasManyToManyReference($modelClass)) {
         if (is_null($crit)) {
             $select = $this->_getDbTable()->select();
         } else {
             $select = $this->_critToQuery($crit);
         }
         return $this->_fetchRowsetBySelect($select->from(array('a' => $this->_getReferenceTable($modelClass)), '')->joinLeft(array('b' => $this->_getDbTable()->info('name')), 'a.' . $this->_getReferenceTableCol($modelClass) . ' = b.' . $this->_getReferenceCol($modelClass), 'b.*')->where('a.' . $this->_getReferenceModelCol($modelClass) . ' = ?', $modelValue));
     }
     throw new Dkplus_Model_Exception('There is no relation defined for class ' . $modelClass . '.');
 }