Durations.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ F+up6fgKGS+K5hZbei9IEHRW6aVgjqCaD7k7bxWI26E=
  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. * currencies table service class
  14. */
  15. namespace Ppb\Service\Table;
  16. use Ppb\Db\Table\Durations as DurationsTable;
  17. class Durations extends AbstractServiceTable
  18. {
  19. public function __construct()
  20. {
  21. parent::__construct();
  22. $this->setTable(
  23. new DurationsTable());
  24. }
  25. /**
  26. *
  27. * get all durations
  28. * to be used for the listing duration selector
  29. *
  30. * @param string $listingType
  31. * @return array
  32. */
  33. public function getMultiOptions($listingType = null)
  34. {
  35. $data = array();
  36. $translate = $this->getTranslate();
  37. $settings = $this->getSettings();
  38. if ($listingType == 'product' && $settings['enable_unlimited_duration']) {
  39. $data[0] = $translate->_('Unlimited');
  40. }
  41. $displayOptions = ($listingType == 'product' && $settings['enable_unlimited_duration'] && $settings['force_unlimited_duration']) ?
  42. false : true;
  43. if ($displayOptions) {
  44. $rows = $this->fetchAll()->toArray();
  45. foreach ((array)$rows as $row) {
  46. $data[(string)$row['days']] = $translate->_($row['description']);
  47. }
  48. }
  49. return $data;
  50. }
  51. /**
  52. *
  53. * get all table columns needed to generate the
  54. * durations management table in the admin area
  55. *
  56. * @return array
  57. */
  58. public function getColumns()
  59. {
  60. return array(
  61. array(
  62. 'label' => $this->_('Days'),
  63. 'class' => 'size-mini',
  64. 'element_id' => 'days',
  65. ),
  66. array(
  67. 'label' => $this->_('Description'),
  68. 'element_id' => 'description',
  69. ),
  70. array(
  71. 'label' => $this->_('Order ID'),
  72. 'class' => 'size-mini',
  73. 'element_id' => 'order_id',
  74. ),
  75. array(
  76. 'label' => $this->_('Delete'),
  77. 'class' => 'size-mini',
  78. 'element_id' => array(
  79. 'id', 'delete'
  80. ),
  81. ),
  82. );
  83. }
  84. /**
  85. *
  86. * get all form elements that are needed to generate the
  87. * durations management table in the admin area
  88. *
  89. * @return array
  90. */
  91. public function getElements()
  92. {
  93. return array(
  94. array(
  95. 'id' => 'id',
  96. 'element' => 'hidden',
  97. ),
  98. array(
  99. 'id' => 'days',
  100. 'element' => 'text',
  101. 'attributes' => array(
  102. 'class' => 'form-control input-mini',
  103. ),
  104. ),
  105. array(
  106. 'id' => 'description',
  107. 'element' => 'text',
  108. 'attributes' => array(
  109. 'class' => 'form-control input-medium',
  110. ),
  111. ),
  112. array(
  113. 'id' => 'order_id',
  114. 'element' => 'text',
  115. 'attributes' => array(
  116. 'class' => 'form-control input-mini',
  117. ),
  118. ),
  119. // array(
  120. // 'id' => 'selected',
  121. // 'element' => 'radio',
  122. // ),
  123. array(
  124. 'id' => 'delete',
  125. 'element' => 'checkbox',
  126. ),
  127. );
  128. }
  129. /**
  130. *
  131. * fetches all matched rows
  132. *
  133. * @param string|\Cube\Db\Select $where SQL where clause, or a select object
  134. * @param string|array $order
  135. * @param int $count
  136. * @param int $offset
  137. * @return array
  138. */
  139. public function fetchAll($where = null, $order = null, $count = null, $offset = null)
  140. {
  141. if ($order === null) {
  142. $order = 'order_id ASC, days ASC';
  143. }
  144. return parent::fetchAll($where, $order, $count, $offset);
  145. }
  146. }