コード例 #1
0
 /**
  * Action to adds a comment to a post
  *
  * This method should only be called via HTTP POST.
  *
  * The user of the comment is taken from the {@link BaseController::currentUser}
  * property.
  * The expected HTTP parameters are:
  * <ul>
  * <li>id: Id of the post (via HTTP POST)</li>
  * <li>content: Content of the comment (via HTTP POST)</li>
  * </ul>
  *
  * The views are:
  * <ul>
  * <li>posts/view?id=post: If comment was successfully added of, 
  * or if it was not validated (via redirect). Includes these view variables:</li>
  * <ul>   
  *  <li>errors (flash): Array including per-field validation errors</li>
  *  <li>comment (flash): The current Comment instance, empty or being added</li>   
  * </ul>
  * </ul>
  *
  * @return void
  */
 public function add()
 {
     if (!isset($this->currentUser)) {
         throw new Exception("Not in session. Adding posts requires login");
     }
     if (isset($_POST["id"])) {
         // reaching via HTTP Post...
         // Get the Post object from the database
         $postid = $_POST["id"];
         $post = $this->postmapper->findById($postid);
         // Does the post exist?
         if ($post == NULL) {
             throw new Exception("no such post with id: " . $postid);
         }
         // Create and populate the Comment object
         $comment = new Comment();
         $comment->setContent($_POST["content"]);
         $comment->setAuthor($this->currentUser);
         $comment->setPost($post);
         try {
             // validate Comment object
             $comment->checkIsValidForCreate();
             // if it fails, ValidationException
             // save the Comment object into the database
             $this->commentmapper->save($comment);
             // POST-REDIRECT-GET
             // Everything OK, we will redirect the user to the list of posts
             // We want to see a message after redirection, so we establish
             // a "flash" message (which is simply a Session variable) to be
             // get in the view after redirection.
             $this->view->setFlash("Comment \"" . $post->getTitle() . "\" successfully added.");
             // perform the redirection. More or less:
             // header("Location: index.php?controller=posts&action=view&id=$postid")
             // die();
             $this->view->redirect("posts", "view", "id=" . $post->getId());
         } catch (ValidationException $ex) {
             $errors = $ex->getErrors();
             // Go back to the form to show errors.
             // However, the form is not in a single page (comments/add)
             // It is in the View Post page.
             // We will save errors as a "flash" variable (third parameter true)
             // and redirect the user to the referring page
             // (the View post page)
             $this->view->setVariable("comment", $comment, true);
             $this->view->setVariable("errors", $errors, true);
             $this->view->redirect("posts", "view", "id=" . $post->getId());
         }
     } else {
         throw new Exception("No such post id");
     }
 }
コード例 #2
0
ファイル: PostsController.php プロジェクト: ragomez/abp2015
 /**
  * Action to delete a post
  * 
  * This action should only be called via HTTP POST
  * 
  * The expected HTTP parameters are:
  * <ul>
  * <li>id: Id of the post (via HTTP POST)</li>   
  * </ul>
  * 
  * The views are:
  * <ul>
  * <li>posts/index: If post was successfully deleted (via redirect)</li>
  * </ul>
  * @throws Exception if no id was provided
  * @throws Exception if no user is in session
  * @throws Exception if there is not any post with the provided id
  * @throws Exception if the author of the post to be deleted is not the current user
  * @return void
  */
 public function delete()
 {
     if (!isset($_POST["id"])) {
         throw new Exception("id is mandatory");
     }
     if (!isset($this->currentUser)) {
         throw new Exception("Not in session. Editing posts requires login");
     }
     // Get the Post object from the database
     $postid = $_REQUEST["id"];
     $post = $this->postMapper->findById($postid);
     // Does the post exist?
     if ($post == NULL) {
         throw new Exception("no such post with id: " . $postid);
     }
     // Check if the Post author is the currentUser (in Session)
     if ($post->getAuthor() != $this->currentUser) {
         throw new Exception("Post author is not the logged user");
     }
     // Delete the Post object from the database
     $this->postMapper->delete($post);
     // POST-REDIRECT-GET
     // Everything OK, we will redirect the user to the list of posts
     // We want to see a message after redirection, so we establish
     // a "flash" message (which is simply a Session variable) to be
     // get in the view after redirection.
     $this->view->setFlash("Post \"" . $post->getTitle() . "\" successfully deleted.");
     // perform the redirection. More or less:
     // header("Location: index.php?controller=posts&action=index")
     // die();
     $this->view->redirect("posts", "index");
 }
コード例 #3
0
ファイル: PageMapper.php プロジェクト: cyberwani/wpmvc
 protected function wpmvcAddData($item)
 {
     $item = parent::wpmvcAddData($item);
     $item->url = get_permalink($item->ID);
     $item->attachments = $this->getAttachments($item);
     $item->meta = $this->getMeta($item->ID);
     $item->author = $this->getAuthor($item);
     return $item;
 }
コード例 #4
0
ファイル: PinchoController.php プロジェクト: ragomez/abp2015
 public function meterVoto()
 {
     //esto lo que hace es votar a los pinchos del jurado popular
     if (isset($_POST["submit"])) {
         $user = new Pincho();
         $user->setPuntosPopular(1);
     }
     $this->pinchoMapper->votar($_POST["idPincho"]);
     $this->view->redirect("Pincho", "listarTodosPinchos");
 }
コード例 #5
0
ファイル: results.php プロジェクト: ogontaro/elites-output
<?php

require_once 'functions.php';
require_once "post_mapper.php";
require_once "post.php";
$post_mapper = new PostMapper(connectDb());
$posts = $post_mapper->all();
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>投稿内容</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
          integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div class="container">
    <h1>投稿された内容</h1>
    <?php 
if (count($posts)) {
    ?>
        <ul>
            <?php 
    foreach ($posts as $post) {
        ?>
                <li>
                    <div class="post-header">
                        <?php 
コード例 #6
0
ファイル: example1.php プロジェクト: TheProjecter/skeleton
<?php

include '../config.php';
include 'orm_config.php';
#include('PostMapper.php');
#include('UserMapper.php');
#include('DomainObjects.php');
$mapper = new PostMapper($db);
$post = new Post();
$post->title = 'New Title';
$post->content = 'New content...';
$post->author_id = 1;
//$mapper->insert($post);
$post->id = 2;
$mapper->update($post);
$post = $mapper->find(1);
$post->title = 'Updated Title';
$post->content = 'Updated content...';
$mapper->update($post);
$posts = $mapper->find();
$userMapper = new UserMapper($db);
$user = $userMapper->find(1);
p($user);
?>

<?php 
foreach ($posts as $post) {
    ?>
<h1><?php 
    echo $post->title;
    ?>
コード例 #7
0
 /**
  * @return Post
  */
 public function createPost()
 {
     $post_mapper = new PostMapper(connectDb());
     return $post_mapper->create($this->name, $this->impression, $this->image_type, $this->image_file);
 }
コード例 #8
0
ファイル: image.php プロジェクト: ogontaro/elites-output
<?php

require_once 'functions.php';
require_once 'post_mapper.php';
require_once 'post.php';
if (isset($_GET['id'])) {
    $post_mapper = new PostMapper(connectDb());
    $post = $post_mapper->findByID($_GET['id']);
    if ($post == false || is_null($post->getImageFile())) {
        header("HTTP/1.1 404 Not Found");
        echo "Image Not Found";
    } else {
        header("Content-type: " . $post->getImageType());
        echo $post->getImageFile();
    }
} else {
    header("HTTP/1.1 404 Not Found");
    echo "Image Not Found";
}