Example #1
0
 function save($contact)
 {
     parent::save($contact, self::OBJECT_CLASS);
     $data = array(DB::CONTACT_CONTACT => $contact->getContact(), DB::CONTACT_NAME => $contact->getName(), DB::CONTACT_USER => $contact->getUserId());
     $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $contact);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
     }
     $c = $this->quickLoad($this->db->last_inserted_id());
     return $c;
 }
Example #2
0
 function save($comm)
 {
     parent::save($comm, self::OBJECT_CLASS);
     $data = array(DB::COMMENT_COMMENT => $comm->getComment(), DB::COMMENT_POST => $comm->getPost(), DB::COMMENT_AUTHOR => $comm->getAuthor());
     $rs = $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $comm);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Errore durante l'inserimento dell'oggetto.");
     }
     //carico il post inserito.
     $c = $this->quickLoad(intval($this->db->last_inserted_id()));
     return $c;
 }
Example #3
0
 function save($report)
 {
     parent::save($report, self::OBJECT_CLASS);
     $data = array(DB::REPORT_TEXT => $report->getReport(), DB::REPORT_OBJECT_ID => $report->getObject()->getID(), DB::REPORT_OBJECT_CLASS => get_class($report->getObject()), DB::REPORT_USER => $report->getAuthor());
     $rs = $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $report);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore. Riprovare.");
     }
     //aggiorno lo stato dell'oggetto che è stato segnalato.
     $this->updateObjectState($report->getObject());
     return $this->db->quickLoad($report->getID());
 }
Example #4
0
 function addFeedbackFrom($user, $value)
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineFeedbackColumns();
         $table = Query::getDBSchema()->getTable(TABLE_FEEDBACK);
         $db->execute($s = Query::generateInsertStm($table, array(FEEDBACK_CREATOR => $user->getID(), FEEDBACK_SUBJECT => $this->getID(), FEEDBACK_VALUE => $value ? 1 : 0)), $table->getName(), $this);
         if ($db->affected_rows() != 1) {
             $db->display_error("User::addFeedbackFrom()");
         }
         //Genera un errore ma ritorna comunque $this
     } else {
         $db->display_connect_error("User::addFeedbackFrom()");
     }
     return $this->loadFeedback();
 }
Example #5
0
 /**
  * Crea un tag.
  * @param string $tag
  * @return TRUE se il tag è stato creato, FALSE altrimenti.
  */
 static function createTag($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::generateInsertStm($table, $data), $table->getName(), $tag);
         if ($db->affected_rows() == 1) {
             return true;
         } else {
             return false;
         }
     } else {
         $db->display_connect_error("TagManager::createTag()");
     }
 }
Example #6
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 #7
0
 /**
  * Salva l'oggetto nella cartella di storicizzazione.
  * @param Object $object l'oggetto da salvare
  * @param User $editor l'utente che lo modifica
  * @param string $operation l'operazione che è stata fatta (modifica o eliminazione)
  * @throws Exception lancia eccezione se non è riuscito a salvare l'oggetto.
  * @return l'id della riga salvata.
  */
 protected function saveHistory($object, $editor, $operation)
 {
     //$this->save($object);
     if (!is_a($editor, "User")) {
         throw new Exception("Non hai settato chi ha fatto la modifica.");
     }
     $modDate = $_SERVER["REQUEST_TIME"];
     $data = array(DB::HISTORY_OBJECT => serialize($object), DB::HISTORY_DATE => date("Y/m/d G:i:s", $modDate), DB::HISTORY_EDITOR => $editor->getID(), DB::HISTORY_OPERATION => $operation);
     $this->db->execute(Query::generateInsertStm($this->historyTable, $data), $this->historyTable, $object);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Errore salvando la precedente vesrione dell'oggetto. Riprovare.");
     }
     return $this->db->last_inserted_id();
 }
