Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AdCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Finds the AdCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return AdCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AdCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 3
0
<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use common\models\User;
use common\models\AdCategory;
/* @var $this yii\web\View */
/* @var $model common\models\Advs */
/* @var $form yii\widgets\ActiveForm */
$authors = User::find()->all();
$items = ArrayHelper::map($authors, 'id', 'username');
$params = ['prompt' => 'Укажите автора'];
$category = AdCategory::find()->all();
$categoryItem = ArrayHelper::map($category, 'id', 'title');
$categoryParams = ['prompt' => 'Укажите категорию'];
?>

<div class="advs-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'anons')->textarea(['rows' => 3]);
?>
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdCategories()
 {
     return $this->hasMany(AdCategory::className(), ['category' => 'id']);
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSubDir()
 {
     $count = \common\models\AdCategory::find()->where(['category' => 1])->groupBy('ad_id')->count();
     $count = floor($count / 1000);
     return $count;
 }
Exemplo n.º 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(AdCategory::className(), ['id' => 'category_id']);
 }
Exemplo n.º 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdCategory()
 {
     return $this->hasOne(AdCategory::className(), ['ad_id' => 'id', 'category' => 'images_label']);
 }