diff --git a/app/Http/Controllers/Admin/CreateNewContent.php b/app/Http/Controllers/Admin/CreateNewContent.php
index 10e1c17e..48697d0e 100644
--- a/app/Http/Controllers/Admin/CreateNewContent.php
+++ b/app/Http/Controllers/Admin/CreateNewContent.php
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Enumerations\ActiveContentStatuses;
use App\Http\Requests\CreateNewContentRequest;
use App\Models\Content;
+use App\Models\File;
use App\Models\Module;
use App\Models\Template;
use Illuminate\Support\Str;
@@ -11,6 +12,22 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class CreateNewContent extends Controller
{
+ /**
+ * @var File
+ */
+ private $file;
+ /**
+ * @var Content
+ */
+ private $content;
+
+ public function __construct(File $file, Content $content)
+ {
+ parent::__construct();
+ $this->file = $file;
+ $this->content = $content;
+ }
+
/**
* Display form for new content page
*
@@ -29,16 +46,15 @@ class CreateNewContent extends Controller
->get();
// create default content object
- $page = new Content();
- $page->status = Content::STATUS_DRAFT;
+ $this->content->status = Content::STATUS_DRAFT;
// render view
return view('admin.content.new', [
'contentStatuses' => $statuses,
'templates' => $templates,
'moduleId' => $moduleId,
- 'page' => $page,
- 'rootPages' => $page->rootPages(),
+ 'page' => $this->content,
+ 'rootPages' => $this->content->rootPages(),
'moduleName' => trans($module->name),
'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']),
'formSections' => call_user_func([$module->handler, 'getExtendedFormInputsCreate']),
@@ -82,6 +98,13 @@ class CreateNewContent extends Controller
$page->parent_id = $request->parentPage;
}
+ // upload file - if provided
+ if ($request->hasFile('titlePhoto')) {
+ $file = $this->file->upload($request->file('titlePhoto'), $request);
+
+ $page->title_photo = $file['filename'];
+ }
+
// save module-specific stuff
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
diff --git a/app/Http/Controllers/Admin/EditContent.php b/app/Http/Controllers/Admin/EditContent.php
index c6e22d7d..2acab439 100644
--- a/app/Http/Controllers/Admin/EditContent.php
+++ b/app/Http/Controllers/Admin/EditContent.php
@@ -6,9 +6,9 @@ use App\Enumerations\ModulesHandlerToId;
use App\Http\Requests\EditContentRequest;
use App\Models\Content;
use App\Models\ContentHistory;
+use App\Models\File;
use App\Models\Template;
use Illuminate\Support\Str;
-use Modules\StaticPages\Http\Requests\EditStaticPageRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class EditContent extends Controller
@@ -17,10 +17,15 @@ class EditContent extends Controller
* @var ContentHistory
*/
private $history;
+ /**
+ * @var File
+ */
+ private $file;
- public function __construct(ContentHistory $history)
+ public function __construct(ContentHistory $history, File $file)
{
$this->history = $history;
+ $this->file = $file;
}
/**
@@ -81,6 +86,14 @@ class EditContent extends Controller
$request->url = Str::slug($request->url);
$request->parentPage = $request->parentPage ? $request->parentPage : null;
+ $request->titlePhotoFilename = $page->title_photo;
+
+ // upload file - if provided
+ if ($request->hasFile('titlePhoto')) {
+ $file = $this->file->upload($request->file('titlePhoto'), $request);
+
+ $request->titlePhotoFilename = $file['filename'];
+ }
// array of fields in database and fields from request
$fields = [
@@ -93,7 +106,8 @@ class EditContent extends Controller
'meta_description' => 'metaDescription',
'content' => 'pageContent',
'parent_id' => 'parentPage',
- 'status' => 'status'
+ 'status' => 'status',
+ 'title_photo' => 'titlePhotoFilename'
];
// save new values with history
diff --git a/app/Http/Requests/CreateNewContentRequest.php b/app/Http/Requests/CreateNewContentRequest.php
index 3d995ba6..7284b6ae 100644
--- a/app/Http/Requests/CreateNewContentRequest.php
+++ b/app/Http/Requests/CreateNewContentRequest.php
@@ -12,15 +12,15 @@ class CreateNewContentRequest extends Request
public function rules()
{
return [
- 'title' => 'required',
- 'url' => 'required|unique:contents,url',
- 'template' => 'required|exists:templates,template_name',
- 'published_from' => 'date',
- 'published_to' => 'date',
- 'title_photo' => 'exists:files,id',
- 'module_settings' => 'json',
- 'status' => 'required|in:draft,protected,public',
- 'parentPage' => 'exists:contents,id'
+ 'titlePhoto' => 'image',
+ 'title' => 'required',
+ 'url' => 'required|unique:contents,url',
+ 'template' => 'required|exists:templates,template_name',
+ 'status' => 'required|in:draft,protected,public',
+ 'title_photo' => 'exists:files,id',
+ 'parentPage' => 'exists:contents,id',
+ 'published_from' => 'date',
+ 'published_to' => 'date',
];
}
}
diff --git a/app/Models/File.php b/app/Models/File.php
index 447950ff..a5962fd6 100644
--- a/app/Models/File.php
+++ b/app/Models/File.php
@@ -3,7 +3,7 @@
namespace App\Models;
use App\Events\UploadFile;
-use App\Http\Requests\UploadRequest;
+use App\Http\Requests\Request;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
@@ -49,13 +49,13 @@ class File extends Model
/**
* Saves file into FS and creates new record in database
*
- * @param UploadedFile $file
- * @param UploadRequest $request
+ * @param UploadedFile $file
+ * @param Request $request
*
* @return array associative array - key 'file' is type of SymphonyFile and contains info about real file, key 'id'
* is ID of row in files table
*/
- public function upload(UploadedFile $file, UploadRequest $request)
+ public function upload(UploadedFile $file, Request $request)
{
$destination = config('app.upload_path');
$filename = $this->getFilename($file);
@@ -70,8 +70,9 @@ class File extends Model
Event::fire(new UploadFile($uploadedFile, $id));
return [
- 'file' => $file,
- 'id' => $id
+ 'filename' => $filename,
+ 'file' => $file,
+ 'id' => $id
];
}
@@ -81,12 +82,12 @@ class File extends Model
* This file saves new record into database. It also calculates hash of given file, obtains MIME type etc.
*
* @param SymphonyFile $file
- * @param UploadRequest $request
+ * @param Request $request
* @param $originalFilename
*
* @return mixed
*/
- protected function saveIntoDatabase(SymphonyFile $file, UploadRequest $request, $originalFilename)
+ protected function saveIntoDatabase(SymphonyFile $file, Request $request, $originalFilename)
{
// get path and hash of uploaded file
$path = config('app.upload_path') . DIRECTORY_SEPARATOR . $file->getFilename();
@@ -101,13 +102,14 @@ class File extends Model
$newFile->hash_algorithm = self::HASH_ALGORITHM;
$newFile->mime_type = $file->getMimeType();
$newFile->file_size = $file->getSize();
- $newFile->directory_id = $request->directoryId;
// save optional fields
- $optionalFields = ['description', 'keywords'];
+ $optionalFields = ['description', 'keywords', 'directoryId'];
foreach ($optionalFields as $field) {
if ($request->has($field)) {
- $newFile->$field = $request->$field;
+
+ $snakeField = snake_case($field);
+ $newFile->$snakeField = $request->$field;
}
}
diff --git a/database/migrations/2016_03_31_192238_ChangeContentTitleImageIdForFilename.php b/database/migrations/2016_03_31_192238_ChangeContentTitleImageIdForFilename.php
new file mode 100644
index 00000000..2d04429b
--- /dev/null
+++ b/database/migrations/2016_03_31_192238_ChangeContentTitleImageIdForFilename.php
@@ -0,0 +1,86 @@
+dropForeign('fk_content_file1');
+ });
+ } catch (\Illuminate\Database\QueryException $e) {
+ // probably foreign does not exist, try to remove one from migration
+
+ try {
+ Schema::table('contents', function (Blueprint $table) {
+ $table->dropForeign('contents_title_photo_foreign');
+ });
+ } catch (\Illuminate\Database\QueryException $ex) {
+ // ignore this error
+ }
+ }
+
+ // force Doctrine to consider enum type as string
+ $platform = Schema::getConnection()
+ ->getDoctrineSchemaManager()
+ ->getDatabasePlatform();
+ $platform->registerDoctrineTypeMapping('enum', 'string');
+
+ Schema::table('contents', function (Blueprint $table) {
+ $table->string('title_photo', 128)
+ ->nullable()
+ ->default(null)
+ ->comment('This photo is supposed to be displayed e.g. on list of all pages.')
+ ->change();
+
+ $table->foreign('title_photo')
+ ->references('filename')
+ ->on('files')
+ ->onUpdate('cascade')
+ ->onDelete('set null');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ // force Doctrine to consider enum type as string
+ $platform = Schema::getConnection()
+ ->getDoctrineSchemaManager()
+ ->getDatabasePlatform();
+ $platform->registerDoctrineTypeMapping('enum', 'string');
+
+ // delete all title photos
+ DB::statement('UPDATE contents SET title_photo = NULL');
+
+ Schema::table('contents', function (Blueprint $table) {
+ $table->dropForeign('contents_title_photo_foreign');
+ });
+
+ Schema::table('contents', function (Blueprint $table) {
+ $table->integer('title_photo', false)
+ ->change();
+ });
+
+ Schema::table('contents', function (Blueprint $table) {
+ $table->foreign('title_photo')
+ ->references('id')
+ ->on('files');
+ });
+ }
+}
diff --git a/resources/assets/css/admin.css b/resources/assets/css/admin.css
index cddaaff2..c5b041ba 100644
--- a/resources/assets/css/admin.css
+++ b/resources/assets/css/admin.css
@@ -127,6 +127,10 @@ code {
font-size: 80%;
}
+#appearance .title-photo img {
+ max-height: 10em;
+}
+
.red {
color: red;
}
diff --git a/resources/lang/en/admin/contents.php b/resources/lang/en/admin/contents.php
index 2f6175fd..40ebb560 100644
--- a/resources/lang/en/admin/contents.php
+++ b/resources/lang/en/admin/contents.php
@@ -36,5 +36,6 @@ return [
'overview' => 'List of all content pages',
'homepageSetup' => 'Homepage successfully set up.',
'setHomepage' => 'Set page as homepage',
- 'noParentPage' => ' -- No parent page -- '
+ 'noParentPage' => ' -- No parent page -- ',
+ 'uploadTitleImage' => 'Upload title image'
];
\ No newline at end of file
diff --git a/resources/lang/en/admin/history.php b/resources/lang/en/admin/history.php
index 0f40784e..09632f62 100644
--- a/resources/lang/en/admin/history.php
+++ b/resources/lang/en/admin/history.php
@@ -1,22 +1,23 @@
'History of :name',
- 'columnPageContent' => 'Page content',
- 'columnUrl' => 'URL',
- 'columnTitle' => 'Title',
- 'columnMetaKeywords' => 'Meta keywords',
- 'columnMetaDescription' => 'Description',
- 'columnStatus' => 'Page visibility',
- 'columnTemplate' => 'Template',
- 'columnIs_homepage' => 'Homepage',
- 'columnParentPage' => 'Parent page',
- 'emptyValue' => 'none',
- 'changedFromTo' => 'Changed from :from to :to',
- 'numOfChanges' => 'One change|:count changes',
- 'diff' => 'Difference',
- 'diffPageName' => 'Difference of :column',
- 'backToOverview' => 'Back to history overview',
- 'backToEdit' => 'Back to editation form',
- 'setupAsHomepage' => 'Setup as homepage'
+ 'pageName' => 'History of :name',
+ 'columnPageContent' => 'Page content',
+ 'columnUrl' => 'URL',
+ 'columnTitle' => 'Title',
+ 'columnMetaKeywords' => 'Meta keywords',
+ 'columnMetaDescription' => 'Description',
+ 'columnStatus' => 'Page visibility',
+ 'columnTemplate' => 'Template',
+ 'columnIs_homepage' => 'Homepage',
+ 'columnParentPage' => 'Parent page',
+ 'columnTitlePhotoFilename' => 'Title photo',
+ 'emptyValue' => 'none',
+ 'changedFromTo' => 'Changed from :from to :to',
+ 'numOfChanges' => 'One change|:count changes',
+ 'diff' => 'Difference',
+ 'diffPageName' => 'Difference of :column',
+ 'backToOverview' => 'Back to history overview',
+ 'backToEdit' => 'Back to editation form',
+ 'setupAsHomepage' => 'Setup as homepage'
];
\ No newline at end of file
diff --git a/resources/views/admin/content/editForm.blade.php b/resources/views/admin/content/editForm.blade.php
index c2b46270..f0319dd6 100644
--- a/resources/views/admin/content/editForm.blade.php
+++ b/resources/views/admin/content/editForm.blade.php
@@ -10,7 +10,7 @@
@endif
-