Example #8
0
 function save($post)
 {
     parent::save($post, self::OBJECT_CLASS);
     $data = array(DB::POST_TYPE => $post->getType());
     if (!is_null($post->getTitle())) {
         $data[DB::POST_TITLE] = $post->getTitle();
     }
     if (!is_null($post->getSubtitle())) {
         $data[DB::POST_SUBTITLE] = $post->getSubtitle();
     }
     if (!is_null($post->getHeadline())) {
         $data[DB::POST_HEADLINE] = $post->getHeadline();
     }
     if (!is_null($post->getTags())) {
         $data[DB::POST_TAGS] = $post->getTags();
     }
     if (!is_null($post->getCategories())) {
         // check sulle categorie, eliminazione di quelle che non esistono nel sistema, se vuoto inserimento di quella di default
         require_once 'manager/CategoryManager.php';
         $new_cat = CategoryManager::filterWrongCategories(explode(",", $post->getCategories()));
         if (is_null($post->getCategories()) || count($new_cat) == 0) {
             $new_cat[] = self::DEFAULT_CATEGORY;
         }
         $post->setCategories(Filter::arrayToText($new_cat));
         $data[DB::POST_CATEGORIES] = $post->getCategories();
     }
     if (!is_null($post->getContent())) {
         if ($post->getType() == Post::NEWS || $post->getType() == Post::VIDEOREP) {
             $data[DB::POST_CONTENT] = $post->getContent();
         } else {
             $data[DB::POST_CONTENT] = serialize($post->getContent());
         }
     }
     if (!is_null($post->isVisible())) {
         $data[DB::POST_VISIBLE] = $post->isVisible() ? 1 : 0;
     }
     if (!is_null($post->getAuthor())) {
         $data[DB::POST_AUTHOR] = $post->getAuthor();
     }
     if (!is_null($post->getPlace())) {
         $data[DB::POST_PLACE] = $post->getPlace();
     }
     $post->setCreationDate($_SERVER["REQUEST_TIME"]);
     if (is_null($post->getPermalink())) {
     }
     $post->setPermalink($this->generatePermalink($post));
     $data[DB::POST_PERMALINK] = $post->getPermalink();
     $rand = "";
     $count = 0;
     while ($this->permalinkExists($post->getPermalink() . $rand)) {
         if ($count >= 1000) {
             throw new Exception("Attenzione! Hai troppi atricol che si chiamano in questo modo. Prova a cambiare titolo.");
         }
         //finché esiste già un permalink del genere, ne genero uno random.
         $rand = "(" . rand(65535, $_SERVER["REQUEST_TIME"]) . ")";
         $data[DB::POST_PERMALINK] = $post->getPermalink() . $rand;
         $count++;
     }
     $data[DB::POST_CREATION_DATE] = date("Y-m-d G:i:s", $post->getCreationDate());
     $rs = $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $this);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
     }
     //carico il post inserito.
     $p = $this->load(intval($this->db->last_inserted_id()));
     //salvo i tag che non esistono
     if (isset($data[DB::POST_TAGS]) && !is_null($data[DB::POST_TAGS]) && trim($data[DB::POST_TAGS]) != "") {
         require_once 'manager/TagManager.php';
         TagManager::createTags(explode(",", $data[DB::POST_TAGS]));
     }
     //salvo lo stato del post perché l'utente potrebbe aver già modificato il suo "colore".
     $this->updateState($p);
     return $p;
 }
Example #9
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 #10
0
 function save()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineUserColumns();
         $table = Query::getDBSchema()->getTable(TABLE_USER);
         $data = array();
         if (isset($this->avatar)) {
             $data[USER_AVATAR] = $this->getAvatar();
         }
         if (isset($this->birthday)) {
             $data[USER_BIRTHDAY] = date("Y/m/d", $this->getBirthday());
         }
         if (isset($this->birthplace)) {
             $data[USER_BIRTHPLACE] = $this->getBirthplace();
         }
         if (isset($this->email)) {
             $data[USER_E_MAIL] = $this->getEMail();
         }
         if (isset($this->gender)) {
             $data[USER_GENDER] = $this->getGender();
         }
         if (isset($this->hobbies)) {
             $data[USER_HOBBIES] = $this->getHobbies();
         }
         if (isset($this->job)) {
             $data[USER_JOB] = $this->getJob();
         }
         if (isset($this->livingPlace)) {
             $data[USER_LIVINGPLACE] = $this->getLivingPlace();
         }
         if (isset($this->name)) {
             $data[USER_NAME] = $this->getName();
         }
         if (isset($this->nickname)) {
             $data[USER_NICKNAME] = $this->getNickname();
         }
         if (isset($this->password)) {
             $data[USER_PASSWORD] = $this->getPassword();
         }
         if (isset($this->role)) {
             $data[USER_ROLE] = $this->getRole();
         }
         if (isset($this->surname)) {
             $data[USER_SURNAME] = $this->getSurname();
         }
         if (isset($this->visible)) {
             $data[USER_VISIBLE] = $this->getVisible() ? 1 : 0;
         }
         $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
         if ($db->affected_rows() == 1) {
             $this->setID($db->last_inserted_id());
             $db->execute(Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(USER_ID), Operator::EQUAL, $this->getID())), array()));
             if ($db->num_rows() == 1) {
                 $row = $db->fetch_result();
                 $this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[USER_CREATION_DATE])));
                 return $this;
             } else {
                 $db->display_error("User::save()");
             }
         } else {
             $db->display_error("User::save()");
         }
     } else {
         $db->display_connect_error("User::save()");
     }
     return false;
 }
