From 52033f3a6f0761309b000da05bbb3f6289e48409 Mon Sep 17 00:00:00 2001
From: Dan Brown
Date: Sat, 8 Aug 2015 21:28:50 +0100
Subject: [PATCH] Added created_by and updated_by to entities. Fixes #3
---
app/Book.php | 10 ++++
app/Chapter.php | 10 ++++
app/Http/Controllers/BookController.php | 4 ++
app/Http/Controllers/ChapterController.php | 4 ++
app/Http/Controllers/ImageController.php | 3 +
app/Http/Controllers/PageController.php | 4 ++
app/Image.php | 10 ++++
app/Page.php | 9 ++-
...015_08_08_200447_add_users_to_entities.php | 57 +++++++++++++++++++
resources/assets/sass/_text.scss | 3 +
resources/views/books/show.blade.php | 8 ++-
resources/views/chapters/show.blade.php | 6 ++
resources/views/pages/show.blade.php | 7 +++
13 files changed, 132 insertions(+), 3 deletions(-)
create mode 100644 database/migrations/2015_08_08_200447_add_users_to_entities.php
diff --git a/app/Book.php b/app/Book.php
index 35df08338..abd23d64e 100644
--- a/app/Book.php
+++ b/app/Book.php
@@ -29,6 +29,16 @@ class Book extends Model
return $this->hasMany('Oxbow\Chapter');
}
+ public function createdBy()
+ {
+ return $this->belongsTo('Oxbow\User', 'created_by');
+ }
+
+ public function updatedBy()
+ {
+ return $this->belongsTo('Oxbow\User', 'updated_by');
+ }
+
public function children()
{
$pages = $this->pages()->where('chapter_id', '=', 0)->get();
diff --git a/app/Chapter.php b/app/Chapter.php
index 77c161385..b7623798a 100644
--- a/app/Chapter.php
+++ b/app/Chapter.php
@@ -17,6 +17,16 @@ class Chapter extends Model
return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC');
}
+ public function createdBy()
+ {
+ return $this->belongsTo('Oxbow\User', 'created_by');
+ }
+
+ public function updatedBy()
+ {
+ return $this->belongsTo('Oxbow\User', 'updated_by');
+ }
+
public function getUrl()
{
return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php
index 269e240a4..7aed33d19 100644
--- a/app/Http/Controllers/BookController.php
+++ b/app/Http/Controllers/BookController.php
@@ -4,6 +4,7 @@ namespace Oxbow\Http\Controllers;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Oxbow\Http\Requests;
use Oxbow\Repos\BookRepo;
@@ -65,6 +66,8 @@ class BookController extends Controller
$slug .= '1';
}
$book->slug = $slug;
+ $book->created_by = Auth::user()->id;
+ $book->updated_by = Auth::user()->id;
$book->save();
return redirect('/books');
}
@@ -113,6 +116,7 @@ class BookController extends Controller
$slug += '1';
}
$book->slug = $slug;
+ $book->updated_by = Auth::user()->id;
$book->save();
return redirect($book->getUrl());
}
diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php
index 42c511d95..d5ccae024 100644
--- a/app/Http/Controllers/ChapterController.php
+++ b/app/Http/Controllers/ChapterController.php
@@ -4,6 +4,7 @@ namespace Oxbow\Http\Controllers;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
use Oxbow\Http\Requests;
use Oxbow\Http\Controllers\Controller;
use Oxbow\Repos\BookRepo;
@@ -56,6 +57,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;
$book->chapters()->save($chapter);
return redirect($book->getUrl());
}
@@ -102,6 +105,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->save();
return redirect($chapter->getUrl());
}
diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php
index 2014b3604..a2271a547 100644
--- a/app/Http/Controllers/ImageController.php
+++ b/app/Http/Controllers/ImageController.php
@@ -5,6 +5,7 @@ namespace Oxbow\Http\Controllers;
use Illuminate\Filesystem\Filesystem as File;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
use Intervention\Image\Facades\Image as ImageTool;
use Illuminate\Support\Facades\DB;
use Oxbow\Http\Requests;
@@ -126,6 +127,8 @@ class ImageController extends Controller
// Create and save image object
$this->image->name = $name;
$this->image->url = $imagePath . $name;
+ $this->image->created_by = Auth::user()->id;
+ $this->image->updated_by = Auth::user()->id;
$this->image->save();
return response()->json($this->image);
}
diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php
index c84bc803f..b66081928 100644
--- a/app/Http/Controllers/PageController.php
+++ b/app/Http/Controllers/PageController.php
@@ -4,6 +4,7 @@ namespace Oxbow\Http\Controllers;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Oxbow\Http\Requests;
use Oxbow\Repos\BookRepo;
@@ -82,6 +83,8 @@ class PageController extends Controller
$page->book_id = $book->id;
$page->text = strip_tags($page->html);
+ $page->created_by = Auth::user()->id;
+ $page->updated_by = Auth::user()->id;
$page->save();
return redirect($page->getUrl());
}
@@ -130,6 +133,7 @@ class PageController extends Controller
$page->fill($request->all());
$page->slug = $this->pageRepo->findSuitableSlug($page->name, $book->id, $page->id);
$page->text = strip_tags($page->html);
+ $page->updated_by = Auth::user()->id;
$page->save();
return redirect($page->getUrl());
}
diff --git a/app/Image.php b/app/Image.php
index a51c18f75..9d2835dc3 100644
--- a/app/Image.php
+++ b/app/Image.php
@@ -10,4 +10,14 @@ class Image extends Model
{
return storage_path() . $this->url;
}
+
+ public function createdBy()
+ {
+ return $this->belongsTo('Oxbow\User', 'created_by');
+ }
+
+ public function updatedBy()
+ {
+ return $this->belongsTo('Oxbow\User', 'updated_by');
+ }
}
diff --git a/app/Page.php b/app/Page.php
index cb54de442..fd90b6d48 100644
--- a/app/Page.php
+++ b/app/Page.php
@@ -32,9 +32,14 @@ class Page extends Model
return $this->chapter()->count() > 0;
}
- public function parent()
+ public function createdBy()
{
- return $this->belongsTo('Oxbow\Page', 'page_id');
+ return $this->belongsTo('Oxbow\User', 'created_by');
+ }
+
+ public function updatedBy()
+ {
+ return $this->belongsTo('Oxbow\User', 'updated_by');
}
public function getUrl()
diff --git a/database/migrations/2015_08_08_200447_add_users_to_entities.php b/database/migrations/2015_08_08_200447_add_users_to_entities.php
new file mode 100644
index 000000000..7e402bda3
--- /dev/null
+++ b/database/migrations/2015_08_08_200447_add_users_to_entities.php
@@ -0,0 +1,57 @@
+integer('created_by');
+ $table->integer('updated_by');
+ });
+ Schema::table('chapters', function (Blueprint $table) {
+ $table->integer('created_by');
+ $table->integer('updated_by');
+ });
+ Schema::table('images', function (Blueprint $table) {
+ $table->integer('created_by');
+ $table->integer('updated_by');
+ });
+ Schema::table('books', function (Blueprint $table) {
+ $table->integer('created_by');
+ $table->integer('updated_by');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('pages', function (Blueprint $table) {
+ $table->dropColumn('created_by');
+ $table->dropColumn('updated_by');
+ });
+ Schema::table('chapters', function (Blueprint $table) {
+ $table->dropColumn('created_by');
+ $table->dropColumn('updated_by');
+ });
+ Schema::table('images', function (Blueprint $table) {
+ $table->dropColumn('created_by');
+ $table->dropColumn('updated_by');
+ });
+ Schema::table('books', function (Blueprint $table) {
+ $table->dropColumn('created_by');
+ $table->dropColumn('updated_by');
+ });
+ }
+}
diff --git a/resources/assets/sass/_text.scss b/resources/assets/sass/_text.scss
index 375162154..f09c57121 100644
--- a/resources/assets/sass/_text.scss
+++ b/resources/assets/sass/_text.scss
@@ -169,6 +169,9 @@ p.neg, p .neg, span.neg, .text-neg {
p.muted, p .muted, span.muted, .text-muted {
color: lighten($text-dark, 26%);
+ &.small, .small {
+ color: lighten($text-dark, 42%);
+ }
}
p.primary, p .primary, span.primary, .text-primary {
diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php
index b4ae5cdb3..8c03d74ce 100644
--- a/resources/views/books/show.blade.php
+++ b/resources/views/books/show.blade.php
@@ -37,7 +37,7 @@
{{$childElement->getExcerpt()}}
- @if(is_a($childElement, 'Oxbow\Chapter'))
+ @if(is_a($childElement, 'Oxbow\Chapter') && count($childElement->pages) > 0)
@foreach($childElement->pages as $page)
@@ -49,6 +49,12 @@
@endforeach
+
+ Created {{$book->created_at->diffForHumans()}} @if($book->createdBy) by {{$book->createdBy->name}} @endif
+
+ Last Updated {{$book->updated_at->diffForHumans()}} @if($book->createdBy) by {{$book->updatedBy->name}} @endif
+
+
diff --git a/resources/views/chapters/show.blade.php b/resources/views/chapters/show.blade.php
index 3420c1420..a72bbaf6a 100644
--- a/resources/views/chapters/show.blade.php
+++ b/resources/views/chapters/show.blade.php
@@ -42,6 +42,12 @@
@else
No pages are in this chapter
@endif
+
+
+ Created {{$chapter->created_at->diffForHumans()}} @if($chapter->createdBy) by {{$chapter->createdBy->name}} @endif
+
+ Last Updated {{$chapter->updated_at->diffForHumans()}} @if($chapter->createdBy) by {{$chapter->updatedBy->name}} @endif
+
diff --git a/resources/views/pages/show.blade.php b/resources/views/pages/show.blade.php
index a57828b3b..2fae34952 100644
--- a/resources/views/pages/show.blade.php
+++ b/resources/views/pages/show.blade.php
@@ -41,6 +41,13 @@
@endif
{!! $page->html !!}
+
+
+
+ Created {{$page->created_at->diffForHumans()}} @if($page->createdBy) by {{$page->createdBy->name}} @endif
+
+ Last Updated {{$page->updated_at->diffForHumans()}} @if($page->createdBy) by {{$page->updatedBy->name}} @endif
+