예제 #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);
 }
예제 #2
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());
 }
예제 #3
0
 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);
 }
예제 #4
0
 /**
  * Delete group
  * This action will delete all content related to the group, including topics, comments
  * that belong the group
  * @access group creator | administrator
  * @param $groupId
  */
 public function actionDelete($groupId)
 {
     $group = Group::get($groupId);
     RAssert::not_null($group);
     $userId = Rays::user()->id;
     if (Rays::user()->isAdmin() || $group->creator == $userId) {
         // Execute delete group transaction
         Group::deleteGroup($group);
         // Delete group's picture from local file system
         if (isset($group->picture) && $group->picture != '') {
             $picture = Rays::app()->getBaseDir() . "/../" . $group->picture;
             if (file_exists($picture)) {
                 unlink($picture);
             }
         }
         $this->flash("message", "Group " . $group->name . " was deleted.");
         $this->redirectAction("group", "mygroups");
     } else {
         $this->flash("error", "Sorry. You don't have the right to delete the group!");
         $this->redirectAction('group', 'detail', $group->id);
     }
 }
예제 #5
0
 /**
  * Change user info action
  * @param null $userId
  */
 public function actionEdit($userId = null)
 {
     $userId = null === $userId ? Rays::user()->id : $userId;
     $user = User::get($userId);
     RAssert::not_null($user);
     if (Rays::user()->roleId != Role::ADMINISTRATOR_ID && Rays::user()->id != $userId) {
         $this->flash("error", "You don't have the right to change the user information!");
         $this->redirectAction('user', 'view', $userId);
     }
     $data = array('user' => $user);
     if (Rays::isPost()) {
         $config = array(array('field' => 'username', 'label' => 'User name', 'rules' => 'trim|required|min_length[5]|max_length[20]'));
         // if set password, then go changing password
         if (isset($_POST['password']) && $_POST['password'] != '') {
             array_push($config, array('field' => 'password', 'label' => 'New Password', 'rules' => 'trim|required|min_length[6]|max_length[20]'));
             array_push($config, array('field' => 'password-confirm', 'label' => 'New Password Confirm', 'rules' => 'trim|required|min_length[6]|max_length[20]|equals[password]'));
         }
         $validation = new RValidation($config);
         if ($validation->run()) {
             if (isset($_POST['password']) && $_POST['password'] != '') {
                 // set new password
                 $user->password = md5($_POST['password']);
             }
             $user->name = $_POST['username'];
             foreach (User::$mapping as $objCol => $dbCol) {
                 if (in_array($objCol, ["password", "email", "id", "roleId", "credit", "private"])) {
                     continue;
                 }
                 if (isset($_POST[$objCol])) {
                     $user->{$objCol} = $_POST[$objCol];
                 }
             }
             $user->save();
             $this->flash("message", "Update information successfully.");
             // if picture selected
             if (isset($_FILES['user_picture']) && $_FILES['user_picture']['name'] != '') {
                 $pictureName = "pic_u_" . $user->id . RUpload::get_extension($_FILES['user_picture']['name']);
                 $upload = new RUpload(["file_name" => $pictureName, "upload_path" => Rays::app()->getBaseDir() . "/../" . User::PICTURE_DIR]);
                 $upload->upload('user_picture');
                 if ($upload->error != '') {
                     $this->flash("error", $upload->error);
                 } else {
                     $user->picture = "files/images/users/" . $upload->file_name;
                     $user->save();
                     RImage::updateStyle($user->picture, User::getPicOptions());
                 }
             }
             if (Rays::user()->id == $user->id) {
                 $this->redirectAction("user", "profile");
             } else {
                 $this->redirectAction("user", "view", [$user->id, "profile"]);
             }
         } else {
             $errors = $validation->getErrors();
             $data['validation_errors'] = $errors;
             $data['editForm'] = $_POST;
         }
     }
     $this->layout = 'user';
     $this->setHeaderTitle("Edit profile - " . $user->name);
     $this->render('edit', $data, false);
 }