public function actionTryNow($objectId, $modelClass) { if (self::TrialExist()) { Yii::$app->session->setFlash('error', 'Sorry, You already have a trial hybrizy code'); return $this->redirect(['/#packages']); } $order = new OrderForm(['scenario' => OrderForm::SCENARIO_TRIAL]); $order->user_id = Yii::$app->user->id; $request = Yii::$app->request; if ($request->isPost) { if ($order->load($request->post()) && $order->validate()) { $result = $order->save(); $result = Yii::$app->controller->run('/api/process-order/process', ['objectId' => $objectId, 'modelClass' => $modelClass, 'orderId' => $result->id]); if ($result) { return $this->redirect(['/profile/index']); } } $package = Package::findOne($objectId); return $this->render('index', ['model' => $order, 'package' => $package]); } $package = Package::findOne($objectId); $profile = Yii::$app->user->identity->profile; $order->firstname = $profile->firstname; $order->lastname = $profile->lastname; $order->email = Yii::$app->user->identity->email; return $this->render('index', ['model' => $order, 'package' => $package]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Package::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, 'material_id' => $this->material_id, 'weight' => $this->weight, 'label_created' => $this->label_created, 'package_created' => $this->package_created]); $query->andFilterWhere(['like', 'barcode', $this->barcode]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Package::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, 'maxCallOut' => $this->maxCallOut, 'maxAllowedCode' => $this->maxAllowedCode, 'enable' => $this->enable, 'minBalance' => $this->minBalance, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'duration' => $this->duration, 'expiredBy' => $this->expiredBy, 'price' => $this->price, 'position' => $this->position, 'limitBy' => $this->limitBy, 'quota' => $this->quota, 'mask' => $this->mask]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'videoMaxSize', $this->videoMaxSize])->andFilterWhere(['like', 'pictureMaxSize', $this->pictureMaxSize]); return $dataProvider; }
public function actionLanding() { $packages = Package::find()->where(['enable' => 1])->limit(4)->orderBy('position')->all(); $toppups = Topup::find()->where(['enable' => 1])->limit(4)->orderBy('position')->all(); $this->layout = 'unify/front_page'; $temp = new HybrizyCartForm(); $session = Yii::$app->user->isGuest ? $temp->loadSession('Hybrizy') : $temp->loadFromTable(); if ($session == false) { $cart = ['totalCount' => 0]; } else { $cart = $session; } return $this->render('landing', ['packages' => $packages, 'toppups' => $toppups, 'cart' => $cart]); }
public function actionProcess($objectId, $modelClass, $orderId) { $package = Package::findOne($objectId); $op = new OrderProduct(); $op->modelClass = $modelClass; $op->objectId = $objectId; $op->name = $package->name; $op->order_id = $orderId; $op->mask = $package->mask; if ($op->save()) { if ($modelClass === 'Package') { return $this->createCodeBank($package->duration, $op->id, $package->maxCallOut, $package->minBalance); } elseif ($modelClass == 'Topup') { return $this->createTopupBank($op->id); } } return false; }
/** * Displays a single Site model. * @param integer $id * @return mixed */ public function actionView($id) { Yii::$app->response->format = 'json'; $model = Site::find()->where(['site.id' => $id])->select(['site.*', 'package.*', 'material.*'])->innerJoin('location_history')->innerJoin('package')->innerJoin('material')->asArray()->one(); // $response = []; $model = Site::find()->where(['site.id' => $id])->asArray()->one(); $packages = LocationHistory::find()->where(['site_id' => $model['id']])->orderBy('timestamp DESC')->groupBy('package_id')->asArray()->all(); $response = $model; $response['materials'] = []; foreach ($packages as $key => $value) { $package = Package::find()->with('material')->asArray()->one(); if (isset($response['materials'][strtolower($package['material']['name'])])) { $response['materials'][strtolower($package['material']['name'])] = ['weight' => $response['materials'][strtolower($package['material']['name'])] + $package['weight']]; } else { $response['materials'][strtolower($package['material']['name'])] = ['weight' => $package['weight']]; } } return $response; }
/** * Finds the Package model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Package the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Package::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getPackage() { return $this->hasOne(Package::className(), ['id' => 'package_id']); }
public function getSites() { return $this->hasMany(Package::className(), ['material_id' => 'id'])->with('currentLocation'); }
public function actionFindBy($offset, $limit) { $result = Package::find()->where(['enable' => 1])->limit($limit)->offset($offset)->orderBy('position')->all(); return $result; }
/** * Finds the Package model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Package the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Package::find()->where(['package.barcode' => $id])->with('material', 'siteHistory', 'siteHistory.site', 'currentLocation')->asArray()->one()) !== null) { return $model; } else { Yii::$app->response->format = 'json'; Yii::$app->response->setStatusCode(404); Yii::$app->response->data = ['message' => 'Record not found']; Yii::$app->response->send(); } }