Esempio n. 1
0
 /**
  * Создания статьи
  * @param $title
  * @param $text
  * @param $authors
  * @param $rating
  * @param $date
  * @return Article
  */
 private function createArticle($title, $text, $authors, $rating, $date)
 {
     $object = new Article();
     $object->setTitle($title);
     $object->setContent($text);
     $object->setRating($rating);
     $object->setDate(new \DateTime($date));
     $object->setAuthors($authors);
     $this->om->persist($object);
     return $object;
 }
Esempio n. 2
0
 /**
  * Создание статьи
  * @param $title
  * @param $text
  * @param $authors
  * @return Article
  */
 public function createArticle($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 = new Article();
     $article->setTitle($title);
     $article->setContent($text);
     $article->setDate(new \DateTime('now'));
     $article->setAuthors($authorArray);
     $this->em->persist($article);
     $this->em->flush();
     return $article;
 }