This commit is contained in:
akosse
2020-02-05 12:08:01 +03:00
parent dbaeeb3c5a
commit 3da2dd1543
34 changed files with 1173 additions and 3 deletions

View File

@ -3,8 +3,6 @@
namespace frontend\modules\access\models;
use common\classes\Debug;
use common\models\UserCardAccesses;
use frontend\modules\card\models\UserCard;
use Yii;

View File

@ -0,0 +1,24 @@
<?php
namespace frontend\modules\reports;
/**
* reports module definition class
*/
class Reports extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'frontend\modules\reports\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace frontend\modules\reports\controllers;
use yii\web\Controller;
/**
* Default controller for the `reports` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,134 @@
<?php
namespace frontend\modules\reports\controllers;
use common\classes\Debug;
use common\models\Accesses;
use Yii;
use common\models\Reports;
use frontend\modules\reports\models\ReportsSearch;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ReportsController implements the CRUD actions for Reports model.
*/
class ReportsController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Reports models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ReportsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query
->where(['user_card.id_user' => Yii::$app->user->identity->id])
->innerJoin('user_card', 'reports.user_card_id = user_card.id');
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Reports model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Reports model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new \frontend\modules\reports\models\Reports();
if ($model->load(Yii::$app->request->post())) {
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Reports model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Reports model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Reports model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Reports the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Reports::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace frontend\modules\reports\models;
use common\classes\Debug;
use common\models\UserCard;
use Yii;
class Reports extends \common\models\Reports
{
public function init()
{
parent::init();
}
// public function beforeSave($insert)
// {
// $user_card = UserCard::findOne(['id_user' => Yii::$app->user->identity->id]);
// $this->user_card_id = $user_card->id;
// return parent::beforeSave($insert);
// }
public function beforeValidate()
{
if (empty($this->user_card_id)) {
$user_card = UserCard::findOne(['id_user' => Yii::$app->user->identity->id]);
$this->user_card_id = $user_card->id;
}
return parent::beforeValidate();
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace frontend\modules\reports\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Reports;
/**
* ReportsSearch represents the model behind the search form of `common\models\Reports`.
*/
class ReportsSearch extends Reports
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'created_at', 'user_card_id', 'status'], 'integer'],
[['today', 'difficulties', 'tomorrow'], '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 = Reports::find();
// add conditions that should always apply here
$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;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
'user_card_id' => $this->user_card_id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'today', $this->today])
->andFilterWhere(['like', 'difficulties', $this->difficulties])
->andFilterWhere(['like', 'tomorrow', $this->tomorrow]);
return $dataProvider;
}
}

View File

@ -0,0 +1,12 @@
<div class="reports-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,38 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\Reports */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="reports-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'created_at')->input(
'date',
[
'placeholder' => 'Zadejte svůj Datum narození',
'language' => 'en',
"data-format" => "DD MMMM YYYY",
'class' => 'form-control report-date'
]
) ?>
<?= $form->field($model, 'today')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'difficulties')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'tomorrow')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,39 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\reports\models\ReportsSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="reports-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'created_at') ?>
<?= $form->field($model, 'today') ?>
<?= $form->field($model, 'difficulties') ?>
<?= $form->field($model, 'tomorrow') ?>
<?php // echo $form->field($model, 'user_card_id') ?>
<?php // echo $form->field($model, 'status') ?>
<div class="form-group">
<?= Html::submitButton('Поиск', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Сброс', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Reports */
$this->title = 'Добавить отчет';
$this->params['breadcrumbs'][] = ['label' => 'Reports', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="reports-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,38 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\reports\models\ReportsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Отчеты';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="reports-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
'created_at',
'today',
'difficulties',
'tomorrow',
// 'user_card_id',
//'status',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>

View File

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Reports */
$this->title = 'Редактировать отчет';
$this->params['breadcrumbs'][] = ['label' => 'Отчеты', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Редактировать';
?>
<div class="reports-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,41 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\Reports */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Отчеты', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="reports-view">
<p>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Вы уверенны, что хотите удалить этот отчет?',
'method' => 'post',
],
]) ?>
<?= Html::a('Список', ['index', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
// 'id',
'created_at',
'today',
'difficulties',
'tomorrow',
// 'user_card_id',
// 'status',
],
]) ?>
</div>