Browse code

Finalize module and also provide content element

Benjamin Roth authored on10/01/2023 21:52:20
Showing14 changed files
... ...
@@ -3,3 +3,5 @@ services:
3 3
         autoconfigure: true
4 4
 
5 5
     vonRotenberg\ModalBundle\Controller\FrontendModule\ModalModuleController: ~
6
+
7
+    vonRotenberg\ModalBundle\Controller\ContentElement\ModalElementController: ~
... ...
@@ -10,8 +10,12 @@ declare(strict_types=1);
10 10
  * @license LGPL-3.0-or-later
11 11
  */
12 12
 
13
+use vonRotenberg\ModalBundle\Model\ModalModel;
13 14
 
14 15
 $GLOBALS['BE_MOD']['content']['modals'] = array
15 16
 (
16 17
     'tables'      => array('tl_vr_modal', 'tl_content'),
17 18
 );
19
+
20
+
21
+$GLOBALS['TL_MODELS']['tl_vr_modal'] = ModalModel::class;
18 22
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of modal bundle for Contao.
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license LGPL-3.0-or-later
11
+ */
12
+
13
+use vonRotenberg\ModalBundle\Controller\ContentElement\ModalElementController;
14
+
15
+$GLOBALS['TL_DCA']['tl_content']['palettes'][ModalElementController::TYPE] = '{type_legend},type;{modalconfig_legend},modal_configurations';
16
+
17
+
18
+$GLOBALS['TL_DCA']['tl_content']['fields']['modal_configurations'] = array
19
+(
20
+    'exclude'                  => true,
21
+    'inputType'                => 'select',
22
+    'foreignKey'               => 'tl_vr_modal.title',
23
+    'eval'                     => array('mandatory' => true, 'tl_class' => 'w50', 'includeBlankOption' => true, 'chosen' => true),
24
+    'sql'                      => 'int(10) unsigned NOT NULL default 0'
25
+);
... ...
@@ -12,7 +12,7 @@ declare(strict_types=1);
12 12
 
13 13
 use vonRotenberg\ModalBundle\Controller\FrontendModule\ModalModuleController;
14 14
 
15
-$GLOBALS['TL_DCA']['tl_module']['palettes'][ModalModuleController::TYPE] = '{title_legend},name,type;{config_legend},modal_configurations';
15
+$GLOBALS['TL_DCA']['tl_module']['palettes'][ModalModuleController::TYPE] = '{title_legend},name,type;{modalconfig_legend},modal_configurations';
16 16
 
17 17
 
18 18
 $GLOBALS['TL_DCA']['tl_module']['fields']['modal_configurations'] = array
... ...
@@ -20,6 +20,6 @@ $GLOBALS['TL_DCA']['tl_module']['fields']['modal_configurations'] = array
20 20
     'exclude'                  => true,
21 21
     'inputType'                => 'select',
22 22
     'foreignKey'               => 'tl_vr_modal.title',
23
-    'eval'                     => array('mandatory' => true, 'tl_class' => 'w50', 'insertBlankOption' => true, 'chosen' => true),
23
+    'eval'                     => array('mandatory' => true, 'tl_class' => 'w50', 'includeBlankOption' => true, 'chosen' => true),
24 24
     'sql'                      => 'int(10) unsigned NOT NULL default 0'
25 25
 );
... ...
@@ -92,7 +92,7 @@ $GLOBALS['TL_DCA']['tl_vr_modal'] = array
92 92
     'palettes' => array
93 93
     (
94 94
         '__selector__'                => array(''),
95
-        'default'                     => '{title_legend},title;{config_legend},modal_title,delay;{publish_legend},published,start,stop'
95
+        'default'                     => '{title_legend},title;{config_legend},modal_title,delay,show_once;{publish_legend},published,start,stop'
96 96
     ),
97 97
     'subpalettes' => array
