Commit 6a06aef103c737d6f94aaf14b0149cee4bb4808e

Authored by Administrator
1 parent 07c45ae4

24.03.16 finish 1

backend/controllers/OrdersController.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\controllers;
  4 +
  5 +use Yii;
  6 +use common\models\Orders;
  7 +use common\models\OrdersSearch;
  8 +use yii\web\Controller;
  9 +use yii\web\NotFoundHttpException;
  10 +use yii\filters\VerbFilter;
  11 +
  12 +/**
  13 + * OrdersController implements the CRUD actions for Orders model.
  14 + */
  15 +class OrdersController extends Controller
  16 +{
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public function behaviors()
  21 + {
  22 + return [
  23 + 'verbs' => [
  24 + 'class' => VerbFilter::className(),
  25 + 'actions' => [
  26 + 'delete' => ['POST'],
  27 + ],
  28 + ],
  29 + ];
  30 + }
  31 +
  32 + /**
  33 + * Lists all Orders models.
  34 + * @return mixed
  35 + */
  36 + public function actionIndex()
  37 + {
  38 + $searchModel = new OrdersSearch();
  39 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  40 +
  41 + return $this->render('index', [
  42 + 'searchModel' => $searchModel,
  43 + 'dataProvider' => $dataProvider,
  44 + ]);
  45 + }
  46 +
  47 + /**
  48 + * Displays a single Orders model.
  49 + * @param integer $id
  50 + * @return mixed
  51 + */
  52 + public function actionView($id)
  53 + {
  54 + return $this->render('view', [
  55 + 'model' => $this->findModel($id),
  56 + ]);
  57 + }
  58 +
  59 + /**
  60 + * Creates a new Orders model.
  61 + * If creation is successful, the browser will be redirected to the 'view' page.
  62 + * @return mixed
  63 + */
  64 + public function actionCreate()
  65 + {
  66 + $model = new Orders();
  67 +
  68 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  69 + return $this->redirect(['view', 'id' => $model->order_id]);
  70 + } else {
  71 + return $this->render('create', [
  72 + 'model' => $model,
  73 + ]);
  74 + }
  75 + }
  76 +
  77 + /**
  78 + * Updates an existing Orders model.
  79 + * If update is successful, the browser will be redirected to the 'view' page.
  80 + * @param integer $id
  81 + * @return mixed
  82 + */
  83 + public function actionUpdate($id)
  84 + {
  85 + $model = $this->findModel($id);
  86 +
  87 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  88 + return $this->redirect(['view', 'id' => $model->order_id]);
  89 + } else {
  90 + return $this->render('update', [
  91 + 'model' => $model,
  92 + ]);
  93 + }
  94 + }
  95 +
  96 + /**
  97 + * Deletes an existing Orders model.
  98 + * If deletion is successful, the browser will be redirected to the 'index' page.
  99 + * @param integer $id
  100 + * @return mixed
  101 + */
  102 + public function actionDelete($id)
  103 + {
  104 + $this->findModel($id)->delete();
  105 +
  106 + return $this->redirect(['index']);
  107 + }
  108 +
  109 + /**
  110 + * Finds the Orders model based on its primary key value.
  111 + * If the model is not found, a 404 HTTP exception will be thrown.
  112 + * @param integer $id
  113 + * @return Orders the loaded model
  114 + * @throws NotFoundHttpException if the model cannot be found
  115 + */
  116 + protected function findModel($id)
  117 + {
  118 + if (($model = Orders::findOne($id)) !== null) {
  119 + return $model;
  120 + } else {
  121 + throw new NotFoundHttpException('The requested page does not exist.');
  122 + }
  123 + }
  124 +}
... ...
backend/views/layouts/main-sidebar.php
... ... @@ -39,7 +39,7 @@ use yii\widgets\Menu;
39 39 ['label' => 'Создать', 'url' => ['blog/create']],
40 40 ],
41 41 ],
42   - ['label' => 'Заказы', 'url' => ['cart/index'], 'template'=>'<a href="{url}"> <i class="fa fa-dashboard"></i> <span>{label}</span></a>'],
  42 + ['label' => 'Заказы', 'url' => ['orders/index'], 'template'=>'<a href="{url}"> <i class="fa fa-dashboard"></i> <span>{label}</span></a>'],
