Browse Source

add model and controller for urls

ksieren 2 năm trước cách đây
mục cha
commit
b97476aefa

+ 15 - 2
Classes/Controller/DashboardController.php

@@ -5,6 +5,7 @@ declare(strict_types=1);
 namespace Meramo\Begriffmgt\Controller;
 namespace Meramo\Begriffmgt\Controller;
 
 
 use Meramo\Begriffmgt\Domain\Repository\TypeRepository;
 use Meramo\Begriffmgt\Domain\Repository\TypeRepository;
+use Meramo\Begriffmgt\Domain\Repository\UrlRepository;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 use Meramo\Begriffmgt\Domain\Repository\TermRepository;
 use Meramo\Begriffmgt\Domain\Repository\TermRepository;
 use Meramo\Begriffmgt\Domain\Repository\CategoryRepository;
 use Meramo\Begriffmgt\Domain\Repository\CategoryRepository;
@@ -17,6 +18,8 @@ class DashboardController extends ActionController
     protected $categoryController;
     protected $categoryController;
     protected $typeRepository;
     protected $typeRepository;
     protected $typeController;
     protected $typeController;
+    protected $urlRepository;
+    protected $urlController;
 
 
     public function __construct(
     public function __construct(
         TermRepository $termRepository,
         TermRepository $termRepository,
@@ -24,6 +27,8 @@ class DashboardController extends ActionController
         CategoryController $categoryController,
         CategoryController $categoryController,
         TypeRepository $typeRepository,
         TypeRepository $typeRepository,
         TypeController $typeController,
         TypeController $typeController,
+        UrlRepository $urlRepository,
+        UrlController $urlController,
         TermController $termController
         TermController $termController
     ) {
     ) {
         $this->termRepository = $termRepository;
         $this->termRepository = $termRepository;
@@ -32,15 +37,21 @@ class DashboardController extends ActionController
         $this->termController = $termController;
         $this->termController = $termController;
         $this->typeRepository = $typeRepository;
         $this->typeRepository = $typeRepository;
         $this->typeController = $typeController;
         $this->typeController = $typeController;
+        $this->urlRepository = $urlRepository;
+        $this->urlController = $urlController;
     }
     }
 
 
     public function indexAction(): void
     public function indexAction(): void
     {
     {
         $terms = $this->termRepository->findAll();
         $terms = $this->termRepository->findAll();
         $categories = $this->categoryRepository->findAll();
         $categories = $this->categoryRepository->findAll();
+        $types = $this->typeRepository->findAll();
+        $urls = $this->urlRepository->findAll();
         $this->view->assignMultiple([
         $this->view->assignMultiple([
             'terms' => $terms,
             'terms' => $terms,
             'categories' => $categories,
             'categories' => $categories,
+            'types' => $types,
+            'urls' => $urls
         ]);
         ]);
     }
     }
 
 
@@ -52,13 +63,15 @@ class DashboardController extends ActionController
         $this->view->assign('terms', $terms);
         $this->view->assign('terms', $terms);
     }
     }
 
 
-    public function createAction(string $termList, string $categoryTitle, string $typeTitle): void {
+    public function createAction(string $termList, string $categoryTitle, string $typeTitle, string $urlTitle): void {
         $terms = array_map('trim', explode(',', $termList));
         $terms = array_map('trim', explode(',', $termList));
         $category = $this->categoryController->createAction($categoryTitle);
         $category = $this->categoryController->createAction($categoryTitle);
         $categoryObj = $this->categoryRepository->findByUid($category);
         $categoryObj = $this->categoryRepository->findByUid($category);
         $type = $this->typeController->createAction($typeTitle);
         $type = $this->typeController->createAction($typeTitle);
         $typeObj = $this->typeRepository->findByUid($type);
         $typeObj = $this->typeRepository->findByUid($type);
-        $this->termController->createAction($terms, $categoryObj, $typeObj);
+        $url = $this->urlController->createAction($urlTitle);
+        $urlObj = $this->urlRepository->findByUid($url);
+        $this->termController->createAction($terms, $categoryObj, $typeObj, $urlObj);
         $this->redirect('index');
         $this->redirect('index');
     }
     }
 }
 }

