public function getPageSize($key, $default = BaseController::DEFAULT_PAGE_SIZE) { $size = Rays::getParam($key, $default); if (!is_numeric($size) || $size < 1) { $size = DEFAULT_PAGE_SIZE; } return $size; }
public function actionRead($msgId = null) { $msgId = Rays::getParam("messageId", $msgId); $message = Message::get($msgId); if (Rays::isAjax()) { if (Rays::user()->id != $message->receiverId) { echo "Sorry. You don't have the right to mark the message read."; exit; } $message->status = Message::STATUS_READ; $message->save(); echo 'success'; exit; } RAssert::not_null($message); if (Rays::user()->id != $message->receiverId) { $this->flash("error", "Sorry. You don't have the right to mark the message read."); } $message->status = Message::STATUS_READ; $message->save(); $this->redirect(Rays::referrerUri()); }
public function actionAdmin() { $this->setHeaderTitle('Advertisement'); $this->layout = 'admin'; if (Rays::isPost()) { if (isset($_POST['checked_ads'])) { $selected = $_POST['checked_ads']; if (is_array($selected)) { $operation = $_POST['operation_type']; foreach ($selected as $id) { $ad = Ads::get($id); if ($ad == null) { break; } switch ($operation) { case "block": $ad->status = Ads::BLOCKED; $ad->save(); break; case "active": $ad->status = Ads::APPROVED; $ad->save(); break; } } } } } $curPage = $this->getPage('page'); $pageSize = $this->getPageSize("pagesize", 10); $filterStr = Rays::getParam('search', null); $query = Ads::find()->join("publisher"); if ($name = trim($filterStr)) { $names = preg_split("/[\\s]+/", $name); foreach ($names as $key) { $query = $query->like("name", $key); } } $count = $query->count(); $ads = $query->order_desc("id")->range($pageSize * ($curPage - 1), $pageSize); $data = ['ads' => $ads, 'count' => $count]; $url = RHtml::siteUrl('ads/admin'); if ($filterStr != null) { $url .= '?search=' . urlencode(trim($filterStr)); } $pager = new RPager('page', $count, $pageSize, $url, $curPage); $data['pager'] = $pager->showPager(); $this->render('admin', $data, false); }
echo '<span class="glyphicon glyphicon-chevron-up"></span>'; } else { echo '<span class="glyphicon glyphicon-chevron-down"></span>'; } } ?> </a> </th> <th><a class="highlight" href="<?php echo RHtml::siteUrl("group/admin?orderBy=likes&&order=" . $order); ?> "> Likes <?php if (Rays::getParam("orderBy", null) == "likes") { if (Rays::getParam("order", "asc") == "asc") { echo '<span class="glyphicon glyphicon-chevron-up"></span>'; } else { echo '<span class="glyphicon glyphicon-chevron-down"></span>'; } } ?> </a> </th> </tr> </thead> <tbody> <?php // That's bad to load user names and category names for each group // Need to be fixed. It's better to add "join" support in the database models foreach ($groups as $group) {
/** * Recommend groups to users * @access: administrator */ public function actionRecommend() { if (Rays::isAjax()) { $action = Rays::getParam('action', null); if ($action) { $name = Rays::getParam('name', null); $query = Group::find(); $queryUser = User::find(); $like = array(); if (isset($name) && $name != '') { $names = explode(' ', $name); foreach ($names as $val) { $query = $query->like("name", $val); $queryUser = $queryUser->like("name", $val); } } switch ($action) { case "search_groups": $groups = $query->range(0, 20); $results = array(); foreach ($groups as $item) { $result['id'] = $item->id; $result['name'] = $item->name; $result['link'] = RHtml::siteUrl('group/detail/' . $item->id); $result['picture'] = $item->picture; $results[] = $result; } echo json_encode($results); exit; break; case "search_users": $users = $queryUser->range(0, 20); $results = array(); foreach ($users as $item) { $result['id'] = $item->id; $result['name'] = $item->name; $result['link'] = RHtml::siteUrl('user/view/' . $item->id); $result['picture'] = $item->picture; $results[] = $result; } echo json_encode($results); exit; break; default: } } } if (Rays::isPost()) { if (isset($_POST['selected_recommend_groups']) && isset($_POST['selected_recommend_users'])) { $groups = $_POST['selected_recommend_groups']; $users = $_POST['selected_recommend_users']; $words = $_POST['recommend-words']; Group::recommendGroups($groups, $users, $words); $this->flash('message', 'Send group recommendations successfully.'); } } $this->layout = 'admin'; $data = array(); $this->setHeaderTitle("Groups recommendation"); $this->render('recommend', $data, false); }
public function actionAdmin() { $this->layout = 'admin'; $this->setHeaderTitle('User administration'); if (Rays::isPost()) { if (isset($_POST['checked_users'])) { $selected = $_POST['checked_users']; if (is_array($selected)) { $operation = $_POST['operation_type']; foreach ($selected as $id) { switch ($operation) { case "block": User::blockUser($id); break; case "active": User::activateUser($id); break; } } } } } $searchStr = Rays::getParam('search', null); $query = User::find(); if ($name = trim($searchStr)) { $names = preg_split("/[\\s]+/", $name); foreach ($names as $key) { $query = $query->like("name", $key); } } $page = $this->getPage("page"); $pageSize = $this->getPageSize("pagesize", 10); $count = $query->count(); $users = $query->order_desc("id")->order_desc("id")->range($pageSize * ($page - 1), $pageSize); $url = RHtml::siteUrl('user/admin' . ($searchStr != null ? '?search=' . urlencode(trim($searchStr)) : "")); if ($searchStr != null) { $url .= '?search=' . urlencode(trim($searchStr)); } $pager = new RPager('page', $count, $pageSize, $url, $page); $data = ['count' => $count, 'users' => $users, 'pager' => $pager->showPager()]; $this->render('admin', $data, false); }
/** * Topics administration */ public function actionAdmin() { $this->layout = 'admin'; $data = array(); // delete request if (Rays::app()->request()->isPostRequest()) { if (isset($_POST['checked_topics'])) { $checkedTopics = $_POST['checked_topics']; foreach ($checkedTopics as $item) { if (!is_numeric($item)) { return; } else { $topic = new Topic(); $topic->id = $item; $topic->delete(); } } } } $curPage = $this->getPage("page"); $pageSize = $this->getPageSize("pagesize"); $count = Topic::find()->count(); $data['count'] = $count; $query = Topic::find()->join("user")->join("group")->join("rating")->join("counter"); $orderBy = Rays::getParam("orderBy", "id"); $order = Rays::getParam("order", "desc"); switch ($orderBy) { case "id": $query = $query->order($order, "[Topic.id]"); break; case "likes": $query = $query->order($order, "[RatingStatistic.value]"); break; case "views": $query = $query->order($order, "[Counter.totalCount]"); break; case "createTime": $query = $query->order($order, "[Topic.id]"); break; default: $query = $query->order_desc("id"); } $posts = $query->range(($curPage - 1) * $pageSize, $pageSize); $data['topics'] = $posts; $pager = new RPager('page', $count, $pageSize, RHtml::siteUrl("post/admin?orderBy={$orderBy}&&order={$order}"), $curPage); $pager = $pager->showPager(); $data['pager'] = $pager; $this->render('admin', $data, false); }