43 43 [
44 44 'label' => 'Products',
45 45 'url' => ['/product/manage'],
... ...
backend/views/orders/_form.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\Orders */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="orders-form">
  12 +
  13 + <?php $form = ActiveForm::begin(); ?>
  14 +
  15 + <?= $form->field($model, 'customer_id')->textInput() ?>
  16 +
  17 + <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
  18 +
  19 + <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
  20 +
  21 + <?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?>
  22 +
  23 + <?= $form->field($model, 'delivery')->textInput() ?>
  24 +
  25 + <?= $form->field($model, 'payment')->textInput() ?>
  26 +
  27 + <?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>
  28 +
  29 + <?= $form->field($model, 'status')->textInput() ?>
  30 +
  31 + <?= $form->field($model, 'created_at')->textInput() ?>
  32 +
  33 + <?= $form->field($model, 'updated_at')->textInput() ?>
  34 +
  35 + <div class="form-group">
  36 + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  37 + </div>
  38 +
  39 + <?php ActiveForm::end(); ?>
  40 +
  41 +</div>
... ...
backend/views/orders/_search.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\OrdersSearch */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="orders-search">
  12 +
  13 + <?php $form = ActiveForm::begin([
  14 + 'action' => ['index'],
  15 + 'method' => 'get',
  16 + ]); ?>
  17 +
  18 + <?= $form->field($model, 'order_id') ?>
  19 +
  20 + <?= $form->field($model, 'customer_id') ?>
  21 +
  22 + <?= $form->field($model, 'name') ?>
  23 +
  24 + <?= $form->field($model, 'email') ?>
  25 +
  26 + <?= $form->field($model, 'phone') ?>
  27 +
  28 + <?php // echo $form->field($model, 'delivery') ?>
  29 +
  30 + <?php // echo $form->field($model, 'payment') ?>
  31 +
  32 + <?php // echo $form->field($model, 'code') ?>
  33 +
  34 + <?php // echo $form->field($model, 'status') ?>
  35 +
  36 + <?php // echo $form->field($model, 'created_at') ?>
  37 +
  38 + <?php // echo $form->field($model, 'updated_at') ?>
  39 +
  40 + <div class="form-group">
  41 + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
  42 + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
  43 + </div>
  44 +
  45 + <?php ActiveForm::end(); ?>
  46 +
  47 +</div>
... ...
backend/views/orders/create.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\Orders */
  8 +
  9 +$this->title = Yii::t('app', 'Create Orders');
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Orders'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="orders-create">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <?= $this->render('_form', [
  18 + 'model' => $model,
  19 + ]) ?>
  20 +
  21 +</div>
... ...
backend/views/orders/index.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\grid\GridView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $searchModel common\models\OrdersSearch */
  8 +/* @var $dataProvider yii\data\ActiveDataProvider */
  9 +
  10 +$this->title = Yii::t('app', 'Orders');
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="orders-index">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 + <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
  17 +
  18 + <p>
  19 + <?= Html::a(Yii::t('app', 'Create Orders'), ['create'], ['class' => 'btn btn-success']) ?>
  20 + </p>
  21 + <?= GridView::widget([
  22 + 'dataProvider' => $dataProvider,
  23 + 'filterModel' => $searchModel,
  24 + 'columns' => [
  25 + ['class' => 'yii\grid\SerialColumn'],
  26 +
  27 + 'order_id',
  28 + 'customer_id',
  29 + 'name',
  30 + 'email:email',
  31 + 'phone',
  32 + // 'delivery',
  33 + // 'payment',
  34 + // 'code',
  35 + // 'status',
  36 + // 'created_at',
  37 + // 'updated_at',
  38 +
  39 + ['class' => 'yii\grid\ActionColumn'],
  40 + ],
  41 + ]); ?>
  42 +</div>
