2018-10-11 11:15:09 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace backend\modules\card\controllers;
|
|
|
|
|
|
|
|
use common\classes\Debug;
|
2018-11-06 11:44:27 +03:00
|
|
|
use common\models\AdditionalFields;
|
2018-10-12 14:52:08 +03:00
|
|
|
use common\models\CardSkill;
|
2018-10-11 11:15:09 +03:00
|
|
|
use common\models\FieldsValue;
|
2019-06-27 15:41:58 +03:00
|
|
|
use common\models\FieldsValueNew;
|
2018-11-23 16:09:29 +03:00
|
|
|
use common\models\Status;
|
2018-10-11 11:15:09 +03:00
|
|
|
use Yii;
|
|
|
|
use backend\modules\card\models\UserCard;
|
|
|
|
use backend\modules\card\models\UserCardSearch;
|
|
|
|
use yii\data\ActiveDataProvider;
|
2018-11-06 11:44:27 +03:00
|
|
|
use yii\db\Expression;
|
2018-10-11 11:15:09 +03:00
|
|
|
use yii\web\Controller;
|
|
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
use yii\filters\VerbFilter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserCardController implements the CRUD actions for UserCard model.
|
|
|
|
*/
|
|
|
|
class UserCardController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'verbs' => [
|
|
|
|
'class' => VerbFilter::className(),
|
|
|
|
'actions' => [
|
|
|
|
'delete' => ['POST'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all UserCard models.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function actionIndex()
|
|
|
|
{
|
2018-11-23 16:09:29 +03:00
|
|
|
$status = new Status();
|
2018-10-11 11:15:09 +03:00
|
|
|
$searchModel = new UserCardSearch();
|
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
|
|
|
|
|
|
|
return $this->render('index', [
|
|
|
|
'searchModel' => $searchModel,
|
|
|
|
'dataProvider' => $dataProvider,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a single UserCard model.
|
|
|
|
* @param integer $id
|
|
|
|
* @return mixed
|
|
|
|
* @throws NotFoundHttpException if the model cannot be found
|
|
|
|
*/
|
|
|
|
public function actionView($id)
|
|
|
|
{
|
|
|
|
$dataProvider = new ActiveDataProvider([
|
2019-06-27 15:41:58 +03:00
|
|
|
'query' => FieldsValueNew::find()
|
|
|
|
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_PROFILE])
|
|
|
|
->orderBy('order'),
|
2018-10-11 11:15:09 +03:00
|
|
|
'pagination' => [
|
|
|
|
'pageSize' => 200,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2018-10-12 14:52:08 +03:00
|
|
|
$skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all();
|
|
|
|
|
2018-10-11 11:15:09 +03:00
|
|
|
return $this->render('view', [
|
|
|
|
'model' => $this->findModel($id),
|
|
|
|
'modelFildValue' => $dataProvider,
|
2018-10-12 14:52:08 +03:00
|
|
|
'skills' => $skills,
|
2018-10-11 11:15:09 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new UserCard model.
|
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function actionCreate()
|
|
|
|
{
|
|
|
|
$model = new UserCard();
|
|
|
|
|
|
|
|
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 UserCard 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);
|
2019-06-27 15:41:58 +03:00
|
|
|
// Debug::dd($model);
|
2018-10-11 11:15:09 +03:00
|
|
|
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 UserCard 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)
|
|
|
|
{
|
2018-11-06 11:44:27 +03:00
|
|
|
//CardSkill::deleteAll(['card_id' => $id]);
|
|
|
|
//FieldsValue::deleteAll(['card_id' => $id]);
|
|
|
|
$model = $this->findModel($id);
|
|
|
|
$d = new \DateTime();
|
|
|
|
$model->deleted_at = $d->format('Y-m-d H:i');
|
|
|
|
$model->save();
|
2018-10-11 11:15:09 +03:00
|
|
|
|
|
|
|
return $this->redirect(['index']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the UserCard model based on its primary key value.
|
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
|
|
|
* @param integer $id
|
|
|
|
* @return UserCard the loaded model
|
|
|
|
* @throws NotFoundHttpException if the model cannot be found
|
|
|
|
*/
|
|
|
|
protected function findModel($id)
|
|
|
|
{
|
|
|
|
if (($model = UserCard::findOne($id)) !== null) {
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new NotFoundHttpException('The requested page does not exist.');
|
|
|
|
}
|
|
|
|
}
|