Example #1
0
 /**
  * View all groups under the category
  * @param string $categoryId
  */
 public function actionGroups($categoryId = '')
 {
     RAssert::not_empty($categoryId);
     $category = Category::get($categoryId);
     RAssert::not_null($category);
     $page = $this->getPage("page", 1);
     $pageSize = $this->getPageSize("pagesize", 10);
     $groups = Group::getGroupsOfCategory($categoryId, ($page - 1) * $pageSize, $pageSize);
     if (Rays::isAjax()) {
         if (!count($groups)) {
             echo 'nomore';
         } else {
             $this->renderPartial("_groups_list", array("groups" => $groups), false);
         }
         exit;
     }
     $this->addCss("/public/css/group.css");
     $this->addJs("/public/js/masonry.pkgd.min.js");
     $this->render('groups', ['category' => $category, 'groups' => $groups], false);
 }
Example #2
0
 public function actionException(Exception $e)
 {
     if (Rays::isAjax()) {
         print $e;
         exit;
     }
     $this->layout = 'error';
     switch ($e->getCode()) {
         case 404:
             $this->render('404', ['message' => $e->getMessage()]);
             Rays::log('Page not found! (' . $e->getMessage() . ')', "warning", "system");
             break;
         default:
             if (Rays::app()->isDebug()) {
                 print $e;
             } else {
                 $this->render("exception", ['code' => $e->getCode(), 'message' => $e->getMessage()]);
             }
     }
     Rays::logger()->flush();
 }
Example #3
0
 public function actionPlus()
 {
     if (Rays::isAjax()) {
         $result = ["result" => false];
         if (isset($_POST['plusId']) && isset($_POST['plusType'])) {
             if (is_numeric($_POST['plusId'])) {
                 $plusId = $_POST['plusId'];
                 $userId = 0;
                 if (Rays::isLogin()) {
                     $userId = Rays::user()->id;
                 }
                 $host = Rays::app()->request()->getUserHostAddress();
                 switch ($_POST['plusType']) {
                     case Topic::ENTITY_TYPE:
                         if (Topic::get($plusId) !== null) {
                             $plus = new RatingPlus(Topic::ENTITY_TYPE, $plusId, $userId, $host);
                             if ($plus->rate()) {
                                 $result = ["result" => true, "counter" => $plus->getCounter()->value];
                             }
                         }
                         break;
                     case Group::ENTITY_TYPE:
                         if (Group::get($plusId) !== null) {
                             $plus = new RatingPlus(Group::ENTITY_TYPE, $plusId, $userId, $host);
                             if ($plus->rate()) {
                                 $result = ["result" => true, "counter" => $plus->getCounter()->value];
                             }
                         }
                         break;
                 }
             }
         }
         echo json_encode($result);
         exit;
     }
 }
Example #4
0
 public function actionDelete($msgId)
 {
     $message = Message::get($msgId);
     if (Rays::isAjax() && $message != null) {
         if (Rays::user()->id != $message->receiverId) {
             echo "Sorry. You don't have the right to delete the message.";
             exit;
         }
         $message->delete();
         echo 'success';
         exit;
     }
     RAssert::not_null($message);
     $user = Rays::user();
     if ($message->receiverId == $user->id || $user->isAdmin()) {
         $message->delete();
     }
     $this->redirect(Rays::referrerUri());
 }
Example #5
0
 public function actionHitAd()
 {
     if (Rays::isAjax()) {
         $adId = (int) $_POST['adId'];
         $ad = Ads::get($adId);
         if ($ad !== null) {
             (new Counter())->increaseCounter($adId, Ads::ENTITY_TYPE);
             //Ad访问计数器
             /** TODO 刷广告访问监测机制 */
             $user = User::get($ad->userId);
             if ($user !== null) {
                 $wallet = $user->getWallet();
                 //访问一次挣一元钱
                 $wallet->addMoney(1);
             }
         }
     }
 }
Example #6
0
 /**
  * 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);
 }
Example #7
0
 /**
  * User home page
  */
 public function actionHome()
 {
     $this->layout = 'user';
     $user = Rays::user();
     $data = array('user' => $user);
     $defaultSize = 10;
     $friends = Friend::find("uid", $user->id)->all();
     foreach ($friends as $friend) {
         $ids[] = $friend->fid;
     }
     $ids[] = $user->id;
     $query = Topic::find()->join("user")->join("group")->join("rating")->in("User.id", $ids)->order_desc("id");
     // ajax request
     // load more posts
     if (Rays::isAjax()) {
         $lastLoadedTime = @$_POST['lastLoadedTime'];
         $lastLoadedTime = $lastLoadedTime != '' ? $lastLoadedTime : null;
         $topics = $query->where("[createdTime] < ?", $lastLoadedTime)->range(0, $defaultSize);
         $result = array();
         if (count($topics) > 0) {
             $result['content'] = $this->renderPartial('_posts_list', array('topics' => $topics), true);
             $result['lastLoadTime'] = $topics[count($topics) - 1]->createdTime;
             echo json_encode($result);
         } else {
             echo json_encode(['content' => '']);
         }
         exit;
     }
     $data['topics'] = $query->range(0, $defaultSize);
     $this->setHeaderTitle($user->name);
     $this->addCss('/public/css/post.css');
     $this->render('home', $data, false);
 }