mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 20:22:18 +00:00
Started work on bookshelves
This commit is contained in:
parent
b3cc3130f0
commit
4948b443b6
@ -48,14 +48,6 @@ class Book extends Entity
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Image::class, 'image_id');
|
return $this->belongsTo(Image::class, 'image_id');
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Get the edit url for this book.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getEditUrl()
|
|
||||||
{
|
|
||||||
return $this->getUrl() . '/edit';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all pages within this book.
|
* Get all pages within this book.
|
||||||
|
74
app/BookShelf.php
Normal file
74
app/BookShelf.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php namespace BookStack;
|
||||||
|
|
||||||
|
|
||||||
|
class BookShelf extends Entity
|
||||||
|
{
|
||||||
|
protected $table = 'bookshelves';
|
||||||
|
|
||||||
|
public $searchFactor = 3;
|
||||||
|
|
||||||
|
protected $fillable = ['name', 'description', 'image_id'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the url for this bookshelf.
|
||||||
|
* @param string|bool $path
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUrl($path = false)
|
||||||
|
{
|
||||||
|
if ($path !== false) {
|
||||||
|
return baseUrl('/shelves/' . urlencode($this->slug) . '/' . trim($path, '/'));
|
||||||
|
}
|
||||||
|
return baseUrl('/shelves/' . urlencode($this->slug));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns BookShelf cover image, if cover does not exists return default cover image.
|
||||||
|
* @param int $width - Width of the image
|
||||||
|
* @param int $height - Height of the image
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBookCover($width = 440, $height = 250)
|
||||||
|
{
|
||||||
|
$default = baseUrl('/book_default_cover.png');
|
||||||
|
if (!$this->image_id) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default;
|
||||||
|
} catch (\Exception $err) {
|
||||||
|
$cover = $default;
|
||||||
|
}
|
||||||
|
return $cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cover image of the book
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function cover()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Image::class, 'image_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an excerpt of this book's description to the specified length or less.
|
||||||
|
* @param int $length
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getExcerpt($length = 100)
|
||||||
|
{
|
||||||
|
$description = $this->description;
|
||||||
|
return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a generalised, common raw query that can be 'unioned' across entities.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function entityRawQuery()
|
||||||
|
{
|
||||||
|
return "'BookStack\\\\BookShelf' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text,'' as html, '0' as book_id, '0' as priority, '0' as chapter_id, '0' as draft, created_by, updated_by, updated_at, created_at";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateBookshelvesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('bookshelves', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('name', 200);
|
||||||
|
$table->string('slug', 200);
|
||||||
|
$table->text('description');
|
||||||
|
$table->integer('created_by')->nullable()->default(null);
|
||||||
|
$table->integer('updated_by')->nullable()->default(null);
|
||||||
|
$table->boolean('restricted')->default(false);
|
||||||
|
$table->integer('image_id')->nullable()->default(null);
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->index('slug');
|
||||||
|
$table->index('created_by');
|
||||||
|
$table->index('updated_by');
|
||||||
|
$table->index('restricted');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get roles with permissions we need to change
|
||||||
|
$adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
|
||||||
|
$editorRole = DB::table('roles')->where('name', '=', 'editor')->first();
|
||||||
|
|
||||||
|
// TODO - Copy existing role permissions from Books
|
||||||
|
$entity = 'BookShelf';
|
||||||
|
$ops = ['View All', 'View Own', 'Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
|
||||||
|
foreach ($ops as $op) {
|
||||||
|
$permId = DB::table('permissions')->insertGetId([
|
||||||
|
'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
|
||||||
|
'display_name' => $op . ' ' . 'BookShelves',
|
||||||
|
'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
|
||||||
|
'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
|
||||||
|
]);
|
||||||
|
// Assign view permission to all current roles
|
||||||
|
DB::table('permission_role')->insert([
|
||||||
|
'role_id' => $adminRoleId,
|
||||||
|
'permission_id' => $permId
|
||||||
|
]);
|
||||||
|
if ($editorRole !== null) {
|
||||||
|
DB::table('permission_role')->insert([
|
||||||
|
'role_id' => $editorRole->id,
|
||||||
|
'permission_id' => $permId
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('bookshelves');
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@
|
|||||||
<a dropdown-toggle class="text-primary text-button">@icon('more'){{ trans('common.more') }}</a>
|
<a dropdown-toggle class="text-primary text-button">@icon('more'){{ trans('common.more') }}</a>
|
||||||
<ul>
|
<ul>
|
||||||
@if(userCan('book-update', $book))
|
@if(userCan('book-update', $book))
|
||||||
<li><a href="{{$book->getEditUrl()}}" class="text-primary">@icon('edit'){{ trans('common.edit') }}</a></li>
|
<li><a href="{{ $book->getUrl('/edit') }}" class="text-primary">@icon('edit'){{ trans('common.edit') }}</a></li>
|
||||||
<li><a href="{{ $book->getUrl('/sort') }}" class="text-primary">@icon('sort'){{ trans('common.sort') }}</a></li>
|
<li><a href="{{ $book->getUrl('/sort') }}" class="text-primary">@icon('sort'){{ trans('common.sort') }}</a></li>
|
||||||
@endif
|
@endif
|
||||||
@if(userCan('restrictions-manage', $book))
|
@if(userCan('restrictions-manage', $book))
|
||||||
|
Loading…
Reference in New Issue
Block a user