public function picture($id) { $advert = Advert::findOne(['id' => $id]); if (file_exists('img/page_' . $id)) { if (count(scandir('img/page_' . $id)) > 2) { if ($advert->avatar !== null) { return substr($advert->avatar, 1); } return 'img/page_' . $id . '/' . scandir('img/page_' . $id)[2]; } } return 'img/default.png'; }
public function actionModal($id) { $advert = Advert::findOne(['id' => $id]); $advert->avatar = $_POST['img']; if ($advert->save()) { return true; } return false; }
/** * Finds the Advert model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Advert the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Advert::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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; } return $this->render('view_advert', ['model' => $model, 'model_feedback' => $model_feedback, 'user' => $user, 'images' => $images, 'current_user' => $current_user]); }
public function actionContactAuthor($id) { $model = new ContactAuthor(); $receiver = Advert::findOne(['id' => $id]); $sender = User::findOne(['id' => Yii::$app->user->identity->getId()]); if ($model->load(Yii::$app->request->post())) { if ($model->sendEmail($sender->email, $receiver->user->email, $model->subject, $receiver, $model)) { Yii::$app->getSession()->setFlash('success', 'Your email was sent successfully'); return $this->redirect(['advert/view?id=' . $id]); } } return $this->render('contact', ['model' => $model, 'receiver' => $receiver, 'sender' => $sender]); }
public function countViews($id) { $advert = Advert::findOne(['id' => $id]); $advert->views = $advert->views + 1; $advert->save(); }