Example #11
0
 function save()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineMailColumns();
         $table = Query::getDBSchema()->getTable(TABLE_MAIL);
         $data = array();
         if (isset($this->subject) && !is_null($this->getSubject())) {
             $data[MAIL_SUBJECT] = $this->getSubject();
         }
         if (isset($this->from) && !is_null($this->getFrom())) {
             $data[MAIL_FROM] = intval($this->getFrom());
         }
         if (isset($this->to) && !is_null($this->getTo())) {
             $data[MAIL_TO] = $this->getTo();
         }
         if (isset($this->text) && !is_null($this->getText())) {
             $data[MAIL_TEXT] = $this->getText();
         }
         if (isset($this->repliesTo) && !is_null($this->getRepliesTo())) {
             $data[MAIL_REPLIES_TO] = intval($this->getRepliesTo());
         }
         $rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
         //echo "<br />" . $s; //DEBUG
         //echo "<br />" . $db->affected_rows(); //DEBUG
         if ($db->affected_rows() == 1) {
             $this->setID(intval($db->last_inserted_id()));
             //echo "<br />" . serialize($this->ID); //DEBUG
             $rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(MAIL_ID), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
             //echo "<br />" . $s; //DEBUG
             if ($db->num_rows() == 1) {
                 $row = $db->fetch_result();
                 $this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[MAIL_CREATION_DATE])));
                 //echo "<br />" . serialize($row[MAIL_CREATION_DATE]); //DEBUG
                 //inserisce il messaggio nelle mailbox dei $to
                 $toes = explode("|", $this->getTo());
                 //echo serialize($toes); //DEBUG
                 require_once "mail/MailManager.php";
                 for ($i = 0; $i < count($toes); $i++) {
                     $dir = MailManager::loadDirectoryFromName(MAILBOX, intval($toes[$i]));
                     MailManager::addMailToDir($this, $dir);
                 }
                 //echo "<br />" . $this; //DEBUG
                 return $this;
             } else {
                 $db->display_error("Mail::save()");
             }
         } else {
             $db->display_error("Mail::save()");
         }
     } else {
         $db->display_connect_error("Mail::save()");
     }
     return false;
 }
