add frontend basics
This commit is contained in:
71
frontend/components/FrontendMenuStructure.php
Normal file
71
frontend/components/FrontendMenuStructure.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace frontend\components;
|
||||
|
||||
use Yii;
|
||||
use common\models\Order;
|
||||
use yii\helpers\Html;
|
||||
|
||||
class FrontendMenuStructure{
|
||||
|
||||
public $menuItems;
|
||||
|
||||
public function FrontendMenuStructure(){
|
||||
$this->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
130
frontend/controllers/CustomerController.php
Normal file
130
frontend/controllers/CustomerController.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\Customer;
|
||||
use frontend\models\CustomerSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* CustomerController implements the CRUD actions for Customer model.
|
||||
*/
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
85
frontend/models/CustomerSearch.php
Normal file
85
frontend/models/CustomerSearch.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Customer;
|
||||
|
||||
/**
|
||||
* CustomerSearch represents the model behind the search form about `common\models\Customer`.
|
||||
*/
|
||||
class CustomerSearch extends Customer
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_customer', 'id_customer_card', 'id_user', 'id_partner_card', 'id_proposer', 'sex'], 'integer'],
|
||||
[['name', 'email', 'password', 'phone', 'date_stundent_card_expire', 'birthdate', 'image', 'description', 'tax_number', 'country', 'zip', 'city', 'address', 'created_at', 'updated_at'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
// bypass scenarios() implementation in the parent class
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = Customer::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_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;
|
||||
}
|
||||
}
|
||||
61
frontend/views/customer/_form.php
Normal file
61
frontend/views/customer/_form.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Customer */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="customer-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'id_customer_card')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'id_user')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'id_partner_card')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'id_proposer')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'password')->passwordInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'sex')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'date_stundent_card_expire')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'birthdate')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'image')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'tax_number')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'country')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'zip')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'city')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'created_at')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'updated_at')->textInput() ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton($model->isNewRecord ? Yii::t('frontend/customer', 'Create') : Yii::t('frontend/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
67
frontend/views/customer/_search.php
Normal file
67
frontend/views/customer/_search.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model frontend\models\CustomerSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="customer-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id_customer') ?>
|
||||
|
||||
<?= $form->field($model, 'id_customer_card') ?>
|
||||
|
||||
<?= $form->field($model, 'id_user') ?>
|
||||
|
||||
<?= $form->field($model, 'id_partner_card') ?>
|
||||
|
||||
<?= $form->field($model, 'id_proposer') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'name') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'email') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'password') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'phone') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'sex') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'date_stundent_card_expire') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'birthdate') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'image') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'description') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'tax_number') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'country') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'zip') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'city') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'address') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'created_at') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'updated_at') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('frontend/customer', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton(Yii::t('frontend/customer', 'Reset'), ['class' => 'btn btn-default']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
21
frontend/views/customer/create.php
Normal file
21
frontend/views/customer/create.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Customer */
|
||||
|
||||
$this->title = Yii::t('frontend/customer', 'Create Customer');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/customer', 'Customers'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="customer-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
54
frontend/views/customer/index.php
Normal file
54
frontend/views/customer/index.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel frontend\models\CustomerSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t('frontend/customer', 'Customers');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="customer-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('frontend/customer', 'Create Customer'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= 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'],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
</div>
|
||||
7
frontend/views/customer/main.php
Normal file
7
frontend/views/customer/main.php
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<h1>Recepció</h1>
|
||||
23
frontend/views/customer/update.php
Normal file
23
frontend/views/customer/update.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Customer */
|
||||
|
||||
$this->title = Yii::t('frontend/customer', 'Update {modelClass}: ', [
|
||||
'modelClass' => 'Customer',
|
||||
]) . ' ' . $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/customer', 'Customers'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_customer]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('frontend/customer', 'Update');
|
||||
?>
|
||||
<div class="customer-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
55
frontend/views/customer/view.php
Normal file
55
frontend/views/customer/view.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Customer */
|
||||
|
||||
$this->title = $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/customer', 'Customers'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="customer-view">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= 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',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
|
||||
<?= 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',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
@@ -9,6 +9,8 @@ use yii\bootstrap\NavBar;
|
||||
use yii\widgets\Breadcrumbs;
|
||||
use frontend\assets\AppAsset;
|
||||
use common\widgets\Alert;
|
||||
use common\components\FrotnendMenuStructure;
|
||||
use frontend\components\FrontendMenuStructure;
|
||||
|
||||
AppAsset::register($this);
|
||||
?>
|
||||
@@ -27,6 +29,10 @@ AppAsset::register($this);
|
||||
|
||||
<div class="wrap">
|
||||
<?php
|
||||
|
||||
$menuStruct = new FrontendMenuStructure();
|
||||
$items = $menuStruct->run();
|
||||
|
||||
NavBar::begin([
|
||||
'brandLabel' => 'My Company',
|
||||
'brandUrl' => Yii::$app->homeUrl,
|
||||
|
||||
Reference in New Issue
Block a user