예제 #1
0
 public static function isUserInGroup($userId, $groupId)
 {
     if (GroupUser::find(array("groupId", $groupId, "userId", $userId))->first() != null) {
         return true;
     }
     return false;
 }
예제 #2
0
 public function actionView($userId, $part = 'joins')
 {
     $user = User::get($userId);
     RAssert::not_null($user);
     $data = array('user' => $user, 'part' => $part);
     if (Rays::isLogin()) {
         $loginUser = Rays::user();
         $friend = new Friend();
         $friend->uid = Rays::user()->id;
         $friend->fid = $user->id;
         $data['canAdd'] = $loginUser->id != $user->id && !Friend::isFriend($loginUser->id, $userId);
         $data['canCancel'] = $loginUser->id != $user->id && !$data['canAdd'];
     }
     $page = $this->getPage("page");
     $pageSize = $this->getPageSize("pageSize", 10);
     $count = 0;
     switch ($part) {
         case 'joins':
             $pageSize = $this->getPageSize("pageSize", 5);
             $data['userGroup'] = GroupUser::getGroups(GroupUser::find("userId", $userId)->join("group")->order_desc("groupId")->range(($page - 1) * $pageSize, $pageSize));
             $count = User::countGroups($userId);
             break;
         case 'posts':
             $data['postTopics'] = Topic::find("userId", $userId)->join("group")->order_desc("id")->range(($page - 1) * $pageSize, $pageSize);
             $count = User::countPosts($userId);
             break;
         case 'likes':
             $data['likeTopics'] = RatingPlus::getUserPlusTopics($userId, ($page - 1) * $pageSize, $pageSize);
             $count = RatingPlus::countUserPostsPlus($userId);
             break;
         case 'profile':
             break;
         default:
             return;
     }
     if (Rays::isAjax()) {
         echo empty($data['userGroup']) ? 'nomore' : $this->renderPartial("_common._groups_list", ["groups" => $data['userGroup']], true);
         exit;
     }
     if ($part == "posts" || $part == "likes") {
         if ($count > $pageSize) {
             $pager = new RPager("page", $count, $pageSize, RHtml::siteUrl("user/view/" . $userId . "/" . $part), $page);
             $data['pager'] = $pager->showPager();
         }
     }
     if ($part == "joins") {
         $this->addCss('/public/css/group.css');
         $this->addJs('/public/js/masonry.pkgd.min.js');
     }
     //$this->addJs("/public/js/jquery.dotdotdot.min.js");
     $this->setHeaderTitle($user->name);
     $this->render('view', $data, false);
     // Need to be complete because the codes below will increase the counter every time this page is viewed
     $counter = new Counter();
     $counter->increaseCounter($user->id, User::ENTITY_TYPE);
 }
예제 #3
0
파일: Group.php 프로젝트: a4501150/FDUGroup
 public static function getMembers($groupId, $start = 0, $limit = 0, $orderBy = "", $order = 'DESC')
 {
     $query = GroupUser::find("groupId", $groupId);
     if ($orderBy != "") {
         $query = $order == "ASC" || $order == "asc" ? $query->order_asc($orderBy) : $query->order_desc($orderBy);
     }
     $groupUsers = $start != 0 || $limit != 0 ? $query->range($start, $limit) : $query->all();
     // todo get all members at a time
     $users = [];
     foreach ($groupUsers as $item) {
         $users[] = User::get($item->userId);
     }
     unset($groupUsers);
     return $users;
 }
예제 #4
0
 public function getFriendsToInvite($uid, $groupId, $start = 0, $limit = 0)
 {
     $groupUsers = GroupUser::find("groupId", $groupId)->all();
     $result = Friend::find("uid", $uid)->join("user");
     if ($groupUsers != null && !empty($groupUsers)) {
         $where = "[fid] not in(";
         $args = [];
         for ($count = count($groupUsers), $i = 0; $i < $count; $i++) {
             $where .= "?" . ($i < $count - 1 ? "," : "");
             $args[] = $groupUsers[$i]->userId;
         }
         unset($groupUsers);
         $where .= ")";
         $result = $result->where($where, $args);
     }
     return $limit != 0 || $start != 0 ? $result->range($start, $limit) : $result->all();
 }
예제 #5
0
 public function actionEdit($topicId)
 {
     $topic = Topic::get($topicId);
     if (Rays::isPost()) {
         $validation = new RValidation(array(array("field" => "title", "label" => "Title", "rules" => "trim|required"), array("field" => "post-content", "label" => "Content", "rules" => "trim|required")));
         $topic->title = $_POST['title'];
         $topic->content = RHtml::encode($_POST['post-content']);
         if ($validation->run()) {
             $topic->save();
             $this->flash("message", "Post " . $topic->title . " was updated successfully.");
             $this->redirectAction('post', 'view', $topic->id);
         } else {
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $group = Group::get($topic->groupId);
     $data = array("type" => "edit", "topic" => $topic, 'group' => $group, 'groupId' => $group->id);
     $data['groups'] = GroupUser::getGroups(GroupUser::find("userId", Rays::user()->id)->join("group")->order_desc("groupId")->all());
     $this->layout = 'user';
     $this->addCss('/public/css/post.css');
     $this->setHeaderTitle("Edit post: " . $topic->title);
     $this->render('edit', $data, false);
 }
예제 #6
0
 public function actionExit($groupId = null)
 {
     $groupUser = GroupUser::find(array("groupId", $groupId, "userId", Rays::user()->id))->first();
     $group = Group::get($groupId);
     if ($group == null) {
         $this->flash("error", "You are not the member of the group!");
     } else {
         if ($group->creator == $groupUser->userId) {
             // group creator cannot exit the group
             $this->flash("error", "You cannot exit group " . RHtml::linkAction('group', $group->name, 'detail', $group->id) . " , because you're the group creator!");
         } else {
             $groupUser->delete();
             $group->memberCount--;
             $group->save();
             $this->flash("message", "You have exited the group successfully.");
         }
     }
     $this->redirectAction('group', 'mygroups', Rays::user()->id);
 }