PaginatorPostsTable.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright 2005-2011, Cake Software Foundation, Inc.
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
  10. * @link http://cakephp.org CakePHP Project
  11. * @since 3.0.0
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. namespace TestApp\Model\Table;
  15. use Cake\ORM\Query;
  16. use Cake\ORM\Table;
  17. use Cake\Utility\Hash;
  18. /**
  19. * PaginatorPostsTable class
  20. *
  21. */
  22. class PaginatorPostsTable extends Table {
  23. /**
  24. * initialize method
  25. *
  26. * @return void
  27. */
  28. public function initialize(array $config) {
  29. $this->table('posts');
  30. $this->belongsTo('PaginatorAuthor', [
  31. 'foreignKey' => 'author_id'
  32. ]);
  33. }
  34. /**
  35. * Finder method for find('popular');
  36. */
  37. public function findPopular(Query $query, array $options) {
  38. $field = $this->alias() . '.' . $this->primaryKey();
  39. $query->where([$field . ' >' => '1']);
  40. return $query;
  41. }
  42. /**
  43. * Finder for published posts.
  44. */
  45. public function findPublished(Query $query, array $options) {
  46. $query->where(['published' => 'Y']);
  47. return $query;
  48. }
  49. }