示例#1
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;
     }
 }
示例#2
0
 public function actionDelete($topicId)
 {
     $topic = Topic::get($topicId);
     if ($topic === null) {
         $this->flash("message", "No such topic!");
     } else {
         $topic->delete();
         $this->flash("message", "Post " . $topic->title . " was deleted.");
     }
     if ($url = Rays::getParam("returnUrl", null)) {
         $this->redirect($url);
     } else {
         $this->redirect(Rays::referrerUri());
     }
 }
示例#3
0
 function lists()
 {
     $t = new Topic();
     $t->get();
     //datamapper的json扩展真是强大
     echo $t->all_to_json();
 }