Exemplo n.º 1
0
 function loadFeedback()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineFeedbackColumns();
         $table = Query::getDBSchema()->getTable(TABLE_FEEDBACK);
         $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(FEEDBACK_SUBJECT), Operator::EQUAL, $this->getID())), array()));
         if ($db->num_rows() > 0) {
             require_once "strings/strings.php";
             $fb = FEEDBACK_INITIAL_VALUE;
             while ($row = $db->fetch_result()) {
                 $fb += intval($row[FEEDBACK_VALUE]) > 0 ? 1 : -1;
                 //se sul DB è 0 allora è -1 se è positivo allora +1;
             }
             return $this->setFeedback($fb);
         } else {
             if ($db->errno()) {
                 $db->display_error("User::loadFeedback()");
             }
         }
     } else {
         $db->display_connect_error("User::loadFeedback()");
     }
     return $this->setFeedback(FEEDBACK_INITIAL_VALUE);
 }
Exemplo n.º 2
0
 function loadFollows()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineFollowColumns();
         $table = Query::getDBSchema()->getTable(TABLE_FOLLOW);
         $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(FOLLOW_FOLLOWER), Operator::EQUAL, $this->getID())), array()));
         if ($db->num_rows() > 0) {
             $fols = array();
             while ($row = $db->fetch_result()) {
                 define_tables();
                 defineFollowColumns();
                 $f = self::loadFromDatabase(intval($row[FOLLOW_SUBJECT]), false);
                 if ($f !== false) {
                     $fols[$f->getID()] = $f;
                 }
             }
             return $this->setFollows($fols);
         } else {
             if ($db->errno()) {
                 $db->display_error("User::loadFollows()");
             }
         }
     } else {
         $db->display_connect_error("User::loadFollows()");
     }
     return $this->setFollows(array());
 }
Exemplo n.º 3
0
 /**
  * Controlla l'esistenza di un tag
  * @param string $tag il nome di un tag.
  * @return TRUE se il tag esiste già nel sistema, FALSE altrimenti.
  */
 static function tagExists($tag)
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineTagColumns();
         $table = Query::getDBSchema()->getTable(TABLE_TAG);
         $data = array(TAG_NAME => $tag);
         $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(TAG_NAME), Operator::EQUAL, $tag)), array()));
         if ($db->num_rows() == 1) {
             return true;
         } else {
             return false;
         }
     } else {
         $db->display_connect_error("TagManager::tagExists()");
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * @deprecated
  * Enter description here ...
  * @param unknown_type $type
  * @param unknown_type $id
  */
 static function getAccessCount($type, $id)
 {
     if ($type == null || $type == "" || $id == null) {
         return 0;
     }
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineLogColumns();
         $table = Query::getDBSchema()->getTable("AccessLog");
         $exists = false;
         if ($type == "Post") {
             require_once 'post/PostManager.php';
             return 0;
             $exists = PostManager::postExists($id);
         } else {
             if ($type == "User") {
                 require_once 'user/UserManager.php';
                 return 0;
                 $exists = UserManager::userExists($id);
             } elseif ($type == "Partner") {
                 //TODO: implementa Partner
                 //				require_once 'post/PartnerManager.php';
                 //				$exists = PartnerManager::partnerExists($id);
             }
         }
         if ($exists) {
             $wheres = array(new WhereConstraint($table->getColumn("alog_type"), Operator::EQUAL, $type), new WhereConstraint($table->getColumn("alog_id"), Operator::EQUAL, $id));
             $db->execute($s = Query::generateSelectStm(array($table), array(), $wheres, array()));
             if ($db->num_rows() == 1) {
                 $row = $db->fetch_result();
                 $data = array("alog_count" => ++$row["alog_count"]);
                 $db->execute($s = Query::generateUpdateStm($table, $data, $wheres), null, LOGMANAGER);
                 if ($db->affected_rows() == 1) {
                     return $row["alog_count"];
                 }
             } else {
                 $data = array("alog_type" => $type, "alog_id" => $id);
                 $db->execute($s = Query::generateInsertStm($table, $data));
                 if ($db->affected_rows() == 1) {
                 }
                 return 1;
             }
         }
         return 0;
     }
 }
Exemplo n.º 5
0
 static function loadMailsFromUser($user)
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineMailColumns();
         $table = Query::getDBSchema()->getTable(TABLE_MAIL);
         $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(MAIL_FROM), Operator::EQUAL, $user)), array()), $table->getName(), $this);
         //echo "<p>" . $s . "</p>"; //DEBUG
         //echo "<p>" . $db->num_rows() . "</p>"; //DEBUG
         if ($db->num_rows() == 1) {
             // echo serialize(mysql_fetch_assoc($rs)); //DEBUG
             $mails = array();
             while ($row = $db->fetch_result()) {
                 $data = array("text" => $row[MAIL_TEXT], "subject" => $row[MAIL_SUBJECT], "from" => intval($row[MAIL_FROM]), "to" => $row[MAIL_TO], "repliesTo" => $row[MAIL_REPLIES_TO]);
                 $m = new Mail($data);
                 $m->setID(intval($row[MAIL_ID]))->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[MAIL_CREATION_DATE])));
                 $mails[] = $m;
             }
             //echo "<p>" .$m ."</p>";
             return $mails;
         } else {
             $db->display_error("Mail::loadMailsFromUser()");
         }
     } else {
         $db->display_connect_error("Mail::loadMailsFromUser()");
     }
     return false;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 function loadWinners()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         $table = Query::getDBSchema()->getTable(TABLE_CONTEST_SUBSCRIBER);
         $rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(CONTEST_SUBSCRIBER_CONTEST), Operator::EQUAL, $this->getID()), new WhereConstraint($table->getColumn(CONTEST_SUBSCRIBER_PLACEMENT), Operator::GREATER, 0)), array()), $table->getName(), $this);
         //echo "<p>" . $s . "</p>"; //DEBUG;
         //echo "<p>" . mysql_num_rows($rs) . "</p>"; //DEBUG;
         if ($db->num_rows() > 0) {
             $win = array();
             while ($row = $db->fetch_result()) {
                 $win[$row[CONTEST_SUBSCRIBER_PLACEMENT]] = $row[CONTEST_SUBSCRIBER_POST];
                 // Con in cs_winner il numero di posizione
                 //$win[] = $row[CONTEST_SUBSCRIBER_POST];  // Con in cs_winner true o false
             }
             $this->setWinners($win);
         } else {
             if ($db->errno()) {
                 $db->display_error("Contest::loadWinners()");
             }
         }
     } else {
         $db->display_connect_error("Contest::loadWinners()");
     }
     return $this;
 }
Exemplo n.º 8
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;
 }