示例#1
0
 public static function getRandomAdvertByPlace($place)
 {
     $ads = Advert::where('place', '=', $place)->orderByRaw("RAND()")->first();
     if (!$ads) {
         return null;
     }
     if (!$ads->active) {
         return null;
     }
     if ($ads->show_title) {
         $advert['title'] = $ads->title;
     } else {
         $advert['title'] = null;
     }
     if ($ads->show_img) {
         $advert['img'] = $ads->img;
         $advert['imglink'] = $ads->imglink;
     } else {
         $advert['img'] = null;
     }
     if ($ads->show_text) {
         $advert['text'] = $ads->text;
     } else {
         $advert['text'] = null;
     }
     return $advert;
 }
示例#2
0
 public function getAdvertList($ad_position = '')
 {
     $list = Advert::getInstance()->getAdvertList($ad_position);
     $advert_list = [];
     if ($list) {
         $image_id_list = [];
         foreach ($list as $key => $value) {
             $image_id_list[] = $value->img_url;
         }
         //获取商品图片
         $image_list = Images::getInstance()->getDefaultImages($image_id_list);
         $middle_img_list = [];
         if ($image_list) {
             foreach ($image_list as $value) {
                 $middle_img_list[$value->image_id] = $value->large_url;
             }
         }
         foreach ($list as $k => $v) {
             if (array_key_exists($v->img_url, $middle_img_list)) {
                 $list[$k]->img_url = Yii::$app->params['img_url'] . $middle_img_list[$v->img_url];
             } else {
                 $list[$k]->img_url = '';
             }
         }
         if ($ad_position) {
             $advert_list[$ad_position] = $list;
         } else {
             foreach ($list as $advert) {
                 $advert_list[$advert->ad_position][] = $advert->getattributes();
             }
         }
     }
     return $advert_list;
 }
示例#3
0
 public function getMyBookmarks()
 {
     $book = Bookmark::find()->where(['user_id' => 1])->asArray()->all();
     $n = count($book);
     $arr = [];
     for ($i = 0; $i < $n; $i++) {
         $arr[$i] = $book[$i]['advert_id'];
     }
     $query = Advert::find()->andFilterWhere(['IN', 'id', $arr]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
示例#4
0
 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';
 }
示例#5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Advert::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, 'user_id' => $this->user_id, 'region_id' => $this->region_id, 'city_id' => $this->city_id, 'category_id' => $this->category_id, 'subcategory_id' => $this->subcategory_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'views' => $this->views]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
示例#6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Advert::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, 'price' => $this->price, 'fk_agent' => $this->fk_agent, 'bedroom' => $this->bedroom, 'livingroom' => $this->livingroom, 'parking' => $this->parking, 'kitchen' => $this->kitchen, 'hot' => $this->hot, 'sold' => $this->sold, 'recommend' => $this->recommend, 'createAt' => $this->createAt, 'ipdatedAt' => $this->ipdatedAt]);
     $query->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'general_image', $this->general_image])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'type', $this->type]);
     return $dataProvider;
 }
示例#7
0
 public function getAdvertList($ad_position = '')
 {
     $list = Advert::getInstance()->getAdvertList($ad_position);
     $advert_list = [];
     if ($list) {
         if ($ad_position) {
             $advert_list[$ad_position] = $list;
         } else {
             foreach ($list as $advert) {
                 $advert_list[$advert->ad_position][] = $advert->getattributes();
             }
         }
     }
     return $advert_list;
 }
