public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->title = ucfirst($this->title);
     $user_interest = new UsersInterests();
     $user_interest->user_id = Yii::$app->user->id;
     if (!($interest = Interests::findOne([Interests::FIELD_TITLE => $this->title]))) {
         $interest = new Interests();
         $interest->title = $this->title;
         $interest->save();
     }
     $user_interest->interest_id = $interest->interest_id;
     $user_interest->save();
     return true;
 }
 public function actionDeleteUserInterest($interest_id)
 {
     UsersInterests::deleteAll([UsersInterests::FIELD_INTEREST_ID => $interest_id, UsersInterests::FIELD_USER_ID => Yii::$app->user->id]);
     //        If interest don't assign to another user, remove it
     if (!UsersInterests::findAll([UsersInterests::FIELD_INTEREST_ID => $interest_id])) {
         Interests::deleteAll([Interests::FIELD_INTEREST_ID => $interest_id]);
     }
     Yii::$app->session->setFlash('success', 'Interest deleted successfully');
     return $this->redirect('personal-details');
 }
Example #3
0
 public function getInterests()
 {
     return $this->hasMany(UsersInterests::className(), [UsersInterests::FIELD_USER_ID => self::FIELD_USER_ID]);
 }
 public function haveInterestCurrentUser()
 {
     return UsersInterests::findOne([self::FIELD_USER_ID => Yii::$app->user->id, self::FIELD_INTEREST_ID => $this->interest_id]);
 }