1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Added further tests, Fixed speed_update issues, improved search result query count

This commit is contained in:
Dan Brown
2015-11-29 17:33:25 +00:00
parent 22f8a408fa
commit 62338e4a8f
12 changed files with 115 additions and 53 deletions

View File

@@ -3,7 +3,6 @@
class Chapter extends Entity
{
protected $fillable = ['name', 'description', 'priority', 'book_id'];
public function book()
@@ -18,7 +17,7 @@ class Chapter extends Entity
public function getUrl()
{
$bookSlug = isset($this->bookSlug) ? $this->bookSlug : $this->book->slug;
$bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
return '/books/' . $bookSlug. '/chapter/' . $this->slug;
}

View File

@@ -69,19 +69,18 @@ abstract class Entity extends Model
* @param $type
* @return bool
*/
public function isA($type)
public static function isA($type)
{
return $this->getName() === strtolower($type);
return static::getName() === strtolower($type);
}
/**
* Gets the class name.
* @return string
*/
public function getName()
public static function getName()
{
$fullClassName = get_class($this);
return strtolower(array_slice(explode('\\', $fullClassName), -1, 1)[0]);
return strtolower(array_slice(explode('\\', static::class), -1, 1)[0]);
}
/**
@@ -102,6 +101,15 @@ abstract class Entity extends Model
foreach ($wheres as $whereTerm) {
$search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
}
if (!static::isA('book')) {
$search = $search->with('book');
}
if(static::isA('page')) {
$search = $search->with('chapter');
}
return $search->get();
}

View File

@@ -150,14 +150,16 @@ class BookController extends Controller
{
$this->checkPermission('book-update');
$book = $this->bookRepo->getBySlug($bookSlug);
$bookChildren = $this->bookRepo->getChildren($book);
$books = $this->bookRepo->getAll();
return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books]);
return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]);
}
public function getSortItem($bookSlug)
{
$book = $this->bookRepo->getBySlug($bookSlug);
return view('books/sort-box', ['book' => $book]);
$bookChildren = $this->bookRepo->getChildren($book);
return view('books/sort-box', ['book' => $book, 'bookChildren' => $bookChildren]);
}
/**

View File

@@ -33,7 +33,6 @@ class ChapterController extends Controller
/**
* Show the form for creating a new chapter.
*
* @param $bookSlug
* @return Response
*/
@@ -46,7 +45,6 @@ class ChapterController extends Controller
/**
* Store a newly created chapter in storage.
*
* @param $bookSlug
* @param Request $request
* @return Response
@@ -62,8 +60,8 @@ class ChapterController extends Controller
$chapter = $this->chapterRepo->newFromInput($request->all());
$chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id);
$chapter->priority = $this->bookRepo->getNewPriority($book);
$chapter->created_by = Auth::user()->id;
$chapter->updated_by = Auth::user()->id;
$chapter->created_by = auth()->user()->id;
$chapter->updated_by = auth()->user()->id;
$book->chapters()->save($chapter);
Activity::add($chapter, 'chapter_create', $book->id);
return redirect($chapter->getUrl());
@@ -71,7 +69,6 @@ class ChapterController extends Controller
/**
* Display the specified chapter.
*
* @param $bookSlug
* @param $chapterSlug
* @return Response
@@ -87,7 +84,6 @@ class ChapterController extends Controller
/**
* Show the form for editing the specified chapter.
*
* @param $bookSlug
* @param $chapterSlug
* @return Response
@@ -102,7 +98,6 @@ class ChapterController extends Controller
/**
* Update the specified chapter in storage.
*
* @param Request $request
* @param $bookSlug
* @param $chapterSlug
@@ -115,7 +110,7 @@ class ChapterController extends Controller
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
$chapter->fill($request->all());
$chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id, $chapter->id);
$chapter->updated_by = Auth::user()->id;
$chapter->updated_by = auth()->user()->id;
$chapter->save();
Activity::add($chapter, 'chapter_update', $book->id);
return redirect($chapter->getUrl());
@@ -137,7 +132,6 @@ class ChapterController extends Controller
/**
* Remove the specified chapter from storage.
*
* @param $bookSlug
* @param $chapterSlug
* @return Response

View File

@@ -141,7 +141,7 @@ class BookRepo
*/
public function getNewPriority($book)
{
$lastElem = $book->children()->pop();
$lastElem = $this->getChildren($book)->pop();
return $lastElem ? $lastElem->priority + 1 : 0;
}