コード例 #1
0
ファイル: Comment.php プロジェクト: rjha/sc
 function execute($params)
 {
     $action = $params->action;
     $comment = $params->comment;
     if (empty($action) || empty($comment)) {
         $response = array("code" => 500, "message" => "Bad input: missing required parameters.");
         return $response;
     }
     $commentDao = new \com\indigloo\sc\dao\Comment();
     $code = 200;
     switch ($action) {
         case UIConstants::ADD_COMMENT:
             $loginId = $params->loginId;
             $name = $params->name;
             $ownerId = $params->ownerId;
             $postId = $params->postId;
             $title = $params->title;
             $comment = $params->comment;
             $commentDao->create($loginId, $name, $ownerId, $postId, $title, $comment);
             $message = sprintf("success. your comment added to item %s ", $title);
             break;
         default:
             break;
     }
     $response = array("code" => $code, "message" => $message);
     return $response;
 }
コード例 #2
0
ファイル: comment.php プロジェクト: rjha/sc
 $fhandler->addRule('comment', 'Comment', array('required' => 1));
 $fhandler->addRule('post_id', 'post id', array('required' => 1));
 $fhandler->addRule('owner_id', 'owner id', array('required' => 1));
 $fhandler->addRule('post_title', 'post title', array('required' => 1));
 $fvalues = $fhandler->getValues();
 // UI checks
 if ($fhandler->hasErrors()) {
     throw new UIException($fhandler->getErrors());
 }
 //trim comments to 512 chars
 $fvalues["comment"] = substr($fvalues["comment"], 0, 512);
 //use login is required for comments
 if (Login::hasSession()) {
     $gSessionLogin = \com\indigloo\sc\auth\Login::getLoginInSession();
     $commentDao = new com\indigloo\sc\dao\Comment();
     $commentDao->create($gSessionLogin->id, $gSessionLogin->name, $fvalues['owner_id'], $fvalues['post_id'], $fvalues['post_title'], $fvalues['comment']);
     // go back to comment form
     header("Location: " . $fUrl);
 } else {
     //create data object representing pending session action
     $actionObj = new \stdClass();
     $actionObj->endPoint = "/qa/form/comment.php";
     $params = new \stdClass();
     $params->ownerId = $fvalues['owner_id'];
     $params->postId = $fvalues['post_id'];
     $params->title = $fvalues['post_title'];
     $params->comment = $fvalues['comment'];
     $params->action = UIConstants::ADD_COMMENT;
     $actionObj->params = $params;
     //base64 encode to transfer as payload in URL
     $gSessionAction = base64_encode(json_encode($actionObj));