Exemple #1
3
 public function actionViewAdvert($id)
 {
     $model = Advert::findOne($id);
     $data = ['name', 'email', 'text'];
     $model_feedback = new DynamicModel($data);
     $model_feedback->addRule('name', 'required');
     $model_feedback->addRule('email', 'required');
     $model_feedback->addRule('text', 'required');
     $model_feedback->addRule('email', 'email');
     if (Yii::$app->request->isPost) {
         if ($model_feedback->load(Yii::$app->request->post()) && $model_feedback->validate()) {
             Yii::$app->common->sendMail('Subject Advert', $model_feedback->text);
         }
     }
     $user = $model->user;
     $images = Common::getImageAdvert($model, false);
     $current_user = ['email' => '', 'username' => ''];
     if (!Yii::$app->user->isGuest) {
         $current_user['email'] = Yii::$app->user->identity->email;
         $current_user['username'] = Yii::$app->user->identity->username;
     }
     $coords = str_replace(['(', ')'], '', $model->location);
     $coords = explode(',', $coords);
     $coord = new LatLng(['lat' => $coords[0], 'lng' => $coords[1]]);
     $map = new Map(['center' => $coord, 'zoom' => 15]);
     $marker = new Marker(['position' => $coord, 'title' => Common::getTitleAdvert($model)]);
     $map->addOverlay($marker);
     return $this->render('view_advert', ['model' => $model, 'model_feedback' => $model_feedback, 'user' => $user, 'images' => $images, 'current_user' => $current_user, 'map' => $map]);
 }
Exemple #2
0
 public function actionViewAdvert($id)
 {
     $this->layout = 'inner';
     $model = Advert::findOne($id);
     $user = $model->user;
     $images = Common::getImageAdvert($model, false);
     return $this->render('view_advert', ['model' => $model, 'user' => $user, 'images' => $images]);
 }
Exemple #3
0
 protected function findModel($id)
 {
     if (($model = Advert::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #4
0
    public function beforeAction($action)
    {
        $id = \Yii::$app->request->get('id');
        $model = Advert::findOne($id);

        if (null == $model) {
            throw new HttpException(404, 'Unknown advert');
            return false;
        }

        return parent::beforeAction($action);
    }