modules/api/v2/controllers/SellerRatingController.php
/**
     * Creates a new SellerRating model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new SellerRating model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new SellerRating model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new SellerRating();
        $postData = Yii::$app->request->post();
        if (empty($postData) || empty($postData['seller_id'])) {
            throw new BadRequestHttpException('Invalid parameter passed. Request must required parameter "seller_id"');
        }
        $sellerRating['SellerRating'] = $postData;
        $sellerRating['SellerRating']['user_id'] = Yii::$app->user->identity->id;
        $alreadyExist = SellerRating::find()->where(['seller_id' => $sellerRating['SellerRating']['seller_id'], 'user_id' => $sellerRating['SellerRating']['user_id']])->all();
        if (!empty($alreadyExist)) {
            throw new ForbiddenHttpException('You have already reviewed this seller');
        }
        if ($model->load($sellerRating) && $model->validate()) {
            $model->save();
            $getUsers[] = $model->seller;
            if (!empty($getUsers)) {
                foreach ($getUsers as $keys => $userROW) {
                    if ($userROW instanceof User && ($model->user_id != $userROW->id)) {
                        if ($userROW->is_new_message_notification_on == User::IS_NOTIFICATION_ON && !empty($userROW->userDevice)) {
                            $userDevice = $userROW->userDevice;
                            $notificationText = $model->user->first_name . " " . $model->user->last_name . " has added rate or review for your profile";
                            $modelNotification = new Notification();
                            $modelNotification->owner_id = $model->user_id;
                            $modelNotification->notification_receiver_id = $userROW->id;
                            $modelNotification->ref_id = $model->id;
                            $modelNotification->notification_text = $notificationText;
                            $modelNotification->action = "Add";
                            $modelNotification->ref_type = "seller_ratings"; 
                            $modelNotification->save(false);
                            $badge = Notification::find()->where(['notification_receiver_id' => $userROW->id, 'is_read' => Notification::NOTIFICATION_IS_READ_NO])->count();
                            if ($userDevice->device_platform == 'android') {
                                $notificationToken = array($userDevice->notification_token);
                                $senderName = $model->user->first_name . " " . $model->user->last_name;
                                $modelNotification->sendPushNotificationAndroid($modelNotification->ref_id, $modelNotification->ref_type, $notificationToken, $notificationText, $senderName, $modelNotification);
                            } else {
                                $note = Yii::$app->fcm->createNotification(Yii::$app->name, $notificationText);
                                $note->setBadge($badge);
                                $note->setSound('default');
                                $message = Yii::$app->fcm->createMessage();
                                $message->addRecipient(new \paragraph1\phpFCM\Recipient\Device($userDevice->notification_token));
                                $message->setNotification($note)
                                    ->setData([
                                        'id' => $modelNotification->ref_id,
                                        'type' => $modelNotification->ref_type,
                                        'message' => $notificationText,
                                        'action' => (!empty($modelNotification) && !empty($modelNotification->action)) ? $modelNotification->action : "",
                                    ]);
                                $response = Yii::$app->fcm->send($message);
                            }
                        }
                        if ($userROW->is_new_message_email_notification_on == User::IS_NOTIFICATION_ON) {
                            $message = $model->user->first_name . " " . $model->user->last_name . " has added rate or review for your profile";
                            if (!empty($userROW->email)) {
                                try {
                                    Yii::$app->mailer->compose('api/addNewProfileRateReview', ['sender' => $model->user, 'receiver' => $userROW, 'message' => $message])
                                        ->setFrom([Yii::$app->params['adminEmail'] => Yii::$app->name])
                                        ->setTo($userROW->email)
                                        ->setSubject('Added rate or review for your profile!')
                                        ->send();
                                } catch (HttpException $e) {
                                    echo "Error: " . $e->getMessage();
                                }
                            }
                        }
                    }
                }
            }
        }
        return $model;
    }
public function actionCreate ( ) { $ model = new SellerRating ( ) ; $ postData = Yii :: $ app -> request -> post ( ) ; if ( empty ( $ postData ) || empty ( $ postData [ 'seller_id' ] ) ) { throw new BadRequestHttpException ( 'Invalid parameter passed. Request must required parameter "seller_id"' ) ; } $ sellerRating [ 'SellerRating' ] = $ postData ; $ sellerRating [ 'SellerRating' ] [ 'user_id' ] = Yii :: $ app -> user -> identity -> id ; $ alreadyExist = SellerRating :: find ( ) -> where ( [ 'seller_id' => $ sellerRating [ 'SellerRating' ] [ 'seller_id' ] , 'user_id' => $ sellerRating [ 'SellerRating' ] [ 'user_id' ] ] ) -> all ( ) ; if ( ! empty ( $ alreadyExist ) ) { throw new ForbiddenHttpException ( 'You have already reviewed this seller' ) ; } if ( $ model -> load ( $ sellerRating ) && $ model -> validate ( ) ) { $ model -> save ( ) ; $ getUsers [ ] = $ model -> seller ; if ( ! empty ( $ getUsers ) ) { foreach ( $ getUsers as $ keys => $ userROW ) { if ( $ userROW instanceof User && ( $ model -> user_id != $ userROW -> id ) ) { if ( $ userROW -> is_new_message_notification_on == User :: IS_NOTIFICATION_ON && ! empty ( $ userROW -> userDevice ) ) { $ userDevice = $ userROW -> userDevice ; $ notificationText = $ model -> user -> first_name . " " . $ model -> user -> last_name . "  has added rate or review for your profile " ; $ modelNotification = new Notification ( ) ; $ modelNotification -> owner_id = $ model -> user_id ; $ modelNotification -> notification_receiver_id = $ userROW -> id ; $ modelNotification -> ref_id = $ model -> id ; $ modelNotification -> notification_text = $ notificationText ; $ modelNotification -> action = " Add " ; $ modelNotification -> ref_type = " seller_ratings " ; $ modelNotification -> save ( false ) ; $ badge = Notification :: find ( ) -> where ( [ 'notification_receiver_id' => $ userROW -> id , 'is_read' => Notification :: NOTIFICATION_IS_READ_NO ] ) -> count ( ) ; if ( $ userDevice -> device_platform == 'android' ) { $ notificationToken = array ( $ userDevice -> notification_token ) ; $ senderName = $ model -> user -> first_name . " " . $ model -> user -> last_name ; $ modelNotification -> sendPushNotificationAndroid ( $ modelNotification -> ref_id , $ modelNotification -> ref_type , $ notificationToken , $ notificationText , $ senderName , $ modelNotification ) ; } else { $ note = Yii :: $ app -> fcm -> createNotification ( Yii :: $ app -> name , $ notificationText ) ; $ note -> setBadge ( $ badge ) ; $ note -> setSound ( 'default' ) ; $ message = Yii :: $ app -> fcm -> createMessage ( ) ; $ message -> addRecipient ( new \ paragraph1 \ phpFCM \ Recipient \ Device ( $ userDevice -> notification_token ) ) ; $ message -> setNotification ( $ note ) -> setData ( [ 'id' => $ modelNotification -> ref_id , 'type' => $ modelNotification -> ref_type , 'message' => $ notificationText , 'action' => ( ! empty ( $ modelNotification ) && ! empty ( $ modelNotification -> action ) ) ? $ modelNotification -> action : " " , ] ) ; $ response = Yii :: $ app -> fcm -> send ( $ message ) ; } } if ( $ userROW -> is_new_message_email_notification_on == User :: IS_NOTIFICATION_ON ) { $ message = $ model -> user -> first_name . " " . $ model -> user -> last_name . "  has added rate or review for your profile " ; if ( ! empty ( $ userROW -> email ) ) { try { Yii :: $ app -> mailer -> compose ( 'api/addNewProfileRateReview' , [ 'sender' => $ model -> user , 'receiver' => $ userROW , 'message' => $ message ] ) -> setFrom ( [ Yii :: $ app -> params [ 'adminEmail' ] => Yii :: $ app -> name ] ) -> setTo ( $ userROW -> email ) -> setSubject ( 'Added rate or review for your profile!' ) -> send ( ) ; } catch ( HttpException $ e ) { echo " Error:  " . $ e -> getMessage ( ) ; } } } } } } } return $ model ; }
Creates a new SellerRating model.
Creates a new SellerRating model .
// Send Push notification start // Insert into notification. // For seller rate review // Send Push notification end