Ejemplo n.º 1
0
 /**
  * @param $ratingFormArray
  * @param $post_id
  * @param int $user_id
  * @return mixed
  */
 public static function viewPerCriteriaRatingResult($ratingFormArray, $post_id, $user_id = 0)
 {
     //$time1 = microtime();
     if (!empty($post_id)) {
         if (!is_array($ratingFormArray) and is_numeric($ratingFormArray)) {
             $ratingFormArray = CBRatingSystemData::get_ratingForm($ratingFormArray);
         }
         if (is_array($ratingFormArray)) {
             $data['form_id'] = $ratingFormArray['id'];
             $data['ratings'] = CBRatingSystemData::get_ratings($ratingFormArray['id'], $post_id);
             $data['avgRatingArray']['ratingsCount'][$ratingFormArray['id'] . '-' . $post_id] = count($data['ratings']);
             foreach ($data['ratings'] as $k => $rating) {
                 foreach ($rating['rating'] as $cId => $value) {
                     if (is_numeric($cId)) {
                         $data['ratingsValueArray'][$k]['criterias'][$cId]['value'] = $value;
                         $data['ratingsValueArray'][$k]['criterias'][$cId]['count'] = count($ratingFormArray['custom_criteria'][$cId]['stars']);
                         $data['ratingsValueArray'][$k]['criterias'][$cId]['criteria_array'] = $ratingFormArray['custom_criteria'][$cId]['stars'];
                     }
                 }
                 $data['ratingsValueArray'][$k]['user_id'] = $data['ratings'][$k]['user_id'];
             }
             $data['criteria'] = $ratingFormArray['custom_criteria'];
             $userIdToMatch = array('guest' => array(0), 'registered' => -1);
             //var_dump($ratingFormArray['editor_group']);
             $userWithCustomRole = new WP_User_Query(array('role' => $ratingFormArray['editor_group'][0], 'fields' => 'ID'));
             if (!empty($userWithCustomRole->total_users)) {
                 $userIds = $userWithCustomRole->results;
                 $userIdToMatch['editor'] = $userIds;
             }
             $data['userIdToMatch'] = $userIdToMatch;
             CBRatingSystemCalculation::allUserPerCriteriaAverageCalculation($data, $post_id);
             return $data['avgRatingArray'];
         }
     }
 }