public function actionIndex()
 {
     $id = Yii::$app->user->getId();
     $uid = new components\UserId($id);
     $loggedUser = UserService::getUserById($uid);
     if (Yii::$app->request->isPost || Yii::$app->request->isPjax) {
         if (!is_null(Yii::$app->request->post('type'))) {
             switch (Yii::$app->request->post('type')) {
                 case 'newpost':
                     $post_id = PostsService::createPost($uid, Yii::$app->request->post('inputText'));
                     $pliks = $_FILES['kawaiiPicture']['tmp_name'];
                     if ($pliks[0] != '') {
                         PhotoService::addPostAttachmentPhoto($pliks, $post_id);
                     }
                     EventService::createEvent(components\EEvent::POST_CREATE(), $uid);
                     break;
                 case 'newcomment':
                     PostsService::createComment(PostsService::getPostById(Yii::$app->request->post('post_id')), Yii::$app->request->post('inputText'));
                     break;
                 case 'like':
                     $like_form_post_id = Yii::$app->request->post('post_id');
                     $like_form_score_elem = Yii::$app->request->post('score_elem');
                     $like_form_user_id = Yii::$app->request->post('user_id');
                     $score = new components\Score(EScoreType::like(), null, EScoreElem::$like_form_score_elem(), $like_form_post_id, new components\UserId($like_form_user_id));
                     $existing_scores = ScoreService::getScoresByElem(EScoreElem::post(), $like_form_post_id);
                     $found = false;
                     foreach ($existing_scores as $var) {
                         $user = $var->getPublisher();
                         $userId = $user->getId();
                         if ((int) $like_form_user_id == $userId && (int) $like_form_post_id == $var->getElementId()) {
                             $found = true;
                             $found_score_id = $var->getScoreId();
                         }
                     }
                     if (!$found) {
                         ScoreService::addScore($score);
                     } else {
                         ScoreService::revokeScore($found_score_id);
                     }
                     break;
                 case 'delete_post':
                     $rep_post_id = Yii::$app->request->post('post_id');
                     PostsService::deletePost(PostsService::getPostById($rep_post_id));
                     break;
                 case 'delete_comment':
                     $rep_comment_id = Yii::$app->request->post('comment_id');
                     PostsService::deleteComment(PostsService::getCommentById($rep_comment_id));
                     break;
             }
         }
     }
     //$posts = PostsService::getFriendsPosts($uid);
     $posts = PostsService::getFollowersPosts($uid);
     $args = ['posts' => $posts, 'loggedUser' => $loggedUser];
     return $this->render('index', $args);
 }
 public static function getFollowersPosts(UserId $uid, $lastid = null)
 {
     $arr = [];
     $followersList = RelationService::getUsersWhoIFollow($uid);
     for ($i = 0; $i < count($followersList); $i++) {
         $followersList[$i] = new UserId($followersList[$i]);
     }
     $followersList[] = UserService::getUserById($uid);
     $arr = self::getPostsOrderById($followersList, $lastid);
     return $arr;
 }
 public function getUserData()
 {
     $id = Yii::$app->user->getId();
     $uid = new UserId($id);
     $user = UserService::getUserById($uid);
     $this->view->params['userInfo'] = $user;
     ////////////////////////////////////////////////////// request service
     $notification = RequestService::getMyRequests($uid);
     $this->view->params['notification_data'] = $notification;
     $this->view->params['notification_count'] = count($notification);
 }
 private static function createReqObj($user1_id, $date, $req_id, $req_type)
 {
     $u1uid = new UserId($user1_id);
     $u1 = UserService::getUserById($u1uid);
     $uname = $u1->getUsername();
     $fullname = $u1->getFullName();
     return ['type' => $req_type, 'req_id' => $req_id, 'senderUserName' => $uname, 'date' => $date, 'fullname' => $fullname];
 }
예제 #5
0
 public function getUser()
 {
     return UserService::getUserById($this);
 }
 /**
  * Returns an array of friends of User1
  * @param int $user1_id User's ID
  * @return int[] Array of User's ID
  */
 public static function getFriendsList(UserId $user1id)
 {
     $user1_id = $user1id->getId();
     $arr = [];
     $rel = Relationship::find()->where(['user1_id' => $user1_id, 'relation_type' => RelationType::Friend])->all();
     $rel2 = Relationship::find()->where(['user2_id' => $user1_id, 'relation_type' => RelationType::Friend])->all();
     foreach ($rel as $var) {
         $u2id = new UserId($var->user2_id);
         $arr[] = UserService::getUserById($u2id);
     }
     foreach ($rel2 as $var) {
         $u1id = new UserId($var->user1_id);
         $arr[] = UserService::getUserById($u1id);
     }
     return $arr;
 }