Ejemplo n.º 1
0
 function update($contact, $editor)
 {
     parent::update($resource, $editor, self::OBJECT_CLASS);
     $old = $this->quickLoad($resource->getID());
     if (is_null($r_old)) {
         throw new Exception("L'oggetto da modificare non esiste.");
     }
     $data = array();
     if ($contact->getContact() != $old->getContact()) {
         $data[DB::CONTACT_CONTACT] = $contact->getContact();
     }
     if ($contact->getName() != $old->getName()) {
         $data[DB::CONTACT_NAME] = $contact->getName();
     }
     $this->db->execute($s = Query::generateUpdateStm($this->table, $data, array(new WhereConstraint($this->table->getColumn(DB::CONTACT_ID), Operator::EQUAL, $contact->getID()))), $this->table->getName(), $contact);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore aggiornando il dato. Riprovare.");
     }
     return $contact;
 }
Ejemplo n.º 2
0
 function update($user, $editor)
 {
     parent::update($user, $editor, self::OBJECT_CLASS);
     $old = $this->quickLoad($user->getID());
     if (is_null($old)) {
         throw new Exception("L'oggetto da modificare non esiste.");
     }
     $data = array();
     if ($user->getAvatar() != $old->getAvatar()) {
         $data[DB::USER_AVATAR] = $user->getAvatar();
     }
     if ($user->getBirthday() != $old->getBirthday()) {
         $data[DB::USER_BIRTHDAY] = $user->getBirthday();
     }
     if ($user->getBirthplace() != $old->getBirthplace()) {
         $data[DB::USER_BIRTHPLACE] = $user->getBirthplace();
     }
     if ($user->getEMail() != $old->getEMail()) {
         $data[DB::USER_E_MAIL] = $user->getEMail();
     }
     if ($user->getGender() != $old->getGender()) {
         $data[DB::USER_GENDER] = $user->getGender();
     }
     if ($user->getHobbies() != $old->getHobbies()) {
         $data[DB::USER_HOBBIES] = $user->getHobbies();
     }
     if ($user->getJob() != $old->getJob()) {
         $data[DB::USER_JOB] = $user->getJob();
     }
     if ($user->getLivingPlace() != $old->getLivingPlace()) {
         $data[DB::USER_LIVINGPLACE] = $user->getLivingPlace();
     }
     if ($user->getName() != $old->getName()) {
         $data[DB::USER_NAME] = $user->getName();
     }
     if ($user->getNickname() != $old->getNickname()) {
         $data[DB::USER_NICKNAME] = $user->getNickname();
     }
     if ($user->getPassword() != $old->getPassword()) {
         $data[DB::USER_PASSWORD] = $user->getPassword();
     }
     if ($user->getRole() != $old->getRole()) {
         $data[DB::USER_ROLE] = $user->getRole();
     }
     if ($user->getSurname() != $old->getSurname()) {
         $data[DB::USER_SURNAME] = $user->getSurname();
     }
     if ($user->getVisible() != $old->getVisible()) {
         $data[DB::USER_VISIBLE] = $user->getVisible() ? 1 : 0;
     }
     $this->db->execute($s = Query::generateUpdateStm($this->table, $data, array(new WhereConstraint($this->table->getColumn(DB::USER_ID), Operator::EQUAL, $user->getID()))), $this->table->getName(), $user);
     //TODO aggiungere authenitcationManager
     //aggiorno lo stato della risorsa (se chi l'ha modificata è un redattore).
     //if(AuthenticationManager::isUserManager($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.");
     }
     return $user;
 }
Ejemplo n.º 3
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);
 }
 public function update($id, $data)
 {
     $arr_id = array("id" => $id);
     return parent::update($arr_id, $data);
 }
Ejemplo n.º 5
0
 function addWinner($post, $contest, $position)
 {
     parent::update($contest, self::OBJECT_CLASS);
     if (!is_subclass_of($post, "Post")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un post.");
     }
     $this->db->execute($s = Query::generateUpdateStm($this->table_cs, array(DB::CONTEST_SUBSCRIBER_PLACEMENT => intval($position)), array(new WhereConstraint($this->table_cs->getColumn(DB::CONTEST_SUBSCRIBER_POST), Operator::EQUAL, $post->getID()), new WhereConstraint($this->table_cs->getColumn(DB::CONTEST_SUBSCRIBER_CONTEST), Operator::EQUAL, $contest->getID()))), $table->getName(), $contest);
     if ($this->db->affected_rows() != 1) {
         throw new Exception("Si è verificato un errore aggiornando l'oggetto. Riprovare.");
     }
     return $contest;
 }
Ejemplo n.º 6
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);
 }