Ejemplo n.º 1
0
 /**
  * @return array
  */
 public static function loadAll()
 {
     $dbWrapper = new DatabaseWrapper();
     $connection = $dbWrapper->getConnection();
     $query = "SELECT * FROM temos;";
     $temos = [];
     foreach ($connection->query($query) as $row) {
         $tema = new Tema($connection);
         $tema->setId($row['id']);
         $tema->setDate($row['subject_date']);
         $tema->setName($row['name']);
         $query = 'SELECT * FROM comments INNER JOIN temos ON comments.subjectId = ' . $row['id'] . " AND temos.id = " . $row['id'] . ";";
         $comments = [];
         foreach ($connection->query($query) as $i) {
             $comment = new Comment($connection);
             $comment->setId($i['id']);
             $comment->setsubjectId($i['subjectId']);
             $comment->setText($i['text']);
             $comment->setDate($i['date']);
             $comment->setAuthor($i['author']);
             $comments[] = $comment;
         }
         foreach ($comments as $comment) {
             $tema->setComments($comment);
         }
         $temos[] = $tema;
     }
     return $temos;
 }
Ejemplo n.º 2
0
 public function controlerJob($maincont)
 {
     if ($maincont->isLoggued()) {
         /*$_POST["author"]="gg42";
         		$_POST["body"]="move Ur body4242";
         		$_POST["published"]="1";
         		$_POST["postid"]="2";
         		$_POST["id"]=3;
         		
         		$_SESSION["backmod"]="comment";
         		$_SESSION["backact"]="admin";*/
         if (isset($_POST["id"])) {
             $p = new Comment($_POST["id"]);
             $p->setAuthor($_POST["author"]);
             $p->setBody($_POST["body"]);
             //$p->setHour(date("h:i:s"));
             //$p->setDate(date("Y-m-d"));
             $p->setPublished($_POST["published"]);
             $p->setPostid($_POST["postid"]);
         }
         $maincont->goModule("comment", "admin");
         //$maincont->goModule($_SESSION["backmod"],$_SESSION["backact"]);
     } else {
         $maincont->goModule("admin", "loginform");
     }
 }
function comment(array $articleLangs = array())
{
    $comment = new Comment();
    $comment->setAuthor(author('niko'));
    $comment->content = 'Booh.';
    $comment->setArticle(article($articleLangs));
    return $comment;
}
Ejemplo n.º 4
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");
     }
 }
Ejemplo n.º 5
0
 function executeInsertComment(sfWebRequest $request)
 {
     $name = $request->getParameter('author');
     $content = $request->getParameter('content');
     $article_id = $request->getParameter('article_id');
     $comment = new Comment();
     $comment->setAuthor($name);
     $comment->setContent($content);
     $comment->setArticleId($article_id);
     $comment->save();
     echo 'ok';
     $this->redirect('view/showComments?id=' . $article_id);
     //$this->redirect("view/ShowComments",$comment);
 }
Ejemplo n.º 6
0
 public function getAllBySubjectId($subId)
 {
     $query = "SELECT * FROM comments WHERE subjectId = {$subId}";
     $comments = [];
     foreach ($this->connection->query($query) as $row) {
         $comment = new Comment();
         $comment->setSubjectId($row['subjectId']);
         $comment->setDate($row['date']);
         $comment->setText($row['text']);
         $comment->setAuthor($row['author']);
         $comments[] = $comment;
     }
     return $comments;
 }
Ejemplo n.º 7
0
 public function controlerJob($maincont)
 {
     if (isset($_POST["author"])) {
         //print_r($_POST);
         $p = new Comment();
         $p->setAuthor($_POST["author"]);
         $p->setBody($_POST["body"]);
         $p->setHour(date("h:i:s"));
         $p->setDate(date("Y-m-d"));
         $p->setPublished("0");
         $p->setPostid($_POST["postid"]);
     }
     $maincont->goModule("home", "display");
 }
