2019-11-18 10:36:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace frontend\modules\card\controllers;
|
|
|
|
|
2020-01-22 12:18:03 +03:00
|
|
|
use common\classes\Debug;
|
2021-09-13 13:37:59 +03:00
|
|
|
use common\models\AchievementUserCard;
|
2019-11-18 10:36:13 +03:00
|
|
|
use common\models\CardSkill;
|
|
|
|
use common\models\FieldsValueNew;
|
2020-01-22 12:18:03 +03:00
|
|
|
use common\models\User;
|
2019-11-18 10:36:13 +03:00
|
|
|
use Yii;
|
2019-11-18 16:14:06 +03:00
|
|
|
use frontend\modules\card\models\UserCard;
|
2019-11-18 10:36:13 +03:00
|
|
|
use yii\data\ActiveDataProvider;
|
2019-11-18 17:04:32 +03:00
|
|
|
use yii\filters\AccessControl;
|
|
|
|
use yii\filters\VerbFilter;
|
2019-11-18 10:36:13 +03:00
|
|
|
use yii\web\Controller;
|
|
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
|
|
|
|
class UserCardController extends Controller
|
|
|
|
{
|
2019-11-18 17:04:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::className(),
|
2020-02-06 11:28:51 +03:00
|
|
|
//'only' => ['index', 'update'],
|
2019-11-18 17:04:32 +03:00
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'allow' => true,
|
|
|
|
'roles' => ['@'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-11-18 10:36:13 +03:00
|
|
|
/**
|
|
|
|
* Displays a single Product model.
|
|
|
|
* @return mixed
|
|
|
|
* @throws NotFoundHttpException if the model cannot be found
|
|
|
|
*/
|
|
|
|
public function actionIndex()
|
|
|
|
{
|
2019-11-18 17:04:32 +03:00
|
|
|
$id_user = Yii::$app->user->id;
|
2021-09-06 10:29:50 +03:00
|
|
|
echo $id_user;
|
|
|
|
// die();
|
2019-11-18 17:04:32 +03:00
|
|
|
$result = UserCard::find()->where(['id_user' => $id_user])->asArray()->all();
|
|
|
|
if($result) {
|
|
|
|
$id = $result[0]['id'];
|
2021-11-25 14:04:14 +03:00
|
|
|
$model = $this->findModel($id);
|
|
|
|
if ($model->load(Yii::$app->request->post())) {
|
|
|
|
$model->updated_at = date('Y-m-d h:i:s');
|
|
|
|
$model->save();
|
|
|
|
}
|
2019-11-18 17:04:32 +03:00
|
|
|
$dataProvider = new ActiveDataProvider([
|
|
|
|
'query' => FieldsValueNew::find()
|
|
|
|
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_PROFILE])
|
|
|
|
->orderBy('order'),
|
|
|
|
'pagination' => [
|
|
|
|
'pageSize' => 200,
|
|
|
|
],
|
|
|
|
]);
|
2019-11-18 10:36:13 +03:00
|
|
|
|
2019-11-18 17:04:32 +03:00
|
|
|
$skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all();
|
2021-09-13 13:37:59 +03:00
|
|
|
$achievements = AchievementUserCard::find()
|
|
|
|
->where(['user_card_id' => $id])
|
|
|
|
->innerJoinWith(['achievement' => function($query) {
|
|
|
|
$query->andWhere(['status' => \common\models\Achievement::STATUS_ACTIVE]);
|
|
|
|
}])
|
|
|
|
->all();
|
|
|
|
|
2019-11-18 17:04:32 +03:00
|
|
|
return $this->render('view', [
|
2021-11-25 14:04:14 +03:00
|
|
|
'model' => $model,
|
2019-11-18 17:04:32 +03:00
|
|
|
'modelFildValue' => $dataProvider,
|
|
|
|
'skills' => $skills,
|
2021-09-13 13:37:59 +03:00
|
|
|
'achievements' => $achievements,
|
2019-11-18 17:04:32 +03:00
|
|
|
]);
|
2019-11-18 13:06:54 +03:00
|
|
|
}
|
2019-11-18 17:04:32 +03:00
|
|
|
else return $this->render('index', ['info' => '<h3>Ваши личные данные не заненсены в базу.</h3>']);
|
2019-11-18 10:36:13 +03:00
|
|
|
}
|
|
|
|
|
2020-09-09 16:37:35 +03:00
|
|
|
public function actionUpdate()
|
2019-11-18 16:14:06 +03:00
|
|
|
{
|
2020-09-09 16:37:35 +03:00
|
|
|
$model = UserCard::findOne(['id_user' => Yii::$app->user->identity->id]);
|
|
|
|
|
2019-11-18 16:14:06 +03:00
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
|
|
|
return $this->redirect(['index', 'id' => $model->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('update', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:37:35 +03:00
|
|
|
public function actionPassword()
|
2020-01-22 12:18:03 +03:00
|
|
|
{
|
2020-09-09 16:37:35 +03:00
|
|
|
$model = User::findOne(Yii::$app->user->identity->id);
|
|
|
|
|
|
|
|
if (Yii::$app->request->post()) {
|
|
|
|
$model->setPassword(Yii::$app->request->post()['password']);
|
|
|
|
$model->save();
|
|
|
|
|
|
|
|
return $this->redirect(['index', 'id' => $model->id]);
|
|
|
|
}
|
2020-01-22 12:18:03 +03:00
|
|
|
|
|
|
|
return $this->render('password', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-11-18 10:36:13 +03:00
|
|
|
/**
|
|
|
|
* Finds the Product 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.');
|
|
|
|
}
|
|
|
|
}
|