From: Raphaël Barrois Date: Sun, 6 Feb 2011 22:00:46 +0000 (+0100) Subject: Automatically create a new pending issue if it doesn't exist when committing an artic... X-Git-Tag: xorg/1.1.0~1^2~39 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=b8bcbe021ba5e7464897a0701a5f78fb8a6d3c0f;hp=50f5e460f6705d22e6ea230d96744cfb9e4104ee;p=platal.git Automatically create a new pending issue if it doesn't exist when committing an article for the NL Signed-off-by: Raphaël Barrois --- diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 1f42a2d..97f57eb 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -231,9 +231,10 @@ class NewsLetter } /** Return the latest pending issue of the newsletter. + * @p $create Whether to create an empty issue if no pending issue exist. * @return Either null, or a NL object. */ - public function getPendingIssue() + public function getPendingIssue($create = false) { $res = XDB::query('SELECT MAX(id) FROM newsletter_issues @@ -242,6 +243,9 @@ class NewsLetter if ($res->numRows()) { $id = $res->fetchOneCell(); return new NLIssue($id, $this); + } else if ($create) { + $id = $this->createPending(); + return new NLIssue($id, $this); } else { return null; } diff --git a/include/validations/nl.inc.php b/include/validations/nl.inc.php index 0a385ac..2c17f2b 100644 --- a/include/validations/nl.inc.php +++ b/include/validations/nl.inc.php @@ -106,7 +106,7 @@ class NLReq extends Validate public function commit() { - $nl = NewsLetter::forGroup(NewsLetter::GROUP_XORG)->getPendingIssue(); + $nl = NewsLetter::forGroup(NewsLetter::GROUP_XORG)->getPendingIssue(true); $nl->saveArticle($this->art); return true; }