Esempio n. 1
0
 /**
  * Создание автора
  * @param $name
  * @return Author
  */
 private function createAuthor($name)
 {
     $object = new Author();
     $object->setName($name);
     $this->om->persist($object);
     return $object;
 }
Esempio n. 2
0
 /**
  * Редактирование статьи
  * @param $articleId
  * @param $title
  * @param $text
  * @param $authors
  * @return Article
  * @throws \Symfony\Component\Config\Definition\Exception\Exception
  */
 public function editArticle($articleId, $title, $text, $authors)
 {
     $authorArray = array();
     // Проверка и создание авторов
     foreach ($authors as $authorName) {
         $author = $this->authorRepository->findAuthorByName($authorName);
         if (!$author) {
             $author = new Author();
             $author->setName($authorName);
             $this->em->persist($author);
             $result['exist'] = false;
         }
         $authorArray[] = $author;
     }
     // Проверка статьи
     $article = $this->articleRepository->find($articleId);
     if (!$article) {
         throw new Exception("Статья {$articleId} не найдена.");
     }
     $article->setTitle($title);
     $article->setContent($text);
     $article->setDate(new \DateTime('now'));
     $article->setAuthors($authorArray);
     $this->em->persist($article);
     $this->em->flush();
     return $article;
 }