98 98
     (
... ...
@@ -104,12 +104,6 @@ $GLOBALS['TL_DCA']['tl_vr_modal'] = array
104 104
         (
105 105
             'sql'                     => "int(10) unsigned NOT NULL auto_increment"
106 106
         ),
107
-        'pid' => array
108
-        (
109
-            'foreignKey'              => 'tl_news_archive.title',
110
-            'sql'                     => "int(10) unsigned NOT NULL default 0",
111
-            'relation'                => array('type'=>'belongsTo', 'load'=>'lazy')
112
-        ),
113 107
         'tstamp' => array
114 108
         (
115 109
             'sorting'                 => true,
... ...
@@ -139,9 +133,17 @@ $GLOBALS['TL_DCA']['tl_vr_modal'] = array
139 133
             'sorting'                 => true,
140 134
             'flag'                    => DataContainer::SORT_ASC,
141 135
             'inputType'               => 'text',
142
-            'eval'                    => array('mandatory'=>true, 'rgxp'=>'natural','maxlength'=>5, 'maxval'=>65535, 'tl_class'=>'w50'),
136
+            'eval'                    => array('mandatory'=>true, 'rgxp'=>'natural','maxlength'=>5, 'maxval'=>65535, 'tl_class'=>'clr w50'),
143 137
             'sql'                     => "smallint(5) unsigned NOT NULL default 0"
144 138
         ),
139
+        'show_once' => array
140
+        (
141
+            'exclude'                 => true,
142
+            'filter'                  => true,
143
+            'inputType'               => 'checkbox',
144
+            'eval'                    => array('doNotCopy'=>true, 'tl_class'=>'w50 m12'),
145
+            'sql'                     => "char(1) NOT NULL default '1'"
146
+        ),
145 147
         'published' => array
146 148
         (
147 149
             'exclude'                 => true,
... ...
@@ -11,8 +11,11 @@ declare(strict_types=1);
11 11
  */
12 12
 
13 13
 use vonRotenberg\ModalBundle\Controller\FrontendModule\ModalModuleController;
14
+use vonRotenberg\ModalBundle\Controller\ContentElement\ModalElementController;
14 15
 
15 16
 $GLOBALS['TL_LANG']['MOD']['modals'][0] = 'PopUp-Fenster';
16 17
 $GLOBALS['TL_LANG']['MOD']['modals'][1] = 'Verwalten von Popup-Konfigurationen';
17 18
 $GLOBALS['TL_LANG']['FMD'][ModalModuleController::TYPE][0] = 'Pop-Up';
18 19
 $GLOBALS['TL_LANG']['FMD'][ModalModuleController::TYPE][1] = 'Gibt eine Pop-Up Konfiguration aus.';
20
+$GLOBALS['TL_LANG']['CTE'][ModalElementController::TYPE][0] = 'Pop-Up';
21
+$GLOBALS['TL_LANG']['CTE'][ModalElementController::TYPE][1] = 'Gibt eine Pop-Up Konfiguration aus.';
19 22
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of modal bundle for Contao.
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license LGPL-3.0-or-later
11
+ */
12
+
13
+use Contao\DC_Table;
14
+use Contao\DataContainer;
15
+
16
+$GLOBALS['TL_LANG']['tl_content']['modal_configurations'][0] = 'PopUp-Konfiguration';
17
+$GLOBALS['TL_LANG']['tl_content']['modal_configurations'][1] = 'Die zu ladende PopUp-Konfiguration.';
18
+$GLOBALS['TL_LANG']['tl_content']['modal_configurations'][1] = 'Die zu ladende PopUp-Konfiguration.';
19
+
20
+$GLOBALS['TL_LANG']['tl_content']['modalconfig_legend'] = 'PopUp-Einstellungen';
0 21
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of modal bundle for Contao.
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license LGPL-3.0-or-later
11
+ */
12
+
13
+use Contao\DC_Table;
14
+use Contao\DataContainer;
15
+
16
+$GLOBALS['TL_LANG']['tl_module']['modal_configurations'][0] = 'PopUp-Konfiguration';
17
+$GLOBALS['TL_LANG']['tl_module']['modal_configurations'][1] = 'Die zu ladende PopUp-Konfiguration.';
18
+
19
+$GLOBALS['TL_LANG']['tl_module']['modalconfig_legend'] = 'PopUp-Einstellungen';
... ...
@@ -21,3 +21,11 @@ $GLOBALS['TL_LANG']['tl_vr_modal']['modal_title'][0] = 'Titel des Pop-Ups';
21 21
 $GLOBALS['TL_LANG']['tl_vr_modal']['modal_title'][1] = 'Der Titel der als Leiste über dem Pop-Up angezeigt wird.';
22 22
 $GLOBALS['TL_LANG']['tl_vr_modal']['delay'][0] = 'Anzeigeverzögerung';
23 23
 $GLOBALS['TL_LANG']['tl_vr_modal']['delay'][1] = 'Die Zeit, bis das Pop-Up nach dem vollständigen Laden der Seite geöffnet wird.';
24
+$GLOBALS['TL_LANG']['tl_vr_modal']['show_once'][0] = 'Nur einmal pro Session';
25
+$GLOBALS['TL_LANG']['tl_vr_modal']['show_once'][1] = 'Das PopUp wird nur einmal wärend der Browser-Sitzung angezeigt.';
26
+$GLOBALS['TL_LANG']['tl_vr_modal']['published'][0] = 'Veröffentlichen';
27
+$GLOBALS['TL_LANG']['tl_vr_modal']['published'][1] = 'Aktiviert oder deaktiviert das PopUp.';
28
+$GLOBALS['TL_LANG']['tl_vr_modal']['start'][0] = 'Anzeigen ab';
29
+$GLOBALS['TL_LANG']['tl_vr_modal']['start'][1] = 'Wenn das PopUp erst ab einem bestimmten Zeitpunkt angezeigt werden soll, kann hier ein Datum gesetzt werden.';
30
+$GLOBALS['TL_LANG']['tl_vr_modal']['stop'][0] = 'Anzeigen bis';
31
+$GLOBALS['TL_LANG']['tl_vr_modal']['stop'][1] = 'Wenn das PopUp bis zu einem bestimmten Zeitpunkt angezeigt werden soll, kann hier ein Datum gesetzt werden.';
24 32
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+{% extends '@Contao_VonrotenbergModalBundle/mod_modal_module.html.twig' %}
... ...
@@ -0,0 +1,32 @@
1
+<script>
2
+    (function($) {
3
+        $(document).ready(function() {
4
+            var signpost;
5
+
6
+            signpost = new jBox('Modal', {
7
+                title: '{{ (modal_configuration.modal_title) ?: '' }}',
8
+                content: $('#modal-content-{{ modal_configuration.id }}').html(),
9
+                closeButton: 'title',
10
+                width: 650,
11
+                theme: 'DurbachLight'{% if not modal_configuration.show_once is empty %},
12
+                onClose: function() {
13
+                    localStorage.setItem('popState-{{ modal_configuration.id }}',Date.now());
14
+                    sessionStorage.setItem('popState-{{ modal_configuration.id }}','shown');
15
+                }
16
+                {% endif %}
17
+
18
+            });
19
+
20
+            {% if not modal_configuration.show_once is empty %}if((localStorage.getItem('popState-{{ modal_configuration.id }}') < Date.now()-3600 && sessionStorage.getItem('popState-{{ modal_configuration.id }}') != 'shown')){
21
+                {% endif %}setTimeout(function() {
22
+                    signpost.open();
23
+                },{{ modal_configuration.delay|number_format * 1000 }});
24
+            {% if not modal_configuration.show_once is empty %} } {% endif %}
25
+
26
+        });
27
+    })(jQuery);
28
+</script>
29
+
30
+<div style="display: none" id="modal-content-{{ modal_configuration.id }}">
31
+{{ details|raw }}
32
+</div>
0 33
new file mode 100644
... ...
@@ -0,0 +1,66 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of modal bundle for Contao.
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license LGPL-3.0-or-later
11
+ */
12
+
13
+namespace vonRotenberg\ModalBundle\Controller\ContentElement;
14
+
15
+use Contao\ContentModel;
16
+use Contao\Controller;
17
+use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController;
18
+use Contao\CoreBundle\ServiceAnnotation\ContentElement;
19
+use Contao\Template;
20
+use Symfony\Component\HttpFoundation\Request;
21
+use Symfony\Component\HttpFoundation\Response;
22
+use vonRotenberg\ModalBundle\Model\ModalModel;
23
+
24
+/**
25
+ * @ContentElement(ModalElementController::TYPE, category="miscellaneous")
26
+ */
27
+class ModalElementController extends AbstractContentElementController
28
+{
29
+    public const TYPE = 'modal_element';
30
+
31
+    protected function getResponse(Template $template, ContentModel $model, Request $request): ?Response
32
+    {
33
+        if (!$model->modal_configurations || ($modal = ModalModel::findPublishedById($model->modal_configurations)) === null)
34
+        {
35
+            return new Response();
36
+        }
37
+
38
+        $id = $modal->id;
39
+
40
+        $template->details = function () use ($id)
41
+        {
42
+            $strDetails = '';
43
+            $objElement = ContentModel::findPublishedByPidAndTable($id, 'tl_vr_modal');
44
+
45
+            if ($objElement !== null)
46
+            {
47
+                while ($objElement->next())
48
+                {
49
+                    $strDetails .= Controller::getContentElement($objElement->current());
50
+                }
51
+            }
52
+
53
+            return $strDetails;
54
+        };
55
+
56
+        $template->hasDetails = static function () use ($id)
57
+        {
58
+            return ContentModel::countPublishedByPidAndTable($id, 'tl_vr_modal') > 0;
59
+        };
60
+
61
+        $template->modal_configuration = $modal->row();
62
+
63
+        return $template->getResponse();
64
+    }
65
+
66
+}
... ...
@@ -12,12 +12,15 @@ declare(strict_types=1);
12 12
 
13 13
 namespace vonRotenberg\ModalBundle\Controller\FrontendModule;
14 14
 
15
+use Contao\ContentModel;
16
+use Contao\Controller;
15 17
 use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
16 18
 use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
17 19
 use Contao\ModuleModel;
18 20
 use Contao\Template;
19 21
 use Symfony\Component\HttpFoundation\Request;
20 22
 use Symfony\Component\HttpFoundation\Response;
23
+use vonRotenberg\ModalBundle\Model\ModalModel;
21 24
 
22 25
 /**
23 26
  * @FrontendModule(ModalModuleController::TYPE, category="miscellaneous")
... ...
@@ -28,6 +31,36 @@ class ModalModuleController extends AbstractFrontendModuleController
28 31
 
29 32
     protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
30 33
     {
34
+        if (!$model->modal_configurations || ($modal = ModalModel::findPublishedById($model->modal_configurations)) === null)
35
+        {
36
+            return new Response();
37
+        }
38
+
39
+        $id = $modal->id;
40
+
41
+        $template->details = function () use ($id)
42
+        {
43
+            $strDetails = '';
44
+            $objElement = ContentModel::findPublishedByPidAndTable($id, 'tl_vr_modal');
45
+
46
+            if ($objElement !== null)
47
+            {
48
+                while ($objElement->next())
49
+                {
50
+                    $strDetails .= Controller::getContentElement($objElement->current());
51
+                }
52
+            }
53
+
54
+            return $strDetails;
55
+        };
56
+
57
+        $template->hasDetails = static function () use ($id)
58
+        {
59
+            return ContentModel::countPublishedByPidAndTable($id, 'tl_vr_modal') > 0;
60
+        };
61
+
62
+        $template->modal_configuration = $modal->row();
63
+
31 64
         return $template->getResponse();
32 65
     }
33 66
 
34 67
new file mode 100644
... ...
@@ -0,0 +1,94 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of Contao.
5
+ *
6
+ * (c) Leo Feyer
7
+ *
8
+ * @license LGPL-3.0-or-later
9
+ */
10
+
11
+namespace vonRotenberg\ModalBundle\Model;
12
+
13
+use Contao\Date;
14
+use Contao\Model;
15
+use Contao\Model\Collection;
16
+
17
+/**
18
+ * Reads and writes image sizes
19
+ *
20
+ * @property string|integer      $id
21
+ * @property string|integer      $tstamp
22
+ * @property string              $title
23
+ * @property string              $modal_title
24
+ * @property string|integer      $delay
25
+ * @property string|boolean      $show_once
26
+ * @property string|integer      $start
27
+ * @property string|integer      $stop
28
+ *
29
+ * @method static ModalModel|null findById($id, array $opt=array())
30
+ * @method static ModalModel|null findByPk($id, array $opt=array())
31
+ * @method static ModalModel|null findOneBy($col, $val, array $opt=array())
32
+ * @method static ModalModel|null findOneByTstamp($val, array $opt=array())
33
+ * @method static ModalModel|null findOneByTitle($val, array $opt=array())
34
+ * @method static ModalModel|null findOneByModalTitle($val, array $opt=array())
35
+ * @method static ModalModel|null findOneByDelay($val, array $opt=array())
36
+ * @method static ModalModel|null findOneByShowOnce($val, array $opt=array())
37
+ * @method static ModalModel|null findOneByPublished($val, array $opt=array())
38
+ * @method static ModalModel|null findOneByStart($val, array $opt=array())
39
+ * @method static ModalModel|null findOneByStop($val, array $opt=array())
40
+ *
41
+ * @method static Collection|ModalModel[]|ModalModel|null findByTstamp($val, array $opt=array())
42
+ * @method static Collection|ModalModel[]|ModalModel|null findByTitle($val, array $opt=array())
43
+ * @method static Collection|ModalModel[]|ModalModel|null findByModalTitle($val, array $opt=array())
44
+ * @method static Collection|ModalModel[]|ModalModel|null findByDelay($val, array $opt=array())
45
+ * @method static Collection|ModalModel[]|ModalModel|null findByShowOnce($val, array $opt=array())
46
+ * @method static Collection|ModalModel[]|ModalModel|null findByPublished($val, array $opt=array())
47
+ * @method static Collection|ModalModel[]|ModalModel|null findByStart($val, array $opt=array())
48
+ * @method static Collection|ModalModel[]|ModalModel|null findByStop($val, array $opt=array())
49
+ * @method static Collection|ModalModel[]|ModalModel|null findMultipleByIds($val, array $opt=array())
50
+ * @method static Collection|ModalModel[]|ModalModel|null findBy($col, $val, array $opt=array())
51
+ * @method static Collection|ModalModel[]|ModalModel|null findAll(array $opt=array())
52
+ *
53
+ * @method static integer countById($id, array $opt=array())
54
+ * @method static integer countByTstamp($val, array $opt=array())
55
+ * @method static integer countByTitle($val, array $opt=array())
56
+ * @method static integer countByModalTitle($val, array $opt=array())
57
+ * @method static integer countByDelay($val, array $opt=array())
58
+ * @method static integer countByShowOnce($val, array $opt=array())
59
+ * @method static integer countByPublished($val, array $opt=array())
60
+ * @method static integer countByStart($val, array $opt=array())
61
+ * @method static integer countByStop($val, array $opt=array())
62
+ */
63
+class ModalModel extends Model
64
+{
65
+	/**
66
+	 * Table name
67
+	 * @var string
68
+	 */
69
+	protected static $strTable = 'tl_vr_modal';
70
+
71
+    /**
72
+     * Find a published modal by its ID
73
+     *
74
+     * @param integer $intId      The modal ID
75
+     * @param array   $arrOptions An optional options array
76
+     *
77
+     * @return ModalModel|null The model or null if there is no modal
78
+     */
79
+    public static function findPublishedById($intId, array $arrOptions=array())
80
+    {
81
+        $t = static::$strTable;
82
+        $arrColumns = array("$t.id=?");
83
+
84
+        if (!static::isPreviewMode($arrOptions))
85
+        {
86
+            $time = Date::floorToMinute();
87
+            $arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
88
+        }
89
+
90
+        return static::findOneBy($arrColumns, $intId, $arrOptions);
91
+    }
92
+}
93
+
94
+class_alias(ModalModel::class, 'ModalModel');