コード例 #1
0
ファイル: EditArticlePage.php プロジェクト: rutgerkok/rCMS
 /**
  * Gets the article with the given id. If the id is 0, a new article is
  * created.
  * @param ArticleRepository $repository Repository to fetch articles from.
  * @param User $currentUser Becomes the author if a new article is created.
  * @param int $id Id of the article. Use 0 to create a new article.
  * @return Article The article.
  * @throws NotFoundException If no article exists with the given id.
  */
 protected function getArticle(ArticleRepository $repository, User $currentUser, $id)
 {
     if ($id === 0) {
         $article = new Article();
         $article->setAuthor($currentUser);
         return $article;
     } else {
         $article = $repository->getArticleOrFail($id);
         if ($article->authorId === 0) {
             // There was a bug in previous versions of the CMS where the
             // author wasn't saved
             $article->setAuthor($currentUser);
         }
         return $article;
     }
 }
コード例 #2
0
ファイル: Article.php プロジェクト: rutgerkok/rCMS
 /**
  * Creates a new article.
  * @param User $author Author of the article.
  * @return Article The article.
  */
 public static function createArticle(User $author)
 {
     $article = new Article();
     $article->setAuthor($author);
     return $article;
 }