Commit fa67310abde3238a2137e712df1a3ec1b4d98e21

Authored by Yarik
1 parent 5f49082a

test

common/models/Payment.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "payment".
  9 + *
  10 + * @property integer $payment_id
  11 + * @property string $name
  12 + * @property integer $status
  13 + *
  14 + * @property UserPayment[] $userPayments
  15 + */
  16 +class Payment extends \yii\db\ActiveRecord
  17 +{
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public static function tableName()
  22 + {
  23 + return 'payment';
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function rules()
  30 + {
  31 + return [
  32 + [['name'], 'required'],
  33 + [['status'], 'integer'],
  34 + [['name'], 'string', 'max' => 255],
  35 + ];
  36 + }
  37 +
  38 + /**
  39 + * @inheritdoc
  40 + */
  41 + public function attributeLabels()
  42 + {
  43 + return [
  44 + 'payment_id' => Yii::t('app', 'Payment ID'),
  45 + 'name' => Yii::t('app', 'Name'),
  46 + 'status' => Yii::t('app', 'Status'),
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * @return \yii\db\ActiveQuery
  52 + */
  53 + public function getUserPayments()
  54 + {
  55 + return $this->hasMany(UserPayment::className(), ['payment_id' => 'payment_id']);
  56 + }
  57 +}
... ...
common/models/PaymentSearch.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\Payment;
  9 +
  10 +/**
  11 + * PaymentSearch represents the model behind the search form about `common\models\Payment`.
  12 + */
  13 +class PaymentSearch extends Payment
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public function rules()
  19 + {
  20 + return [
  21 + [['payment_id', 'status'], 'integer'],
  22 + [['name'], '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 = Payment::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 + 'payment_id' => $this->payment_id,
  63 + 'status' => $this->status,
  64 + ]);
  65 +
  66 + $query->andFilterWhere(['like', 'name', $this->name]);
  67 +
  68 + return $dataProvider;
  69 + }
  70 +}
... ...
common/models/UserPayment.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "user_payment".
  9 + *
  10 + * @property integer $user_payment_id
  11 + * @property integer $user_id
  12 + * @property integer $payment_id
  13 + *
  14 + * @property Payment $payment
  15 + */
  16 +class UserPayment extends \yii\db\ActiveRecord
  17 +{
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public static function tableName()
  22 + {
  23 + return 'user_payment';
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function rules()
  30 + {
  31 + return [
  32 + [['user_id', 'payment_id'], 'integer'],
  33 + [['payment_id'], 'exist', 'skipOnError' => true, 'targetClass' => Payment::className(), 'targetAttribute' => ['payment_id' => 'payment_id']],
  34 + ];
  35 + }
  36 +
  37 + /**
  38 + * @inheritdoc
  39 + */
  40 + public function attributeLabels()
  41 + {
  42 + return [
  43 + 'user_payment_id' => Yii::t('app', 'User Payment ID'),
  44 + 'user_id' => Yii::t('app', 'User ID'),
  45 + 'payment_id' => Yii::t('app', 'Payment ID'),
  46 + ];
  47 + }
  48 +
  49 + /**
  50 + * @return \yii\db\ActiveQuery
  51 + */
  52 + public function getPayment()
  53 + {
  54 + return $this->hasOne(Payment::className(), ['payment_id' => 'payment_id']);
  55 + }
  56 +}
... ...
common/models/UserSpecialization.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "user_specialization".
  9 + *
  10 + * @property integer $user_specialization_id
  11 + * @property integer $user_id
  12 + * @property integer $specialization_id
  13 + *
  14 + * @property Specialization $specialization
  15 + */
  16 +class UserSpecialization extends \yii\db\ActiveRecord
  17 +{
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public static function tableName()
  22 + {
  23 + return 'user_specialization';
  24 + }
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function rules()
  30 + {
  31 + return [
  32 + [['user_id', 'specialization_id'], 'integer'],
  33 + [['specialization_id'], 'exist', 'skipOnError' => true, 'targetClass' => Specialization::className(), 'targetAttribute' => ['specialization_id' => 'specialization_id']],
  34 + ];
  35 + }
  36 +
  37 + /**
  38 + * @inheritdoc
  39 + */
  40 + public function attributeLabels()
  41 + {
  42 + return [
  43 + 'user_specialization_id' => Yii::t('app', 'User Specialization ID'),
  44 + 'user_id' => Yii::t('app', 'User ID'),
  45 + 'specialization_id' => Yii::t('app', 'Specialization ID'),
  46 + ];
  47 + }
  48 +
  49 + /**
  50 + * @return \yii\db\ActiveQuery
  51 + */
  52 + public function getSpecialization()
  53 + {
  54 + return $this->hasOne(Specialization::className(), ['specialization_id' => 'specialization_id']);
  55 + }
  56 +}
... ...
frontend/controllers/PaymentController.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace frontend\controllers;
  4 +
  5 +use Yii;
  6 +use common\models\Payment;
  7 +use common\models\PaymentSearch;
  8 +use yii\web\Controller;
  9 +use yii\web\NotFoundHttpException;
  10 +use yii\filters\VerbFilter;
  11 +
  12 +/**
  13 + * PaymentController implements the CRUD actions for Payment model.
  14 + */
  15 +class PaymentController 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 Payment models.
  34 + * @return mixed
  35 + */
  36 + public function actionIndex()
  37 + {
  38 + $searchModel = new PaymentSearch();
  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 Payment 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 Payment 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 Payment();
  67 +
  68 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  69 + return $this->redirect(['view', 'id' => $model->payment_id]);
  70 + } else {
  71 + return $this->render('create', [
  72 + 'model' => $model,
  73 + ]);
  74 + }
  75 + }
  76 +
  77 + /**
  78 + * Updates an existing Payment 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->payment_id]);
  89 + } else {
  90 + return $this->render('update', [
  91 + 'model' => $model,
  92 + ]);
  93 + }
  94 + }
  95 +
  96 + /**
  97 + * Deletes an existing Payment 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 Payment 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 Payment the loaded model
  114 + * @throws NotFoundHttpException if the model cannot be found
  115 + */
  116 + protected function findModel($id)
  117 + {
  118 + if (($model = Payment::findOne($id)) !== null) {
  119 + return $model;
  120 + } else {
  121 + throw new NotFoundHttpException('The requested page does not exist.');
  122 + }
  123 + }
  124 +}
... ...
frontend/views/payment/_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\Payment */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="payment-form">
  12 +
  13 + <?php $form = ActiveForm::begin(); ?>
  14 +
  15 + <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
  16 +
  17 + <?= $form->field($model, 'status')->textInput() ?>
  18 +
  19 + <div class="form-group">
  20 + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  21 + </div>
  22 +
  23 + <?php ActiveForm::end(); ?>
  24 +
  25 +</div>
... ...
frontend/views/payment/_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\PaymentSearch */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="payment-search">
  12 +
  13 + <?php $form = ActiveForm::begin([
  14 + 'action' => ['index'],
  15 + 'method' => 'get',
  16 + ]); ?>
  17 +
  18 + <?= $form->field($model, 'payment_id') ?>
  19 +
  20 + <?= $form->field($model, 'name') ?>
  21 +
  22 + <?= $form->field($model, 'status') ?>
  23 +
  24 + <div class="form-group">
  25 + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
  26 + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
  27 + </div>
  28 +
  29 + <?php ActiveForm::end(); ?>
  30 +
  31 +</div>
... ...
frontend/views/payment/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\Payment */
  8 +
  9 +$this->title = Yii::t('app', 'Create Payment');
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Payments'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="payment-create">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <?= $this->render('_form', [
  18 + 'model' => $model,
  19 + ]) ?>
  20 +
  21 +</div>
