Commit 7eb294393edf40feb487595a115b671bd49180de

Authored by Yarik
1 parent a82865e3

test

common/models/Gallery.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "gallery".
  9 + *
  10 + * @property integer $gallery_id
  11 + * @property integer $user_id
  12 + * @property string $name
  13 + * @property string $date_add
  14 + * @property integer $user_add_id
  15 + * @property string $cover
  16 + * @property integer $type
  17 + * @property string $photo
  18 + */
  19 +class Gallery extends \yii\db\ActiveRecord
  20 +{
  21 + /**
  22 + * @inheritdoc
  23 + */
  24 + public static function tableName()
  25 + {
  26 + return 'gallery';
  27 + }
  28 +
  29 + /**
  30 + * @inheritdoc
  31 + */
  32 + public function rules()
  33 + {
  34 + return [
  35 + [['user_id', 'name', 'date_add'], 'required'],
  36 + [['user_id', 'user_add_id', 'type'], 'integer'],
  37 + [['date_add'], 'safe'],
  38 + [['photo'], 'string'],
  39 + [['name', 'cover'], 'string', 'max' => 255],
  40 + ];
  41 + }
  42 +
  43 + /**
  44 + * @inheritdoc
  45 + */
  46 + public function attributeLabels()
  47 + {
  48 + return [
  49 + 'gallery_id' => Yii::t('app', 'Gallery ID'),
  50 + 'user_id' => Yii::t('app', 'User ID'),
  51 + 'name' => Yii::t('app', 'Name'),
  52 + 'date_add' => Yii::t('app', 'Date Add'),
  53 + 'user_add_id' => Yii::t('app', 'User Add ID'),
  54 + 'cover' => Yii::t('app', 'Cover'),
  55 + 'type' => Yii::t('app', 'Type'),
  56 + 'photo' => Yii::t('app', 'Photo'),
  57 + ];
  58 + }
  59 +}
