Exemple #1
0
 public function getAllCoupons($pageSize = '100')
 {
     $coupons1 = Coupon::find();
     $pagination = new Pagination(['defaultPageSize' => $pageSize, 'totalCount' => $coupons1->count()]);
     $coupons = $coupons1->with('website')->joinWith('couponCategories')->offset($pagination->offset)->limit($pagination->limit)->all();
     //this one works and to display just 60 coupons on the main page
     //$this->lastresult = $coupons;
     return ['coupons' => $coupons, 'pagination' => $pagination];
 }
Exemple #2
0
 function couponType()
 {
     $result = Coupon::find()->orderBy('CouponType')->distinct(true)->select('CouponType')->limit(10)->all();
     $myarray = array();
     $i = 0;
     foreach ($result as $value) {
         $myarray[$i++] = $value->CouponType;
     }
     return $myarray;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Coupon::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, 'expireDatetime' => $this->expireDatetime, 'lastModifyDatetime' => $this->lastModifyDatetime, 'requireScore' => $this->requireScore]);
     $query->andFilterWhere(['like', 'Coupon_name', $this->Coupon_name])->andFilterWhere(['like', 'Coupon_description', $this->Coupon_description])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
 /**
  * Lists all Coupon models.
  * @return mixed
  */
 public function actionIndex($apply = 0)
 {
     if (Yii::$app->user->can('couponIndex')) {
         $searchModel = new CouponSearch();
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
         return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'apply' => $apply, 'coupons' => Coupon::find()->asArray()->all()]);
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
 private function _validate($id)
 {
     if ($id == null) {
         return false;
     }
     $coupon = Coupon::find($id);
     if (!$coupon) {
         return false;
     }
     return $coupon;
 }
 private function _validate_coupon($id)
 {
     return Coupon::find($id);
 }
Exemple #7
0
 function getAllCouponType()
 {
     $result = Coupon::find()->orderBy('CouponType')->distinct(true)->select('CouponType')->limit(10)->all();
     $type = array();
     $ind = 0;
     foreach ($result as $value) {
         $type[$ind++] = $value->CouponType;
     }
     return $type;
 }