Merge pull request #20 from apuc/show_user_info

Show user info
This commit is contained in:
kavalar 2019-11-18 09:58:18 +02:00 committed by GitHub
commit d35ebc680b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 196 additions and 5 deletions

View File

@ -9,6 +9,7 @@ use yii\widgets\DetailView;
/* @var $userData common\models\User */
/* @var $skills \common\models\CardSkill */
/* @var $skill \common\models\Skill */
/* @var $modelFildValue yii\data\ActiveDataProvider */
$this->title = $model->fio;
$this->params['breadcrumbs'][] = ['label' => 'User Cards', 'url' => ['index']];

View File

@ -16,6 +16,9 @@ return [
'access' => [
'class' => 'frontend\modules\access\Access',
],
'card' => [
'class' => 'frontend\modules\card\Card',
],
],
'components' => [
@ -48,7 +51,10 @@ return [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
'rules' => [
'' => 'card/user-card/index',
'site/index' => 'card/user-card/index',
],
],
],

View File

@ -1,6 +1,8 @@
<?php
namespace frontend\controllers;
use common\classes\Debug;
use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
@ -13,6 +15,7 @@ use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
/**
* Site controller
*/

View File

@ -2,11 +2,10 @@
namespace frontend\modules\access\controllers;
use common\classes\Debug;
use common\models\Accesses;
use Yii;
use yii\web\Controller;
use yii\data\ActiveDataProvider;
use common\models\Accesses;
class AccessController extends Controller
{

View File

@ -1,7 +1,6 @@
<?php
use yii\grid\GridView;
use yii\widgets\DetailView;
echo GridView::widget([
'dataProvider' => $dataProvider,

View File

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

View File

@ -0,0 +1,61 @@
<?php
namespace frontend\modules\card\controllers;
use common\models\CardSkill;
use common\models\FieldsValueNew;
use Yii;
use common\models\UserCard;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
class UserCardController extends Controller
{
/**
* Displays a single Product model.
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionIndex()
{
$id_user = Yii::$app->user->id;
$result = UserCard::find()->where(['id_user' => $id_user])->asArray()->all();
$id = $result[0]['id'];
$dataProvider = new ActiveDataProvider([
'query' => FieldsValueNew::find()
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_PROFILE])
->orderBy('order'),
'pagination' => [
'pageSize' => 200,
],
]);
$skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all();
return $this->render('index', [
'model' => $this->findModel($id),
'modelFildValue' => $dataProvider,
'skills' => $skills,
]);
}
/**
* 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.');
}
}

View File

@ -0,0 +1,80 @@
<?php
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $skills \common\models\CardSkill */
/* @var $skill \common\models\Skill */
/* @var $modelFildValue yii\data\ActiveDataProvider */
?>
<div class="user-card-view">
<h3>Личная информация</h3>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
['label' => 'ФИО', 'attribute' => 'fio',],
['label' => 'Пасспорт', 'attribute' => 'passport',],
['label' => 'Email', 'attribute' => 'email',],
[
'attribute' => 'gender',
'value' => $model->gendersText,
],
['label' => 'Дата рождения', 'attribute' => 'dob',],
[
'attribute' => 'status',
'value' => $model->status0->name,
],
['label' => 'Зарплата', 'attribute' => 'salary',],
[
'attribute' => 'position_id',
'value' => (isset($model->position->name)) ? $model->position->name : 'Без должности',
],
[
'attribute' => 'Фото',
'format' => 'raw',
'value' => function ($model) {
return Html::tag('img', null, ['src' => $model->photo, 'width' => '100px']);
}
],
[
'attribute' => 'Resume',
'format' => 'raw',
'value' => function ($model) {
return Html::a('Скачать', $model->resume, ['target' => '_blank']);
}
],
['label' => 'Добвлен', 'attribute' => 'created_at',],
['label' => 'Изменен', 'attribute' => 'updated_at',],
],
]) ?>
<h2>Навыки</h2>
<?php foreach ($skills as $skill) : ?>
<span class="btn btn-default btn-sm"><?= $skill['skill']->name; ?></span>
<?php endforeach; ?>
<h2>Дополнительные сведения</h2>
<?= GridView::widget([
'dataProvider' => $modelFildValue,
'layout' => "{items}",
'columns' => [
'field.name:text:Поле',
[
'attribute' => 'value',
'format' => 'raw',
'value' => function ($model) {
if ($model->type_file == 'file') {
return $model->value . ' (' . Html::a('Скачать', $model->value, ['target' => '_blank', 'download' => 'download']) . ')';
}
return $model->value;
}
],
],
]); ?>
</div>

View File

@ -46,7 +46,7 @@ AppAsset::register($this);
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = ['label' => 'Access', 'url' => ['/access/access/index']];
$menuItems[] = ['label' => 'Доступы', 'url' => ['/access/access/index']];
$menuItems[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(

View File

@ -0,0 +1,18 @@
<?php
use common\classes\Debug;
use yii\widgets\DetailView;
use yii\grid\GridView;
echo GridView::widget([
'dataProvider' => $model,
]);
// Debug::dd($model);
// echo DetailView::widget([
// 'model' => $model,
// 'attributes' => [
// 'email',
// ],
// ]);