Your IP : 216.73.216.79


Current Path : /var/www/html/dosm/backend/modules/feedback/controllers/
Upload File :
Current File : /var/www/html/dosm/backend/modules/feedback/controllers/FeedbackController-20221228.php

<?php

namespace backend\modules\feedback\controllers;

use Yii;
use backend\modules\feedback\models\Feedback;
use backend\modules\feedback\models\FeedbackSearch;
use backend\modules\feedback\models\FeedbackMessages;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * FeedbackController implements the CRUD actions for Feedback model.
 */
class FeedbackController extends Controller {

    /**
     * {@inheritdoc}
     */
    public function behaviors() {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Feedback models.
     * @return mixed
     */
    public function actionIndex() {
        $searchModel = new FeedbackSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
                    'searchModel' => $searchModel,
                    'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single Feedback model.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($id) {
        $model = $this->findModel($id);
        $model->scenario = 'reply';
        if ($model->load(Yii::$app->request->post())) {

            //add to message
            $modelMsg = new FeedbackMessages();
            $modelMsg->feedback_id = $model->id;
            $modelMsg->user_type = 'admin';
            $modelMsg->message = $model->message;
            $modelMsg->submit_at = date("Y-m-d H:i:s");
            $modelMsg->save(false);


            //submit email to user submit form
            $to_mail2 = $model->emel;
            $subject_mail2 = "New message for feedback from DOSM Portal #" . $model->ticket_no;
            $content_mail2 = "<p>Hi " . $model->name . ",</p>
                    <p>Admin has send new message to you for your feedback at DOSM Portal (#" . $model->ticket_no . ")</p>
                    <p><b><i>" . $model->message . "</i></b></p>
                    <p>Thank you.</p>";
            Yii::$app->emailModule->sendemail($to_mail2, $subject_mail2, $content_mail2);
            
            //submit email to all superadmin & admin feedback
            $queryAdmin = new \yii\db\Query();
            $queryAdmin->select(['dmg_user.*'])->from('dmg_user')
                    ->innerJoin('auth_assignment', 'dmg_user.id=auth_assignment.user_id')
                    ->where(['IN', 'auth_assignment.item_name', ['super-admin', 'admin-feedback']])
                    ->andwhere(['=', 'dmg_user.status', '10']);
            $modelAdmin = $queryAdmin->all();
            if (!empty($modelAdmin)) {
                foreach ($modelAdmin as $rowAdmin) { 
                    $to_mail = $rowAdmin['email'];
                    $subject_mail = "New message - DOSM Portal Feedback #" . $model->ticket_no;
                    $content_mail = "<p>Hi " . $rowAdmin['fullname'] . ",</p>
                    <p>Admin has send new message for feedback #" . $model->ticket_no . "</p>
                    <p><b><i>" . $model->message . "</i></b></p>";
                    Yii::$app->emailModule->sendemail($to_mail, $subject_mail, $content_mail);
                }
            }


            return $this->redirect(['view', 'id' => $model->id]);
        }
        return $this->render('view', ['model' => $model]);
    }

    /**
     * Creates a new Feedback model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate() {
        $model = new Feedback();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }

        return $this->render('create', [
                    'model' => $model,
        ]);
    }

    /**
     * Updates an existing Feedback model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($id) {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }

        return $this->render('update', [
                    'model' => $model,
        ]);
    }

    /**
     * Deletes an existing Feedback model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete($id) {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the Feedback model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Feedback the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id) {
        if (($model = Feedback::findOne($id)) !== null) {
            return $model;
        }

        throw new NotFoundHttpException('The requested page does not exist.');
    }

    public function actionCloseticket($id) {
        $model = $this->findModel($id);
        $model->status = 'closed';
        if ($model->save()) {

            //submit email to all superadmin & admin feedback
            $queryAdmin = new \yii\db\Query();
            $queryAdmin->select(['dmg_user.*'])->from('dmg_user')
                    ->innerJoin('auth_assignment', 'dmg_user.id=auth_assignment.user_id')
                    ->where(['IN', 'auth_assignment.item_name', ['super-admin', 'admin-feedback']])
                    ->andwhere(['=', 'dmg_user.status', '10']);
            $modelAdmin = $queryAdmin->all();
            if (!empty($modelAdmin)) {
                foreach ($modelAdmin as $rowAdmin) {
                    $to_mail = $rowAdmin['email'];
                    $subject_mail = "Closed - DOSM Portal Feedback #" . $model->ticket_no;
                    $content_mail = "<p>Hi " . $rowAdmin['fullname'] . ",</p>
                    <p>Feedback has been closed from CMS DOSM Portal as below:</p>
                    <table cellpadding='0' cellspacing='0' border='0'>
                        <tr>
                            <td style='padding-right:2em;'>Ticket No.</td>
                            <td>" . $model->ticket_no . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Type</td>
                            <td>" . \backend\modules\refdynawebv2\models\Ref::getDesc('FEEDBACKTYPE', $model->feedback_type, 'descr_en') . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Name</td>
                            <td>" . $model->name . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Email Address</td>
                            <td>" . $model->emel . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Feedback</td>
                            <td>" . $model->details . "</td>
                        </tr>
                    </table>
                    <p>Thank you.</p>";
                    Yii::$app->emailModule->sendemail($to_mail, $subject_mail, $content_mail);
                }
            }

            //submit email to user submit form
            $to_mail2 = $model->emel;
            $subject_mail2 = "Feedback from DOSM Portal closed #" . $model->ticket_no;
            $content_mail2 = "<p>Hi " . $model->name . ",</p>
                    <p>Admin has closed your feedback that you have submitted at DOSM Portal as below:</p>
                    <table cellpadding='0' cellspacing='0' border='0'>
                        <tr>
                            <td style='padding-right:2em;'>Ticket No.</td>
                            <td>" . $model->ticket_no . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Type</td>
                            <td>" . \backend\modules\refdynawebv2\models\Ref::getDesc('FEEDBACKTYPE', $model->feedback_type, 'descr_en') . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Name</td>
                            <td>" . $model->name . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Email Address</td>
                            <td>" . $model->emel . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Feedback</td>
                            <td>" . $model->details . "</td>
                        </tr>
                    </table>
                    <p>Thank you.</p>";
            Yii::$app->emailModule->sendemail($to_mail2, $subject_mail2, $content_mail2);

            return $this->redirect(['view', 'id' => $model->id]);
        }
    }

}