Exemplo n.º 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);
 }
Exemplo n.º 2
0
 public function actionView($type = 'published')
 {
     $userId = Rays::user()->id;
     RAssert::is_true($type != '' && in_array($type, ["blocked", 'published', 'applying']));
     if ($type === 'blocked') {
         $data['ads'] = Ads::find(["userId", $userId, "status", Ads::BLOCKED])->all();
         $data['type'] = Ads::BLOCKED;
     } else {
         if ($type === 'published') {
             $data['ads'] = Ads::find(["userId", $userId, "status", Ads::APPROVED])->all();
             $data['type'] = Ads::APPROVED;
         } else {
             $data['ads'] = Ads::find(["userId", $userId, "status", Ads::APPLYING])->all();
             $data['type'] = Ads::APPLYING;
         }
     }
     $this->setHeaderTitle('My Advertisements');
     $this->render('view', $data, false);
 }