Example #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);
 }
Example #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());
 }
Example #3
0
 function getCount($object)
 {
     parent::load($object);
     $objectClass = get_class($object);
     $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(REPORT_OBJECT_ID), Operator::EQUAL, $object->getID()), new WhereConstraint($this->table->getColumn(REPORT_OBJECT_CLASS), Operator::EQUAL, get_class($object))), array("count" => 2)));
     if ($this->db->num_rows() != 1) {
         throw new Exception("Si è verificato un errore. Riprovare.");
     }
     $row = $this->db->fetch_row();
     return intval($row[0]);
 }
Example #4
0
 function loadByNickname($nickname)
 {
     parent::load($nickname);
     $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::USER_NICKNAME), Operator::EQUAL, $nickname)), array()));
     if ($this->db->num_rows() != 1) {
         throw new Exception("L'oggetto cercato non è stato trovato. Riprovare.");
     }
     $row = $this->db->fetch_result();
     $user = $this->createFromDBRow($row);
     return $user;
 }
Example #5
0
 function loadForAuthor($author)
 {
     parent::load($author);
     if (!is_subclass_of($post, "User")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un utente.");
     }
     $this->db->execute(Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::RESOURCE_OWNER), Operator::EQUAL, intval($author->getID()))), array()));
     $resources = array();
     while ($row = $db->fetch_result()) {
         $resources[] = $this->createFromDBRow($row);
     }
     return $resources;
 }
Example #6
0
 function loadAll($post)
 {
     parent::load($post);
     if (!is_subclass_of($post, "Post")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un post.");
     }
     $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::COMMENT_POST), Operator::EQUAL, intval($post->getID()))), array()), $this->table->getName(), $this);
     $comm = array();
     if ($this->db->num_rows() > 0) {
         while ($row = $this->db->fetch_result()) {
             $c = new Comment($row[DB::COMMENT_COMMENT], intval($row[DB::COMMENT_POST]), intval($row[DB::COMMENT_AUTHOR]));
             $com->setID($row[DB::COMMENT_ID])->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::COMMENT_CREATION_DATE])));
             $comm[] = $com;
         }
     }
     return $post->setComments($comm);
 }
Example #7
0
 function save($post, $author, $vote)
 {
     parent::save($post, "Post");
     parent::save($author, "User");
     settype($vote, "boolean");
     //elimino il vecchio voto
     $this->db->execute(Query::generateDeleteStm($this->table, array(new WhereConstraint($this->table->getColumn(DB::VOTE_AUTHOR), Operator::EQUAL, intval($author->getID()), new WhereConstraint($this->table->getColumn(DB::VOTE_POST), Operator::EQUAL, intval($post->getID()))))), $this->table->getName(), array($author->getID(), $post->getID()));
     //non controllo se è stato cancellato perché può non esserci
     $data = array(DB::VOTE_VOTE => $vote ? 1 : 0, DB::VOTE_POST => intval($post->getID()), DB::VOTE_AUTHOR => intval($author->getID()));
     $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $data);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
     }
     //carico il voto inserito.
     $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::VOTE_AUTHOR), Operator::EQUAL, intval($author->getID()), new WhereConstraint($this->table->getColumn(DB::VOTE_POST), Operator::EQUAL, intval($post->getID())))), array()), $this->table->getName(), $data);
     if ($this->db->num_rows() != 1) {
         throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
     }
     return true;
 }
Example #8
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;
 }
Example #9
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;
 }
Example #10
0
 private static function searchPostsBy($keys, $options, $echo_query = false)
 {
     require_once "query.php";
     require_once "strings/strings.php";
     define_tables();
     definePostColumns();
     $table = Query::getDBSchema()->getTable(TABLE_POST);
     $loadComments = true;
     $wheres = array();
     foreach ($keys as $key => $value) {
         if ($key == "name" || $key == "title") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_TITLE), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "permalink") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_PERMALINK), Operator::EQUAL, intval($value));
         }
         if ($key == "id") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_ID), Operator::EQUAL, intval($value));
         }
         if ($key == "tag") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_TAGS), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "day") {
             if (!is_numeric($value)) {
                 $value = date_timestamp_get(date_create_from_format("Y-m-d", $value));
             }
             $daystart = date("Y-m-d", $value);
             $dayend = date("Y-m-d", $value + 24 * 60 * 60);
             //echo "<br />" . $daystart . "-" . $dayend; //DEBUG
             $wheres[] = new WhereConstraint($table->getColumn(POST_CREATION_DATE), Operator::GREATEROREQUAL, $daystart);
             $wheres[] = new WhereConstraint($table->getColumn(POST_CREATION_DATE), Operator::LESSER, $dayend);
         }
         if ($key == "category") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_CATEGORIES), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "title") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_TITLE), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "content") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_CONTENT), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "author") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_AUTHOR), Operator::EQUAL, intval($value));
         }
         if ($key == "no_id") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_ID), Operator::NOTEQUAL, intval($value));
         }
         if ($key == "loadComments") {
             $loadComments = $value == true;
         }
     }
     $newopt = array();
     foreach ($options as $key => $value) {
         if ($key == "by") {
             if (!is_array($value)) {
                 $value = array($value);
             }
             $newvalue = array();
             foreach ($value as $column) {
                 if (!is_a($column, "Column")) {
                     $column = $table->getColumn($column);
                 }
                 if (!is_null($column)) {
                     $newvalue[] = $column;
                 }
             }
             $value = $newvalue;
         }
         $newopt[$key] = $value;
     }
     $db = new DBManager();
     $db->execute($s = Query::generateSelectStm(array($table), array(), $wheres, $newopt));
     if ($echo_query) {
         echo "<font color='red'>" . $s . "</font>";
     }
     //DEBUG
     $posts = array();
     while ($row = $db->fetch_result()) {
         require_once "post/Post.php";
         $posts[] = Post::createFromDBResult($row, $loadComments);
     }
     return $posts;
 }