+ 2 - 1
Classes/Controller/TermController.php

@@ -13,12 +13,13 @@ class TermController extends ActionController
         $this->termRepository = $termRepository;
         $this->termRepository = $termRepository;
     }
     }
 
 
-    public function createAction($terms, $categoryObj, $typeObj): void {
+    public function createAction($terms, $categoryObj, $typeObj, $urlObj): void {
         foreach ($terms as $term) {
         foreach ($terms as $term) {
             $termObj = new Term();
             $termObj = new Term();
             $termObj->setTerm($term);
             $termObj->setTerm($term);
             $termObj->setCategory($categoryObj);
             $termObj->setCategory($categoryObj);
             $termObj->setType($typeObj);
             $termObj->setType($typeObj);
+            $termObj->setUrl($urlObj);
             $this->termRepository->add($termObj);
             $this->termRepository->add($termObj);
         }
         }
     }
     }

+ 23 - 0
Classes/Controller/UrlController.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Meramo\Begriffmgt\Controller;
+
+use Meramo\Begriffmgt\Domain\Model\Url;
+use Meramo\Begriffmgt\Domain\Repository\UrlRepository;
+use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
+use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
+
+class UrlController extends ActionController
+{
+    public function __construct(UrlRepository $urlRepository) {
+        $this->urlRepository = $urlRepository;
+    }
+
+    public function createAction(string $title) {
+        $url = new Url();
+        $url->setTitle($title);
+        $this->urlRepository->add($url);
+        $this->objectManager->get(PersistenceManager::class)->persistAll();
+        return $url->getUid();
+    }
+}

+ 3 - 6
Classes/Domain/Model/Term.php

@@ -9,11 +9,10 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
 
 
 class Term extends AbstractEntity
 class Term extends AbstractEntity
 {
 {
-    protected string $url = '';
-
     protected string $term = '';
     protected string $term = '';
     protected ?Category $category = null;
     protected ?Category $category = null;
     protected ?Type $type = null;
     protected ?Type $type = null;
+    protected ?Url $url = null;
 
 
     public function getTerm(): string {
     public function getTerm(): string {
         return $this->term;
         return $this->term;
@@ -39,13 +38,11 @@ class Term extends AbstractEntity
         $this->type = $type;
         $this->type = $type;
     }
     }
 
 
-    public function getUrl(): string
-    {
+    public function getUrl(): ?Url {
         return $this->url;
         return $this->url;
     }
     }
 
 
-    public function setUrl($url): void
-    {
+    public function setUrl(?Url $url): void {
         $this->url = $url;
         $this->url = $url;
     }
     }
 }
 }

+ 43 - 0
Classes/Domain/Model/Url.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace Meramo\Begriffmgt\Domain\Model;
+
+use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
+use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
+
+class Url extends AbstractEntity
+{
+    protected $uid;
+    protected string $title = '';
+    protected ObjectStorage $urls;
+
+    public function __construct()
+    {
+        $this->urls = new ObjectStorage();
+    }
+
+    public function getUid(): int
+    {
+        return $this->uid;
+    }
+
+    public function getTitle(): string
+    {
+        return $this->title;
+    }
+
+    public function setTitle(string $title): void
+    {
+        $this->title = $title;
+    }
+
+    public function getTerms(): ObjectStorage
+    {
+        return $this->terms;
+    }
+
+    public function setTerms(ObjectStorage $terms): void
+    {
+        $this->terms = $terms;
+    }
+}

+ 9 - 0
Classes/Domain/Repository/UrlRepository.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace Meramo\Begriffmgt\Domain\Repository;
+
+use TYPO3\CMS\Extbase\Persistence\Repository;
+
+class UrlRepository extends Repository {
+    // Add any custom methods or queries for the Url repository if needed.
+}

