}
/** 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
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;
}
public function commit()
{
- $nl = NewsLetter::forGroup(NewsLetter::GROUP_XORG)->getPendingIssue();
+ $nl = NewsLetter::forGroup(NewsLetter::GROUP_XORG)->getPendingIssue(true);
$nl->saveArticle($this->art);
return true;
}