示例#8
0
文件: try.php 项目: aiskimzhi/advert
use app\models\AdvertSearch;
use app\models\Bookmark;
use app\models\Currency;
use yii\data\ActiveDataProvider;
use yii\helpers\Html;
use yii\helpers\Url;
$columns = [['attribute' => 'price', 'format' => 'html', 'value' => function ($searchModel) {
    $currency = Currency::find()->where(['>', 'date', time()])->asArray()->one();
    $dropDownItems = ['uan' => 'грн.', 'rur' => 'руб.', 'usd' => 'USD', 'eur' => 'EURO'];
    if (isset($_GET['currency']) && $_GET['currency'] !== 'default') {
        $cur = $_GET['currency'];
    } else {
        $cur = $searchModel->currency;
    }
    $price = round($searchModel->price * ($currency[$searchModel->currency] / $currency[$cur]), 2);
    return '<h4><strong>' . $price . ' ' . $dropDownItems[$cur] . '</strong></h4>';
}, 'options' => ['style' => 'width: 130px; max-width: 130px;']], ['attribute' => 'price', 'format' => 'html', 'value' => function ($searchModel) {
    $span = '<span class="glyphicon glyphicon-trash"></span>';
    $url = Url::toRoute(['bookmark/delete-bm', 'advert_id' => $searchModel->id]);
    return Html::a($span, [$url]);
}]];
$searchModel = new AdvertSearch();
$book = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId()])->asArray()->all();
$n = count($book);
$arr = [0];
for ($i = 0; $i < $n; $i++) {
    $arr[$i] = $book[$i]['advert_id'];
}
$query = Advert::find()->andFilterWhere(['IN', 'id', $arr]);
$dataProvider = new ActiveDataProvider(['query' => $query]);
echo $this->render('_try', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'columns' => $columns]);
示例#9
0
 public function lookFor()
 {
     $query = Advert::find()->andFilterWhere(['user_id' => Yii::$app->user->identity->getId()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
示例#10
0
 /**
  * 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.');
     }
 }
示例#11
0
 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]);
 }
示例#12
0
 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]);
 }
示例#13
0
文件: my.php 项目: aiskimzhi/new.loc
}], ['attribute' => 'city_id', 'filter' => Advert::getCities()]]]);
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions' => ['class' => 'table'], 'showHeader' => false, 'columns' => ['user_id', ['attribute' => 'user_id', 'label' => ''], ['label' => 'content', 'format' => 'html', 'value' => function ($model) {
    $text = '<div><strong><a href="' . Url::toRoute('advert/view?id=') . $model->id . '"> ' . $model->title . '</a></strong></div>';
    $text .= '<div>' . $model->category->name . ' >> ' . $model->subcategory->name . '</div>';
    $text .= '<br>';
    $format = 'd M Y H:i';
    $text .= date($format, $model->updated_at);
    return $text;
}], 'price', 'views']]);
?>

    <?php 
$adv = new Advert();
echo '<pre>';
print_r($adv->getCities());
?>

</div>

<?php 
/**
* <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<?php $this->title = 'My Adverts'?>
</head>
<body>
示例#14
0
use yii\grid\GridView;
use yii\grid\ActionColumn;
use yii\jui\DatePicker;
/* @var $this yii\web\View */
/* @var $searchModel app\models\AdvertCRUD */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Adverts';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="advert-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Create Advert', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'region_id', 'value' => 'region.name', 'label' => 'Region', 'filter' => Advert::getAllRegions()], ['attribute' => 'city_id', 'value' => 'city.name', 'label' => 'City', 'filter' => Advert::getCities()], ['attribute' => 'category_id', 'value' => 'category.name', 'label' => 'Category', 'filter' => Advert::getAllICategories()], ['attribute' => 'subcategory_id', 'value' => 'subcategory.name', 'label' => 'Subcategory', 'filter' => Advert::getSubcategories()], 'title', ['attribute' => 'updated_at', 'format' => ['date', 'php:d M Y, H:i']], 'views', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
示例#15
0
 public function updateAdv()
 {
     if ($this->validate()) {
         $advert = new Advert();
         $advert->category_id = $this->category_id;
         $advert->subcategory_id = $this->subcategory_id;
         $advert->region_id = $this->region_id;
         $advert->city_id = $this->city_id;
         $advert->title = $this->title;
         $advert->text = $this->text;
         $advert->updated_at = time();
         if ($advert->save()) {
             return $advert;
         }
     }
     return null;
 }
示例#16
0
文件: Advert.php 项目: aiskimzhi/repo
 public function countViews($id)
 {
     $advert = Advert::findOne(['id' => $id]);
     $advert->views = $advert->views + 1;
     $advert->save();
 }
示例#17
0
 /**
  * Store a newly created resource in storage.
  * POST /adverts
  *
  * @return Response
  */
 public function store()
 {
     $data = Input::all();
     //unset all empty control
     foreach ($data as $key => $value) {
         if ($value == "") {
             unset($data[$key]);
         }
     }
     $advert = new Advert();
     if ($advert->validate($data)) {
         $advert->fill($data);
         $user = Auth::user();
         if ($user->isBuyer()) {
             $advert->buyer_id = $user->buyer->id;
         } elseif ($user->isBroker()) {
             $advert->broker_id = $user->broker->id;
         } else {
             Auth::logout();
             return Redirect::to('/');
         }
         $advert->save();
         Alert::success('Your advert has been created successfully. Keep an eye on your inbox for sellers contacting you', 'Congratulations');
         return Redirect::to(Auth::user()->role->name . '/adverts')->withSuccess('<strong>Congratulations. Your advert has been created successfully. Keep an eye on your inbox for messages from sellers/brokers.</strong>');
     }
     Input::flash();
     return View::make(Auth::user()->role->name . '.adverts.create')->withErrors($advert->getValidator());
 }
示例#18
0
 public function actionCreate()
 {
     $model = new Advert();
     $user = User::findOne(['id' => Yii::$app->user->id]);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->createAdvert()) {
             return $this->redirect(['my']);
         }
         return $this->render('create', ['model' => $model]);
     }
     $catList = ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'name');
     $subcatList = ArrayHelper::map(Subcategory::find()->asArray()->all(), 'id', 'name');
     $regionList = ArrayHelper::map(Region::find()->asArray()->all(), 'id', 'name');
     $cityList = ArrayHelper::map(City::find()->asArray()->all(), 'id', 'name');
     return $this->render('create', ['model' => $model, 'user' => $user, 'catList' => $catList, 'subcatList' => $subcatList, 'regionList' => $regionList, 'cityList' => $cityList]);
 }
示例#19
0
文件: User.php 项目: aiskimzhi/rep
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdverts()
 {
     return $this->hasMany(Advert::className(), ['user_id' => 'id']);
 }
示例#20
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdvert()
 {
     return $this->hasOne(Advert::className(), ['id' => 'advert_id']);
 }
示例#21
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdverts()
 {
     return $this->hasMany(Advert::className(), ['subcategory_id' => 'id']);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $advert = Advert::find($id);
     if ($advert->author_id == Auth::user()->id) {
         $advert->delete();
         return redirect()->action('Insertions\\AdvertsController@index');
     } else {
         return view('errors.503');
     }
 }
示例#23
0
 public function actionModal($id)
 {
     $advert = Advert::findOne(['id' => $id]);
     $advert->avatar = $_POST['img'];
     if ($advert->save()) {
         return true;
     }
     return false;
 }
示例#24
0
文件: Advert.php 项目: aiskimzhi/rep
 public function getMyAdvert($id)
 {
     $query = new Query();
     $array = $query->select(['title', 'updated_at', 'views'])->from(Advert::tableName())->where(['id' => $id])->all();
     return $array;
 }