commit a80fe7b2fe64200cbc9659c69e16828795aa163e
Author: Jan Šedivý <honza.seeda@gmail.com>
Date:   Tue Jun 11 16:19:42 2019 +0200

    Re #7608 Editor pro domovskou stránku

diff --git a/app/AdminModule/component/Settings/HomepageEditForm.latte b/app/AdminModule/component/Settings/HomepageEditForm.latte
new file mode 100644
index 0000000..93ce36b
--- /dev/null
+++ b/app/AdminModule/component/Settings/HomepageEditForm.latte
@@ -0,0 +1 @@
+{control form}
\ No newline at end of file
diff --git a/app/AdminModule/component/Settings/HomepageEditForm.php b/app/AdminModule/component/Settings/HomepageEditForm.php
new file mode 100644
index 0000000..5e80036
--- /dev/null
+++ b/app/AdminModule/component/Settings/HomepageEditForm.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace App\AdminModule\Components;
+
+use App\Enum\EFlashMessage;
+use App\Model\Repository\SettingsRepository;
+use App\Utils\Form;
+use Nette\Application\UI\Control;
+
+class HomepageEditForm extends Control
+{
+    /**
+     * @var \App\Model\Repository\SettingsRepository
+     */
+    private $settingsRepository;
+
+    public function __construct(\App\Model\Repository\SettingsRepository $settingsRepository)
+    {
+        $this->settingsRepository = $settingsRepository;
+        parent::__construct();
+    }
+
+    public function render()
+    {
+        $this->template->setFile(__DIR__ . '/HomepageEditForm.latte');
+        $this->template->render();
+    }
+
+    public function createComponentForm()
+    {
+        $form = new Form();
+
+        $form->addText(\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_HEADER, 'Page Header')
+            ->addRule(Form::REQUIRED, 'Field %label is required.');
+
+        $form->addText(\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_MOTTO, 'Motto');
+
+        $form->addCheckbox(\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_SHOW_SIGNS_FORM, "Show Borger's number search form");
+
+        $form->addTextArea(\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_CONTENT, 'Page content', 10, 15)
+            ->setAttribute('class', 'mceEditor');
+
+        $form->addSubmit('submit', 'Save');
+
+        $form->onSuccess[] = [$this, 'formSuccess'];
+        $form->getElementPrototype()->onsubmit('tinyMCE.triggerSave()');
+
+        $form->setDefaults($this->settingsRepository->getHomepageSettings());
+
+        return $form;
+    }
+
+    public function formSuccess(Form $form)
+    {
+        $values = $form->getValues();
+
+        $result = TRUE;
+        foreach ($values as $key => $value)
+        {
+            $row = $this->settingsRepository->findBy([SettingsRepository::COLUMN_KEY => $key]);
+            if(!$row)
+            {
+                $result = FALSE;
+                continue;
+            }
+            $row->update([SettingsRepository::COLUMN_VALUE => $value]);
+        }
+
+        if($result)
+        {
+            $this->presenter->flashMessage('Settings were successfully changed', EFlashMessage::SUCCESS);
+        }
+        else
+        {
+            $this->presenter->flashMessage('Settings could not be saved', EFlashMessage::ERROR);
+        }
+    }
+}
+
+interface IHomepageEditFormFactory
+{
+    /** @return HomepageEditForm */
+    public function create();
+}
\ No newline at end of file
diff --git a/app/AdminModule/presenters/SettingsPresenter.php b/app/AdminModule/presenters/SettingsPresenter.php
new file mode 100644
index 0000000..f74b2b1
--- /dev/null
+++ b/app/AdminModule/presenters/SettingsPresenter.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace App\AdminModule\Presenters;
+
+
+use App\AdminModule\Components\IHomepageEditFormFactory;
+
+class SettingsPresenter extends BaseUserPresenter
+{
+    /**
+     * @var IHomepageEditFormFactory
+     */
+    private $homepageEditFormFactory;
+
+    public function __construct(IHomepageEditFormFactory $homepageEditFormFactory)
+    {
+        $this->homepageEditFormFactory = $homepageEditFormFactory;
+        parent::__construct();
+    }
+
+    public function actionDefault()
+    {
+    }
+
+    public function createComponentHomepageEditForm()
+    {
+        return $this->homepageEditFormFactory->create();
+    }
+
+}
\ No newline at end of file
diff --git a/app/AdminModule/templates/@adminMenu.latte b/app/AdminModule/templates/@adminMenu.latte
index 113e957..3cfff34 100644
--- a/app/AdminModule/templates/@adminMenu.latte
+++ b/app/AdminModule/templates/@adminMenu.latte
@@ -19,4 +19,7 @@
             Origin </a></li>
     <li class="nav-item"><a n:href="Transport:default" n:class="nav-link, $presenter->isLinkCurrent('Transport:*') ? active" title="Transport">
             Import texts </a></li>
