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; }
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; }
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; }
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()); }
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; }
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; }
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; }
/** * Activate an entity instance * * @param BaseEntityAbstract $entity The entity that we are trying to activate * * @return int The number rows affected */ public function activate(BaseEntityAbstract $entity) { $entity->setActive(true); $entity = Dao::save($entity); $this->_affectedRows = 1; $this->_lastId = -1; $this->resetQuery(); return $this->_affectedRows; }
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; }
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; }