Example #1
0
 /**
  * Aggiorna il post e le sue dipendenze nel database.
  * Le dipendenze aggiornate sono quelle che dipendono dall'autore ovvero: tag e categorie
  * Potrebbe salvare alcune tuple in Tag.
  *
  * @return: modificationDate o FALSE se c'è un errore.
  */
 function update()
 {
     require_once "query.php";
     $db = new DBManager();
     if (!$db->connect_errno()) {
         define_tables();
         definePostColumns();
         $table = Query::getDBSchema()->getTable(TABLE_POST);
         $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 />" . $s; //DEBUG
         $data = array();
         if ($db->num_rows() == 1) {
             $row = $db->fetch_result();
             //cerco le differenze e le salvo.
             if ($row[POST_TITLE] != $this->getTitle()) {
                 $data[POST_TITLE] = $this->getTitle();
             }
             if ($row[POST_SUBTITLE] != $this->getSubtitle()) {
                 $data[POST_SUBTITLE] = $this->getSubtitle();
             }
             if ($row[POST_HEADLINE] != $this->getHeadline()) {
                 $data[POST_HEADLINE] = $this->getHeadline();
             }
             if ($row[POST_CONTENT] != $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 ($row[POST_PLACE] != $this->getPlace()) {
                 $data[POST_PLACE] = $this->getPlace();
             }
             if ($row[POST_TAGS] != $this->getTags()) {
                 $data[POST_TAGS] = $this->getTags();
             }
             if ($row[POST_CATEGORIES] != $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 (count($new_cat) == 0) {
                     $new_cat[] = self::DEFAULT_CATEGORY;
                 }
                 $this->setCategories(Filter::arrayToText($new_cat));
                 $data[POST_CATEGORIES] = $this->getCategories();
             }
             settype($row[POST_VISIBLE], "boolean");
             if ($row[POST_VISIBLE] !== $this->isVisible()) {
                 $data[POST_VISIBLE] = $this->isVisible() ? 1 : 0;
             }
             if ($row[POST_PERMALINK] != $this->getPermalink()) {
                 if (self::permalinkExists($this->getPermalink())) {
                     return false;
                 }
                 $data[POST_PERMALINK] = $this->getPermalink();
             }
             if (count($data) == 0) {
                 return $this->getModificationDate();
             }
             $data[POST_MODIFICATION_DATE] = date("Y/m/d G:i:s", $_SERVER["REQUEST_TIME"]);
             // se mi dicono di fare l'update, cambio modificationDate
             //echo "<br />" . serialize($data); //DEBUG
             $rs = $db->execute($s = Query::generateUpdateStm($table, $data, array(new WhereConstraint($table->getColumn(POST_ID), Operator::EQUAL, $this->getID()))), $table->getName(), $this);
             //echo "<br />" . $s; //DEBUG
             //echo "<br />" . mysql_affected_rows(); //DEBUG
             if ($db->affected_rows() == 1) {
                 //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 />" . $this; //DEBUG
                 return $this->getModificationDate();
             } else {
                 $db->display_error("Post::update()");
             }
         } else {
             $db->display_error("Post::update()");
         }
     } else {
         $db->display_connect_error("Post::update()");
     }
     return false;
 }
Example #2
0
 function update($post, $editor)
 {
     parent::update($post, $editor, self::OBJECT_CLASS);
     if (!AuthorizationManager::canUserDo(DB::EDIT_POST, $object)) {
         throw new Exception("L'utente non è autorizzato ad effettuare questa operazione.");
     }
     $p_old = $this->quickLoad($post->getID());
     $data = array();
     if (is_null($p_old)) {
         throw new Exception("L'oggetto da modificare non esiste.");
     }
     //cerco le differenze e le salvo.
     if ($p_old->getTitle() != $post->getTitle()) {
         $data[DB::POST_TITLE] = $post->getTitle();
     }
     if ($p_old->getSubtitle() != $post->getSubtitle()) {
         $data[DB::POST_SUBTITLE] = $post->getSubtitle();
     }
     if ($p_old->getHeadline() != $post->getHeadline()) {
         $data[DB::POST_HEADLINE] = $post->getHeadline();
     }
     if ($p_old->getContent() != $post->getContent()) {
         if ($post->type == Post::NEWS || $post->type == Post::VIDEOREP) {
             $data[DB::POST_CONTENT] = $post->getContent();
         } else {
             $data[DB::POST_CONTENT] = serialize($post->getContent());
         }
     }
     if ($p_old->getPlace() != $post->getPlace()) {
         $data[DB::POST_PLACE] = $post->getPlace();
     }
     if ($p_old->getPlaceName() != $post->getPlaceName()) {
         $data[DB::POST_PLACE_NAME] = $post->getPlaceName();
     }
     if ($p_old->getTags() != $post->getTags()) {
         $data[DB::POST_TAGS] = $post->getTags();
     }
     if ($p_old->getCategories() != $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 (count($new_cat) == 0) {
             $new_cat[] = self::DEFAULT_CATEGORY;
         }
         $post->setCategories(Filter::arrayToText($new_cat));
         $data[DB::POST_CATEGORIES] = $post->getCategories();
     }
     if ($p_old->isVisible() !== $post->isVisible()) {
         $data[DB::POST_VISIBLE] = $post->isVisible() ? 1 : 0;
     }
     if ($p_old->getPermalink() != $post->getPermalink()) {
         if ($this->permalinkExists($post->getPermalink())) {
             throw new Exception("Il permalink inserito esiste già. Riprova.");
         }
         $data[DB::POST_PERMALINK] = $post->getPermalink();
     }
     if (count($data) == 0) {
         throw new Exception("Nessuna modifica da effettuare.");
     }
     $modDate = $_SERVER["REQUEST_TIME"];
     $data[DB::POST_MODIFICATION_DATE] = date("Y/m/d G:i:s", $modDate);
     // se mi dicono di fare l'update, cambio modificationDate
     //salvo la versione precedente e ne tengo traccia.
     $history_id = $this->saveHistory($p_old, "UPDATED");
     $post->setPreviousVersion($history_id);
     $data[DB::POST_PREVIOUS_VERSION] = $post->getPreviousVersion();
     $rs = $this->db->execute($s = Query::generateUpdateStm($this->table, $data, array(new WhereConstraint($this->table->getColumn(DB::POST_ID), Operator::EQUAL, $post->getID()))), $this->table->getName(), $post);
     //aggiorno lo stato del post (se chi l'ha modificato è un redattore).
     if (AuthenticationManager::isEditor($editor)) {
         $post->setEditable(false);
         $post->setRemovable(false);
         $this->updateState($post);
     }
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore aggiornando il dato. Riprovare.");
     }
     //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]));
         //TODO
     }
     return $post->setModificationDate($modDate);
 }
