Beispiel #1
0
 public static function getAveragesByProduct($id_product, $id_lang)
 {
     /* Get all grades */
     $grades = ProductComment::getGradeByProduct((int) $id_product, (int) $id_lang);
     $total = ProductComment::getGradedCommentNumber((int) $id_product);
     if (!count($grades) || !$total) {
         return array();
     }
     /* Addition grades for each criterion */
     $criterionsGradeTotal = array();
     $count_grades = count($grades);
     for ($i = 0; $i < $count_grades; ++$i) {
         if (array_key_exists($grades[$i]['id_product_comment_criterion'], $criterionsGradeTotal) === false) {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] = (int) $grades[$i]['grade'];
         } else {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] += (int) $grades[$i]['grade'];
         }
     }
     /* Finally compute the averages */
     $averages = array();
     foreach ($criterionsGradeTotal as $key => $criterionGradeTotal) {
         $averages[(int) $key] = (int) $total ? (int) $criterionGradeTotal / (int) $total : 0;
     }
     return $averages;
 }
Beispiel #2
0
 public static function getAveragesByProduct($id_product, $id_lang)
 {
     /* Get all grades */
     $grades = ProductComment::getGradeByProduct(intval($id_product), intval($id_lang));
     $total = ProductComment::getGradedCommentNumber(intval($id_product));
     if (!sizeof($grades) or !$total) {
         return array();
     }
     /* Addition grades for each criterion */
     $criterionsGradeTotal = array();
     for ($i = 0; $i < count($grades); ++$i) {
         if (array_key_exists($grades[$i]['id_product_comment_criterion'], $criterionsGradeTotal) === false) {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] = intval($grades[$i]['grade']);
         } else {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] += intval($grades[$i]['grade']);
         }
     }
     /* Finally compute the averages */
     $averages = array();
     foreach ($criterionsGradeTotal as $key => $criterionGradeTotal) {
         $averages[intval($key)] = intval($total) ? intval($criterionGradeTotal) / intval($total) : 0;
     }
     return $averages;
 }