PageRenderTime 124ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/controllers/component/ecommerce/recipe_list.php

https://github.com/laposa/onxshop
PHP | 142 lines | 72 code | 40 blank | 30 comment | 30 complexity | 890e600af4c4c17b7d85b9f5634085e1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Copyright (c) 2013-2017 Laposa Limited (https://laposa.ie)
  4. * Licensed under the New BSD License. See the file LICENSE.txt for details.
  5. *
  6. */
  7. require_once('controllers/list.php');
  8. require_once('models/ecommerce/ecommerce_recipe.php');
  9. class Onyx_Controller_Component_Ecommerce_Recipe_List extends Onyx_Controller_List {
  10. /**
  11. * main action (only a router in this case)
  12. */
  13. public function mainAction()
  14. {
  15. // init models
  16. $Recipe = new ecommerce_recipe();
  17. // get taxonomy ids
  18. if (empty($this->GET['taxonomy_tree_id'])) {
  19. $taxonomy_ids = array();
  20. } else {
  21. $taxonomy_ids = explode(",", $this->GET['taxonomy_tree_id']);
  22. // validate input
  23. if (!is_array($taxonomy_ids)) return false;
  24. foreach ($taxonomy_ids as $taxonomy_id)
  25. if (!is_numeric($taxonomy_id)) return false;
  26. }
  27. // is there a limit?
  28. if (is_numeric($this->GET['limit_from'])) $limit_from = $this->GET['limit_from'];
  29. else $limit_from = 0;
  30. if (is_numeric($this->GET['limit_per_page'])) $limit_per_page = $this->GET['limit_per_page'];
  31. else $limit_per_page = 25;
  32. // is there requested sorting?
  33. if ($this->GET['sort']['by'] && in_array($this->GET['sort']['by'], array('title', 'created', 'modified', 'priority', 'share_counter'))) $sort_by = $this->GET['sort']['by'];
  34. else $sort_by = 'modified';
  35. if ($this->GET['sort']['direction'] && in_array($this->GET['sort']['direction'], array('DESC', 'ASC'))) $sort_direction = $this->GET['sort']['direction'];
  36. else $sort_direction = 'DESC';
  37. // image role
  38. if ($this->GET['image_role']) $image_role = $this->GET['image_role'];
  39. else $image_role = 'teaser';
  40. // disjunctive (0 for OR, 1 for AND)
  41. if (is_numeric($this->GET['conjunction']) && $this->GET['conjunction'] == 0) $conjunction = false;
  42. else $conjunction = true;
  43. /**
  44. * get the list
  45. */
  46. $list = $Recipe->getRecipeListForTaxonomy($taxonomy_ids, $sort_by, $sort_direction, $limit_from, $limit_per_page, $image_role, $conjunction);
  47. $this->parseItems($list);
  48. if ($this->GET['display_pagination'] == 1) {
  49. $count = $Recipe->getRecipeCountForTaxonomy($taxonomy_ids);
  50. $_Onyx_Request = new Onyx_Request("component/pagination~limit_from=$limit_from:limit_per_page=$limit_per_page:count=$count~");
  51. $this->tpl->assign('PAGINATION', $_Onyx_Request->getContent());
  52. }
  53. return true;
  54. }
  55. /**
  56. * Parse recipe list items
  57. */
  58. public function parseItems(&$list)
  59. {
  60. foreach ($list as $i => $item) {
  61. /**
  62. * create taxonomy_class from related_taxonomy
  63. */
  64. if ($item['taxonomy']) {
  65. $related_taxonomy = explode(',', $item['taxonomy']);
  66. $item['taxonomy_class'] = '';
  67. if (is_array($related_taxonomy)) {
  68. foreach ($related_taxonomy as $t_item) {
  69. $item['taxonomy_class'] .= "t{$t_item} ";
  70. }
  71. }
  72. } else {
  73. $item['taxonomy_class'] = '';
  74. }
  75. $this->parseItem($item);
  76. }
  77. }
  78. /**
  79. * Parse one item
  80. */
  81. public function parseItem($item, $block_name = 'content.item')
  82. {
  83. $this->tpl->assign("ITEM", $item);
  84. $this->setImageOptions();
  85. if ($item['image']['src']) $this->tpl->parse("$block_name.image");
  86. $this->parseItemReview($item, $block_name);
  87. $this->tpl->parse("$block_name");
  88. }
  89. /**
  90. * parseItemReview
  91. */
  92. public function parseItemReview($item, $block_name = 'content.item') {
  93. if ($item['review']['count'] > 0) {
  94. $rating = round($item['review']['rating']);
  95. $_Onyx_Request = new Onyx_Request("component/rating_stars~rating={$rating}~");
  96. $this->tpl->assign('RATING_STARS', $_Onyx_Request->getContent());
  97. if ($item['review']['count'] == 1) $this->tpl->assign('REVIEWS', 'Review');
  98. else $this->tpl->assign('REVIEWS', 'Reviews');
  99. $this->tpl->parse("$block_name.reviews");
  100. }
  101. }
  102. }