runRequest($sql); $result = $result[0]; if (!$result) { return false; } $newArticle->abstract = $result['abstract']; $newArticle->text = $result['text']; $newArticle->authorId = $result['authorId']; $newArticle->date = DateParser::parseSQL($result['publicationDate']); $newArticle->writingDate = DateParser::parseSQL($result['writingDate']); $newArticle->needSaving = false; return $newArticle; } public static function Create($writingDate, $publicationDate, $authorId, $abstract, $text) { $text = InputSanitizer::Sanitize($text); $abstract = InputSanitizer::Sanitize($abstract); $publicationDate = InputSanitizer::Number($publicationDate); $writingDate = InputSanitizer::Number($writingDate); $authorId = InputSanitizer::Number($authorId); $publicationDate = DateFormatter::formatSQL($publicationDate); $writingDate = DateFormatter::formatSQL($writingDate); $sql = "INSERT INTO `news` ( `identifier`, `writingDate`, `publicationDate`, `authorId`, `abstract`, `text`) VALUES ( NULL, '$writingDate', '$publicationDate', '$authorId', '$abstract', '$text');"; $result = MySQLDatabase::getInstance()->runOperation($sql); $sql = "SELECT identifier FROM `news` WHERE `writingDate` = '$writingDate' LIMIT 1;"; $result = MySQLDatabase::getInstance()->runRequest($sql); $identifier = $result[0]['identifier']; $newArticle = Article::Get($identifier); return $newArticle; } /** * Removes the article corresponding to the given identifier. * * @param int $identifier * @return int/bool */ public static function Remove($identifier) { $sql = "DELETE FROM `news` WHERE `news`.`identifier` = $identifier;"; $result = MySQLDatabase::getInstance()->runOperation($sql); return $result; } private function __construct($identifier) { $this->identifier = $identifier; } function __destruct() { if ($this->needSaving) { $this->save(); } } /** * Saves the article in the database */ private function save() { $writingDate = DateFormatter::formatSQL($this->writingDate); $publicationDate = DateFormatter::formatSQL($this->date); $sql = "UPDATE `news` SET `writingDate` = '$writingDate', `publicationDate` = '$publicationDate', `authorId` = '$this->authorId', `abstract` = '$this->abstract', `text` = '$this->text' WHERE `identifier` = $this->identifier;"; $result = MySQLDatabase::getInstance()->runOperation($sql); } public function setContent($abstract, $text, $date) { $text = InputSanitizer::Sanitize($text); $abstract = InputSanitizer::Sanitize($abstract); $date = InputSanitizer::Number($date); $this->abstract = $abstract; $this->text = $text; $this->date = $date; $this->writingDate = time(); $this->needSaving = true; } public function getIdentifier() { return $this->identifier; } public function getText() { return $this->text; } public function getAbstract() { return $this->abstract; } public function getAuthor() { $user = Member::Get($this->authorId); return $user->getFullName(); } public function getAuthorId() { return $this->authorId; } public function getDate() { return $this->date; } public function getWritingDate() { return $this->writingDate; } public function setAuthorId($authorId) { $authorId = InputSanitizer::Number($authorId); $this->authorId = $authorId; $this->needSaving = true; } } ?>