+ 11 - 8
Configuration/TCA/tx_begriffmgt_domain_model_term.php

@@ -69,6 +69,17 @@ return [
                 'maxitems' => 1,
                 'maxitems' => 1,
             ],
             ],
         ],
         ],
+        'url' => [
+            'exclude' => 0,
+            'label' => 'Direct-Link',
+            'config' => [
+                'type' => 'select',
+                'renderType' => 'selectSingle',
+                'foreign_table' => 'tx_begriffmgt_domain_model_url',
+                'minitems' => 0,
+                'maxitems' => 1,
+            ],
+        ],
         'term' => [
         'term' => [
             'exclude' => true,
             'exclude' => true,
             'label' => 'Begriffe Einfügen (Komma getrennt)',
             'label' => 'Begriffe Einfügen (Komma getrennt)',
@@ -109,13 +120,5 @@ return [
                 ]
                 ]
             ],
             ],
         ],
         ],
-        'url' => [
-          'exclude' => true,
-          'label' => 'Link',
-          'config' => [
-              'type' => 'input',
-              'renderType' => 'inputLink',
-          ],
-      ],
     ],
     ],
 ];
 ];

+ 58 - 0
Configuration/TCA/tx_begriffmgt_domain_model_url.php

@@ -0,0 +1,58 @@
+<?php
+
+return [
+    'ctrl' => [
+        'title' => 'LLL:EXT:begriffmgt/Resources/Private/Language/locallang.xlf:tx_begriffmgt_domain_model_url',
+        'label' => 'title',
+        'tstamp' => 'tstamp',
+        'crdate' => 'crdate',
+        'cruser_id' => 'cruser_id',
+        'versioningWS' => true,
+        'origUid' => 't3_origuid',
+        'languageField' => 'sys_language_uid',
+        'transOrigPointerField' => 'l10n_parent',
+        'transOrigDiffSourceField' => 'l10n_diffsource',
+        'delete' => 'deleted',
+        'enablecolumns' => [
+            'disabled' => 'hidden',
+            'starttime' => 'starttime',
+            'endtime' => 'endtime',
+        ],
+        'searchFields' => 'title',
+        'iconfile' => 'EXT:begriffmgt/Resources/Public/Icons/chatbot.svg',
+    ],
+    'interface' => [
+        'showRecordFieldList' => 'title, terms',
+    ],
+    'types' => [
+        '1' => ['showitem' => 'title, terms'],
+    ],
+    'columns' => [
+        'title' => [
+            'exclude' => 0,
+            'label' => 'LLL:EXT:begriffmgt/Resources/Private/Language/locallang.xlf:tx_begriffmgt_domain_model_url.title',
+            'config' => [
+                'type' => 'input',
+                'size' => 30,
+                'eval' => 'trim,required'
+            ],
+        ],
+        'terms' => [
+            'exclude' => 1,
+            'label' => 'Terms',
+            'config' => [
+                'type' => 'inline',
+                'foreign_table' => 'tx_begriffmgt_domain_model_term',
+                'foreign_field' => 'url',
+                'maxitems' => 9999,
+                'appearance' => [
+                    'collapseAll' => 1,
+                    'levelLinksPosition' => 'top',
+                    'showSynchronizationLink' => 1,
+                    'showPossibleLocalizationRecords' => 1,
+                    'showAllLocalizationLink' => 1
+                ],
+            ],
+        ],
+    ],
+];

+ 31 - 9
Resources/Private/Templates/Dashboard/Index.html

@@ -20,9 +20,35 @@
 <!--    <f:form.select name="category" options="{categories}" optionValueField="uid" optionLabelField="title" /><br>-->
 <!--    <f:form.select name="category" options="{categories}" optionValueField="uid" optionLabelField="title" /><br>-->
     <label for="typeTitle">Type:</label>
     <label for="typeTitle">Type:</label>
     <f:form.textfield name="typeTitle" /><br>
     <f:form.textfield name="typeTitle" /><br>