Ejemplo n.º 8
0
 /**
  * Metodo del controlador Comments cuya funcionalidad es insertar un comentario
  * en un post.
  * Verifica que el usuario ha iniciado sesion y que el post existe
  *
  * @throws Exception Si el usuario no inicio sesion
  * @return void
  */
 public function add()
 {
     if (!isset($this->currentUser)) {
         throw new Exception("Not in session. Adding comments requires login");
     }
     if (isset($_GET["id"])) {
         // reaching via HTTP Post...
         // Se obtiene el post de la BD
         $idPost = $_GET["id"];
         $post = $this->postDAO->findByIdPost($idPost);
         // Si no existe el post lanza una excepcion
         if ($post == NULL) {
             throw new Exception("no such post with id: " . $idPost);
         }
         // Crea el objeto Comment
         $comment = new Comment();
         $comment->setDate(date("Y-m-d H:i:s"));
         $comment->setContent($_POST["content"]);
         $comment->setAuthor($this->currentUser->getEmail());
         $comment->setIdPost($post->getIdPost());
         try {
             // Valida el comentario, si falla lanza una excepcion
             $comment->checkIsValidForCreate();
             // Guarda el comentario en la BD
             $this->commentDAO->save($comment);
             // Redirige al post
             $this->view->redirect("posts", "viewPosts", "id=" . $post->getIdPost());
         } catch (ValidationException $ex) {
             $errors = $ex->getErrors();
             $this->view->setVariable("comment", $comment, true);
             $this->view->setVariable("errors", $errors, true);
             $this->view->redirect("posts", "viewPosts", "id=" . $post->getIdPost());
         }
     } else {
         throw new Exception("No such post id");
     }
 }
Ejemplo n.º 9
0
<?php

namespace Akademija\ActiveRecord;

include_once 'Theme.php';
include_once 'Comment.php';
include_once 'dbConnection.php';
if (isset($_POST["themeId"])) {
    $db = new dbConnection('localhost', 'root', '', 'akademija-nd');
    $db = $db->connect();
    $themeId = (int) $_POST["themeId"];
    $theme = new Theme($db);
    $theme = $theme->load($themeId);
    $comment = new Comment($db);
    $comment->setThemeId($themeId);
    $comment->setDate(date("Y-m-d H:i:s"));
    $comment->setAuthor($_POST["author"]);
    $comment->setComment($_POST["comment"]);
    $theme->addComments($comment);
    echo "<h2>Komentaras pridetas!</h2>";
} else {
    echo "<h2>Klaida!</h2>";
}
//header( "Refresh:15; url=List.php", true, 303);
echo '<a href="List.php"><- Atgal</a>';
Ejemplo n.º 10
0
<?php

require_once 'Comment.php';
require_once '../databaseWrapper.php';
$dbWrapper = new DatabaseWrapper();
$connection = $dbWrapper->getConnection();
$ids = [];
foreach ($connection->query('SELECT id FROM temos') as $row) {
    $ids[] = $row['id'];
}
$text = "Lambada lambada lambada";
$comment = new Comment($connection);
$comment->setAuthor('Anonymous');
$comment->setSubjectID($ids[rand(0, sizeof($ids) - 1)]);
$comment->setText($text);
$comment->save();
header('Location:  Controller.php');
Ejemplo n.º 11
0
<?php

namespace sql_nd_3\DDD;

require_once "Comment.php";
require_once "CommentRepository.php";
require_once "TopicRepository.php";
$commentRepository = new CommentRepository();
$topicRepository = new TopicRepository();
$bla = "blablablabla";
$comment = new Comment();
$comment->setAuthor('Author' . rand(0, 1000));
$comment->setTopicID($topicRepository->getRandomId());
$comment->setComment(substr($bla, 0, rand(12, strlen($bla))));
$commentRepository->saveComment($comment);
echo "<div>" . $comment->getTopicID() . "</div>";
echo "<div>" . $comment->getAuthor() . "</div>";
echo "<div>" . $comment->getComment() . "</div>";
Ejemplo n.º 12
0
<?php

