Ejemplo n.º 1
0
 /**
  * get list
  */
 public function getList()
 {
     require_once 'models/ecommerce/ecommerce_recipe_review.php';
     $Review = new ecommerce_recipe_review();
     $list = $Review->getCommentList(false, 'id DESC');
     return $list;
 }
Ejemplo n.º 2
0
 /**
  * hook before parsing
  */
 public function parseContentTagsBeforeHook()
 {
     parent::parseContentTagsBeforeHook();
     /**
      * pass GET.recipe_id into template
      */
     $Node = new common_node();
     $node_data = $Node->nodeDetail($this->GET['id']);
     $this->GET['recipe_id'] = $node_data['content'];
     /**
      * pass GET.taxonomy_ids into template
      */
     $Recipe_Taxonomy = new ecommerce_recipe_taxonomy();
     $taxonomy_ids = (array) $Recipe_Taxonomy->getRelationsToRecipe($this->GET['recipe_id']);
     $this->GET['taxonomy_tree_id'] = implode(",", $taxonomy_ids);
     /**
      * rating & reviews
      */
     require_once 'models/ecommerce/ecommerce_recipe_review.php';
     $Review = new ecommerce_recipe_review();
     $review_data = $Review->getRating($this->GET['recipe_id']);
     if ($review_data['count'] > 0) {
         $rating = round($review_data['rating']);
         $_Onxshop_Request = new Onxshop_Request("component/rating_stars~rating={$rating}~");
         $this->tpl->assign('RATING_STARS', $_Onxshop_Request->getContent());
         if ($review_data['count'] == 1) {
             $this->tpl->assign('REVIEWS', 'Review');
         } else {
             $this->tpl->assign('REVIEWS', 'Reviews');
         }
         $this->tpl->assign('REVIEW', $review_data);
         $this->tpl->parse('content.reviews');
     }
 }
Ejemplo n.º 3
0
 /**
  * getRating
  */
 static function getRating($recipe_id)
 {
     if (!is_numeric($recipe_id)) {
         return false;
     }
     require_once 'models/ecommerce/ecommerce_recipe_review.php';
     $Review = new ecommerce_recipe_review();
     $review_data = $Review->getRating($recipe_id);
     $rating = array();
     $rating['value'] = (int) $review_data['rating'];
     $rating['votes_sum'] = (int) $review_data['count'];
     $rating['voters_sum'] = (int) $review_data['count'];
     return $rating;
 }