+    <label for="urlTitle">URL:</label>
+    <f:form.textfield name="urlTitle" /><br>
     <f:form.submit value="Save" />
     <f:form.submit value="Save" />
   </f:form>
   </f:form>
 
 
+  <h2>List of terms</h2>
+  <table>
+    <thead>
+    <tr>
+      <th>ID</th>
+      <th>Term</th>
+      <th>Type</th>
+      <th>Category</th>
+      <th>Url</th>
+    </tr>
+    </thead>
+    <tbody>
+    <f:for each="{terms}" as="term">
+      <tr>
+        <td>{term.uid}</td>
+        <td>{term.term}</td>
+        <td>{term.type.title}</td>
+        <td>{term.category.title}</td>
+        <td>{term.url.title}</td>
+      </tr>
+    </f:for>
+    </tbody>
+  </table>
+
 
 
   <h2>List of categories</h2>
   <h2>List of categories</h2>
   <table>
   <table>
@@ -60,23 +86,19 @@
     </tbody>
     </tbody>
   </table>
   </table>
 
 
-  <h2>List of terms</h2>
+  <h2>List of urls</h2>
   <table>
   <table>
     <thead>
     <thead>
     <tr>
     <tr>
       <th>ID</th>
       <th>ID</th>
-      <th>Type</th>
-      <th>Category</th>
-      <th>Term</th>
+      <th>Title</th>
     </tr>
     </tr>
     </thead>
     </thead>
     <tbody>
     <tbody>
-    <f:for each="{terms}" as="term">
+    <f:for each="{urls}" as="url">
       <tr>
       <tr>
-        <td>{term.uid}</td>
-        <td>{term.type.title}</td>
-        <td>{term.category.title}</td>
-        <td>{term.term}</td>
+        <td>{url.uid}</td>
+        <td>{url.title}</td>
       </tr>
       </tr>
     </f:for>
     </f:for>
     </tbody>
     </tbody>

+ 14 - 1
ext_tables.sql

@@ -8,8 +8,8 @@ CREATE TABLE tx_begriffmgt_domain_model_term (
     hidden tinyint(1) unsigned DEFAULT '0' NOT NULL,
     hidden tinyint(1) unsigned DEFAULT '0' NOT NULL,
 	type int(11) DEFAULT '0' NOT NULL,
 	type int(11) DEFAULT '0' NOT NULL,
     category int(11) DEFAULT '0' NOT NULL,
     category int(11) DEFAULT '0' NOT NULL,
+    url int(11) DEFAULT '0' NOT NULL,
 	term text NOT NULL DEFAULT '',
 	term text NOT NULL DEFAULT '',
-	url varchar(255) DEFAULT '',
     PRIMARY KEY (uid)
     PRIMARY KEY (uid)
 );
 );
 
 
@@ -39,3 +39,16 @@ CREATE TABLE tx_begriffmgt_domain_model_type (
      terms text DEFAULT '',
      terms text DEFAULT '',
      PRIMARY KEY (uid)
      PRIMARY KEY (uid)
 );
 );
+
+CREATE TABLE tx_begriffmgt_domain_model_url (
+     uid int(11) unsigned NOT NULL AUTO_INCREMENT,
+     pid int(11) DEFAULT '0' NOT NULL,
+     tstamp int(11) unsigned DEFAULT '0' NOT NULL,
+     crdate int(11) unsigned DEFAULT '0' NOT NULL,
+     cruser_id int(11) DEFAULT '0' NOT NULL,
+     deleted tinyint(1) unsigned DEFAULT '0' NOT NULL,
+     hidden tinyint(1) unsigned DEFAULT '0' NOT NULL,
+     title varchar(255) NOT NULL,
+     terms text DEFAULT '',
+     PRIMARY KEY (uid)
+);