Exemple #1
0
 /**
  * @deprecated il voto viene caricato attraverso getAvgVote()
  * Carica in this i voti recuperati dal database per questo post (deve avere un ID!).
  */
 function loadVotes()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineVoteColumns();
         $table = Query::getDBSchema()->getTable(TABLE_VOTE);
         $rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(VOTE_POST), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
         //echo "<p>" . $s . "</p>"; //DEBUG;
         if ($db->num_rows() > 0) {
             $votes = array();
             while ($row = $db->fetch_result()) {
                 require_once "post/PostCommon.php";
                 $vote = new Vote(intval($row[VOTE_AUTHOR]), intval($row[VOTE_POST]), $row[VOTE_VOTE] > 0);
                 $vote->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[VOTE_CREATION_DATE])));
                 $votes[] = $vote;
             }
             //echo "<p>" . serialize($votes) . "</p>"; //DEBUG;
             $this->setVotes($votes);
         } else {
             if ($db->errno()) {
                 $db->display_error("Post::loadVotes()");
             }
         }
     } else {
         $db->display_connect_error("Post::loadVotes()");
     }
     return $this;
 }
Exemple #2
0
 /**
  * Crea un voto caricando i dati dal database.
  * È come fare una ricerca sul database e poi fare new Vote().
  *
  * @param $id: l'ID del voto da caricare.
  * @return: il voto caricato o FALSE se non lo trova.
  */
 static function loadFromDatabase($author, $post)
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         require_once 'strings/strings.php';
         define_tables();
         defineVoteColumns();
         $table = Query::getDBSchema()->getTable(TABLE_VOTE);
         $rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(VOTE_AUTHOR), Operator::EQUAL, $author), new WhereConstraint($table->getColumn(VOTE_POST), Operator::EQUAL, $post)), array()), $table->getName(), null);
         if ($db->num_rows() == 1) {
             $row = $db->fetch_result();
             $v = new Vote(intval($row[VOTE_AUTHOR]), intval($row[VOTE_POST]), $row[VOTE_VOTE] > 0);
             $v->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[VOTE_CREATION_DATE])));
             return $v;
         }
         //else $db->display_error("Vote::loadFromDatabase()");
     } else {
         $db->display_connect_error("Vote::LoadFromDatabase()");
     }
     return false;
 }