[TYPO3-mvc] extbase SetOrderings doesn't work

Johannes C. Schulz - EnzephaloN IT-Solutions info at enzephalon.de
Mon Jan 24 16:31:18 CET 2011


Hello Franz

Yes you're right! I've optimized the code a little:

public function listOfBandsInYearBy($year,$sortby,$sorttype){
      $frage = $this->createQuery();
      $frage->matching($frage->equals('year',$year) );
      if($sortby=='ORDER_ASCENDING'){
                $frage->setOrderings(array($sorttype =>
Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING) );
      }
      else{
                $frage->setOrderings(array($sorttype =>
Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING) );
      }
      return $frage->execute();
}

Best regards
Johannes

Btw: You don't have to explicitly set "setRespectEnalbeFields" to TRUE - 
this is the default, and you have quite some redundancy in your 
repository function. Wouldn't it be wiser (and less error prone) to 
create only the orderings array depending on the if condition and write 
the rest of the query only once?

public function listOfBandxInYearBy($year, $orderBy, $orderDirection) {
	$query = $this->createQuery();
	$orderings = array(
		$orderBy => $orderDirection === 'ORDERNG_ASCENDING' ? 
Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING : 
Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
	);

	return $query->matching( $query->equals('year', intval($year))
		->setOrderings( $orderings )
		->execute();
}
-- 
kind regards,
Franz Koch
_______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc




More information about the TYPO3-project-typo3v4mvc mailing list