/** * Crea un post caricando i dati dal database. * È come fare una ricerca sul database e poi fare new Post(). * * @param $id: l'ID del post da caricare. * @return: il post caricato o FALSE se non lo trova. */ static function loadFromDatabase($id) { require_once "query.php"; $db = new DBManager(); if (!$db->connect_errno()) { $table = Query::getDBSchema()->getTable(TABLE_CONTEST); $rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(CONTEST_ID), Operator::EQUAL, $id)), array()), $table->getName(), null); //echo "<p>" . $s . "</p>"; //DEBUG //echo "<p>" . mysql_num_rows($rs) . "</p>"; //DEBUG if ($db->num_rows() == 1) { // echo serialize(mysql_fetch_assoc($rs)); //DEBUG $row = $db->fetch_result(); $data = array("title" => $row[CONTEST_TITLE], "description" => $row[CONTEST_DESCRIPTION], "rules" => $row[CONTEST_RULES], "prizes" => $row[CONTEST_PRIZES], "start" => date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[CONTEST_START])), "end" => date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[CONTEST_END])), "subscriberType" => $row[CONTEST_TYPE_OF_SUBSCRIBER]); $c = new Contest($data); $c->setID(intval($row[CONTEST_ID])); $c->loadSubscribers()->loadWinners(); //echo "<p>" .$p ."</p>"; return $c; } else { $db->display_error("Contest::loadFromDatabase()"); } } else { $db->display_connect_error("Contest::loadFromDatabase()"); } return false; }