Categories.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ IkuJpeISJMvMSB2o7xC37aFalCA5KBXMHgG9AXBjGos=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * categories service view helper class
  14. */
  15. namespace Ppb\View\Helper;
  16. use Cube\View\Helper\AbstractHelper,
  17. Ppb\Service\Table\Relational\Categories as CategoriesService;
  18. class Categories extends AbstractHelper
  19. {
  20. /**
  21. *
  22. * categories table service
  23. *
  24. * @var \Ppb\Service\Table\Relational\Categories
  25. */
  26. protected $_categories;
  27. /**
  28. *
  29. * data resulted from a previous fetch operation
  30. *
  31. * @var array
  32. */
  33. protected $_data = array();
  34. public function __construct()
  35. {
  36. $this->setCategories();
  37. }
  38. /**
  39. *
  40. * get categories table service
  41. *
  42. * @return \Ppb\Service\Table\Relational\Categories
  43. */
  44. public function getCategories()
  45. {
  46. return $this->_categories;
  47. }
  48. /**
  49. *
  50. * set categories table service
  51. *
  52. * @param \Ppb\Service\Table\Relational\Categories $categories
  53. * @return $this
  54. */
  55. public function setCategories(CategoriesService $categories = null)
  56. {
  57. if (!$categories instanceof CategoriesService) {
  58. $categories = new CategoriesService();
  59. }
  60. $this->_categories = $categories;
  61. return $this;
  62. }
  63. public function getData()
  64. {
  65. return $this->_data;
  66. }
  67. /**
  68. *
  69. * get all categories having a certain parent id
  70. *
  71. * @param string|\Cube\Db\Select $where SQL where clause, or a select object
  72. * @return array
  73. */
  74. public function categories($where = null)
  75. {
  76. if ($where === null) {
  77. return $this;
  78. }
  79. $this->_data = $this->getCategories()->fetchAll($where);
  80. return $this->_data;
  81. }
  82. }