Example #11
0
 function permalinkExists($permalink)
 {
     parent::load($permalink);
     $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::POST_PERMALINK), Operator::EQUAL, $permalink)), array("count" => 2)));
     if ($this->db->num_rows() != 1) {
         throw new Exception("Si è verificato un errore. Riprovare.");
     }
     $row = $this->db->fetch_row();
     return $row[0] > 0;
 }
Example #12
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;
     }
 }
Example #13
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;
 }
Example #14
0
 /**
  * Carica in this i report recuperati dal database per questo post (deve avere un ID!).
  */
 function loadReports()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineReportColumns();
         $table = Query::getDBSchema()->getTable(TABLE_REPORT);
         $rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(REPORT_POST), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
         if ($rs !== false) {
             $reports = array();
             while ($row = $db->fetch_result()) {
                 require_once "common.php";
                 $report = new Report(intval($row[REPORT_USER]), intval($row[REPORT_POST]), $row[REPORT_TEXT]);
                 $report->setID($row[REPORT_ID]);
                 $reports[] = $report;
             }
             $this->setReports($reports);
         } else {
             if ($db->errno()) {
                 $db->display_error("Post::loadReports()");
             }
         }
     } else {
         $db->display_connect_error("Post::loadReports()");
     }
     return $this;
 }
Example #15
0
 function loadAll()
 {
     $loadA = $this->loadAccessCount;
     $this->loadAccessCount = false;
     parent::checkConnection();
     $s = "SELECT * from " . DB::TABLE_CATEGORY . " WHERE " . DB::CATEGORY_NAME . " NOT IN (SELECT DISTINCT " . DB::SUB_CATEGORY_CATEGORY . " FROM " . DB::TABLE_SUB_CATEGORY . ")";
     $this->db->execute(Query::generateSelectStm(array($this->table, $this->table_sc), array(new JoinConstraint($this->table->getColumn(DB::CATEGORY_NAME), $this->table_sc->getColumn(DB::SUB_CATEGORY_CATEGORY))), array(), array()));
     $this->db->execute($s);
     $cat = array();
     $res = $this->db->fetch_all_results();
     foreach ($res as $row) {
         $cat[] = $this->createFromDBRow($row);
     }
     return $cat;
 }
Example #16
0
 function getContactsNames()
 {
     $this->checkConnection();
     $this->db->execute($s = Query::generateSelectStm(array($this->table_ct), array(), array(), array()));
     $names = array();
     while ($row = $this->db->fetch_result()) {
         $names[$row[DB::CONTACT_TYPE_NAME]] = $row[DB::CONTACT_TYPE_TYPE];
     }
     return $names;
 }
Example #17
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;
 }
Example #18
0
 private function loadSubscribers($contest, $limit = null)
 {
     parent::load($contest);
     if (!is_subclass_of($contest, self::OBJECT_CLASS)) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un contest.");
     }
     $options = array();
     if (!is_null($limit) && is_numeric($limit)) {
         $options = array("limit" => intval($limit));
     }
     $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table_cs), array(), array(new WhereConstraint($this->table_cs->getColumn(DB::CONTEST_SUBSCRIBER_CONTEST), Operator::EQUAL, $contest->getID())), $options), $this->table_cs->getName(), $contest);
     $subscribers = array();
     while ($row = $this->db->fetch_result()) {
         require_once 'dao/PostDao.php';
         $postdao = new PostDao();
         $subscribers[] = $postdao->quickLoad(intval($row[CONTEST_SUBSCRIBER_POST]));
     }
     return $contest->setSubscribers($subscribers);
 }