+    <li class="nav-item"><a n:href="Settings:default" n:class="nav-link, $presenter->isLinkCurrent('Settings:*') ? active" title="Settings">
+            Settings </a></li>
+
 </ul>
\ No newline at end of file
diff --git a/app/AdminModule/templates/Settings/default.latte b/app/AdminModule/templates/Settings/default.latte
new file mode 100644
index 0000000..1c2648d
--- /dev/null
+++ b/app/AdminModule/templates/Settings/default.latte
@@ -0,0 +1,15 @@
+{block content}
+
+{control homepageEditForm}
+
+{block scripts}
+    <script src="https://cdn.tiny.cloud/1/yum19i37uf1ffh15ll7d2u8jaxq0jwbbp4tzjwytli8mdg8h/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
+
+    <script>
+        tinyMCE.init({
+            mode: "specific_textareas",
+            plugins: "link",
+            editor_selector: "mceEditor"
+        });
+    </script>
+{/block}
\ No newline at end of file
diff --git a/app/FrontModule/presenters/HomepagePresenter.php b/app/FrontModule/presenters/HomepagePresenter.php
index 9475dcb..d9c6ad4 100644
--- a/app/FrontModule/presenters/HomepagePresenter.php
+++ b/app/FrontModule/presenters/HomepagePresenter.php
@@ -5,6 +5,7 @@ namespace App\FrontModule\Presenters;
 use App\FrontModule\Components\IUserSettingsFormFactory;
 use App\FrontModule\Components\ILoginFormFactory;
 use App\Enum\EFlashMessage;
+use App\Model\Repository\SettingsRepository;
 use Nette;
 
 
@@ -15,20 +16,27 @@ final class HomepagePresenter extends Nette\Application\UI\Presenter
 
     /** @var IUserSettingsFormFactory */
     private $userSettingsFormFactory;
+    /**
+     * @var SettingsRepository
+     */
+    private $settingsRepository;
 
     public function __construct(ILoginFormFactory $loginFormFactory,
-                                IUserSettingsFormFactory $userSettingsFormFactory
+                                IUserSettingsFormFactory $userSettingsFormFactory,
+                                SettingsRepository $settingsRepository
     )
     {
         parent::__construct();
 
         $this->loginFormFactory = $loginFormFactory;
         $this->userSettingsFormFactory = $userSettingsFormFactory;
+        $this->settingsRepository = $settingsRepository;
     }
 
     public function actionDefault()
     {
-
+        $settings = $this->settingsRepository->getHomepageSettings();
+        $this->template->settings = $settings;
     }
 
     public function actionUserSettings()
diff --git a/app/FrontModule/templates/Homepage/default.latte b/app/FrontModule/templates/Homepage/default.latte
index 4fd8635..5744fe8 100644
--- a/app/FrontModule/templates/Homepage/default.latte
+++ b/app/FrontModule/templates/Homepage/default.latte
@@ -1,20 +1,22 @@
 {block content}
-    <div class="display-5">Old Babylonian Text Corpus by Cuneiform Circle</div>
+    <div class="display-5">{$settings[\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_HEADER]}</div>
     <hr>
 
     <div class="row">
         <div class="col">
+            {if !empty($settings[\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_MOTTO])}
             <dl class="row">
                 <dt class="col-sm-3">OB motto</dt>
-                <dd class="col-sm-9">a-na D:na-bi-um-ma-lik a-wi-lim dam-qí-im ša D:AMAR.UTU ù D:na-bi-um GI.DUB.BA-šu
-                    ú-še-še-ru (AbB 3,33,1-4)
+                <dd class="col-sm-9">{$settings[\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_MOTTO]}
                 </dd>
             </dl>
+            {/if}
 
             <div class="alert alert-primary">
                 If you have interest in Old Babylonian Akkadian Texts, don't hesitate to join us! You are welcome!
             </div>
         </div>
