public function createArticle($articleType, $language, $user, $publication, $attributes = array(), $issue = null, $section = null)
{
$this->checkForArticleConflicts($attributes['name'], $publication, $issue, $section);
$article = new Article($this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextArticleNumber(), $language);
if (!$section) {
$articleOrder = $article->getNumber();
} else {
$minArticleOrder = $this->em->getRepository('Newscoop\\Entity\\Article')->getMinArticleOrder($publication, $issue, $section)->getSingleScalarResult();
$increment = $minArticleOrder > 0 ? 1 : 2;
$this->em->getRepository('Newscoop\\Entity\\Article')->updateArticleOrder($increment, $publication, $issue, $section)->getResult();
$articleOrder = 1;
}
$article->setArticleOrder($articleOrder);
$article->setPublication($publication);
$article->setType($articleType);
$article->setCreator($user);
$article->setIssueId(0);
$article->setSectionId(0);
if (!is_null($issue)) {
$article->setIssueId($issue->getNumber());
$article->setIssue($issue);
}
if (!is_null($section)) {
$article->setSectionId($section->getNumber());
$article->setSection($section);
}
$this->updateArticleMeta($article, $attributes);
$article->setCommentsLocked(false);
//TODO - add this to type
$article->setWorkflowStatus('N');
$article->setShortName($article->getNumber());
$article->setLockTime(null);
$article->setPublished(new \Datetime());
$article->setUploaded(new \Datetime());
$article->setLockUser();
$article->setPublic('Y');
$article->setIsIndexed('N');
$this->em->persist($article);
$this->em->flush();
$articleData = new \ArticleData($article->getType(), $article->getNumber(), $article->getLanguageId());
$articleData->create();
return $article;
}