コード例 #1
0
ファイル: SiteController.php プロジェクト: shahid80/EWay
 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]);
 }
コード例 #2
0
 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());
 }
コード例 #3
0
ファイル: CategoryController.php プロジェクト: shahid80/EWay
 /**
  * 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]);
 }
コード例 #4
0
ファイル: AdSearch.php プロジェクト: shahid80/EWay
 /**
  * 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;
 }
コード例 #5
0
ファイル: Subcategory.php プロジェクト: shahid80/EWay
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAds()
 {
     return $this->hasMany(Ad::className(), ['subcategory_id' => 'id']);
 }
コード例 #6
0
ファイル: AdImage.php プロジェクト: shahid80/EWay
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAd()
 {
     return $this->hasOne(Ad::className(), ['id' => 'ad_id']);
 }
コード例 #7
0
ファイル: AdsController.php プロジェクト: shahid80/EWay
 /**
  * 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.');
     }
 }
コード例 #8
0
ファイル: _form.php プロジェクト: shahid80/EWay
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 
コード例 #9
0
 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;
 }