Example #12
0
 /**
  * Salva il post e le sue dipendenze nel database.
  * Le dipendenze salvate sono quelle che dipendono dall'autore ovvero: tag e categorie.
  * Potrebbe salvare alcune tuple in Tag.
  *
  * @return: ID della tupla inserita (o aggiornata), FALSE se c'è un errore.
  */
 function save()
 {
     require_once "post/PostCommon.php";
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         definePostColumns();
         $table = Query::getDBSchema()->getTable(TABLE_POST);
         $data = array(POST_TYPE => $this->getType());
         if (isset($this->title) && !is_null($this->getTitle())) {
             $data[POST_TITLE] = $this->getTitle();
         }
         if (isset($this->subtitle) && !is_null($this->getSubtitle())) {
             $data[POST_SUBTITLE] = $this->getSubtitle();
         }
         if (isset($this->headline) && !is_null($this->getHeadline())) {
             $data[POST_HEADLINE] = $this->getHeadline();
         }
         if (isset($this->tags) && !is_null($this->getTags())) {
             $data[POST_TAGS] = $this->getTags();
         }
         if (isset($this->categories) && !is_null($this->getCategories())) {
             // check sulle categorie, eliminazione di quelle che non esistono nel sistema, se vuoto inserimento di quella di default
             $new_cat = CategoryManager::filterWrongCategories(explode(",", $this->getCategories()));
             if (!isset($this->categories) || is_null($this->getCategories()) || count($new_cat) == 0) {
                 $new_cat[] = self::DEFAULT_CATEGORY;
             }
             $this->setCategories(Filter::arrayToText($new_cat));
             $data[POST_CATEGORIES] = $this->getCategories();
         }
         if (isset($this->content) && !is_null($this->getContent())) {
             if ($this->type == "post" || $this->type == "news" || $this->type == "videoreportage") {
                 $data[POST_CONTENT] = $this->getContent();
             } else {
                 $data[POST_CONTENT] = serialize($this->getContent());
             }
         }
         if (isset($this->visible) && !is_null($this->isVisible())) {
             $data[POST_VISIBLE] = $this->isVisible() ? 1 : 0;
         }
         if (isset($this->author) && !is_null($this->getAuthor())) {
             $data[POST_AUTHOR] = $this->getAuthor();
         }
         if (isset($this->place) && !is_null($this->getPlace())) {
             $data[POST_PLACE] = $this->getPlace();
         }
         $data[POST_PERMALINK] = $this->getPermalink();
         if (self::permalinkExists($this->getPermalink())) {
             //finché esiste già un permalink del genere, ne genero uno radfom.
             $data[POST_PERMALINK] = $this->getPermalink() . "(" . rand(1024, $_SERVER["REQUEST_TIME"]) . ")";
         }
         $data[POST_CREATION_DATE] = date("Y-m-d G:i:s", $_SERVER["REQUEST_TIME"]);
         $rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
         //echo "<br />" . $s; //DEBUG
         //echo "<br />" . $db->affected_rows(); //DEBUG
         if ($db->affected_rows() == 1) {
             $this->setID($db->last_inserted_id());
             //echo "<br />" . serialize($this->ID); //DEBUG
             $rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(POST_ID), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
             //echo "<br />" . serialize($rs); //DEBUG
             if ($db->num_rows() == 1) {
                 $row = $db->fetch_result();
                 //echo "<br />" . $row; //DEBUG
                 $this->setPermalink($row[POST_PERMALINK]);
                 $this->setModificationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[POST_CREATION_DATE])));
                 //salvo i tag che non esistono
                 if (isset($data[POST_TAGS]) && !is_null($data[POST_TAGS]) && trim($data[POST_TAGS]) != "") {
                     TagManager::createTags(explode(",", $data[POST_TAGS]));
                 }
                 //echo "<br />" . serialize($row[POST_CREATION_DATE]); //DEBUG
                 //echo "<br />" . $this; //DEBUG
                 return $this->ID;
             } else {
                 $db->display_error("Post::save()");
             }
         } else {
             $db->display_error("Post::save()");
         }
     } else {
         $db->display_connect_error("Post::save()");
     }
     return false;
 }
Example #13
0
 function save($cat)
 {
     parent::save($cat, self::OBJECT_CLASS);
     $data = array();
     if (!is_null($cat->getName())) {
         $data[DB::CATEGORY_NAME] = $cat->getName();
     }
     if (!is_null($cat->getAuthorId())) {
         $data[DB::CATEGORY_AUTHOR] = $cat->getAuthorId();
     }
     if (!is_null($cat->getCreationDate())) {
         $data[DB::CATEGORY_CREATION_DATE] = date("Y-m-d G:i:s", $cat->getCreationDate());
     }
     $this->db->execute(Query::generateInsertStm($this->table, $data));
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
     }
     if (!is_null($cat->getParentName())) {
         $this->db->execute(Query::generateInsertStm($this->table_sc, array(DB::SUB_CATEGORY_CATEGORY => $cat->getName(), DB::SUB_CATEGORY_PARENT => $cat->getParentName())));
         if ($this->db->affected_rows() != 1) {
             throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
         }
     }
     return $cat;
 }
