Commit a02e2fdb105962443f01d610a00e3812a34004c1

Authored by Yarik
1 parent 0ca0742e

test

common/models/BlogSearch.php
1 1 <?php
2 2  
3   -namespace common\models;
4   -
5   -use Yii;
6   -use yii\base\Model;
7   -use yii\data\ActiveDataProvider;
8   -use common\models\Blog;
9   -
10   -/**
11   - * BlogSearch represents the model behind the search form about `common\models\Blog`.
12   - */
13   -class BlogSearch extends Blog
14   -{
15   - /**
16   - * @inheritdoc
17   - */
18   - public function rules()
19   - {
20   - return [
21   - [['blog_id', 'user_id', 'user_add_id', 'view_count'], 'integer'],
22   - [['name', 'link', 'date_add', 'description', 'cover'], 'safe'],
23   - ];
24   - }
  3 + namespace common\models;
25 4  
26   - /**
27   - * @inheritdoc
28   - */
29   - public function scenarios()
30   - {
31   - // bypass scenarios() implementation in the parent class
32   - return Model::scenarios();
33   - }
  5 + use Yii;
  6 + use yii\base\Model;
  7 + use yii\bootstrap\ActiveForm;
  8 + use yii\data\ActiveDataProvider;
  9 + use common\models\Blog;
  10 + use yii\db\ActiveQuery;
  11 + use yii\db\ActiveRecord;
34 12  
35 13 /**
36   - * Creates data provider instance with search query applied
37   - *
38   - * @param array $params
39   - *
40   - * @return ActiveDataProvider
  14 + * BlogSearch represents the model behind the search form about `common\models\Blog`.
41 15 */
42   - public function search($params)
  16 + class BlogSearch extends Blog
43 17 {
44   - $query = Blog::find();
45 18  
46   - // add conditions that should always apply here
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function rules()
  23 + {
  24 + return [
  25 + [
  26 + [
  27 + 'blog_id',
  28 + 'user_id',
  29 + 'user_add_id',
  30 + 'view_count',
  31 + ],
  32 + 'integer',
  33 + ],
  34 + [
  35 + [
  36 + 'name',
  37 + 'link',
  38 + 'date_add',
  39 + 'description',
  40 + 'cover',
  41 + ],
  42 + 'safe',
  43 + ],
  44 + ];
  45 + }
47 46  
48   - $dataProvider = new ActiveDataProvider([
49   - 'query' => $query,
50   - ]);
  47 + /**
  48 + * @inheritdoc
  49 + */
  50 + public function scenarios()
  51 + {
  52 + // bypass scenarios() implementation in the parent class
  53 + return Model::scenarios();
  54 + }
51 55  
52   - $this->load($params);
  56 + /**
  57 + * Creates data provider instance with search query applied
  58 + *
  59 + * @param array $params
  60 + *
  61 + * @return ActiveDataProvider
  62 + */
  63 + public function search($params)
  64 + {
  65 + $query = Blog::find();
  66 +
  67 + // add conditions that should always apply here
  68 +
  69 + $dataProvider = new ActiveDataProvider([
  70 + 'query' => $query,
  71 + ]);
  72 +
  73 + $this->load($params);
  74 +
  75 + if(!$this->validate()) {
  76 + // uncomment the following line if you do not want to return any records when validation fails
  77 + // $query->where('0=1');
  78 + return $dataProvider;
  79 + }
  80 +
  81 + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
  82 +
  83 + // grid filtering conditions
  84 + $query->andFilterWhere([
  85 + 'blog_id' => $this->blog_id,
  86 + 'date_add' => $this->date_add,
  87 + 'user_add_id' => $this->user_add_id,
  88 + 'view_count' => $this->view_count,
  89 + ]);
  90 +
  91 + $query->andFilterWhere([
  92 + 'like',
  93 + 'name',
  94 + $this->name,
  95 + ])
  96 + ->andFilterWhere([
  97 + 'like',
  98 + 'link',
  99 + $this->link,
  100 + ])
  101 + ->andFilterWhere([
  102 + 'like',
  103 + 'description',
  104 + $this->description,
  105 + ])
  106 + ->andFilterWhere([
  107 + 'like',
  108 + 'cover',
  109 + $this->cover,
  110 + ]);
53 111  
54   - if (!$this->validate()) {
55   - // uncomment the following line if you do not want to return any records when validation fails
56   - // $query->where('0=1');
57 112 return $dataProvider;
58 113 }
59 114  
60   - // grid filtering conditions
61   - $query->andFilterWhere([
62   - 'blog_id' => $this->blog_id,
63   - 'user_id' => $this->user_id,
64   - 'date_add' => $this->date_add,
65   - 'user_add_id' => $this->user_add_id,
66   - 'view_count' => $this->view_count,
67   - ]);
68   -
69   - $query->andFilterWhere(['like', 'name', $this->name])
70   - ->andFilterWhere(['like', 'link', $this->link])
71   - ->andFilterWhere(['like', 'description', $this->description])
72   - ->andFilterWhere(['like', 'cover', $this->cover]);
73   -
74   - return $dataProvider;
  115 + public function searchByUser($params)
  116 + {
  117 + $query = $this->search($params);
  118 +
  119 + }
75 120 }
76   -}
... ...
common/models/GallerySearch.php
1 1 <?php
2 2  
3   -namespace common\models;
  3 + namespace common\models;
4 4  
5   -use Yii;
6   -use yii\base\Model;
7   -use yii\data\ActiveDataProvider;
8   -use common\models\Gallery;
  5 + use Yii;
  6 + use yii\base\Model;
  7 + use yii\data\ActiveDataProvider;
  8 + use common\models\Gallery;
9 9  
10   -/**
11   - * GallerySearch represents the model behind the search form about `common\models\Gallery`.
12   - */
13   -class GallerySearch extends Gallery
14   -{
15 10 /**
16   - * @inheritdoc
  11 + * GallerySearch represents the model behind the search form about `common\models\Gallery`.
17 12 */
18   - public function rules()
  13 + class GallerySearch extends Gallery
19 14 {
20   - return [
21   - [['gallery_id', 'user_id', 'user_add_id', 'type'], 'integer'],
22   - [['name', 'date_add', 'cover', 'photo'], 'safe'],
23   - ];
24   - }
25 15  
26   - /**
27   - * @inheritdoc
28   - */
29   - public function scenarios()
30   - {
31   - // bypass scenarios() implementation in the parent class
32   - return Model::scenarios();
33   - }
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public function rules()
  20 + {
  21 + return [
  22 + [
  23 + [
  24 + 'gallery_id',
  25 + 'user_add_id',
  26 + 'type',
  27 + ],
  28 + 'integer',
  29 + ],
  30 + [
  31 + [
  32 + 'name',
  33 + 'date_add',
  34 + 'cover',
  35 + 'photo',
  36 + ],
  37 + 'safe',
  38 + ],
  39 + ];
  40 + }
34 41  
35   - /**
36   - * Creates data provider instance with search query applied
37   - *
38   - * @param array $params
39   - *
40   - * @return ActiveDataProvider
41   - */
42   - public function search($params)
43   - {
44   - $query = Gallery::find();
  42 + /**
  43 + * @inheritdoc
  44 + */
  45 + public function scenarios()
  46 + {
  47 + // bypass scenarios() implementation in the parent class
  48 + return Model::scenarios();
  49 + }
45 50  
46   - // add conditions that should always apply here
  51 + /**
  52 + * Creates data provider instance with search query applied
  53 + *
  54 + * @param array $params
  55 + *
  56 + * @return ActiveDataProvider
  57 + */
  58 + public function search($params)
  59 + {
  60 + $query = Gallery::find();
47 61  
48   - $dataProvider = new ActiveDataProvider([
49   - 'query' => $query,
50   - ]);
  62 + // add conditions that should always apply here
51 63  
52   - $this->load($params);
  64 + $dataProvider = new ActiveDataProvider([
  65 + 'query' => $query,
  66 + ]);
53 67  
54   - if (!$this->validate()) {
55   - // uncomment the following line if you do not want to return any records when validation fails
56   - // $query->where('0=1');
57   - return $dataProvider;
58   - }
  68 + $this->load($params);
59 69  
60   - // grid filtering conditions
61   - $query->andFilterWhere([
62   - 'gallery_id' => $this->gallery_id,
63   - 'user_id' => $this->user_id,
64   - 'date_add' => $this->date_add,
65   - 'user_add_id' => $this->user_add_id,
66   - 'type' => $this->type,
67   - ]);
  70 + if(!$this->validate()) {
  71 + // uncomment the following line if you do not want to return any records when validation fails
  72 + // $query->where('0=1');
  73 + return $dataProvider;
  74 + }
68 75  
69   - $query->andFilterWhere(['like', 'name', $this->name])
70   - ->andFilterWhere(['like', 'cover', $this->cover])
71   - ->andFilterWhere(['like', 'photo', $this->photo]);
  76 + $query->andWhere([
  77 + 'user_id' => \Yii::$app->user->getId(),
  78 + ]);
72 79  
73   - return $dataProvider;
  80 + // grid filtering conditions
  81 + $query->andFilterWhere([
  82 + 'gallery_id' => $this->gallery_id,
  83 + 'date_add' => $this->date_add,
  84 + 'user_add_id' => $this->user_add_id,
  85 + 'type' => $this->type,
  86 + ]);
  87 +
  88 + $query->andFilterWhere([
  89 + 'like',
  90 + 'name',
  91 + $this->name,
  92 + ])
  93 + ->andFilterWhere([
  94 + 'like',
  95 + 'cover',
  96 + $this->cover,
  97 + ])
  98 + ->andFilterWhere([
  99 + 'like',
  100 + 'photo',
  101 + $this->photo,
  102 + ]);
  103 +
  104 + return $dataProvider;
  105 + }
74 106 }
75   -}
... ...
common/models/PortfolioSearch.php
... ... @@ -22,7 +22,6 @@
22 22 [
23 23 [
24 24 'portfolio_id',
25   - 'user_id',
26 25 'user_add_id',
27 26 'view_count',
28 27 'gallery_id',
... ... @@ -82,10 +81,11 @@
82 81  
83 82 $query->joinWith('specializations');
84 83  
  84 + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
  85 +
85 86 // grid filtering conditions
86 87 $query->andFilterWhere([
87 88 'portfolio_id' => $this->portfolio_id,
88   - 'user_id' => $this->user_id,
89 89 'date_add' => $this->date_add,
90 90 'user_add_id' => $this->user_add_id,
91 91 'view_count' => $this->view_count,
... ...
common/models/Project.php
... ... @@ -108,6 +108,14 @@
108 108 'default',
109 109 'value' => 0,
110 110 ],
  111 + [
  112 + [
  113 + 'paymentInput',
  114 + 'specializationInput',
  115 + ],
  116 + 'default',
  117 + 'value' => [ ],
  118 + ],
111 119 ];
112 120 }
113 121  
... ... @@ -117,26 +125,26 @@
117 125 public function attributeLabels()
118 126 {
119 127 return [
120   - 'project_id' => Yii::t('app', 'Project ID'),
121   - 'user_id' => Yii::t('app', 'User ID'),
122   - 'name' => Yii::t('app', 'Название'),
123   - 'link' => Yii::t('app', 'URL'),
124   - 'project_pid' => Yii::t('app', 'Родительский проект'),
125   - 'date_add' => Yii::t('app', 'Дата добавления'),
126   - 'date_end' => Yii::t('app', 'Дата окончания'),
127   - 'user_add_id' => Yii::t('app', 'User Add ID'),
128   - 'view_count' => Yii::t('app', 'Количество просмотров'),
129   - 'budget' => Yii::t('app', 'Бюджет'),
130   - 'city' => Yii::t('app', 'Город'),
131   - 'street' => Yii::t('app', 'Улица'),
132   - 'house' => Yii::t('app', 'Дом'),
133   - 'payment_variant' => Yii::t('app', 'Варианты оплаты'),
134   - 'deadline' => Yii::t('app', 'Срок выполнения'),
135   - 'description' => Yii::t('app', 'Описание'),
136   - 'contractual' => Yii::t('app', 'Договорной'),
137   - 'file' => Yii::t('app', 'Присоединить файл'),
138   - 'specializationInput' => Yii::t('app', 'Специализации'),
139   - 'paymentInput' => Yii::t('app', 'Способ оплаты'),
  128 + 'project_id' => Yii::t('app', 'Project ID'),
  129 + 'user_id' => Yii::t('app', 'User ID'),
  130 + 'name' => Yii::t('app', 'Название'),
  131 + 'link' => Yii::t('app', 'URL'),
  132 + 'project_pid' => Yii::t('app', 'Родительский проект'),
  133 + 'date_add' => Yii::t('app', 'Дата добавления'),
  134 + 'date_end' => Yii::t('app', 'Дата окончания'),
  135 + 'user_add_id' => Yii::t('app', 'User Add ID'),
  136 + 'view_count' => Yii::t('app', 'Количество просмотров'),
  137 + 'budget' => Yii::t('app', 'Бюджет'),
  138 + 'city' => Yii::t('app', 'Город'),
  139 + 'street' => Yii::t('app', 'Улица'),
  140 + 'house' => Yii::t('app', 'Дом'),
  141 + 'payment_variant' => Yii::t('app', 'Варианты оплаты'),
  142 + 'deadline' => Yii::t('app', 'Срок выполнения'),
  143 + 'description' => Yii::t('app', 'Описание'),
  144 + 'contractual' => Yii::t('app', 'Договорной'),
  145 + 'file' => Yii::t('app', 'Присоединить файл'),
  146 + 'specializationInput' => Yii::t('app', 'Специализации'),
  147 + 'paymentInput' => Yii::t('app', 'Способ оплаты'),
140 148 'specializationString' => Yii::t('app', 'Специализации'),
141 149 ];
142 150 }
... ...
common/models/ProjectSearch.php
... ... @@ -22,7 +22,6 @@
22 22 [
23 23 [
24 24 'project_id',
25   - 'user_id',
26 25 'project_pid',
27 26 'user_add_id',
28 27 'payment_variant',
... ... @@ -90,10 +89,11 @@
90 89  
91 90 $query->joinWith('specializations');
92 91  
  92 + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
  93 +
93 94 // grid filtering conditions
94 95 $query->andFilterWhere([
95 96 'project_id' => $this->project_id,
96   - 'user_id' => $this->user_id,
97 97 'project_pid' => $this->project_pid,
98 98 'date_add' => $this->date_add,
99 99 'date_end' => $this->date_end,
... ...
common/models/TeamSearch.php
... ... @@ -30,7 +30,6 @@
30 30 [
31 31 [
32 32 'team_id',
33   - 'user_id',
34 33 'department_id',
35 34 'user_add_id',
36 35 'experience_from',
... ... @@ -105,6 +104,8 @@
105 104 return $dataProvider;
106 105 }
107 106  
  107 + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
  108 +
108 109 $query->joinWith(Department::tableName());
109 110  
110 111 $dataProvider->setSort([
... ... @@ -154,7 +155,6 @@
154 155 // grid filtering conditions
155 156 $query->andFilterWhere([
156 157 'team_id' => $this->team_id,
157   - 'user_id' => $this->user_id,
158 158 'department_id' => $this->department_id,
159 159 'date_add' => $this->date_add,
160 160 'user_add_id' => $this->user_add_id,
... ...
common/models/User.php
... ... @@ -343,21 +343,21 @@
343 343 return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]);
344 344 }
345 345  
346   -
347   - public function getPhones(){
348   - return Fields::getData($this->id, self::className(),'phone');
  346 + public function getPhones()
  347 + {
  348 + return Fields::getData($this->id, self::className(), 'phone');
349 349 }
350 350  
351   -
352   - public function getSite(){
353   - return Fields::getData($this->id, self::className(),'site');
  351 + public function getSite()
  352 + {
  353 + return Fields::getData($this->id, self::className(), 'site');
354 354 }
355 355  
356   - public function getAddress(){
357   - return $this->userInfo->country.', '.$this->userInfo->city.', '.$this->companyInfo->street.', '.$this->companyInfo->house;
  356 + public function getAddress()
  357 + {
  358 + return $this->userInfo->country . ', ' . $this->userInfo->city . ', ' . $this->companyInfo->street . ', ' . $this->companyInfo->house;
358 359 }
359 360  
360   -
361 361 public function getLiveTime()
362 362 {
363 363 $now = new \DateTime('now');
... ... @@ -416,4 +416,24 @@
416 416 $this->specializationInput = $value;
417 417 }
418 418  
  419 + public function getPortfolios()
  420 + {
  421 + return $this->hasMany(Portfolio::className(), [ 'user_id' => 'id' ]);
  422 + }
  423 +
  424 + public function getProjects()
  425 + {
  426 + return $this->hasMany(Project::className(), [ 'user_id' => 'id' ]);
  427 + }
  428 +
  429 + public function getTeams()
  430 + {
  431 + return $this->hasMany(Team::className(), [ 'user_id' => 'id' ]);
  432 + }
  433 +
  434 + public function getVacancies()
  435 + {
  436 + return $this->hasMany(Vacancy::className(), [ 'user_id' => 'id' ]);
  437 + }
  438 +
419 439 }
... ...
common/models/VacancySearch.php
1 1 <?php
2 2  
3   -namespace common\models;
  3 + namespace common\models;
4 4  
5   -use Yii;
6   -use yii\base\Model;
7   -use yii\data\ActiveDataProvider;
8   -use common\models\Vacancy;
  5 + use Yii;
  6 + use yii\base\Model;
  7 + use yii\data\ActiveDataProvider;
  8 + use common\models\Vacancy;
9 9  
10   -/**
11   - * VacancySearch represents the model behind the search form about `common\models\Vacancy`.
12   - */
13   -class VacancySearch extends Vacancy
14   -{
15 10 /**
16   - * @inheritdoc
  11 + * VacancySearch represents the model behind the search form about `common\models\Vacancy`.
17 12 */
18   - public function rules()
  13 + class VacancySearch extends Vacancy
19 14 {
20   - return [
21   - [['vacancy_id', 'user_id', 'user_add_id', 'view_count'], 'integer'],
22   - [['name', 'link', 'date_add', 'user_name', 'city', 'description'], 'safe'],
23   - ];
24   - }
25 15  
26   - /**
27   - * @inheritdoc
28   - */
29   - public function scenarios()
30   - {
31   - // bypass scenarios() implementation in the parent class
32   - return Model::scenarios();
33   - }
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public function rules()
  20 + {
  21 + return [
  22 + [
  23 + [
  24 + 'vacancy_id',
  25 + 'user_add_id',
  26 + 'view_count',
  27 + ],
  28 + 'integer',
  29 + ],
  30 + [
  31 + [
  32 + 'name',
  33 + 'link',
  34 + 'date_add',
  35 + 'user_name',
  36 + 'city',
  37 + 'description',
  38 + ],
  39 + 'safe',
  40 + ],
  41 + ];
  42 + }
34 43  
35   - /**
36   - * Creates data provider instance with search query applied
37   - *
38   - * @param array $params
39   - *
40   - * @return ActiveDataProvider
41   - */
42   - public function search($params)
43   - {
44   - $query = Vacancy::find();
  44 + /**
  45 + * @inheritdoc
  46 + */
  47 + public function scenarios()
  48 + {
  49 + // bypass scenarios() implementation in the parent class
  50 + return Model::scenarios();
  51 + }
45 52  
46   - // add conditions that should always apply here
  53 + /**
  54 + * Creates data provider instance with search query applied
  55 + *
  56 + * @param array $params
  57 + *
  58 + * @return ActiveDataProvider
  59 + */
  60 + public function search($params)
  61 + {
  62 + $query = Vacancy::find();
47 63  
48   - $dataProvider = new ActiveDataProvider([
49   - 'query' => $query,
50   - ]);
  64 + // add conditions that should always apply here
51 65  
52   - $this->load($params);
  66 + $dataProvider = new ActiveDataProvider([
  67 + 'query' => $query,
  68 + ]);
53 69  
54   - if (!$this->validate()) {
55   - // uncomment the following line if you do not want to return any records when validation fails
56   - // $query->where('0=1');
57   - return $dataProvider;
58   - }
  70 + $this->load($params);
59 71  
60   - // grid filtering conditions
61   - $query->andFilterWhere([
62   - 'vacancy_id' => $this->vacancy_id,
63   - 'user_id' => $this->user_id,
64   - 'date_add' => $this->date_add,
65   - 'user_add_id' => $this->user_add_id,
66   - 'view_count' => $this->view_count,
67   - ]);
  72 + if(!$this->validate()) {
  73 + // uncomment the following line if you do not want to return any records when validation fails
  74 + // $query->where('0=1');
  75 + return $dataProvider;
  76 + }
68 77  
69   - $query->andFilterWhere(['like', 'name', $this->name])
70   - ->andFilterWhere(['like', 'link', $this->link])
71   - ->andFilterWhere(['like', 'user_name', $this->user_name])
72   - ->andFilterWhere(['like', 'city', $this->city])
73   - ->andFilterWhere(['like', 'description', $this->description]);
  78 + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]);
74 79  
75   - return $dataProvider;
  80 + // grid filtering conditions
  81 + $query->andFilterWhere([
  82 + 'vacancy_id' => $this->vacancy_id,
  83 + 'date_add' => $this->date_add,
  84 + 'user_add_id' => $this->user_add_id,
  85 + 'view_count' => $this->view_count,
  86 + ]);
  87 +
  88 + $query->andFilterWhere([
  89 + 'like',
  90 + 'name',
  91 + $this->name,
  92 + ])
  93 + ->andFilterWhere([
  94 + 'like',
  95 + 'link',
  96 + $this->link,
  97 + ])
  98 + ->andFilterWhere([
  99 + 'like',
  100 + 'user_name',
  101 + $this->user_name,
  102 + ])
  103 + ->andFilterWhere([
  104 + 'like',
  105 + 'city',
  106 + $this->city,
  107 + ])
  108 + ->andFilterWhere([
  109 + 'like',
  110 + 'description',
  111 + $this->description,
  112 + ]);
  113 +
  114 + return $dataProvider;
  115 + }
76 116 }
77   -}
... ...
frontend/controllers/AccountsController.php
... ... @@ -29,6 +29,8 @@
29 29 use common\models\User;
30 30 use common\models\UserInfo;
31 31  
  32 + use yii\base\ErrorException;
  33 + use yii\db\ActiveRecord;
32 34 use yii\filters\AccessControl;
33 35 use yii\filters\VerbFilter;
34 36 use yii\web\Controller;
... ... @@ -42,6 +44,8 @@
42 44  
43 45 public $layout = 'admin';
44 46  
  47 + public $defaultAction = 'general';
  48 +
45 49 public function behaviors()
46 50 {
47 51 return [
... ... @@ -68,6 +72,16 @@
68 72 ];
69 73 }
70 74  
  75 + /**
  76 + * Page of additional skills, consist:
  77 + *
  78 + * * working with programs;
  79 + * * education;
  80 + * * own developments and patents;
  81 + * * courses and trainings;
  82 + *
  83 + * @return string
  84 + */
71 85 public function actionAddSkills()
72 86 {
73 87 $user = \Yii::$app->user->identity;
... ... @@ -77,6 +91,11 @@
77 91 return $this->render('add-skills', [ 'user' => $user ]);
78 92 }
79 93  
  94 + /**
  95 + * Page of blog grid view
  96 + *
  97 + * @return string
  98 + */
80 99 public function actionBlog()
81 100 {
82 101 $searchModel = new BlogSearch();
... ... @@ -88,6 +107,11 @@
88 107 ]);
89 108 }
90 109  
  110 + /**
  111 + * Page of creating one record of blog.
  112 + *
  113 + * @return string|\yii\web\Response Page html / Redirect
  114 + */
91 115 public function actionBlogCreate()
92 116 {
93 117 $blog = new Blog();
... ... @@ -102,9 +126,23 @@
102 126 }
103 127 }
104 128  
  129 + /**
  130 + * Page of editting one User's record of blog.
  131 + *
  132 + * @param integer $id ID of User's record
  133 + *
  134 + * @return string|\yii\web\Response Page html / Redirect
  135 + * @throws NotFoundHttpException if not found or someone else's post
  136 + */
105 137 public function actionBlogUpdate($id)
106 138 {
107   - $blog = Blog::findOne($id);
  139 + $user = \Yii::$app->user->identity;
  140 + $blog = $user->getBlog()
  141 + ->where([ 'blog_id' => $id ])
  142 + ->one();
  143 + if(!$blog instanceof ActiveRecord) {
  144 + throw new NotFoundHttpException('Запись не найдена');
  145 + }
108 146 $post = \Yii::$app->request->post();
109 147 if($blog->load($post) && $blog->save()) {
110 148 return $this->redirect('blog');
... ... @@ -113,52 +151,40 @@
113 151 }
114 152 }
115 153  
  154 + /**
  155 + * Delete User's blog record
  156 + *
  157 + * @param $id ID of User's record
  158 + *
  159 + * @return \yii\web\Response Redirect
  160 + * @throws NotFoundHttpException
  161 + */
116 162 public function actionBlogDelete($id)
117 163 {
118   - Blog::findOne($id)
119   - ->delete();
120   - $this->redirect('blog');
121   - }
122   -
123   - public function actionBookmarks()
124   - {
125   - return $this->render('bookmarks');
126   - }
127   -
128   - public function actionCabinet()
129   - {
130   -
131   - $user = $this->findUser(Yii::$app->user->identity->id);
132   -
133   - $langs = Language::getActiveLanguages();
134   -
135   - if($user->load(Yii::$app->request->post()) && $user->save()) {
136   - $user->userInfo->load(Yii::$app->request->post());
137   - $user->userInfo->save();
138   - Fields::saveFieldData(Yii::$app->request->post('Fields'), $user->id, $user::className(), 'ru');
139   - return $this->render('cabinet', [
140   - 'user' => $user,
141   - 'user_info' => $user->userInfo,
142   - 'langs' => $langs,
143   - ]);
144   -
145   - } else {
146   -
147   - return $this->render('cabinet', [
148   - 'user' => $user,
149   - 'user_info' => $user->userInfo,
150   - 'langs' => $langs,
151   - ]);
152   -
  164 + $user = \Yii::$app->user->identity;
  165 + $blog = $user->getBlog()
  166 + ->where([ 'blog_id' => $id ])
  167 + ->one();
  168 + if(!$blog instanceof ActiveRecord) {
  169 + throw new NotFoundHttpException('Запись не найдена');
153 170 }
154   -
  171 + $blog->delete();
  172 + return $this->redirect('blog');
155 173 }
156 174  
  175 + /**
  176 + * Page of contacts. Consist:
  177 + *
  178 + * * phones;
  179 + * * social pages;
  180 + * * sites;
  181 + *
  182 + * @return string page html
  183 + */
157 184 public function actionContacts()
158 185 {
159   - $user_info = UserInfo::find()
160   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
161   - ->one();
  186 + $user = \Yii::$app->user->identity;
  187 + $user_info = $user->userInfo;
162 188 if(empty( $user_info )) {
163 189 $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
164 190 }
... ... @@ -170,11 +196,15 @@
170 196 return $this->render('contacts', [ 'user_info' => $user_info ]);
171 197 }
172 198  
  199 + /**
  200 + * Page of description. Consist of information about User.
  201 + *
  202 + * @return string page html
  203 + */
173 204 public function actionDescription()
174 205 {
175   - $user_info = UserInfo::find()
176   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
177   - ->one();
  206 + $user = \Yii::$app->user->identity;
  207 + $user_info = $user->userInfo;
178 208 if(empty( $user_info )) {
179 209 $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
180 210 }
... ... @@ -186,11 +216,19 @@
186 216 return $this->render('description', [ 'user_info' => $user_info ]);
187 217 }
188 218  
  219 + /**
  220 + * Page of seniority. Consist:
  221 + *
  222 + * * current job;
  223 + * * year of the beginning of designing
  224 + * * previous jobs
  225 + *
  226 + * @return string page html
  227 + */
189 228 public function actionEmployment()
190 229 {
191   - $user_info = UserInfo::find()
192   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
193   - ->one();
  230 + $user = \Yii::$app->user->identity;
  231 + $user_info = $user->userInfo;
194 232 if(empty( $user_info )) {
195 233 $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
196 234 }
... ... @@ -215,10 +253,9 @@
215 253 }
216 254 }
217 255 } else {
218   - $job = Job::find()
219   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
220   - ->orderBy([ 'current' => SORT_DESC ])
221   - ->all();
  256 + $job = $user->getJobs()
  257 + ->orderBy([ 'current' => SORT_DESC ])
  258 + ->all();
222 259 if(empty( $job )) {
223 260 $job[] = new Job([
224 261 'user_id' => \Yii::$app->user->getId(),
... ... @@ -232,8 +269,9 @@
232 269 ]));
233 270 }
234 271 }
235   - return $this->render('employment', [ 'job' => $job,
236   - 'user_info' => $user_info,
  272 + return $this->render('employment', [
  273 + 'job' => $job,
  274 + 'user_info' => $user_info,
237 275 ]);
238 276 }
239 277  
... ... @@ -313,20 +351,51 @@
313 351 $this->redirect('gallery');
314 352 }
315 353  
  354 + /**
  355 + * Page of credentials. Consist:
  356 + * <ul>
  357 + * <li>
  358 + * Company info:
  359 + * <ul>
  360 + * <li>Company name</li>
  361 + * <li>Employees count</li>
  362 + * <li>Street</li>
  363 + * <li>House</li>
  364 + * </ul>
  365 + * </li>
  366 + * <li>
  367 + * User info:
  368 + * <ul>
  369 + * <li>User name</li>
  370 + * <li>User surname</li>
  371 + * <li>Email</li>
  372 + * </ul>
  373 + * </li>
  374 + * <li>
  375 + * Common info:
  376 + * <ul>
  377 + * <li>Status (free/busy)</li>
  378 + * <li>City</li>
  379 + * <li>Avatar</li>
  380 + * <li>Cover</li>
  381 + * <li>Membership</li>
  382 + * </ul>
  383 + * </li>
  384 + * </ul>
  385 + *
  386 + * @return string page html
  387 + */
316 388 public function actionGeneral()
317 389 {
318   - $user_info = UserInfo::find()
319   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
320   - ->one();
321   - $company_info = CompanyInfo::find()
322   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
323   - ->one();
  390 + $user = \Yii::$app->user->identity;
  391 + $user_info = $user->userInfo;
  392 + $company_info = $user->companyInfo;
324 393 $user = \Yii::$app->user->identity;
325 394 if(empty( $user_info )) {
326   - $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
  395 + $user_info = new UserInfo([ 'user_id' => $user->id ]);
327 396 }
328 397 if(empty( $company_info )) {
329   - $company_info = new CompanyInfo([ 'user_id' => \Yii::$app->user->getId() ]);
  398 + $company_info = new CompanyInfo([ 'user_id' => $user->id ]);
330 399 }
331 400 $post = \Yii::$app->request->post();
332 401 if(!empty( $post )) {
... ... @@ -394,7 +463,13 @@
394 463  
395 464 public function actionPortfolioUpdate($id)
396 465 {
397   - $portfolio = Portfolio::findOne($id);
  466 + $user = \Yii::$app->user->identity;
  467 + $portfolio = $user->getPortfolios()
  468 + ->where([ 'portfolio_id' => $id ])
  469 + ->one();
  470 + if(!$portfolio instanceof ActiveRecord) {
  471 + throw new NotFoundHttpException('Запись не найдена');
  472 + }
398 473 $specialization = Specialization::find()
399 474 ->select([
400 475 'specialization_name',
... ... @@ -424,8 +499,14 @@
424 499  
425 500 public function actionPortfolioDelete($id)
426 501 {
427   - Portfolio::findOne($id)
428   - ->delete();
  502 + $user = \Yii::$app->user->identity;
  503 + $portfolio = $user->getPortfolios()
  504 + ->where([ 'portfolio_id' => $id ])
  505 + ->one();
  506 + if(!$portfolio instanceof ActiveRecord) {
  507 + throw new NotFoundHttpException('Запись не найдена');
  508 + }
  509 + $portfolio->delete();
429 510 $this->redirect('portfolio');
430 511 }
431 512  
... ... @@ -510,7 +591,13 @@
510 591  
511 592 public function actionProjectsUpdate($id)
512 593 {
513   - $project = Project::findOne($id);
  594 + $user = \Yii::$app->user->identity;
  595 + $project = $user->getProjects()
  596 + ->where([ 'project_id' => $id ])
  597 + ->one();
  598 + if(!$project instanceof ActiveRecord) {
  599 + throw new NotFoundHttpException('Запись не найдена');
  600 + }
514 601 $specialization = Specialization::find()
515 602 ->select([
516 603 'specialization_name',
... ... @@ -527,19 +614,18 @@
527 614 ->indexBy('payment_id')
528 615 ->asArray()
529 616 ->column();
530   - $projects = Project::find()
531   - ->select([
532   - 'name',
533   - 'project_id',
534   - ])
535   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
536   - ->andWhere([
537   - 'not',
538   - [ 'project_id' => $project->project_id ],
539   - ])
540   - ->indexBy('project_id')
541   - ->asArray()
542   - ->column();
  617 + $projects = $user->getProjects()
  618 + ->select([
  619 + 'name',
  620 + 'project_id',
  621 + ])
  622 + ->andWhere([
  623 + 'not',
  624 + [ 'project_id' => $project->project_id ],
  625 + ])
  626 + ->indexBy('project_id')
  627 + ->asArray()
  628 + ->column();
543 629 $post = \Yii::$app->request->post();
544 630 if(!empty( $post )) {
545 631 $project->load($post);
... ... @@ -566,13 +652,6 @@
566 652 foreach($project->paymentInput as $one_payment) {
567 653 $project->link('payments', Payment::findOne($one_payment));
568 654 }
569   - return $this->render('_projects_form', [
570   - 'project' => $project,
571   - 'specialization' => $specialization,
572   - 'payment' => $payment,
573   - 'projects' => $projects,
574   - ]);
575   - //return $this->redirect('projects');
576 655 }
577 656 }
578 657 return $this->render('_projects_form', [
... ... @@ -585,17 +664,21 @@
585 664  
586 665 public function actionProjectsDelete($id)
587 666 {
588   - Project::findOne($id)
589   - ->delete();
  667 + $user = \Yii::$app->user->identity;
  668 + $project = $user->getProjects()
  669 + ->where([ 'project_id' => $id ])
  670 + ->one();
  671 + if(!$project instanceof ActiveRecord) {
  672 + throw new NotFoundHttpException('Запись не найдена');
  673 + }
  674 + $project->delete();
590 675 $this->redirect('projects');
591 676 }
592 677  
593 678 public function actionService()
594 679 {
595 680 $user = \Yii::$app->user->identity;
596   - $user_info = UserInfo::find()
597   - ->where([ 'user_id' => \Yii::$app->user->getId() ])
598   - ->one();
  681 + $user_info = $user->userInfo;
599 682 if(empty( $user_info )) {
600 683 $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
601 684 }
... ... @@ -722,7 +805,13 @@
722 805  
723 806 public function actionTeamUpdate($id)
724 807 {
725   - $team = Team::findOne($id);
  808 + $user = \Yii::$app->user->identity;
  809 + $team = $user->getTeams()
  810 + ->where([ 'team_id' => $id ])
  811 + ->one();
  812 + if(!$team instanceof ActiveRecord) {
  813 + throw new NotFoundHttpException('Запись не найдена');
  814 + }
726 815 $department = Department::find()
727 816 ->select([
728 817 'name',
... ... @@ -753,8 +842,15 @@
753 842  
754 843 public function actionTeamDelete($id)
755 844 {
756   - Team::findOne($id)
757   - ->delete();
  845 + $user = \Yii::$app->user->identity;
  846 + $team = $user->getTeams()
  847 + ->where([ 'team_id' => $id ])
  848 + ->one();
  849 + if(!$team instanceof ActiveRecord) {
  850 + throw new NotFoundHttpException('Запись не найдена');
  851 +
  852 + }
  853 + $team->delete();
758 854 $this->redirect('team');
759 855 }
760 856  
... ... @@ -805,7 +901,13 @@
805 901  
806 902 public function actionVacancyUpdate($id)
807 903 {
808   - $vacancy = Vacancy::findOne($id);
  904 + $user = \Yii::$app->user->identity;
  905 + $vacancy = $user->getVacancies()
  906 + ->where([ 'vacancy_id' => $id ])
  907 + ->one();
  908 + if(!$vacancy instanceof ActiveRecord) {
  909 + throw new NotFoundHttpException('Запись не найдена');
  910 + }
809 911 $employment = Employment::find()
810 912 ->select([
811 913 'name',
... ... @@ -839,8 +941,15 @@
839 941  
840 942 public function actionVacancyDelete($id)
841 943 {
842   - Vacancy::findOne($id)
843   - ->delete();
  944 + $user = \Yii::$app->user->identity;
  945 + $vacancy = $user->getVacancies()
  946 + ->where([ 'vacancy_id' => $id ])
  947 + ->one();
  948 + if(!$vacancy instanceof ActiveRecord) {
  949 + throw new NotFoundHttpException('Запись не найдена');
  950 +
  951 + }
  952 + $vacancy->delete();
844 953 $this->redirect('vacancy');
845 954 }
846 955  
... ...
frontend/views/site/error.php
1   -<h1>404</h1>
2 1 \ No newline at end of file
  2 +<?php
  3 + /**
  4 + * @var string $name
  5 + * @var string $message
  6 + * @var Exception $exception
  7 + */
  8 +
  9 + use yii\base\Exception;
  10 +
  11 + echo $name . ':' . $message;
  12 +?>
... ...