コード例 #1
0
 public function actionSend($type = 'private', $toUserId = null)
 {
     $types = array('system', 'user', 'private', 'group');
     RAssert::is_true(in_array($type, $types));
     $data = array('type' => $type);
     if ($toUserId != null) {
         $data['toUser'] = User::get($toUserId);
     }
     if (Rays::isPost()) {
         if (isset($_POST['new'])) {
             if (isset($_POST['receiverName'])) {
                 $data['sendForm'] = array('receiver' => $_POST['receiverName']);
             }
             $this->render('send', $data, false);
             return;
         }
         $form = $_POST;
         $config = array(array('field' => 'title', 'label' => 'Title', 'rules' => 'trim|required'), array('field' => 'msg-content', 'label' => 'Content', 'rules' => 'trim|required'), array('field' => 'receiver', 'label' => 'Receiver', 'rules' => 'required'), array('field' => 'type', 'label' => 'Message type', 'rules' => 'trim|required'));
         $validation = new RValidation($config);
         if ($validation->run()) {
             $receiver = User::find("name", $_POST['receiver'])->first();
             if ($receiver == null) {
                 $this->flash("error", "No such user.");
             } else {
                 $senderId = 0;
                 if (isset($_POST['sender'])) {
                     //mainly for group and system message
                     $senderId = $_POST['sender'];
                 } else {
                     $senderId = Rays::user()->id;
                 }
                 $title = isset($_POST['title']) ? trim($_POST['title']) : "";
                 $msgContent = RHtml::encode($_POST['msg-content']);
                 $message = Message::sendMessage($_POST['type'], $senderId, $receiver->id, $title, $msgContent, null, 1);
                 if (isset($message->id) && $message->id != '') {
                     $this->flash("message", "Send message successfully.");
                     $this->redirectAction('message', 'view');
                     return;
                 } else {
                     $this->flash("message", "Send message failed.");
                 }
             }
         }
         $data['sendForm'] = $form;
         if ($validation->getErrors() != '') {
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $this->render('send', $data, false);
 }
コード例 #2
0
ファイル: AdsController.php プロジェクト: a4501150/FDUGroup
 public function actionEdit($adId, $type)
 {
     $ad = Ads::get($adId);
     RAssert::not_null($ad);
     $data = ['ad' => $ad, 'edit' => true, 'type' => $type];
     if (Rays::isPost()) {
         $rules = array(array('field' => 'ads-title', 'label' => 'Ads title', 'rules' => 'trim|required|min_length[5]|max_length[255]'), array('field' => 'ads-content', 'label' => 'Ads content', 'rules' => 'required'), array('field' => 'paid-price', 'label' => 'Paid price', 'rules' => 'trim|required|number'));
         $validation = new RValidation($rules);
         if ($validation->run()) {
             $ad->title = $_POST['ads-title'];
             $ad->content = RHtml::encode($_POST['ads-content']);
             $ad->save();
             $this->flash('message', 'Your ads was edited successfully.');
             $redirect = null;
             switch ($type) {
                 case Ads::APPROVED:
                     $redirect = 'published';
                     break;
                 case Ads::APPLYING:
                     $redirect = 'applying';
                     break;
                 case Ads::BLOCKED:
                     $redirect = 'blocked';
                     break;
             }
             $this->redirectAction('ads', 'view', $redirect);
         } else {
             $data['applyForm'] = $_POST;
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $this->setHeaderTitle("Edit Advertisement");
     $this->render('apply', $data, false);
 }
コード例 #3
0
ファイル: UserController.php プロジェクト: a4501150/FDUGroup
 /**
  * Apply for VIP
  * by songrenchu
  */
 public function actionApplyVIP()
 {
     $this->setHeaderTitle('VIP application');
     $this->layout = 'user';
     $user = Rays::user();
     $data = array('user' => $user);
     if (Rays::isPost()) {
         $config = [['field' => 'content', 'label' => 'Statement', 'rules' => 'trim|required|min_length[10]|max_length[1000]']];
         $validation = new RValidation($config);
         if ($validation->run()) {
             $censor = new Censor();
             $censor->applyVIPApplication($user->id, RHtml::encode($_POST['content']));
             $this->flash('message', 'VIP application sent.');
             $this->redirectAction('user', 'profile');
         } else {
             $errors = $validation->getErrors();
             $data['validation_errors'] = $errors;
             $data['editForm'] = $_POST;
             $this->render('apply_vip', $data, false);
         }
         return;
     }
     $censor = new Censor();
     if ($censor->applyVIPExist($user->id) != null) {
         $this->flash('error', 'Your previous VIP application is under review!');
         $this->redirectAction('user', 'profile');
         return;
     }
     $this->render('apply_vip', $data, false);
 }
コード例 #4
0
ファイル: GroupController.php プロジェクト: a4501150/FDUGroup
 /**
  * Edit group information
  * @param $groupId
  */
 public function actionEdit($groupId)
 {
     $group = Group::get($groupId);
     RAssert::not_null($group);
     if (Rays::isPost()) {
         $rules = array(array('field' => 'group-name', 'label' => 'Group name', 'rules' => 'trim|required|min_length[5]|max_length[50]'), array('field' => 'category', 'label' => 'Category', 'rules' => 'required'), array('field' => 'intro', 'label' => 'Group Introduction', 'rules' => 'trim|required|min_length[10]'));
         $validation = new RValidation($rules);
         if ($validation->run()) {
             // succeed
             $group->name = $_POST['group-name'];
             $group->categoryId = $_POST['category'];
             $group->intro = RHtml::encode($_POST['intro']);
             $group->save();
             // upload group picture
             $file = $_FILES['group_picture'];
             if (isset($file) && $file['name'] != '') {
                 if (($result = $group->uploadPicture('group_picture')) != true) {
                     $this->flash('error', $result);
                 }
             }
             $this->flash("message", "Edit group successfully.");
             $this->redirectAction('group', 'detail', $group->id);
             return;
         } else {
             // validation failed
             $data['editForm'] = $_POST;
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $this->setHeaderTitle("Edit my group");
     $data = array('categories' => Category::find()->all(), 'groupId' => $groupId, 'group' => $group);
     $this->render('edit', $data, false);
 }
コード例 #5
0
ファイル: PostController.php プロジェクト: a4501150/FDUGroup
 public function actionComment($topicId)
 {
     $topic = Topic::get($topicId);
     if (Rays::isPost()) {
         $validation = new RValidation(array(array('field' => 'content', 'label' => 'Content', 'rules' => 'trim|required')));
         if (!$validation->run()) {
             $this->flash("error", "Comment content cannot be empty!");
             $this->redirectAction('post', 'view', $topicId);
         }
         $form = $_POST;
         $topic->commentCount++;
         $topic->lastCommentTime = date('Y-m-d H:i:s');
         $topic->save();
         $user = Rays::user();
         $comment = new Comment();
         $comment->topicId = $topicId;
         $comment->userId = $user->id;
         $comment->createdTime = date('Y-m-d H:i:s');
         $comment->content = $form["content"];
         if (isset($form['replyTo'])) {
             $comment->pid = (int) $form['replyTo'];
         } else {
             $comment->pid = 0;
         }
         $comment->save();
         $cid = $comment->id;
         if (isset($form['replyTo'])) {
             $exactComment = Comment::get($form['exactReplyTo']);
             Message::sendMessage('user', $user->id, $exactComment->userId, 'New reply', $user->name . ' has replied to your comment ' . RHtml::linkAction('post', $topic->title, 'view', $topic->id . '?reply=' . $cid));
         } else {
             if ($topic->userId !== $user->id) {
                 //send message to topic author
                 Message::sendMessage('user', $user->id, $topic->userId, 'New Comment', $user->name . ' has replied to your topic ' . RHtml::linkAction('post', $topic->title, 'view', $topic->id . '?reply=' . $cid));
             }
         }
     }
     $this->redirectAction('post', 'view', $topicId);
 }