/**
  * Finds the AdMain model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AdMain the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AdMain::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAd()
 {
     return $this->hasOne(AdMain::className(), ['id' => 'ad_id']);
 }
 /**
  * Finds the AdRealEstate model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AdRealEstate the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelAdMain($id)
 {
     if (($modelAdMain = AdMain::findOne($id)) !== null) {
         return $modelAdMain;
     } else {
         //throw new NotFoundHttpException('The requested page does not exist.');
         return $this->redirect(['/ad/default/index']);
     }
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdMain()
 {
     return $this->hasOne(AdMain::className(), ['category_id' => 'id']);
 }
Exemple #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdMains()
 {
     return $this->hasMany(AdMain::className(), ['ad_style_id' => 'id']);
 }
Exemple #6
0
 public function run()
 {
     $modelAdMain = new AdMain();
     $items = $modelAdMain->getSmallImagesList($this->images);
     return $this->render('view', ['widget' => $this, 'items' => $items, 'user' => $user = Yii::$app->user->identity]);
 }
Exemple #7
0
 public function compliteAd($modelAdRealEstate)
 {
     /* @var $modelAdRealEstate \common\models\AdRealEstate */
     $modelAdRealEstate->temp = 1;
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if ($modelAdRealEstate->save()) {
             $modelCategory = new AdCategory();
             $modelCategory->category = $modelAdRealEstate->property;
             // Категория для недвижемость 1
             $modelCategory->ad_id = $modelAdRealEstate->id;
             if ($modelCategory->save()) {
                 $modelAdMain = new AdMain();
                 $modelAdMain->user_id = Yii::$app->user->id;
                 $modelAdMain->place_city_id = $this->place_city_id;
                 $modelAdMain->category_id = $modelCategory->id;
                 $modelAdMain->phone_temp_ad = $this->phone_temp_ad;
                 //$modelAdMain->ad_style_id = 1;
                 if ($modelAdMain->save()) {
                     $transaction->commit();
                 }
             }
         } else {
             \Yii::$app->session->set('error', 'Объявление недвижимости не добавлено.');
             // если все в порядке, пишем в сессию путь к изображениею
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
     return $modelAdRealEstate;
 }
Exemple #8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function searchFavorites($params)
 {
     $query = AdMain::find()->joinWith('adCategory')->joinWith('adFavorites')->where(['temp' => 0])->andWhere([AdFavorite::tableName() . '.user_id' => Yii::$app->user->id])->orderBy(['updated_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }