public function actionIndex() { $limit = 10; // Make Latest Ads $latestAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['id' => SORT_DESC])->limit($limit)->all(); // Most Popular Ads $popularAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['view_count' => SORT_DESC])->limit($limit)->all(); // Random Ads $randomAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['rand()' => SORT_DESC])->limit($limit)->all(); return $this->render('index', ['categories' => Category::findAll(['status' => 1]), 'latestAds' => $latestAds, 'popularAds' => $popularAds, 'randomAds' => $randomAds]); }
public function after($number) { if (Input::has('key') == false) { return $this->response->errorUnauthorized(); } $ads = Ad::whereRaw('id > ' . $number)->orderBy('message_number', 'DESC')->paginate(50); // Pass this array (collection) into a resource, which will also have a "Transformer" // This "Transformer" can be a callback or a new instance of a Transformer object // We type hint for array, because each item in the $ads var is an array return $this->response->withPaginator($ads, new AdTransformer()); }
/** * Lists all Category models. * @return mixed */ public function actionIndex($id, $location = null) { $categories = Category::find(['status' => 1])->joinWith(['subcategories'])->all(); $where = ['subcategory_id' => $id]; if (!is_null($location)) { $where['location_id'] = $location; } $ads = Ad::find()->where($where)->joinWith(['adsImages'])->all(); // $ads = Ad::find(['subcategory_id'=> 1]) // ->all(); return $this->render('index', ['categories' => $categories, 'ads' => $ads]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ad::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $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, 'subcategory_id' => $this->subcategory_id, 'user_id' => $this->user_id, 'location_id' => $this->location_id, 'price' => $this->price, 'view_count' => $this->view_count, 'status' => $this->status, 'date_created' => $this->date_created, 'date_expired' => $this->date_expired]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['>', 'price', $this->min_price])->andFilterWhere(['<', 'price', $this->max_price])->andFilterWhere(['>', 'view_count', $this->min_view_count])->andFilterWhere(['<', 'view_count', $this->max_view_count])->andFilterWhere(['>', 'date_created', $this->min_date_created])->andFilterWhere(['<', 'date_created', $this->max_date_created])->andFilterWhere(['>', 'date_expired', $this->min_date_expired])->andFilterWhere(['<', 'date_expired', $this->max_date_expired]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getAds() { return $this->hasMany(Ad::className(), ['subcategory_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getAd() { return $this->hasOne(Ad::className(), ['id' => 'ad_id']); }
/** * Finds the Ad model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Ad the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Ad::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use app\models\Ad; use app\models\User; use dosamigos\datepicker\DatePicker; /* @var $this yii\web\View */ /* @var $model app\models\AdComment */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="ad-comment-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'ad_id')->label('Ad')->dropDownList(Ad::getList()); ?> <?php echo $form->field($model, 'user_id')->label('User')->dropDownList(User::getList()); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'date_created')->widget(DatePicker::className(), ['inline' => true, 'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php
private function slug($slug) { $latestSlug = Ad::whereRaw("slug RLIKE '^" . $slug . "(-[0-9]*)?\$'")->latest('id')->pluck('slug'); if ($latestSlug) { $pieces = explode('-', $latestSlug); $number = end($pieces); $slug .= '-' . ($number + 1); } return $slug; }