Exemplo n.º 1
0
 /**
  * create new thread
  * @param Comment $comment
  * @throws ValidationException
  */
 public function create(Comment $comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('invalid thread or comment');
     }
     $db = DB::conn();
     $db->begin();
     $db->query('INSERT INTO thread SET title = ?, created = NOW()', array($this->title));
     $this->id = $db->lastInsertId();
     // write first comment at the same time
     $this->write($comment);
     $db->commit();
 }
Exemplo n.º 2
0
 public function edit(Comment &$comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('Invalid thread or comment.');
     }
     $db = DB::conn();
     $db->begin();
     try {
         $db->query("UPDATE thread SET title=?, category_name=?,\n                last_modified=NOW() WHERE id=?", array($this->title, $this->category, $this->id));
         $comment->edit();
         $db->commit();
     } catch (PDOException $e) {
         $db->rollback();
     }
 }
Exemplo n.º 3
0
 /**
  * To create comment
  * @param $comment
  * @throws ValidationException
  **/
 public function create(Comment $comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('invalid thread or comment');
     }
     $db = DB::conn();
     try {
         $db->begin();
         $db->insert('thread', array('title' => $this->title));
         $this->id = $db->lastInsertId();
         //write first comment at the same time
         $this->write($comment);
         $db->commit();
     } catch (ValidationException $e) {
         $db->rollback();
         throw $e;
     }
 }
Exemplo n.º 4
0
 /** 
  * Validate first the Thread & Comment.
  * If both hasError() -> throw Exception
  * Get title of Thread, Get Comment
  * Insert to the Database.
  * @param $comment
  */
 public function create(Comment $comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('Invalid thread or comment');
     }
     $db = DB::conn();
     try {
         $db->begin();
         $params = array('user_id' => $this->user_id, 'title' => $this->title);
         $db->insert('thread', $params);
         $this->id = $db->lastInsertId();
         $comment->write($this->id);
         $db->commit();
     } catch (ValidationException $e) {
         $db->rollback();
         throw $e;
     }
 }
Exemplo n.º 5
0
<?php

$picture = glob('bootstrap/img/users/' . $user->username . '.*');
if (isset($_SESSION['old_thread'])) {
    $old_thread = new Thread($_SESSION['old_thread']);
}
if (isset($_SESSION['old_comment'])) {
    $old_comment = new Comment($_SESSION['old_comment']);
}
?>

<?php 
if (isset($old_thread) && $old_thread->hasError() || isset($old_comment) && $old_comment->hasError()) {
    ?>
    <div class="row">
      <div class="col-xs-12 col-md-offset-2 col-md-8 col-lg-offset-2 col-lg-8s">
        <div class="alert alert-danger">
            <h4 class="alert-heading">
              <span class="glyphicon glyphicon-warning-sign"></span> Warning!
            </h4>
            <?php 
    if (!empty($old_thread->validation_errors['title']['length'])) {
        ?>
                <div><em>Title</em> must be between
                    <?php 
        encode_quotes($old_thread->validation['title']['length'][1]);
        ?>
 and
                    <?php 
        encode_quotes($old_thread->validation['title']['length'][2]);
        ?>
Exemplo n.º 6
0
<div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <h1 class="thread-title"><?php encode_quotes($thread->title) ?></h1>
    </div>
</div>

<?php 
    if(isset($_SESSION['old_comment'])) {
        $old_comment = new Comment($_SESSION['old_comment']);
    }
?>
<?php if(isset($old_comment) && $old_comment->hasError()): ?>
    <div class="row">
      <div class="col-xs-12">
        <div class="alert alert-danger">
            <h4 class="alert-heading">
                <span class="glyphicon glyphicon-warning-sign"></span> Warning!
            </h4>
            <?php if(!empty($old_comment->validation_errors['body']['length'])): ?>
                <div><em>Comment</em> must be between
                    <?php encode_quotes($old_comment->validation['body']['length'][1]) ?> and
                    <?php encode_quotes($old_comment->validation['body']['length'][2]) ?> characters in length.
                </div>
            <?php endif ?>
            <?php if(!empty($old_comment->validation_errors['body']['chars'])): ?>
                <div><em>Comment</em> cannot be spaces only.
                </div>
            <?php endif ?>
        </div>
      </div>
    </div>