Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuro committed Jun 9, 2019
1 parent cf451eb commit 7bc76e6
Show file tree
Hide file tree
Showing 61 changed files with 1,407 additions and 195 deletions.
2 changes: 1 addition & 1 deletion backend/controllers/cabinet/RaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function actionUpdate($id)
}

/**
* Deletes an existing User model.
* Deletes an existing Race model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
Expand Down
150 changes: 150 additions & 0 deletions backend/controllers/cabinet/TrackController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

namespace backend\controllers\cabinet;

use cabinet\entities\cabinet\Track;
use cabinet\services\manage\cabinet\TrackManageService;
use backend\forms\cabinet\TrackSearch;
use cabinet\forms\manage\cabinet\TrackForm;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

class TrackController extends Controller
{
public $service;

public function __construct($id, $module, TrackManageService $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
}

/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
],
];
}

/**
* Lists all Track models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new TrackSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}

/**
* Displays a single Track model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'track' => $this->findModel($id),
]);
}

/**
* Updates an existing Track model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$track = $this->findModel($id);

$form = new TrackForm($track);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->edit($track->id, $form);
if(!empty($form->file_screen)) {
$form->upload();
}
return $this->redirect(['view', 'id' => $track->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('update', [
'model' => $form,
'track' => $track,
]);
}

/**
* Deletes an existing Track model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->service->remove($id);
return $this->redirect(['index']);
}

/**
* @param integer $id
* @return mixed
*/
public function actionActivate($id)
{
try {
$this->service->activate($id);
} catch (\DomainException $e) {
Yii::$app->session->setFlash('error', $e->getMessage());
}
return $this->redirect(['view', 'id' => $id]);
}

/**
* @param integer $id
* @return mixed
*/
public function actionDraft($id)
{
try {
$this->service->draft($id);
} catch (\DomainException $e) {
Yii::$app->session->setFlash('error', $e->getMessage());
}
return $this->redirect(['view', 'id' => $id]);
}

/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Track the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Track::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
24 changes: 9 additions & 15 deletions backend/controllers/shop/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use cabinet\services\manage\shop\OrderManageService;
use cabinet\entities\shop\order\Order;
use cabinet\entities\shop\order\Status;
use backend\forms\shop\OrderSearch;
use cabinet\forms\manage\shop\order\OrderEditForm;
use Yii;
Expand Down Expand Up @@ -53,24 +54,17 @@ public function actionIndex()
*/
public function actionExport()
{
$query = Order::find()->orderBy(['id' => SORT_DESC]);
$query = Order::find()->andWhere(['current_status' => STATUS::PAID])->orderBy(['id' => SORT_DESC]);

$objPHPExcel = new \PHPExcel();

$worksheet = $objPHPExcel->getActiveSheet();

foreach ($query->each() as $row => $order) {
/** @var Order $order */

$worksheet->setCellValueByColumnAndRow(0, $row + 1, $order->id);
$worksheet->setCellValueByColumnAndRow(1, $row + 1, date('Y-m-d H:i:s', $order->created_at));
try{
$file = $this->service->export($query);
return Yii::$app->response->sendFile($file, 'report.xlsx');
}catch (\DomainException $e){
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}

$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$file = tempnam(sys_get_temp_dir(), 'export');
$objWriter->save($file);

return Yii::$app->response->sendFile($file, 'report.xlsx');
return false;
}

/**
Expand Down
55 changes: 55 additions & 0 deletions backend/forms/cabinet/TrackSearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace backend\forms\cabinet;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use cabinet\entities\cabinet\Track;
use yii\helpers\ArrayHelper;

class TrackSearch extends Model
{
public $id;
public $date_from;
public $date_to;
public $status;

public function rules()
{
return [
[['id', 'status'], 'integer'],
[['date_from', 'date_to'], 'date', 'format' => 'php:Y-m-d'],
];
}

/**
* @param array $params
* @return ActiveDataProvider
*/
public function search(array $params): ActiveDataProvider
{
$query = Track::find()->alias('t');

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
$query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
't.id' => $this->id,
't.status' => $this->status,
]);

$query
->andFilterWhere(['>=', 't.date_start', $this->date_from ? $this->date_from : null])
->andFilterWhere(['<=', 't.date_start', $this->date_to ? $this->date_to : null]);

return $dataProvider;
}
}
2 changes: 1 addition & 1 deletion backend/forms/shop/OrderSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function search(array $params): ActiveDataProvider
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => ['id' => SORT_DESC]
'defaultOrder' => ['current_status' => SORT_ASC]
]
]);

Expand Down
68 changes: 68 additions & 0 deletions backend/views/cabinet/track/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/* @var $this yii\web\View */
/* @var $model \cabinet\forms\manage\cabinet\RaceForm */
/* @var $race \cabinet\entities\cabinet\Race */

use cabinet\helpers\RaceHelper;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use kartik\widgets\DatePicker;
use kartik\file\FileInput;

?>
<div class="user-update">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>

<?= $form->field($model, 'name')->textInput(['maxLength' => true]) ?>
<?= $form->field($model, 'status')->dropDownList(RaceHelper::statusList()) ?>
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'date_start')->widget(DatePicker::class, [
'value' => date('Y-m-d'),
'options' => ['placeholder' => 'Выберите дату начала забега'],
'pluginOptions' => [
'format' => 'dd.mm.yyyy',
'todayHighlight' => true
]
]) ?>
<?= $form->field($model, 'date_end')->widget(DatePicker::class, [
'value' => date('Y-m-d'),
'options' => ['placeholder' => 'Выберите дату окончания забега'],
'pluginOptions' => [
'format' => 'dd.mm.yyyy',
'todayHighlight' => true
]
]) ?>

<?= $form->field($model, 'type')->dropDownList(RaceHelper::typeList()) ?>

<div class="box box-default">
<div class="box-header with-border">Фотография</div>
<div class="box-body">
<?php echo $form->field($model, 'photo')->widget(FileInput::class, [
'options' => [
'accept' => 'image/*',
'multiple' => false,
]
])->label(false) ?>
</div>
</div>

<div class="box box-default">
<div class="box-header with-border">Макеты файлов для PDF</div>
<div class="box-body">
<?= $form->field($model->template, 'start_number')->dropDownList(RaceHelper::getTemplate('start_number')) ?>
<?= $form->field($model->template, 'diploma')->dropDownList(RaceHelper::getTemplate('diploma')) ?>
<hr/>
<?= $form->field($model->template, 'top_start_number')->dropDownList(RaceHelper::getTemplate('start_number')) ?>
<?= $form->field($model->template, 'top_diploma')->dropDownList(RaceHelper::getTemplate('diploma')) ?>
</div>
</div>

<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>

</div>
Loading

0 comments on commit 7bc76e6

Please sign in to comment.