Advertisement
Guest User

Untitled

a guest
Mar 21st, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. $contentColumns = ['c.id', 'c.type', 'c.createdAt', 'c.updatedAt', 'c.status', 'c.score', 'c.userId', 'c.title', 'c.description', 'c.thumbnail', 'c.rateCount', 'c.rateTotal', 'c.rateUpRatio', 'c.rateUpRatioSource', 'c.origin', 'c.contentHarvestedId', 'c.curated', 'c.tags', 'c.creativeContent', 'c.copyrightCritical', 'c.activeTitleCached', 'c.activeDescriptionCached' ];
  2. $voteColumns = [ 'count(cmr.id) as countVotes','sum(cmr.value) as sumVotes' ];
  3. $supervoteColumns = [ 'count(sv.contentId) as svoteCount' ];
  4. $columns = array_merge( $contentColumns , $voteColumns , $supervoteColumns);
  5. $builder = $this->modelsManager->createBuilder()
  6. $select
  7. ->columns( $columns )
  8. ->from( array('c' => '\Hype\Model\Content'))
  9. ->leftJoin( '\Hype\Model\ContentModRating','cmr.contentId=c.id','cmr')
  10. ->leftJoin( '\Hype\Model\Supervotes','sv.contentId=c.id','sv')
  11. ->groupBy( array('c.id') )
  12. ->orderBy('c.title');
  13.  
  14. // intercepting sql
  15. $intermediate = $builder->getQuery()->parse();
  16. $dialect = $this->di->getDefault()->get('db')->getDialect();
  17. $sql = $dialect->select($intermediate);
  18. print_r($sql);
  19.  
  20.  
  21. $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(array(
  22. "builder" => $builder,
  23. "limit" => $itemCount,
  24. "page" => (int) $value
  25. ) );
  26.  
  27.  
  28.  
  29. ?>
  30. <div class="well text-center">
  31. <a href="/test/index/1">First</a>
  32. <a href="/test/index/<?= $page->before; ?>">Previous</a>
  33. <a href="/test/index/<?= $page->next; ?>">Next</a>
  34. <a href="/test/index/<?= $page->last; ?>">Last</a>
  35. <?php echo "<br>You are on page ", $page->current, " of ", $page->total_pages; ?>
  36. </div>
  37. <?php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement