예제 #1
1
 /**
  * Retrieves an specific Edition
  * specified by the IDs of
  * the article and the edition.
  *
  * @param int $articleID
  * @param int $editionID
  *
  * @throws ModelNotFoundException
  *
  * @return Edition
  **/
 public function editionAtIndex($articleID, $editionID)
 {
     $edition = Edition::where('id', $editionID)->where('article_id', $articleID)->get()->first();
     if ($edition == null) {
         $e = new ModelNotFoundException();
         $e->setModel('Edition');
         throw $e;
     }
     return $edition;
 }
예제 #2
0
 /**
  * Creates an edition and stores
  * it into the DB.
  *
  * @param User $user
  * @param Article $article
  * @param str $content
  * @param int $count
  *
  * @return Edition
  */
 public function createEdition(User $user, Article $article, $content = null, $count = 1)
 {
     $editions = [];
     if (!$content) {
         $content = static::$defaultContent;
     }
     for ($i = 0; $i < $count; $i++) {
         $editionsCount = count($editions);
         $newContent = $editionsCount > 1 ? $content . $editionsCount : $content;
         $edition = new Edition();
         $edition->content = $newContent;
         $edition->article_id = $article->id;
         $edition->created_by = $user->id;
         $edition->save();
         $editions[] = $edition;
     }
     return count($editions) > 1 ? $editions : $editions[0];
 }