... ...
common/models/Portfolio.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace common\models;
  4 +
  5 + use Yii;
  6 + use yii\behaviors\BlameableBehavior;
  7 + use yii\behaviors\TimestampBehavior;
  8 + use yii\db\Expression;
  9 +
  10 + /**
  11 + * This is the model class for table "portfolio".
  12 + * @property integer $portfolio_id
  13 + * @property integer $user_id
  14 + * @property string $name
  15 + * @property string $link
  16 + * @property string $date_add
  17 + * @property integer $user_add_id Currently inactive attribute
  18 + * @property integer $view_count
  19 + * @property string $city
  20 + * @property string $street
  21 + * @property string $house
  22 + * @property string $description
  23 + * @property string $cover
  24 + * @property integer $gallery_id
  25 + * @property PortfolioSpecialization[] $portfolioSpecializations
  26 + * @property Specialization[] $specializations
  27 + */
  28 + class Portfolio extends \yii\db\ActiveRecord
  29 + {
  30 + /**
  31 + * @inheritdoc
  32 + */
  33 + public static function tableName()
  34 + {
  35 + return 'portfolio';
  36 + }
  37 +
  38 + /**
  39 + * @inheritdoc
  40 + */
  41 + public function behaviors()
  42 + {
  43 + return [
  44 + [
  45 + 'class' => BlameableBehavior::className(),
  46 + 'createdByAttribute' => 'user_id',
  47 + 'updatedByAttribute' => false,
  48 + ],
  49 + [
  50 + 'class' => TimestampBehavior::className(),
  51 + 'createdAtAttribute' => 'date_add',
  52 + 'updatedAtAttribute' => false,
  53 + 'value' => new Expression('NOW()'),
  54 + ],
  55 + ];
  56 + }
  57 +
  58 + /**
  59 + * @inheritdoc
  60 + */
  61 + public function rules()
  62 + {
  63 + return [
  64 + [
  65 + [
  66 + 'name',
  67 + ],
  68 + 'required',
  69 + ],
  70 + [
  71 + [
  72 + 'view_count',
  73 + 'gallery_id',
  74 + ],
  75 + 'integer',
  76 + ],
  77 + [
  78 + [
  79 + 'description',
  80 + 'cover',
  81 + ],
  82 + 'string',
  83 + ],
  84 + [
  85 + [
  86 + 'name',
  87 + 'link',
  88 + 'city',
  89 + 'street',
  90 + 'house',
  91 + ],
  92 + 'string',
  93 + 'max' => 255,
  94 + ],
  95 + [
  96 + [
  97 + 'specializationInput'
  98 + ],
  99 + 'safe',
  100 + ],
  101 + ];
  102 + }
  103 +
  104 + /**
  105 + * @inheritdoc
  106 + */
  107 + public function attributeLabels()
  108 + {
  109 + return [
  110 + 'portfolio_id' => Yii::t('app', 'Portfolio ID'),
  111 + 'user_id' => Yii::t('app', 'User ID'),
  112 + 'name' => Yii::t('app', 'Название'),
  113 + 'link' => Yii::t('app', 'URL'),
  114 + 'date_add' => Yii::t('app', 'Дата добавления'),
  115 + 'user_add_id' => Yii::t('app', 'User Add ID'),
  116 + 'view_count' => Yii::t('app', 'Количество просмотров'),
  117 + 'city' => Yii::t('app', 'Город'),
  118 + 'street' => Yii::t('app', 'Улица'),
  119 + 'house' => Yii::t('app', 'Дом'),
  120 + 'description' => Yii::t('app', 'Описание'),
  121 + 'cover' => Yii::t('app', 'Фото главное'),
  122 + 'gallery_id' => Yii::t('app', 'Фото галерея'),
  123 + ];
  124 + }
  125 +
  126 + /**
  127 + * @return \yii\db\ActiveQuery
  128 + */
  129 + public function getPortfolioSpecializations()
  130 + {
  131 + return $this->hasMany(PortfolioSpecialization::className(), [ 'portfolio_id' => 'portfolio_id' ]);
  132 + }
  133 +
  134 + public function getSpecializations()
  135 + {
  136 + return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ])
  137 + ->viaTable('portfolio_specialization', [ 'portfolio_id' => 'portfolio_id' ]);
  138 + }
  139 +
  140 + public function getSpecializationInput()
  141 + {
  142 + return $this->getSpecializations()->asArray()->column();
  143 + }
  144 +
  145 + public function setSpecializationInput($value)
  146 + {
  147 + $this->specializationInput = $value;
  148 + }
  149 + }
... ...
common/models/PortfolioSpecialization.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "portfolio_specialization".
  9 + *
  10 + * @property integer $portfolio_specialization_id
  11 + * @property integer $portfolio_id
  12 + * @property integer $specialization_id
  13 + *
  14 + * @property Portfolio $portfolio
  15 + * @property Specialization $specialization
  16 + */
  17 +class PortfolioSpecialization extends \yii\db\ActiveRecord
  18 +{
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public static function tableName()
  23 + {
  24 + return 'portfolio_specialization';
  25 + }
  26 +
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + [['portfolio_id', 'specialization_id'], 'integer'],
  34 + [['portfolio_id'], 'exist', 'skipOnError' => true, 'targetClass' => Portfolio::className(), 'targetAttribute' => ['portfolio_id' => 'portfolio_id']],
  35 + [['specialization_id'], 'exist', 'skipOnError' => true, 'targetClass' => Specialization::className(), 'targetAttribute' => ['specialization_id' => 'specialization_id']],
  36 + ];
  37 + }
  38 +
  39 + /**
  40 + * @inheritdoc
  41 + */
  42 + public function attributeLabels()
  43 + {
  44 + return [
  45 + 'portfolio_specialization_id' => Yii::t('app', 'Portfolio Specialization ID'),
  46 + 'portfolio_id' => Yii::t('app', 'Portfolio ID'),
  47 + 'specialization_id' => Yii::t('app', 'Specialization ID'),
  48 + ];
  49 + }
  50 +
  51 + /**
  52 + * @return \yii\db\ActiveQuery
  53 + */
  54 + public function getPortfolio()
  55 + {
  56 + return $this->hasOne(Portfolio::className(), ['portfolio_id' => 'portfolio_id']);
  57 + }
  58 +
  59 + /**
  60 + * @return \yii\db\ActiveQuery
  61 + */
  62 + public function getSpecialization()
  63 + {
  64 + return $this->hasOne(Specialization::className(), ['specialization_id' => 'specialization_id']);
  65 + }
  66 +}