Ejemplo n.º 4
0
 /**
  * getRecipeListForTaxonomy
  *
  * list recipes for given taxonomy_ids
  * each item contains
  *    - main image details as 'image' field
  *    - page details as 'page' field
  *
  * @param array $taxonomy_ids
  * @param string $sort_by
  * @param string $sort_direction
  * @param int $limit_from
  * @param int $limit_per_page
  * @param string $image_role
  * @param bool $conjunction - whether included recipes should have all given $taxonomy_ids (true) or any of given $taxonomy_ids (false)
  * @param int|string $publish_status - integer to limit by publishing status, string, i.e. 'all' for no restriction by publishing status
  * @return array
  */
 function getRecipeListForTaxonomy($taxonomy_ids, $sort_by = 'created', $sort_direction = 'DESC', $limit_from = false, $limit_per_page = false, $image_role = 'teaser', $conjunction = true, $publish_status = 1)
 {
     /**
      * input filter
      */
     // sorting
     if (!in_array($sort_by, array('title', 'created', 'modified', 'priority', 'share_counter'))) {
         $sort_by = 'created';
     }
     if (!in_array($sort_direction, array('DESC', 'ASC'))) {
         $sort_direction = 'DESC';
     }
     $order_by = " ORDER BY {$sort_by} {$sort_direction}";
     // limit
     if (!is_numeric($limit_from)) {
         $limit_from = false;
     }
     if (!is_numeric($limit_per_page)) {
         $limit_per_page = false;
     }
     // allow to use limit_per_page without providing limit_from
     if (is_numeric($limit_per_page) && $limit_from === false) {
         $limit_from = 0;
     }
     if (is_numeric($limit_from) && is_numeric($limit_per_page)) {
         $limit = " LIMIT {$limit_per_page} OFFSET {$limit_from}";
     } else {
         $limit = '';
     }
     /**
      * initialise
      */
     require_once 'models/common/common_node.php';
     require_once 'models/ecommerce/ecommerce_recipe_taxonomy.php';
     require_once 'models/ecommerce/ecommerce_recipe_image.php';
     require_once 'models/ecommerce/ecommerce_recipe_review.php';
     $Node = new common_node();
     $Image = new ecommerce_recipe_image();
     $Taxonomy = new ecommerce_recipe_taxonomy();
     $Review = new ecommerce_recipe_review();
     /**
      * recipes list
      */
     $recipes = array();
     $where = "";
     if (is_array($taxonomy_ids) && count($taxonomy_ids) > 0) {
         $id_list = implode(",", $taxonomy_ids);
         if ($conjunction) {
             $count = count($taxonomy_ids);
             $where = "AND ecommerce_recipe.id IN (\n\t\t\t\t\tSELECT ecommerce_recipe.id\n\t\t\t\t\tFROM ecommerce_recipe\n\t\t\t\t\tINNER JOIN ecommerce_recipe_taxonomy ON ecommerce_recipe_taxonomy.node_id = ecommerce_recipe.id\n\t\t\t\t\tWHERE ecommerce_recipe_taxonomy.taxonomy_tree_id IN ({$id_list})\n\t\t\t\t\tGROUP BY ecommerce_recipe.id\n\t\t\t\t\tHAVING count(DISTINCT ecommerce_recipe_taxonomy.taxonomy_tree_id) = {$count}\n\t\t\t\t)";
         } else {
             $where = "AND ecommerce_recipe.id IN (SELECT node_id FROM ecommerce_recipe_taxonomy WHERE taxonomy_tree_id IN ({$id_list}))";
         }
     }
     // $publish_status
     if (is_numeric($publish_status)) {
         $where_node_publish = " AND common_node.publish = {$publish_status}";
         $where_recipe_publish = " AND ecommerce_recipe.publish = {$publish_status}";
     }
     $sql = "SELECT ecommerce_recipe.*, common_node.share_counter\n\t\t\tFROM ecommerce_recipe\n\t\t\tINNER JOIN common_node ON (common_node.node_group = 'page' \n\t\t\t\tAND common_node.node_controller = 'recipe'\n\t\t\t\tAND common_node.content = ecommerce_recipe.id::varchar\n\t\t\t\t{$where_node_publish})\n\t\t\tWHERE 1=1 {$where_recipe_publish} {$where}\n\t\t\t{$order_by}\n\t\t\t{$limit}";
     $recipes = $this->executeSql($sql);
     // return empty array if nothing is found
     if (!is_array($recipes)) {
         return array();
     }
     $recipe_pages = $Node->listing("node_group = 'page' AND node_controller = 'recipe' AND content ~ '[0-9]+' AND publish = 1");
     foreach ($recipe_pages as $recipe_page) {
         foreach ($recipes as &$recipe) {
             if ($recipe_page['content'] == $recipe['id']) {
                 // assign page
                 $recipe['page'] = $recipe_page;
                 // load images
                 $image_list = $Image->listFiles($recipe['id'], $image_role);
                 // if empty list, get any image, without specification of image_role
                 if (is_array($image_list) && count($image_list) == 0) {
                     $image_list = $Image->listFiles($recipe['id']);
                 }
                 // return only one image
                 $recipe['image'] = $image_list[0];
                 // load review
                 $recipe['review'] = $Review->getRating($recipe['id']);
             }
         }
     }
     return $recipes;
 }