static function loadContest($id) { return Contest::loadFromDatabase($id); }
/** * 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: $this o FALSE se c'è un errore. */ function update() { $old = Contest::loadFromDatabase($this->getID()); $data = array(); if ($old->getTitle() != $this->getTitle()) { $data[CONTEST_TITLE] = $this->getTitle(); } if ($old->getDescription() != $this->getDescription()) { $data[CONTEST_DESCRIPTION] = $this->getDescription(); } if ($old->getEnd() != $this->getEnd()) { $data[CONTEST_END] = $this->getEnd(); } if ($old->getPrizes() != $this->getPrizes()) { $data[CONTEST_PRIZES] = $this->getPrizes(); } if ($old->getRules() != $this->getRules()) { $data[CONTEST_RULES] = $this->getRules(); } if ($old->getStart() != $this->getStart()) { $data[CONTEST_START] = $this->getStart(); } if ($old->getWinners() != $this->getWinners()) { $data["ct_winners"] = $this->getWinners(); } //TODO aggiornare i vincitori. if ($old->getSubscriberType() == $this->getSubscriberType()) { $data[CONTEST_TYPE_OF_SUBSCRIBER] = $this->getSubscriberType(); } require_once "query.php"; $db = new DBManager(); if (!$db->connect_errno()) { $table = Query::getDBSchema()->getTable(TABLE_CONTEST); $rs = $db->execute($s = Query::generateUpdateStm($table, $data, array(new WhereConstraint($table->getColumn(CONTEST_ID), Operator::EQUAL, $this->getID()))), $table->getName(), $this); //echo "<br />" . $s; //DEBUG //echo "<br />" . mysql_affected_rows(); //DEBUG if ($db->affected_rows() == 1) { //echo "<br />" . $this; //DEBUG return $this->getID(); } else { $db->display_error("Contest::update()"); } } else { $db->display_connect_error("Contest::update()"); } return false; }