timschoch

Extbase Join

May 24th, 2011
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. $qomFactory = $this->persistenceManager->getBackend()->getQOMFactory();
  2. $source['client'] = $qomFactory->selector ( 'Tx_Hfcrm_Domain_Model_Client', 'tx_hfcrm_domain_model_client' );
  3. $source['project'] = $qomFactory->selector ( 'Tx_Hfcrm_Domain_Model_Project', 'tx_hfcrm_domain_model_project' );
  4. $join = New Tx_Extbase_Persistence_QOM_Join(
  5.   $source['client'],
  6.   $source['project'],
  7.   Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_RIGHT_OUTER,
  8.   $qomFactory->equiJoinCondition (
  9.     'tx_hfcrm_domain_model_client', 'uid',
  10.     'tx_hfcrm_domain_model_project', 'client'
  11.   )
  12. );
  13.  
  14. $query = $this->createQuery();
  15. foreach( $filter->getFilter() as $attribute => $value ) {
  16.   switch( $attribute ) {
  17.  
  18.     // ...
  19.  
  20.     case 'projectManager':
  21.       $query->setSource( $source['project'] );
  22.       $constraint['client'] = $query->equals( 'projectManager', $value );
  23.       break;
  24.  
  25.     case 'clientName':
  26.       $query->setSource( $source['client'] );
  27.       $constraint['clientName'] = $query->like( 'name', '%'.$value.'%' );
  28.       break;
  29.   }
  30. }
  31.  
  32.   // set join as actual source
  33. $query->setSource( $join );
  34. if ( $constraint ) { $query->matching( $constraint ); }
  35. return $query->execute();
Advertisement
Add Comment
Please, Sign In to add comment