PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/classes/XLite/Controller/Customer/OrderList.php

https://github.com/shryans/core
PHP | 263 lines | 129 code | 50 blank | 84 comment | 27 complexity | d4e19a3b7fa35a13aa6805cc12252fc2 MD5 | raw file
  1. <?php
  2. // vim: set ts=4 sw=4 sts=4 et:
  3. /**
  4. * LiteCommerce
  5. *
  6. * NOTICE OF LICENSE
  7. *
  8. * This source file is subject to the Open Software License (OSL 3.0)
  9. * that is bundled with this package in the file LICENSE.txt.
  10. * It is also available through the world-wide-web at this URL:
  11. * http://opensource.org/licenses/osl-3.0.php
  12. * If you did not receive a copy of the license and are unable to
  13. * obtain it through the world-wide-web, please send an email
  14. * to licensing@litecommerce.com so we can send you a copy immediately.
  15. *
  16. * PHP version 5.3.0
  17. *
  18. * @category LiteCommerce
  19. * @author Creative Development LLC <info@cdev.ru>
  20. * @copyright Copyright (c) 2011 Creative Development LLC <info@cdev.ru>. All rights reserved
  21. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  22. * @version GIT: $Id: 7d365c2b9b8e9386e675786474b9e68ad1de069a $
  23. * @link http://www.litecommerce.com/
  24. * @see ____file_see____
  25. * @since 1.0.0
  26. */
  27. namespace XLite\Controller\Customer;
  28. /**
  29. * Orders list
  30. *
  31. * @see ____class_see____
  32. * @since 1.0.0
  33. */
  34. class OrderList extends \XLite\Controller\Customer\ACustomer
  35. {
  36. /**
  37. * Controller parameters
  38. *
  39. * @var array
  40. * @see ____var_see____
  41. * @since 1.0.0
  42. */
  43. protected $params = array('target');
  44. /**
  45. * Handles the request
  46. *
  47. * @return void
  48. * @see ____func_see____
  49. * @since 1.0.0
  50. */
  51. public function handleRequest()
  52. {
  53. parent::handleRequest();
  54. if (isset(\XLite\Core\Request::getInstance()->pageId)) {
  55. $ordersSearch = \XLite\Core\Session::getInstance()->orders_search;
  56. if (!is_array($ordersSearch)) {
  57. $ordersSearch = \XLite\Model\Order::getDefaultSearchConditions();
  58. }
  59. $ordersSearch['pageId'] = intval(\XLite\Core\Request::getInstance()->pageId);
  60. \XLite\Core\Session::getInstance()->orders_search = $ordersSearch;
  61. }
  62. }
  63. /**
  64. * Check if current page is accessible
  65. *
  66. * @return boolean
  67. * @see ____func_see____
  68. * @since 1.0.0
  69. */
  70. public function checkAccess()
  71. {
  72. $auth = \XLite\Core\Auth::getInstance();
  73. return parent::checkAccess()
  74. && $auth->isLogged()
  75. && (
  76. $auth->getProfile()->isAdmin()
  77. || $auth->getProfile()->getProfileId() == \XLite\Core\Request::getInstance()->profile_id
  78. );
  79. }
  80. /**
  81. * Setter
  82. *
  83. * @param string $name Property name
  84. * @param mixed $value Property value
  85. *
  86. * @return void
  87. * @see ____func_see____
  88. * @since 1.0.0
  89. */
  90. public function set($name, $value)
  91. {
  92. switch ($name) {
  93. case 'startDate':
  94. case 'endDate':
  95. $value = intval($value);
  96. break;
  97. default:
  98. }
  99. parent::set($name, $value);
  100. }
  101. /**
  102. * Common method to determine current location
  103. *
  104. * @return string
  105. * @see ____func_see____
  106. * @since 1.0.0
  107. */
  108. protected function getLocation()
  109. {
  110. return 'Search orders';
  111. }
  112. /**
  113. * Save search conditions
  114. * TODO: to revise
  115. *
  116. * @return void
  117. * @see ____func_see____
  118. * @since 1.0.0
  119. */
  120. protected function doActionSearch()
  121. {
  122. $ordersSearch = \XLite\Core\Session::getInstance()->orders_search;
  123. if (!is_array($ordersSearch)) {
  124. $ordersSearch = \XLite\Model\Order::getDefaultSearchConditions();
  125. }
  126. if (isset(\XLite\Core\Request::getInstance()->order_id)) {
  127. $ordersSearch['order_id'] = intval(\XLite\Core\Request::getInstance()->order_id);
  128. if (0 == $ordersSearch['order_id']) {
  129. $ordersSearch['order_id'] = '';
  130. }
  131. }
  132. if (isset(\XLite\Core\Request::getInstance()->status)) {
  133. $ordersSearch['status'] = \XLite\Core\Request::getInstance()->status;
  134. }
  135. if (
  136. isset(\XLite\Core\Request::getInstance()->startDateMonth)
  137. && isset(\XLite\Core\Request::getInstance()->startDateDay)
  138. && isset(\XLite\Core\Request::getInstance()->startDateYear)
  139. ) {
  140. $ordersSearch['startDate'] = mktime(
  141. 0, 0, 0,
  142. intval(\XLite\Core\Request::getInstance()->startDateMonth),
  143. intval(\XLite\Core\Request::getInstance()->startDateDay),
  144. intval(\XLite\Core\Request::getInstance()->startDateYear)
  145. );
  146. } elseif (isset(\XLite\Core\Request::getInstance()->startDate)) {
  147. $time = strtotime(\XLite\Core\Request::getInstance()->startDate);
  148. if (
  149. false !== $time
  150. && -1 !== $time
  151. ) {
  152. $ordersSearch['startDate'] = mktime(
  153. 0, 0, 0,
  154. date('m', $time),
  155. date('d', $time),
  156. date('Y', $time)
  157. );
  158. } elseif (0 == strlen(\XLite\Core\Request::getInstance()->startDate)) {
  159. $ordersSearch['startDate'] = '';
  160. }
  161. }
  162. if (
  163. isset(\XLite\Core\Request::getInstance()->endDateMonth)
  164. && isset(\XLite\Core\Request::getInstance()->endDateDay)
  165. && isset(\XLite\Core\Request::getInstance()->endDateYear)
  166. ) {
  167. $ordersSearch['endDate'] = mktime(
  168. 23, 59, 59,
  169. intval(\XLite\Core\Request::getInstance()->endDateMonth),
  170. intval(\XLite\Core\Request::getInstance()->endDateDay),
  171. intval(\XLite\Core\Request::getInstance()->endDateYear)
  172. );
  173. } elseif (isset(\XLite\Core\Request::getInstance()->endDate)) {
  174. $time = strtotime(\XLite\Core\Request::getInstance()->endDate);
  175. if (
  176. false !== $time
  177. && -1 !== $time
  178. ) {
  179. $ordersSearch['endDate'] = mktime(
  180. 23, 59, 59,
  181. date('m', $time),
  182. date('d', $time),
  183. date('Y', $time)
  184. );
  185. } elseif (0 == strlen(\XLite\Core\Request::getInstance()->endDate)) {
  186. $ordersSearch['endDate'] = '';
  187. }
  188. }
  189. if (\XLite\Core\Request::getInstance()->sortCriterion) {
  190. $ordersSearch['sortCriterion'] = \XLite\Core\Request::getInstance()->sortCriterion;
  191. }
  192. if (\XLite\Core\Request::getInstance()->sortOrder) {
  193. $ordersSearch['sortOrder'] = \XLite\Core\Request::getInstance()->sortOrder;
  194. }
  195. if (isset(\XLite\Core\Request::getInstance()->pageId)) {
  196. $ordersSearch['pageId'] = intval(\XLite\Core\Request::getInstance()->pageId);
  197. }
  198. \XLite\Core\Session::getInstance()->orders_search = $ordersSearch;
  199. $this->setReturnURL($this->buildURL('order_list'));
  200. }
  201. /**
  202. * Reset search conditions
  203. *
  204. * @return void
  205. * @see ____func_see____
  206. * @since 1.0.0
  207. */
  208. protected function doActionReset()
  209. {
  210. \XLite\Core\Session::getInstance()->orders_search = \XLite\Model\Order::getDefaultSearchConditions();
  211. $this->setReturnURL($this->buildURL('order_list'));
  212. }
  213. }