diff --git a/common/models/User.php b/common/models/User.php
index 58b3888..bc43e82 100755
--- a/common/models/User.php
+++ b/common/models/User.php
@@ -17,44 +17,44 @@
/**
* User model
- * @property integer $id
- * @property string $username
- * @property string $password_hash
- * @property string $password_reset_token
- * @property string $email
- * @property string $auth_key
- * @property integer $status
- * @property integer $created_at
- * @property integer $updated_at
- * @property string $password write-only password
- * @property string $type
- * @property UserInfo $userInfo
- * @property string $userName
- * @property array[] $roles
- * @property CompanyInfo $companyInfo
- * @property array[] $phones
- * @property array[] $site
- * @property string $address
- * @property string $liveTime
- * @property Payment[] $payments
- * @property integer[] $paymentInput
- * @property Specialization[] $specializations
- * @property integer[] $specializationInput
- * @property Blog[] $blog
- * @property Job[] $jobs
- * @property Job $currentJob
- * @property Portfolio[] $portfolios
- * @property Project[] $projects
- * @property Team[] $teams
- * @property Vacancy[] $vacancies
- * @property Gallery[] $galleries
+ * @property integer $id
+ * @property string $username
+ * @property string $password_hash
+ * @property string $password_reset_token
+ * @property string $email
+ * @property string $auth_key
+ * @property integer $status
+ * @property integer $created_at
+ * @property integer $updated_at
+ * @property string $password write-only password
+ * @property string $type
+ * @property UserInfo $userInfo
+ * @property string $userName
+ * @property array[] $roles
+ * @property CompanyInfo $companyInfo
+ * @property array[] $phones
+ * @property array[] $site
+ * @property string $address
+ * @property string $liveTime
+ * @property Payment[] $payments
+ * @property integer[] $paymentInput
+ * @property Specialization[] $specializations
+ * @property integer[] $specializationInput
+ * @property Blog[] $blog
+ * @property Job[] $jobs
+ * @property Job $currentJob
+ * @property Portfolio[] $portfolios
+ * @property Project[] $projects
+ * @property Team[] $teams
+ * @property Vacancy[] $vacancies
+ * @property Gallery[] $galleries
* @property UserInfo|CompanyInfo $owner
- * @property string $name
- * @property Comment[] $comments
- * @property Rating[] $commentRating
- * @property int $ratingPG
- * @property string $lastVisit
- * @property string $link
+ * @property string $name
+ * @property Comment[] $comments
+ * @property Rating[] $commentRating
+ * @property int $ratingPG
+ * @property string $lastVisit
+ * @property string $link
*/
class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
{
@@ -587,7 +587,6 @@
/**
* Return all user's galleries
- *
* @return ActiveQuery
*/
public function getGalleries()
@@ -597,7 +596,6 @@
/**
* Return company info or user info according to user type
- *
* @return ActiveQuery
*/
public function getOwner()
@@ -611,7 +609,6 @@
/**
* Return company name or user firstname and lastname according to user type
- *
* @return string
*/
public function getName()
@@ -625,7 +622,6 @@
/**
* Return all comments to user
- *
* @return ActiveQuery
*/
public function getComments()
@@ -640,7 +636,6 @@
/**
* Return all ratings to user
- *
* @return ActiveQuery
*/
public function getCommentRating()
@@ -655,7 +650,6 @@
/**
* Return user's rating
* Available only for PostgreSQL
- *
* @return int
* @throws InvalidConfigException
*/
@@ -665,7 +659,7 @@
throw new InvalidConfigException('This method is available only in PostgreSQL');
}
return $this->getCommentRating()
- ->select(['rating' => 'ROUND(SUM("rating"."value")/COUNT("rating"."rating_id")::numeric, 2)'])
+ ->select([ 'rating' => 'ROUND(SUM("rating"."value")/COUNT("rating"."rating_id")::numeric, 2)' ])
->andWhere([
'not',
[ 'rating.value' => NULL ],
@@ -675,11 +669,8 @@
/**
* Recalculate rating and write it to db.
- *
* Only for PostgreSQL
- *
* @see \common\models\User::getRatingPG()
- *
* @throws InvalidConfigException
*/
public function updateRating()
@@ -697,15 +688,40 @@
/**
* Return link to user personal page according to user type
- *
* @return string
*/
public function getLink($page = 'common')
{
if($this->type == 2) {
- return Url::to(['company/'.$page, 'company_id' => $this->id]);
+ return Url::to([
+ 'company/' . $page,
+ 'company_id' => $this->id,
+ ]);
} else {
- return Url::to(['performer/'.$page, 'performer_id' => $this->id]);
+ return Url::to([
+ 'performer/' . $page,
+ 'performer_id' => $this->id,
+ ]);
+ }
+ }
+
+ public function getIsBookmarked($type = Bookmark::TYPE_PERFORMER)
+ {
+ if(!empty( \Yii::$app->user->identity )) {
+ if(!empty( $this->hasOne(Bookmark::className(), [ 'model_id' => 'id' ])
+ ->andWhere([
+ 'model' => $this->className(),
+ 'user_id' => \Yii::$app->user->getId(),
+ 'type' => $type,
+ ])
+ ->one() )
+ ) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
}
}
diff --git a/frontend/controllers/BookmarksController.php b/frontend/controllers/BookmarksController.php
index dd6feec..01947e0 100644
--- a/frontend/controllers/BookmarksController.php
+++ b/frontend/controllers/BookmarksController.php
@@ -1,8 +1,12 @@
AccessControl::className(),
'rules' => [
[
- //'actions' => ['cabinet','change-password', 'bookmarks', 'projects'],
'allow' => true,
'roles' => [ '@' ],
],
],
],
+ 'verbs' => [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'add-performer' => [ 'post' ],
+ 'add-customer' => [ 'post' ],
+ 'add-project' => [ 'post' ],
+ 'add-vacancy' => [ 'post' ],
+ 'remove-performer' => [ 'post' ],
+ 'remove-customer' => [ 'post' ],
+ 'remove-project' => [ 'post' ],
+ 'remove-vacancy' => [ 'post' ],
+ ],
+ ],
];
}
@@ -31,4 +47,96 @@
return $this->render('bookmarks');
}
+ public function actionAddPerformer()
+ {
+ $response = \Yii::$app->response;
+ $response->format = Response::FORMAT_JSON;
+ $model_id = \Yii::$app->request->post('id');
+ if(empty( $model_id )) {
+ return [ 'error' => 'Ошибка добавления. Отсутствует id исполнителя' ];
+ }
+ $user = User::findOne($model_id);
+ if(empty( $user )) {
+ return [ 'error' => 'Ошибка добавления. Исполнитель не найден.' ];
+ }
+ $model = $user->className();
+ $user_id = \Yii::$app->user->getId();
+ $type = Bookmark::TYPE_PERFORMER;
+ if(Bookmark::findOne([
+ 'model' => $model,
+ 'model_id' => $model_id,
+ 'user_id' => $user_id,
+ 'type' => $type,
+ ])
+ ) {
+ return [ 'error' => 'Ошибка добавления. Исполнитель уже добавлен.' ];
+ }
+ $bookmark = new Bookmark([
+ 'model' => $model,
+ 'model_id' => $model_id,
+ 'user_id' => $user_id,
+ 'type' => $type,
+ ]);
+ if($bookmark->save()) {
+ $result = $this->renderAjax('//site/forms-modal-fav', [
+ 'message' => 'Добавлено в закладки.',
+ 'image' => $user->userInfo->image,
+ 'name' => $user->name,
+ ]);
+ return [ 'result' => $result ];
+ } else {
+ return [ 'error' => 'Ошибка добавления.' ];
+ }
+ }
+
+ public function actionAddCustomer($id)
+ {
+
+ }
+
+ public function actionAddProject($id)
+ {
+
+ }
+
+ public function actionAddVacancy($id)
+ {
+
+ }
+
+ public function actionRemovePerformer()
+ {
+ $response = \Yii::$app->response;
+ $response->format = Response::FORMAT_JSON;
+ $model_id = \Yii::$app->request->post('id');
+ if(empty( $model_id )) {
+ return [ 'error' => 'Ошибка удаления. Отсутствует id исполнителя' ];
+ }
+ $user = User::findOne($model_id);
+ if(empty( $user )) {
+ return [ 'error' => 'Ошибка добавления. Исполнитель не найден.' ];
+ }
+ $model = $user->className();
+ $user_id = \Yii::$app->user->getId();
+ $type = Bookmark::TYPE_PERFORMER;
+ /**
+ * @var Bookmark $bookmark
+ */
+ $bookmark = Bookmark::findOne([
+ 'model' => $model,
+ 'model_id' => $model_id,
+ 'user_id' => $user_id,
+ 'type' => $type,
+ ]);
+ if(!empty($bookmark)) {
+ if($bookmark->delete()) {
+ return ['message' => 'Закладка успешно удалена'];
+ } else {
+ return ['error' => 'Ошибка при удалении'];
+ }
+ } else {
+ return ['error' => 'Закладка не найдена'];
+ }
+ }
+
}
diff --git a/frontend/views/layouts/company.php b/frontend/views/layouts/company.php
index bfc3205..3e771cb 100755
--- a/frontend/views/layouts/company.php
+++ b/frontend/views/layouts/company.php
@@ -11,7 +11,6 @@
$this->beginContent('@app/views/layouts/main.php');
?>
-