modules/api/v2/controllers/SellerRatingController.php
/**
     * Displays a single SellerRating model.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
Displays a single SellerRating model.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
Displays a single SellerRating model . @param integer $id @return mixed @throws NotFoundHttpException if the model cannot be found
public function actionView($id)
    {
        $model = SellerRating::find()->where(['seller_id' => $id])->all();
        $modelSeller = User::findOne($id);
        if (!$modelSeller instanceof User) {
            throw new NotFoundHttpException('Seller doesn\'t exist.');
        }
        if (empty($model)) {
            throw new NotFoundHttpException('Seller rating doesn\'t exist.');
        }
        $totalRatings = count($model);
        $ratings = [];
        $i = $j = $k = $l = $m = $sumRatings = $rating = 0;
        foreach ($model as $dataRatings) {
            if ($dataRatings->rate == 5) {
                $i++;
            }
            if ($dataRatings->rate == 4) {
                $j++;
            }
            if ($dataRatings->rate == 3) {
                $k++;
            }
            if ($dataRatings->rate == 2) {
                $l++;
            }
            if ($dataRatings->rate == 1) {
                $m++;
            }
            $sumRatings += $dataRatings->rate;
        }
        $ratings['5'] = $i;
        $ratings['4'] = $j;
        $ratings['3'] = $k;
        $ratings['2'] = $l;
        $ratings['1'] = $m;
        if ($totalRatings != 0) {
            $rating = $sumRatings / $totalRatings;
        }
        $ratings['averageRatings'] = number_format((float)$rating, 1, '.', '');
        return $ratings;
    }
public function actionView ( $ id ) { $ model = SellerRating :: find ( ) -> where ( [ 'seller_id' => $ id ] ) -> all ( ) ; $ modelSeller = User :: findOne ( $ id ) ; if ( ! $ modelSeller instanceof User ) { throw new NotFoundHttpException ( 'Seller doesn\'t exist.' ) ; } if ( empty ( $ model ) ) { throw new NotFoundHttpException ( 'Seller rating doesn\'t exist.' ) ; } $ totalRatings = count ( $ model ) ; $ ratings = [ ] ; $ i = $ j = $ k = $ l = $ m = $ sumRatings = $ rating = 0 ; foreach ( $ model as $ dataRatings ) { if ( $ dataRatings -> rate == 5 ) { $ i ++ ; } if ( $ dataRatings -> rate == 4 ) { $ j ++ ; } if ( $ dataRatings -> rate == 3 ) { $ k ++ ; } if ( $ dataRatings -> rate == 2 ) { $ l ++ ; } if ( $ dataRatings -> rate == 1 ) { $ m ++ ; } $ sumRatings += $ dataRatings -> rate ; } $ ratings [ '5' ] = $ i ; $ ratings [ '4' ] = $ j ; $ ratings [ '3' ] = $ k ; $ ratings [ '2' ] = $ l ; $ ratings [ '1' ] = $ m ; if ( $ totalRatings != 0 ) { $ rating = $ sumRatings / $ totalRatings ; } $ ratings [ 'averageRatings' ] = number_format ( ( float ) $ rating , 1 , '.' , '' ) ; return $ ratings ; }
Displays a single SellerRating model.
Displays a single SellerRating model .