Example #14
0
 function addFollower($user)
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineFollowColumns();
         $table = Query::getDBSchema()->getTable(TABLE_FOLLOW);
         $db->execute($s = Query::generateInsertStm($table, array(FOLLOW_FOLLOWER => $user->getID(), FOLLOW_SUBJECT => $this->getID())), $table->getName(), $this);
         if ($db->affected_rows() != 1) {
             $db->display_error("User::addFollower()");
         }
         //Genera un errore ma ritorna comunque $this
     } else {
         $db->display_connect_error("User::addFollower()");
     }
     return $this->loadFollowers();
 }
Example #15
0
 function save($resource)
 {
     parent::save($resource, self::OBJECT_CLASS);
     $this->logger->debug("ResourceDao", "salvo risorsa " . $resource->getPath());
     $data = array(DB::RESOURCE_OWNER => $resource->getOwnerId(), DB::RESOURCE_PATH => $resource->getPath(), DB::RESOURCE_TYPE => $resource->getType());
     if (!is_null($resource->getDescription())) {
         $data[DB::RESOURCE_DESCRIPTION] = $resource->getDescription();
     }
     if (!is_null($resource->getTags())) {
         $data[DB::RESOURCE_TAGS] = $resource->getTags();
     }
     $data[DB::POST_CREATION_DATE] = date("Y-m-d G:i:s", $_SERVER["REQUEST_TIME"]);
     $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $this);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
     }
     $r = $this->quickLoad($this->db->last_inserted_id());
     //DEBUG
     //var_dump($this->db->last_inserted_id());
     //inserisco i tag nuovi
     if (!is_null($resource->getTags()) && trim($resource->getTags()) != "") {
         TagManager::createTags(explode(",", $resource->getTags()));
     }
     //salvo lo stato della risorsa perché l'utente potrebbe aver già modificato il suo "colore".
     $this->updateState($r);
     return $r;
 }
Example #16
0
 /**
  * Salva il contest e le sue dipendenze nel database.
  *
  * @return: ID della tupla inserita, FALSE se c'è un errore.
  */
 function save()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineContestColumns();
         $table = Query::getDBSchema()->getTable(TABLE_CONTEST);
         $data = array();
         if (isset($this->title) && !is_null($this->getTitle())) {
             $data[CONTEST_TITLE] = $this->getTitle();
         }
         if (isset($this->description) && !is_null($this->getDescription())) {
             $data[CONTEST_DESCRIPTION] = $this->getDescription();
         }
         if (isset($this->rules) && !is_null($this->getRules())) {
             $data[CONTEST_RULES] = $this->getRules();
         }
         if (isset($this->prizes) && !is_null($this->getPrizes())) {
             $data[CONTEST_PRIZES] = $this->getPrizes();
         }
         if (isset($this->start) && !is_null($this->getStart())) {
             $data[CONTEST_START] = date("Y/m/d G:i:s", $this->getStart());
         }
         if (isset($this->end) && !is_null($this->getEnd())) {
             $data[CONTEST_END] = date("Y/m/d G:i:s", $this->getEnd());
         }
         if (isset($this->subscriberType) && !is_null($this->getSubscriberType())) {
             $data[CONTEST_TYPE_OF_SUBSCRIBER] = $this->getSubscriberType();
         }
         $rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
         //echo "<br />" . $s; //DEBUG
         //echo "<br />" . serialize($rs); //DEBUG
         if ($db->affected_rows() == 1) {
             $this->setID($db->last_inserted_id());
             //echo "<br />" . serialize($this->ID); //DEBUG
             //echo "<br />" . $this; //DEBUG
             return $this->ID;
         } else {
             $db->display_error("Contest::save()");
         }
     } else {
         $db->display_connect_error("Contest::save()");
     }
     return false;
 }
Example #17
0
 function subscribePost($post, $contest)
 {
     parent::save($contest, self::OBJECT_CLASS);
     parent::save($post, "Post");
     if ($post->getType() != $contest->getSubscriberType()) {
         throw new Exception("Non puoi iscrivere questo post nel contest selezionato.");
     }
     if (time() > $contest->getEnd()) {
         throw new Exception("Non puoi iscrivere questo post perché scaduto il termine di iscrizione.");
     }
     $this->db->execute($s = Query::generateInsertStm($this->table_cs, array(DB::CONTEST_SUBSCRIBER_POST => $post->getID(), DB::CONTEST_SUBSCRIBER_CONTEST => $contest->getID())), $table->getName(), $contest);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Errore iscrivendo il post nel contest. Il post potrebbe essere già iscritto.");
     }
     //$this->loadSubscribers($contest); //FIXME vale la pena ricaricare il contest?
     return $contest;
 }
