Browse code

Add opened attribute to downloads to highlight new files

Benjamin Roth authored on09/05/2025 11:18:14
Showing3 changed files
... ...
@@ -111,6 +111,12 @@ $GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array
111 111
             'flag' => 6,
112 112
             'sql' => "int(10) unsigned NOT NULL default '0'"
113 113
         ),
114
+        'opened' => array
115
+        (
116
+            'exclude'               => true,
117
+            'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['opened'],
118
+            'sql' => "int(10) unsigned NOT NULL default '0'"
119
+        ),
114 120
         /*'name' => array
115 121
         (
116 122
             'exclude' => true,
... ...
@@ -5,7 +5,7 @@
5 5
 
6 6
     <ul>
7 7
         {% for file in files %}
8
-            <li class="download-element ext-{{ file.extension }}">
8
+            <li class="download-element ext-{{ file.extension }}{{ file.opened == 0 ? ' new' : '' }}">
9 9
                 {% if file.previews is defined %}
10 10
                     {% for preview in file.previews %}
11 11
                         {{- studio.figure(preview, { attr: { class: ('image_container') }}) -}}
... ...
@@ -77,6 +77,7 @@ class SecureDownloadsController extends AbstractContentElementController
77 77
         {
78 78
             if ($SecFile->pid == $this->User->id)
79 79
             {
80
+                $this->db->update('tl_member_secureDownloads', ['opened' => time()], ['id' => $SecFile->id]);
80 81
                 Controller::sendFileToBrowser($path);
81 82
             } else {
82 83
                 return new Response('',403);
... ...
@@ -110,6 +111,7 @@ class SecureDownloadsController extends AbstractContentElementController
110 111
             }
111 112
 
112 113
             // Single files
114
+            $SecureFile = SecureDownloadsModel::findBy(["uuid = ?"],[$objFiles->uuid]);
113 115
             if ($objFiles->type == 'file')
114 116
             {
115 117
                 $File = new File($objFiles->path);
... ...
@@ -165,7 +167,8 @@ class SecureDownloadsController extends AbstractContentElementController
165 167
                     'meta'      => $arrMeta,
166 168
                     'extension' => $File->extension,
167 169
                     'path'      => $File->dirname,
168
-                    'mtime'     => $File->mtime
170
+                    'mtime'     => $File->mtime,
171
+                    'opened'      => ($SecureFile !== null ? $SecureFile->opened : 0)
169 172
                 );
170 173
 
171 174
                 $auxDate[] = $File->mtime;
... ...
@@ -241,7 +244,8 @@ class SecureDownloadsController extends AbstractContentElementController
241 244
                         'mime'      => $File->mime,
242 245
                         'meta'      => $arrMeta,
243 246
                         'extension' => $File->extension,
244
-                        'path'      => $File->dirname
247
+                        'path'      => $File->dirname,
248
+                        'opened'      => ($SecureFile !== null ? $SecureFile->opened : 0)
245 249
                     );
246 250
 
247 251
                     $auxDate[] = $File->mtime;