... ...
backend/views/orders/update.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +/* @var $this yii\web\View */
  6 +/* @var $model common\models\Orders */
  7 +
  8 +$this->title = Yii::t('app', 'Update {modelClass}: ', [
  9 + 'modelClass' => 'Orders',
  10 +]) . ' ' . $model->name;
  11 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Orders'), 'url' => ['index']];
  12 +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->order_id]];
  13 +$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
  14 +?>
  15 +<div class="orders-update">
  16 +
  17 + <h1><?= Html::encode($this->title) ?></h1>
  18 +
  19 + <?= $this->render('_form', [
  20 + 'model' => $model,
  21 + ]) ?>
  22 +
  23 +</div>
... ...
backend/views/orders/view.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\DetailView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\Orders */
  8 +
  9 +$this->title = $model->name;
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Orders'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="orders-view">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <p>
  18 + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->order_id], ['class' => 'btn btn-primary']) ?>
  19 + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->order_id], [
  20 + 'class' => 'btn btn-danger',
  21 + 'data' => [
  22 + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
  23 + 'method' => 'post',
  24 + ],
  25 + ]) ?>
  26 + </p>
  27 +
  28 + <?= DetailView::widget([
  29 + 'model' => $model,
  30 + 'attributes' => [
  31 + 'order_id',
  32 + 'customer_id',
  33 + 'name',
  34 + 'email:email',
  35 + 'phone',
  36 + 'delivery',
  37 + 'payment',
  38 + 'code',
  39 + 'status',
  40 + 'created_at',
  41 + 'updated_at',
  42 + ],
  43 + ]) ?>
  44 +
  45 +</div>
... ...
backend/views/site/login.php
... ... @@ -19,7 +19,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
19 19 <div class="col-lg-5">
20 20 <?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
21 21  
22   - <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
  22 + <?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?>
23 23  
24 24 <?= $form->field($model, 'password')->passwordInput() ?>
25 25  
... ...
common/models/OrdersSearch.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\data\ActiveDataProvider;
  8 +use common\models\Orders;
  9 +
  10 +/**
  11 + * OrdersSearch represents the model behind the search form about `\common\models\Orders`.
  12 + */
  13 +class OrdersSearch extends Orders
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public function rules()
  19 + {
  20 + return [
  21 + [['order_id', 'customer_id', 'delivery', 'payment', 'status', 'created_at', 'updated_at'], 'integer'],
  22 + [['name', 'email', 'phone', 'code'], 'safe'],
  23 + ];
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function scenarios()
  30 + {
  31 + // bypass scenarios() implementation in the parent class
  32 + return Model::scenarios();
  33 + }
  34 +
  35 + /**
  36 + * Creates data provider instance with search query applied
  37 + *
  38 + * @param array $params
  39 + *
  40 + * @return ActiveDataProvider
  41 + */
  42 + public function search($params)
  43 + {
  44 + $query = Orders::find();
  45 +
  46 + // add conditions that should always apply here
  47 +
  48 + $dataProvider = new ActiveDataProvider([
  49 + 'query' => $query,
  50 + ]);
  51 +
  52 + $this->load($params);
  53 +
  54 + if (!$this->validate()) {
  55 + // uncomment the following line if you do not want to return any records when validation fails
  56 + // $query->where('0=1');
  57 + return $dataProvider;
  58 + }
  59 +
  60 + // grid filtering conditions
  61 + $query->andFilterWhere([
  62 + 'order_id' => $this->order_id,
  63 + 'customer_id' => $this->customer_id,
  64 + 'delivery' => $this->delivery,
  65 + 'payment' => $this->payment,
  66 + 'status' => $this->status,
  67 + 'created_at' => $this->created_at,
  68 + 'updated_at' => $this->updated_at,
  69 + ]);
  70 +
  71 + $query->andFilterWhere(['like', 'name', $this->name])
  72 + ->andFilterWhere(['like', 'email', $this->email])
  73 + ->andFilterWhere(['like', 'phone', $this->phone])
  74 + ->andFilterWhere(['like', 'code', $this->code]);
  75 +
  76 + return $dataProvider;
  77 + }
  78 +}
... ...