require_once '../entity/CommentRep.php';
require_once '../entity/ThemeRep.php';
if (isset($_GET['theme_id']) && is_numeric($_GET['theme_id'])) {
    $comment = new Comment();
    $comment->setDate((new DateTime('now'))->format('Y-m-d H:i:s'));
    $comment->setAuthor(isset($_GET['author']) ? $_GET['author'] : 'bet koks autorius');
    $comment->setComment(isset($_GET['comment']) ? $_GET['comment'] : 'bet koks komentaras');
    $comment->setThemeId($_GET['theme_id']);
    $themeRep = new ThemeRep();
    $theme = $themeRep->findById($_GET['theme_id']);
    if (empty($theme)) {
        echo 'Tema su id ' . $_GET['theme_id'] . ' neegzistuoja';
        return;
    }
    $themeRep->increaseCommentCount($theme);
    $commentRep = new CommentRep();
    $commentRep->save($comment);
    echo 'Komentaras pridetas.';
} else {
    echo 'Reikalingas temos id.';
}
CommentPeer::doDeleteAll();
ArticlePeer::doDeleteAll();
AuthorPeer::doDeleteAll();

$article1 = new Article();
$article1->setTitle('aaaaa');
$article1->setCategory($category1);
$article1->save();
$author1 = new Author();
$author1->setName('John');
$author1->save();
$comment = new Comment();
$comment->setContent('foo');
$comment->setArticleId($article1->getId());
$comment->setAuthor($author1);
$comment->save();
$article = sfPropelFinder::from('Article')->join('Comment')->join('Author')->where('Author.Name', 'John')->findOne();
$t->is($article->getTitle(), 'aaaaa', 'you can chain several join() statements');
$article = sfPropelFinder::from('Article')->join('Comment')->where('Author.Name', 'John')->findOne();
$t->is($article->getTitle(), 'aaaaa', 'join() can be omitted if column names are explicit');
$article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->where('Author.Name', 'John')->findOne();
$t->is($article->getTitle(), 'aaaaa', 'joinXXX() does a join according to the XXX column name');

$comment = sfPropelFinder::from('Comment')->join('Article')->join('Author')->where('Author.Name', 'John')->findOne();
$t->is($comment->getContent(), 'foo', 'you can add several join() statements');
$t->is($comment->getArticle()->getTitle(), 'aaaaa', 'you can add several join() statements');
$t->is($comment->getAuthor()->getName(), 'John', 'you can add several join() statements');

/***************************************************************/
/* sfPropelFinder::join($classAndAlias) and subsequend where() */
Ejemplo n.º 14
0
 public function createComment($postId, $data)
 {
     $currentUser = parent::authenticateUser();
     $post = $this->postMapper->findById($postId);
     if ($post == NULL) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad request');
         echo "Post with id " . $postId . " not found";
     }
     $comment = new Comment();
     $comment->setContent($data->content);
     $comment->setAuthor($currentUser);
     $comment->setPost($post);
     try {
         $comment->checkIsValidForCreate();
         // if it fails, ValidationException
         $this->commentMapper->save($comment);
         header($_SERVER['SERVER_PROTOCOL'] . ' 201 Created');
     } catch (ValidationException $e) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad request');
         echo json_encode($e->getErrors());
     }
 }
Ejemplo n.º 15
0
<?php

require_once '../model/Comment.php';
require_once '../model/Theme.php';
if (isset($_GET['theme_id']) && is_numeric($_GET['theme_id'])) {
    $comment = new Comment();
    $comment->setDate((new DateTime('now'))->format('Y-m-d H:i:s'));
    $comment->setAuthor(isset($_GET['author']) ? $_GET['author'] : 'nežinomas autorius');
    $comment->setComment(isset($_GET['comment']) ? $_GET['comment'] : 'nežinomas komentaras');
    $comment->setThemeId($_GET['theme_id']);
    $theme = Theme::findById($_GET['theme_id']);
    if (empty($theme)) {
        echo 'Tema ' . $_GET['theme_id'] . ' neegzistuoja';
        return;
    }
    $theme->increaseCommentsCount();
    $comment->save();
    echo 'Komentaras pridetas.';
} else {
    echo 'Reikalingas temos id.';
}