... ...
frontend/controllers/AccountsController.php
... ... @@ -6,6 +6,8 @@
6 6 use common\models\Job;
7 7 use common\models\Language;
8 8 use common\models\Payment;
  9 + use common\models\Portfolio;
  10 + use common\models\PortfolioSpecialization;
9 11 use common\models\Specialization;
10 12 use common\models\UserPayment;
11 13 use common\models\UserSpecialization;
... ... @@ -110,7 +112,61 @@
110 112  
111 113 public function actionPortfolio()
112 114 {
  115 + return $this->render('portfolio');
  116 + }
  117 +
  118 + public function actionPortfolioCreate()
  119 + {
  120 + $portfolio = new Portfolio();
  121 + $specialization = Specialization::find()
  122 + ->select([
  123 + 'specialization_name',
  124 + 'specialization_id',
  125 + ])
  126 + ->indexBy('specialization_id')
  127 + ->asArray()
  128 + ->column();
  129 + $post = \Yii::$app->request->post();
  130 + if(!empty($post)) {
  131 + $portfolio->load($post);
  132 + $portfolio->validate();
  133 + if(!$portfolio->hasErrors()) {
  134 + $portfolio->save();
  135 + $portfolio->unlinkAll('specializations', true);
  136 + foreach($portfolio->specializationInput as $one_specialization) {
  137 + $portfolio->link('specializations', Specialization::findOne($one_specialization));
  138 + }
  139 + return $this->render('portfolio');
  140 + }
  141 + }
  142 + return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization ]);
  143 + }
113 144  
  145 + public function actionPortfolioUpdate($id)
  146 + {
  147 + $portfolio = Portfolio::findOne($id);
  148 + $specialization = Specialization::find()
  149 + ->select([
  150 + 'specialization_name',
  151 + 'specialization_id',
  152 + ])
  153 + ->indexBy('specialization_id')
  154 + ->asArray()
  155 + ->column();
  156 + $post = \Yii::$app->request->post();
  157 + if(!empty($post)) {
  158 + $portfolio->load($post);
  159 + $portfolio->validate();
  160 + if(!$portfolio->hasErrors()) {
  161 + $portfolio->save();
  162 + $portfolio->unlinkAll('specializations', true);
  163 + foreach($portfolio->specializationInput as $one_specialization) {
  164 + $portfolio->link('specializations', Specialization::findOne($one_specialization));
  165 + }
  166 + return $this->render('portfolio');
  167 + }
  168 + }
  169 + return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization ]);
