-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,407 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.