Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrconstruction/70fb65bbff61b407fae6ab5a854e1a18 to your computer and use it in GitHub Desktop.
Save andrconstruction/70fb65bbff61b407fae6ab5a854e1a18 to your computer and use it in GitHub Desktop.
$offset = ( $page - 1 ) * $limit;
$qb = $this->_em->createQueryBuilder();
$qb->select(
'c'
, 'cf'
, 'p'
, 'pf'
,'partial uc.{id,displayName,picture}'
,'partial ucp.{id,displayName,picture}'
)
->from( ProjectComment::class, 'c' )
->leftJoin( 'c.files', 'cf' )
->leftJoin( 'c.parent', 'p' )
->leftJoin( 'p.files', 'pf' )
->leftJoin('c.userCreate', 'uc')
->leftJoin('p.userCreate', 'ucp')
->orderBy( 'c.updated', 'desc' )
->setMaxResults( $limit )
->setFirstResult( $offset );
if ( $taskId ) {
$qb->where( 'c.task = :taskId' )
->setParameter( 'taskId', $taskId );
} else {
$qb->where( 'c.project = :id' )
->setParameter( 'id', $id );
}
$query = $qb->getQuery();
$a = $qb->getQuery()->getSQL();
$query->setHint( Query::HINT_CUSTOM_OUTPUT_WALKER, AshPaginationWalker::class );
$query->setHint( "mysqlWalker.sqlCalcFoundRows", true );
$qb->getQuery()->getResult();
$totalCount = $this->_em->getConnection()->query( 'SELECT FOUND_ROWS()' )->fetchColumn( 0 );
// $qb = $this->_em->createQueryBuilder();
//
// $qb->select( 'c', 'p','pf' )
// ->from( ProjectComment::class, 'c' )
// ->leftJoin( 'c.parent', 'p' )
// ->leftJoin( 'p.files', 'pf' );
//
// if ( $taskId ) {
// $qb->where( 'c.task = :taskId' )
// ->setParameter( 'taskId', $taskId );
// } else {
// $qb->where( 'c.project = :id' )
// ->setParameter( 'id', $id );
// }
//
// $qb->getQuery()->getResult();
$rows = new ArrayCollection( $query->getResult() );
$dd = $query->getArrayResult() ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment