/**
  * Finds the Number of Notifications that should be displayed to a follower. Both for APIs and Users.
  * @return int
  */
 public function getFollowingAPIsUsersNotifNum()
 {
     $myId = \Yii::$app->user->id;
     $followUserApis = FollowUserApi::findAll(['follower' => $myId]);
     $notifNum = 0;
     foreach ($followUserApis as $followUserApi) {
         if ($followUserApi->changed_name) {
             $notifNum++;
         }
         if ($followUserApi->changed_descr) {
             $notifNum++;
         }
         if ($followUserApi->changed_version) {
             $notifNum++;
         }
         if ($followUserApi->changed_upvotes) {
             $notifNum++;
         }
         if ($followUserApi->changed_downvotes) {
             $notifNum++;
         }
         if ($followUserApi->changed_proposed) {
             $notifNum++;
         }
         if ($followUserApi->changed_published) {
             $notifNum++;
         }
         if ($followUserApi->changed_privacy) {
             $notifNum++;
         }
         if ($followUserApi->changed_objects_number) {
             $notifNum++;
         }
     }
     $followUserUsers = FollowUserUser::findAll(['follower' => $myId]);
     foreach ($followUserUsers as $followUserUser) {
         if ($followUserUser->changed_photo) {
             $notifNum++;
         }
         if ($followUserUser->changed_linkedin) {
             $notifNum++;
         }
         if ($followUserUser->changed_github) {
             $notifNum++;
         }
         if ($followUserUser->created_api) {
             $notifNum++;
         }
         if ($followUserUser->changed_upvotes_apis) {
             $notifNum++;
         }
         if ($followUserUser->changed_downvotes_apis) {
             $notifNum++;
         }
     }
     return $notifNum;
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFollowUserApis()
 {
     return $this->hasMany(FollowUserApi::className(), ['api' => 'id']);
 }
Example #3
0
 /**
  * Unfollow an API.
  * If deletion is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUnfollow($id)
 {
     $myId = \Yii::$app->user->id;
     FollowUserApi::deleteAll(['follower' => $myId, 'api' => $id]);
     return $this->redirect(['view', 'id' => $id, 'followed' => false]);
 }
Example #4
0
 /**
  * Clears Up all API-related notifications
  * @param integer $id
  */
 public function clearAllAPIChangesIFollow($id)
 {
     $query = FollowUserApi::find(['follower' => $id, ['or', ['changed_name' => 1, 'changed_descr' => 1, ['not', 'changed_upvotes', 0], ['not', 'changed_downvotes', 0], 'changed_proposed' => 1, 'changed_published' => 1, 'changed_privacy' => 1, ['not', 'changed_objects_number', 0]]]])->all();
     foreach ($query as $fUA) {
         $fUA->changed_name = 0;
         $fUA->changed_upvotes = 0;
         $fUA->changed_downvotes = 0;
         $fUA->changed_proposed = 0;
         $fUA->changed_published = 0;
         $fUA->changed_privacy = 0;
         $fUA->changed_objects_number = 0;
         $fUA->update();
     }
 }