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); }
/** * View groups of the login user */ public function actionMyGroups() { $page = $this->getPage("page"); $pageSize = $this->getPageSize("pagesize", 10); $groups = GroupUser::getGroups(GroupUser::find("userId", Rays::user()->id)->join("group")->order_desc("groupId")->range(($page - 1) * $pageSize, $pageSize)); if (Rays::isAjax()) { echo empty($groups) ? 'nomore' : $this->renderPartial("_groups_list", ["groups" => $groups, 'exitGroup' => true], true); exit; } $this->layout = 'user'; $this->addCss('/public/css/group.css'); $this->addJs('/public/js/masonry.pkgd.min.js'); $this->setHeaderTitle("My Groups"); $this->render("my_groups", ['groups' => $groups, 'exitGroup' => true], false); }
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); }