diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php new file mode 100644 index 0000000..e4bef95 --- /dev/null +++ b/frontend/components/FrontendMenuStructure.php @@ -0,0 +1,71 @@ +menuItems = []; + } + + protected function can($authItem){ + $result = false; + if (\Yii::$app->user->can($authItem)) { + $result = true; + } + return $result; + } + + + + + + protected function addUserMainMenu(){ + + $userMainMenu = null; + $items = []; + + + $items[] = ['label' => 'Vendégek', 'url' => ['/customer/main'] ]; + + if ( count($items) > 0 ){ + $userMainMenu = ['label' => 'Beállítások', 'url' => null, + 'items' => $items + ]; + } + + if ( isset($userMainMenu)){ + $this->menuItems[] = $userMainMenu; + } + + + } + + + protected function addLoginMainMenu(){ + if (Yii::$app->user->isGuest) { + $mainMenuItem= ['label' => 'Login', 'url' => ['/site/login']]; + } else { + $mainMenuItem= [ + 'label' => 'Kijelentkezés (' . Yii::$app->user->identity->username . ')', + 'url' => ['/site/logout'], + 'linkOptions' => ['data-method' => 'post'] + ]; + } + $this->menuItems[] = $mainMenuItem; + } + + + public function run(){ + $this->addUserMainMenu(); + $this->addLoginMainMenu(); + return $this->menuItems; + } + + +} \ No newline at end of file diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php new file mode 100644 index 0000000..8f156ee --- /dev/null +++ b/frontend/controllers/CustomerController.php @@ -0,0 +1,130 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + public function actionMain(){ + + + return $this->render('main',[]); + } + + /** + * Lists all Customer models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CustomerSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Customer model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Customer model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Customer(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_customer]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Customer model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_customer]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Customer model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Customer model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Customer the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Customer::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/frontend/models/CustomerSearch.php b/frontend/models/CustomerSearch.php new file mode 100644 index 0000000..c347df1 --- /dev/null +++ b/frontend/models/CustomerSearch.php @@ -0,0 +1,85 @@ + $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_customer' => $this->id_customer, + 'id_customer_card' => $this->id_customer_card, + 'id_user' => $this->id_user, + 'id_partner_card' => $this->id_partner_card, + 'id_proposer' => $this->id_proposer, + 'sex' => $this->sex, + 'date_stundent_card_expire' => $this->date_stundent_card_expire, + 'birthdate' => $this->birthdate, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'email', $this->email]) + ->andFilterWhere(['like', 'password', $this->password]) + ->andFilterWhere(['like', 'phone', $this->phone]) + ->andFilterWhere(['like', 'image', $this->image]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'tax_number', $this->tax_number]) + ->andFilterWhere(['like', 'country', $this->country]) + ->andFilterWhere(['like', 'zip', $this->zip]) + ->andFilterWhere(['like', 'city', $this->city]) + ->andFilterWhere(['like', 'address', $this->address]); + + return $dataProvider; + } +} diff --git a/frontend/views/customer/_form.php b/frontend/views/customer/_form.php new file mode 100644 index 0000000..0545dd4 --- /dev/null +++ b/frontend/views/customer/_form.php @@ -0,0 +1,61 @@ + + +
+ = Html::a(Yii::t('frontend/customer', 'Create Customer'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id_customer', + 'id_customer_card', + 'id_user', + 'id_partner_card', + 'id_proposer', + // 'name', + // 'email:email', + // 'password', + // 'phone', + // 'sex', + // 'date_stundent_card_expire', + // 'birthdate', + // 'image', + // 'description', + // 'tax_number', + // 'country', + // 'zip', + // 'city', + // 'address', + // 'created_at', + // 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + ++ = Html::a(Yii::t('frontend/customer', 'Update'), ['update', 'id' => $model->id_customer], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('frontend/customer', 'Delete'), ['delete', 'id' => $model->id_customer], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('frontend/customer', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id_customer', + 'id_customer_card', + 'id_user', + 'id_partner_card', + 'id_proposer', + 'name', + 'email:email', + 'password', + 'phone', + 'sex', + 'date_stundent_card_expire', + 'birthdate', + 'image', + 'description', + 'tax_number', + 'country', + 'zip', + 'city', + 'address', + 'created_at', + 'updated_at', + ], + ]) ?> + +