114 170 }
115 171  
116 172 /**
... ... @@ -184,13 +240,15 @@
184 240 UserSpecialization::deleteAll([ 'user_id' => \Yii::$app->user->getId() ]);
185 241 UserPayment::deleteAll([ 'user_id' => \Yii::$app->user->getId() ]);
186 242 foreach($post[ 'UserSpecialization' ][ 'specialization_id' ] as $index => $value) {
187   - $user_specialization_values[] = (new UserSpecialization([ 'user_id' => \Yii::$app->user->getId(),
188   - 'specialization_id' => $value,
  243 + $user_specialization_values[] = (new UserSpecialization([
  244 + 'user_id' => \Yii::$app->user->getId(),
  245 + 'specialization_id' => $value,
189 246 ]))->save();
190 247 }
191 248 foreach($post[ 'UserPayment' ][ 'payment_id' ] as $index => $value) {
192   - $user_payment_values[] = (new UserPayment([ 'user_id' => \Yii::$app->user->getId(),
193   - 'payment_id' => $value,
  249 + $user_payment_values[] = (new UserPayment([
  250 + 'user_id' => \Yii::$app->user->getId(),
  251 + 'payment_id' => $value,
194 252 ]))->save();
195 253 }
196 254 }
... ... @@ -234,10 +292,10 @@
234 292 public function actionAddSkills()
235 293 {
236 294 $user = \Yii::$app->user->identity;
237   - if(!empty(\Yii::$app->request->post())) {
  295 + if(!empty( \Yii::$app->request->post() )) {
238 296 Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru');
239 297 }
240   - return $this->render('add-skills', ['user' => $user]);
  298 + return $this->render('add-skills', [ 'user' => $user ]);
241 299 }
242 300  
243 301 public function actionDescription()
... ... @@ -249,7 +307,7 @@
249 307 $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
250 308 }
251 309 $post = \Yii::$app->request->post();
252   - if(!empty($post)) {
  310 + if(!empty( $post )) {
253 311 $user_info->load($post);
254 312 $user_info->save();
255 313 }
... ...
frontend/views/accounts/_portfolio_form.php 0 → 100644
  1 +<?php
  2 + /**
  3 + * @var Portfolio $portfolio
  4 + */
  5 + use common\models\Option;
  6 + use common\models\Portfolio;
  7 + use common\widgets\ImageUploader;
  8 + use mihaildev\ckeditor\CKEditor;
  9 + use yii\helpers\Html;
  10 + use yii\widgets\ActiveForm;
  11 + use \common\widgets\MultiLangForm;
  12 +
  13 + $this->title = 'Мой профиль';
  14 + $this->params[ 'breadcrumbs' ][] = $this->title;
  15 +?>
  16 +<h1><?= $this->title ?></h1>
  17 +
  18 +<?php
  19 + $form = ActiveForm::begin();
  20 +?>
  21 +
  22 +<?= $form->field($portfolio, 'date_add')
  23 + ->textInput([ 'disabled' => 'disabled' ]) ?>
  24 +
  25 +<?= $form->field($portfolio, 'name')
  26 + ->textInput() ?>
  27 +
  28 +<?= $form->field($portfolio, 'link')
  29 + ->textInput() ?>
  30 +
  31 +<?= $form->field($portfolio, 'specializationInput')
  32 + ->checkboxList($specialization) ?>
  33 +
  34 +<?= ImageUploader::widget([
  35 + 'model'=> $portfolio,
  36 + 'field'=>'cover',
  37 + 'width'=>100,
  38 + 'height'=>100,
  39 + 'multi'=>false,
  40 + 'gallery' =>$portfolio->cover,
  41 + 'name' => 'Загрузить главное фото'
  42 +]);
  43 +?>
  44 +
  45 +<div class="form-inline">
  46 + Адрес:
  47 + <?= $form->field($portfolio, 'city', ['template' => "{input}{label}{hint}{error}"])->textInput() ?>
  48 + <?= $form->field($portfolio, 'street', ['template' => "{input}{label}{hint}{error}"])->textInput() ?>
  49 + <?= $form->field($portfolio, 'house', ['template' => "{input}{label}{hint}{error}"])->textInput() ?>
  50 +</div>
  51 +
  52 +<?= $form->field($portfolio, 'description')->widget(CKEditor::className()) ?>
  53 +
  54 +<?= Html::submitButton('Добавить') ?>
  55 +
  56 +<?php
  57 + $form->end();
  58 +?>
... ...
frontend/views/accounts/portfolio.php
... ... @@ -7,20 +7,4 @@ use \common\widgets\MultiLangForm;
7 7 $this->title = 'Мой профиль';
8 8 $this->params['breadcrumbs'][] = $this->title;
9 9 ?>
10   -
11   -<h1><?= $this->title ?></h1>
12   -
13   -
14   -
15   -<?php
16   -
17   -$form = $this->render('_form', [
18   - 'user' => $user,
19   - 'user_info' => $user_info,
20   -]);
21   -
22   -echo MultiLangForm::widget(['form'=>$form]);
23   -
24   -?>
25   -
26   -
  10 +<h1><?= $this->title ?></h1>
27 11 \ No newline at end of file
... ...