Example #18
0
 function save($user)
 {
     parent::save($user, self::OBJECT_CLASS);
     $data = array();
     if (!is_null($user->getAvatar())) {
         $data[DB::USER_AVATAR] = $user->getAvatar();
     }
     if (!is_null($user->getBirthday())) {
         $data[DB::USER_BIRTHDAY] = date("Y/m/d", $user->getBirthday());
     }
     if (!is_null($user->getBirthplace())) {
         $data[DB::USER_BIRTHPLACE] = $user->getBirthplace();
     }
     if (!is_null($user->getEMail())) {
         $data[DB::USER_E_MAIL] = $user->getEMail();
     }
     if (!is_null($user->getGender())) {
         $data[DB::USER_GENDER] = $user->getGender();
     }
     if (!is_null($user->getHobbies())) {
         $data[DB::USER_HOBBIES] = $user->getHobbies();
     }
     if (!is_null($user->getJob())) {
         $data[DB::USER_JOB] = $user->getJob();
     }
     if (!is_null($user->getLivingPlace())) {
         $data[DB::USER_LIVINGPLACE] = $user->getLivingPlace();
     }
     if (!is_null($user->getName())) {
         $data[DB::USER_NAME] = $user->getName();
     }
     if (!is_null($user->getNickname())) {
         $data[DB::USER_NICKNAME] = $user->getNickname();
     }
     if (!is_null($user->getPassword())) {
         $data[DB::USER_PASSWORD] = $user->getPassword();
     }
     if (!is_null($user->getRole())) {
         $data[DB::USER_ROLE] = $user->getRole();
     }
     if (!is_null($user->getSurname())) {
         $data[DB::USER_SURNAME] = $user->getSurname();
     }
     if (!is_null($user->getVisible())) {
         $data[DB::USER_VISIBLE] = $user->getVisible() ? 1 : 0;
     }
     $data[DB::USER_CREATION_DATE] = date("Y-m-d G:i:s", $_SERVER["REQUEST_TIME"]);
     $this->db->execute($s = Query::generateInsertStm($this->table, $data), $this->table->getName(), $user);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore salvando l'oggetto. Riprovare.");
     }
     $u = $this->load(intval($this->db->last_inserted_id()));
     $this->updateState($u);
     return $u;
 }
Example #19
0
 /**
  * Salva il voto nel database.
  * 
  * @param savingMode: uno dei valori della classe SavingMode.
  * se INSERT: crea una nuova tupla in Post.
  * se UPDATE: confronta il Post con quello presente nel database e aggiorna le differenze.
  */
 function save()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         defineVoteColumns();
         $table = Query::getDBSchema()->getTable(TABLE_VOTE);
         $data = array(VOTE_VOTE => $this->getVote() ? 1 : 0, VOTE_POST => $this->getPost(), VOTE_AUTHOR => $this->getAuthor());
         $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
         //echo "<br />" . $s; //DEBUG
         //echo "<br />" . serialize($rs); //DEBUG
         if ($db->affected_rows() == 1) {
             $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(VOTE_AUTHOR), Operator::EQUAL, $this->getAuthor()), new WhereConstraint($table->getColumn(VOTE_POST), Operator::EQUAL, $this->getPost())), array()), $table->getName(), $this);
             //echo "<br />" . $s; //DEBUG
             if ($db->num_rows() == 1) {
                 $row = $db->fetch_result();
                 $this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[VOTE_CREATION_DATE])));
                 //echo "<br />" . serialize($row[VOTE_CREATION_DATE]); //DEBUG
                 //echo "<br />" . $this; //DEBUG
                 return $this->creationDate;
             } else {
                 $db->display_error("Vote::save()");
             }
         } else {
             $db->display_error("Vote::save()");
         }
     } else {
         $db->display_connect_error("Vote::save()");
     }
     return false;
 }