Example #3
0
 function update($resource, $editor)
 {
     parent::update($resource, $editor, self::OBJECT_CLASS);
     $r_old = $this->quickLoad($resource->getID());
     if (is_null($r_old)) {
         throw new Exception("L'oggetto da modificare non esiste.");
     }
     $data = array();
     //cerco le differenze POSSIBILI e le salvo.
     if ($r_old->getDescription() != $resource->getDescription()) {
         $data[DB::RESOURCE_DESCRIPTION] = $resource->getDescription();
     }
     if ($r_old->getTags() != $resource->getTags()) {
         $data[DB::RESOURCE_TAGS] = $resource->getTags();
     }
     $modDate = $_SERVER["REQUEST_TIME"];
     $data[DB::RESOURCE_MODIFICATION_DATE] = date("Y/m/d G:i:s", $modDate);
     //salvo la versione precedente e ne tengo traccia.
     $history_id = $this->saveHistory($r_old, $editor, "UPDATED");
     $resource->setPreviousVersion($history_id);
     $data[DB::PREVIOUS_VERSION] = $resource->getPreviousVersion();
     $rs = $this->db->execute($s = Query::generateUpdateStm($this->table, $data, array(new WhereConstraint($this->table->getColumn(DB::RESOURCE_ID), Operator::EQUAL, $resource->getID()))), $this->table->getName(), $resource);
     //TODO decommentare quando AuthenticationManager è operativo
     //aggiorno lo stato della risorsa (se chi l'ha modificata è un redattore).
     //if(AuthenticationManager::isEditor($editor)) {
     //	$resource->setEditable(false);
     //	$resource->setRemovable(false);
     //	$this->updateState($resource);
     //}
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore aggiornando il dato. Riprovare.");
     }
     //salvo i tag che non esistono
     if (!is_null($resource->getTags()) && trim($resource->getTags()) != "") {
         TagManager::createTags(explode(",", $resource->getTags()));
     }
     return $resource->setModificationDate($modDate);
 }