+        {if $settings[\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_SHOW_SIGNS_FORM]}
         <div class="col">
             <form method="get" action="/utf/show2borger.php">
                 <p class="blue">
@@ -36,29 +38,12 @@
                 </p>
             </form>
         </div>
+        {/if}
     </div>
 
     <hr>
 
-    <p>Cuneiform Circle is a community of scholars engaged in the study of the Old Babylonian Akkadian. Our main goal is
-        to create an Old Babylonian Text Corpus, an Old Babylonian Dictionary, and a List of Old Babylonian Cuneiform
-        Signs.</p>
-
-    <p>The Old Babylonian Text Corpus (OBTC) comprises a large text database of the Old Babylonian Akkadian Language
-        (currently 144097 text lines, letters, documents, legal texts, royal inscriptions, omina, mathematical texts
-        etc.).</p>
-
-    <p><strong>All texts are available for search according to sign-chains (transliteration). The search engine in Old
-            Babylonian Text Corpus verse 1 is available for everybody but the search is restricted to the following
-            texts: Codex Hammurapi and AbB 5. The search in all 144097 lines of OBTC verse 2 is available for members
-            only (<a n:href="Contact:howToBecomeAMember">see how to become a member</a>) .</strong></p>
-
-    <p><strong>Our service includes unique searchable lists of Old Babylonian Signs Variants as appearing in the hand
-            copies selected for the graphemic analysis.</strong></p>
-
-    <p>The work on the project is in progress. We have started in 1988-89 and have accomplished significant advances
-        since. We are currently working towards improving the quality and scope of our databases. The full access to all
-        materials and sources is given to active members only (<a n:href="Contact:howToBecomeAMember">see our policy</a>).</p>
+    {$settings[\App\Model\Repository\SettingsRepository::KEY_HOMEPAGE_CONTENT]|noescape}
 {/block}
 
 {block scripts}
diff --git a/app/config/components.neon b/app/config/components.neon
index 1249d97..ce503e7 100644
--- a/app/config/components.neon
+++ b/app/config/components.neon
@@ -25,6 +25,7 @@ services:
     - App\AdminModule\Components\ITransliterationNewFormFactory
     - App\FrontModule\Components\ICatalogueSearchFormFactory
     - App\FrontModule\Components\IUserSettingsFormFactory
+    - App\AdminModule\Components\IHomepageEditFormFactory
 
     - App\FrontModule\Components\IKeyboard
     - App\FrontModule\Components\ITransliterationSearchResultListFactory
diff --git a/app/config/model.neon b/app/config/model.neon
index cecff7d..bc30ec1 100644
--- a/app/config/model.neon
+++ b/app/config/model.neon
@@ -16,6 +16,7 @@ services:
     - App\Model\Repository\UserLogRepository
     - App\Model\Repository\UserRepository
     - App\Model\Repository\UserRoleRepository
+    - App\Model\Repository\SettingsRepository
 
     #Facade
     - App\Model\Facade\UserFacade
diff --git a/app/model/repository/SettingsRepository.php b/app/model/repository/SettingsRepository.php
new file mode 100644
index 0000000..eb063cf
--- /dev/null
+++ b/app/model/repository/SettingsRepository.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Model\Repository;
+
+
+class SettingsRepository extends Repository
+{
+    const TABLE_NAME = 'settings';
+    protected $tableName = self::TABLE_NAME;
+
+    /** Sloupečky tabulky */
+    const COLUMN_KEY = 'key';
+    const COLUMN_VALUE = 'value';
+
+    /** Setting keys */
+    const KEY_HOMEPAGE_HEADER = 'homepage_header';
+    const KEY_HOMEPAGE_MOTTO = 'homepage_motto';
+    const KEY_HOMEPAGE_CONTENT = 'homepage_content';
+    const KEY_HOMEPAGE_SHOW_SIGNS_FORM = 'homepage_show_signs_form';
+
+    private $homepageSettings =
+        [
+            self::KEY_HOMEPAGE_HEADER,
+            self::KEY_HOMEPAGE_MOTTO,
+            self::KEY_HOMEPAGE_CONTENT,
+            self::KEY_HOMEPAGE_SHOW_SIGNS_FORM
+        ];
+
+    public function getHomepageSettings()
+    {
+        return $this->findBy([self::COLUMN_KEY => $this->homepageSettings])->fetchPairs(self::COLUMN_KEY, self::COLUMN_VALUE);
+    }
+}
\ No newline at end of file
