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); }
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); }
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); }
/** * 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); }
/** * 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); }