... ...
frontend/views/payment/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\PaymentSearch */
  8 +/* @var $dataProvider yii\data\ActiveDataProvider */
  9 +
  10 +$this->title = Yii::t('app', 'Payments');
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="payment-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 Payment'), ['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 + 'payment_id',
  28 + 'name',
  29 + 'status',
  30 +
  31 + ['class' => 'yii\grid\ActionColumn'],
  32 + ],
  33 + ]); ?>
  34 +</div>
... ...
frontend/views/payment/update.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +/* @var $this yii\web\View */
  6 +/* @var $model common\models\Payment */
  7 +
  8 +$this->title = Yii::t('app', 'Update {modelClass}: ', [
  9 + 'modelClass' => 'Payment',
  10 +]) . ' ' . $model->name;
  11 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Payments'), 'url' => ['index']];
  12 +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->payment_id]];
  13 +$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
  14 +?>
  15 +<div class="payment-update">
  16 +
  17 + <h1><?= Html::encode($this->title) ?></h1>
  18 +
  19 + <?= $this->render('_form', [
  20 + 'model' => $model,
  21 + ]) ?>
  22 +
  23 +</div>
... ...
frontend/views/payment/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\Payment */
  8 +
  9 +$this->title = $model->name;
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Payments'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="payment-view">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <p>
  18 + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->payment_id], ['class' => 'btn btn-primary']) ?>
  19 + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->payment_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 + 'payment_id',
  32 + 'name',
  33 + 'status',
  34 + ],
  35 + ]) ?>
  36 +
  37 +</div>
... ...