Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.67 KB | None | 0 0
  1. class shopprodActions extends sfActions
  2. {
  3. public function getDefaultPage()
  4. {
  5. return 1;
  6. }
  7. /*
  8. *
  9. * sorting stuff
  10. *
  11. */
  12. protected function getValidSortColumns() {
  13. return array('id', 'name', 'country_id');
  14. }
  15. protected function getValidSortTypes() {
  16. return array('asc', 'desc');
  17. }
  18. protected function getDefaultSortColumn() {
  19. return 'name';
  20. }
  21. protected function getDefaultSortType() {
  22. return 'asc';
  23. }
  24. protected function getSortColumn() {
  25. return $this->getUser()->getAttribute('element_shopprod.sort_column',
  26. $this->getDefaultSortColumn(),
  27. 'aquis_namespace');
  28. }
  29. protected function setSortColumn($column = null) {
  30. if (!(is_string($column) &&
  31. in_array($column, $this->getValidSortColumns()))) {
  32. $sort_column = null;
  33. }
  34.  
  35. $this->getUser()->setAttribute('element_shopprod.sort_column',
  36. ($column === null ?
  37. $this->getDefaultSortColumn() :
  38. $column),
  39. 'aquis_namespace');
  40.  
  41. return $this->getSortColumn();
  42. }
  43. protected function getSortType() {
  44. return $this->getUser()->getAttribute('element_shopprod.sort_type',
  45. $this->getDefaultSortType(),
  46. 'aquis_namespace');
  47. }
  48. protected function setSortType($type = null) {
  49. if (!(is_string($type) && in_array($type, $this->getValidSortTypes()))) {
  50. $type = null;
  51. }
  52. $this->getUser()->setAttribute('element_shopprod.sort_type',
  53. ($type === null ?
  54. $this->getDefaultSortType() :
  55. $type),
  56. 'aquis_namespace');
  57.  
  58. return $this->getSortType();
  59. }
  60. protected function addSortToQuery($query, $sort_column, $sort_type)
  61. {
  62. $query->addOrderBy($sort_column . ' ' . $sort_type);
  63. }
  64.  
  65.  
  66. public function getMaxPerPage()
  67. {
  68. return $this->maxPerPage;
  69. }
  70. protected function setPage($page)
  71. {
  72. $this->getUser()->setAttribute('element_shopprod.page', $page);
  73. return $page;
  74. }
  75. protected function getPage()
  76. {
  77. return $this->getUser()->getAttribute('element_shopprod.page', 1);
  78. }
  79. public function executeFilter(sfWebRequest $request) {
  80. $values = $this->getFilterValues();
  81. $this->form = new ElementFormFilter($values);
  82. }
  83. protected function getDefaultFilterValues() {
  84. return array();
  85. }
  86. protected function setFilterValues($filter_values = null) {
  87. if (!is_array($filter_values)) {
  88. $filter_values = null;
  89. }
  90. $this->getUser()->setAttribute('element_shopprod.filter_values',
  91. ($filter_values === null ?
  92. $this->getDefaultFilterValues() :
  93. $filter_values),
  94. 'aquis_namespace');
  95. return $this->getFilterValues();
  96. }
  97. protected function getFilterValues() {
  98. return $this->getUser()->getAttribute('element_shopprod.filter_values',
  99. $this->getDefaultFilterValues(),
  100. 'aquis_namespace');
  101. }
  102. public function executeIndex(sfWebRequest $request) {
  103. // session variables
  104. $perpage = sfConfig::get('app_max_shopprod_per_page', 2);
  105. $page = $request->getParameter('page', null);
  106. $max_per_page = $request->getParameter('max_per_page', null);
  107. $sort_column = $request->getParameter('sort_column', null);
  108. $sort_type = $request->getParameter('sort_type', null);
  109. //modify here too
  110. $filter_values = $request->getParameter('shopprod_filters', null);
  111. $filter_reset = $request->getParameter('filter_reset', null);
  112.  
  113. if ($_POST){
  114. $this->setPage(1);
  115. }
  116. (!$page) ?
  117. $page = $this->getPage():
  118. $page = $this->setPage($page);
  119.  
  120. (!$max_per_page) ?
  121. $max_per_page = $this->getMaxPerPage():
  122. ($max_per_page = $this->setMaxPerPage($max_per_page)) &&
  123. ($page = 1);
  124.  
  125. (!$sort_column) ?
  126. $sort_column = $this->getSortColumn():
  127. $sort_column = $this->setSortColumn($sort_column);
  128.  
  129. (!$sort_type) ?
  130. $sort_type = $this->getSortType():
  131. $sort_type = $this->setSortType($sort_type);
  132.  
  133. (!$filter_values) ?
  134. $filter_values = $this->getFilterValues():
  135. $filter_values = $this->setFilterValues($filter_values);
  136.  
  137. //$filter_values = $this->setFiltervalues(array(), array('price'=>93));
  138. //var_dump($filter_values);
  139.  
  140. if ($filter_reset == 1) {
  141. $filter_values = null;
  142. $this->setFilterValues();
  143. }
  144.  
  145. $this->sort_column =
  146. $this->getUser()->getAttribute('element_shopprod.sort_column',
  147. $this->getDefaultSortColumn(),
  148. 'aquis_namespace');
  149. $this->sort_type =
  150. $this->getUser()->getAttribute('element_shopprod.sort_type',
  151. $this->getDefaultSortType(),
  152. 'aquis_namespace');
  153. $this->page =
  154. $this->getUser()->getAttribute('element_shopprod.page',
  155. $this->getDefaultPage(),
  156. 'aquis_namespace');
  157. $filter_values =
  158. $this->getUser()->getAttribute('element_shopprod.filter_values',
  159. $this->getDefaultFilterValues(),
  160. 'aquis_namespace');
  161. // base query
  162. $query = Doctrine::getTable('shopprod')
  163. ->createQuery('p')
  164. ->select()
  165. ->from('shopprod r')
  166. ->orderBy('updated_at DESC')
  167. ;
  168. //Ceva care se adauga daca sunt credentiale
  169. //$query = Doctrine::getTable('Element')
  170. // ->createQuery('e');
  171. //if (!$this->getUser()->hasCredential('validate')) {
  172. // $query = $query->where('e.is_validate = 1');
  173. //}
  174. // Handling filtering
  175. $this->filterform = new shopprodFormFilter($filter_values,
  176. array(
  177. 'isadmingroup' => $this->getUser()->hasGroup('admin'),
  178. )
  179. );
  180. if ($filter_values) {
  181. $this->filterform->setQuery($query);
  182. $this->filterform->bind($filter_values);
  183. //echo $this->filterform->renderGlobalErrors();
  184. //echo $this->filterform->hasErrors();
  185. //die;
  186.  
  187.  
  188. if ($this->filterform->isValid()) {
  189. // aici trebuie sa incepem sa creem un nou QUERY
  190. //$query = $this->filterform->getQuery();
  191.  
  192. $query = Doctrine_Core::getTable('shopprod')->createQuery('a')
  193. ->select('')
  194. ->from('shopprod p')
  195. ->orderBy('updated_at DESC')
  196. ;
  197. if (isset($filter_values["shopcar_id"]) && ($filter_values["shopcar_id"]!=="")){
  198. $query->andWhere('shopcar_id = ?' , $filter_values["shopcar_id"]);
  199. }
  200. if (isset($filter_values["shopcat_id"]) && ($filter_values["shopcat_id"]!=="")){
  201. //echo $query; die;
  202. //var_dump($filter_values["shopcat_id"]); die;
  203. //Aflam obiectul categorie
  204. $shopcat = Doctrine_Core::getTable('shopcat')->find(array($filter_values["shopcat_id"]));
  205. $shopcatlist = Doctrine_Core::getTable('shopcat')->getInList($shopcat);
  206. $shopcarslist = Doctrine_Core::getTable('shopcar')->getCarListInCategory($shopcatlist);
  207. $query->andWhere('shopcar_id IN (' . $shopcarslist . ')');
  208. }
  209. if (isset($filter_values["shoppartname_id"]) && ($filter_values["shoppartname_id"]!=="")){
  210. $shoppartname = Doctrine_Core::getTable('shoppartname')->find(array($filter_values["shoppartname_id"]));
  211. $list = Doctrine_Core::getTable('shoppartname')->getInList($shoppartname);
  212. //echo $list; die;
  213.  
  214. //actualizare in caz de filtrare
  215. //Doctrine_Core::getTable('shoppartname')->filtratplus($filter_values["shoppartname_id"]);
  216. $filtrat = $shoppartname->getFiltrat()+1;
  217. $shoppartname->set('filtrat', $filtrat);
  218. $shoppartname->save();
  219.  
  220. $query->andWhere('shoppartname_id IN (' . $list . ')');
  221. }
  222. if (isset($filter_values["shoplocation_id"]) && ($filter_values["shoplocation_id"]!=="")){
  223. //echo "<pre>"; var_dump($filter_values["shoplocation_id"]); die;
  224. $shoplocation = Doctrine_Core::getTable('shoplocation')->find(array($filter_values["shoplocation_id"]));
  225. $list = Doctrine_Core::getTable('shoplocation')->getInList($shoplocation);
  226. //echo $list; die;
  227. $query->andWhere('shoplocation_id IN (' . $list . ')');
  228. }
  229. //echo $query; die;
  230.  
  231.  
  232. } else {
  233.  
  234. $this->getUser()->setFlash('error',
  235. "Filtering is not possible due " .
  236. "to some errors.".
  237. " Previous filters, if any were resetted !");
  238. $this->redirect('shopprod/index?filter_reset=1');
  239. //$this->setTemplate('filter');
  240. //$this->redirect('@element_filter');
  241. }
  242. }
  243.  
  244. // Applying sorting to filtered query
  245. if ($sort_column !== 'shopcat_id'){
  246. $this->addSortToQuery($query, $sort_column, $sort_type);
  247. }
  248.  
  249. //echo $query;
  250. // Handling pager
  251. if (!$this->shopprods) {
  252. $this->shopprods = new sfDoctrinePager('shopprod', $perpage);
  253. }
  254. $this->shopprods->setQuery($query);
  255. $this->shopprods->setPage($page, 1);
  256. $this->shopprods->init();
  257. }
  258. ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement