Browse code

Progress

Benjamin Roth authored on21/02/2023 19:42:19
Showing1 changed files
... ...
@@ -150,7 +150,7 @@ $GLOBALS['TL_DCA']['tl_esm_team'] = array
150 150
 			'exclude'                 => true,
151 151
 			'search'                  => true,
152 152
 			'inputType'               => 'text',
153
-			'eval'                    => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'),
153
+			'eval'                    => array('mandatory'=>false, 'maxlength'=>128, 'tl_class'=>'w50'),
154 154
 			'sql'                     => "varchar(128) NOT NULL default ''"
155 155
 		),
156 156
         'comment' => array
Browse code

Progress live

Benjamin Roth authored on12/12/2022 09:35:54
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,314 @@
1
+<?php
2
+/**
3
+ * TeamList for Contao
4
+ *
5
+ * Copyright (c) 2016 Benjamin Roth
6
+ *
7
+ * @license LGPL-3.0+
8
+ */
9
+
10
+/**
11
+ * Table tl_esm_team
12
+ */
13
+
14
+use Contao\DC_Table;
15
+use Contao\DataContainer;
16
+
17
+$GLOBALS['TL_DCA']['tl_esm_team'] = array
18
+(
19
+
20
+	// Config
21
+	'config' => array
22
+	(
23
+		'dataContainer'               => DC_Table::class,
24
+        'ptable'                      => 'tl_esm_team_group',
25
+		'enableVersioning'            => true,
26
+		'sql' => array
27
+		(
28
+			'keys' => array
29
+			(
30
+				'id' => 'primary',
31
+                'pid' => 'index',
32
+                'pid,published' => 'index'
33
+            )
34
+		)
35
+	),
36
+
37
+	// List
38
+	'list' => array
39
+	(
40
+		'sorting' => array
41
+		(
42
+
43
+			'mode'                    => DataContainer::MODE_PARENT,
44
+			'fields'                  => array('division', 'lastname'),
45
+            'headerFields'            => array('title'),
46
+            'panelLayout'             => 'filter,search;sort,limit',
47
+//            'child_record_callback'   => array('tl_esm_team', 'listMembers')
48
+        ),
49
+        'label' => array
50
+        (
51
+
52
+        ),
53
+		'global_operations' => array
54
+		(
55
+			'all' => array
56
+			(
57
+				'href'                => 'act=select',
58
+				'class'               => 'header_edit_all',
59
+				'attributes'          => 'onclick="Backend.getScrollOffset()" accesskey="e"'
60
+			)
61
+		),
62
+		'operations' => array
63
+		(
64
+			'edit' => array
65
+			(
66
+				'href'                => 'act=edit',
67
+				'icon'                => 'edit.svg'
68
+			),
69
+			'copy' => array
70
+			(
71
+				'href'                => 'act=paste&amp;mode=copy',
72
+                'attributes'          => 'onclick="Backend.getScrollOffset()"',
73
+				'icon'                => 'copy.svg'
74
+			),
75
+            'cut' => array
76
+            (
77
+                'href'                => 'act=paste&amp;mode=cut',
78
+                'icon'                => 'cut.svg',
79
+                'attributes'          => 'onclick="Backend.getScrollOffset()"'
80
+            ),
81
+			'delete' => array
82
+			(
83
+				'href'                => 'act=delete',
84
+				'icon'                => 'delete.svg',
85
+                'attributes'          => 'onclick="if(!confirm(\'' . ($GLOBALS['TL_LANG']['MSC']['deleteConfirm'] ?? null) . '\'))return false;Backend.getScrollOffset()"'
86
+			),
87
+			'toggle' => array
88
+			(
89
+                'href'                => 'act=toggle&amp;field=invisible',
90
+				'icon'                => 'visible.svg',
91
+//				'button_callback'     => array('tl_esm_team', 'toggleIcon')
92
+			),
93
+            'show' => array
94
+            (
95
+                'href'                => 'act=show',
96
+                'icon'                => 'show.svg'
97
+            )
98
+		)
99
+	),
100
+
101
+	// Palettes
102
+	'palettes' => array
103
+	(
104
+		'default'                     => '{person_legend},firstname,lastname,comment;{company_legend},position,division;{picture_legend},singleSRC;{publish_legend:hide},published'
105
+	),
106
+
107
+	// Subpalettes
108
+	'subpalettes' => array
109
+	(
110
+	),
111
+
112
+	// Fields
113
+	'fields' => array
114
+	(
115
+		'id' => array
116
+		(
117
+			'sql'                     => "int(10) unsigned NOT NULL auto_increment"
118
+		),
119
+        'pid' => array
120
+        (
121
+          'foreignKey'              => 'tl_faq_category.title',
122
+          'sql'                     => "int(10) unsigned NOT NULL default '0'",
123
+          'relation'                => array('type'=>'belongsTo', 'load'=>'eager')
124
+        ),
125
+		'tstamp' => array
126
+		(
127
+			'sql'                     => "int(10) unsigned NOT NULL default '0'"
128
+		),
129
+		'firstname' => array
130
+		(
131
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_team']['firstname'],
132
+			'exclude'                 => true,
133
+			'search'                  => true,
134
+			'inputType'               => 'text',
135
+			'eval'                    => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'),
136
+			'sql'                     => "varchar(128) NOT NULL default ''"
137
+		),
138
+		'lastname' => array
139
+		(
140
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_team']['lastname'],
141
+			'exclude'                 => true,
142
+			'search'                  => true,
143
+			'inputType'               => 'text',
144
+			'eval'                    => array('mandatory'=>false, 'maxlength'=>128, 'tl_class'=>'w50'),
145
+			'sql'                     => "varchar(128) NOT NULL default ''"
146
+		),
147
+		'position' => array
148
+		(
149
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_team']['position'],
150
+			'exclude'                 => true,
151
+			'search'                  => true,
152
+			'inputType'               => 'text',
153
+			'eval'                    => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'),
154
+			'sql'                     => "varchar(128) NOT NULL default ''"
155
+		),
156
+        'comment' => array
157
+        (
158
+            'label'                   => &$GLOBALS['TL_LANG']['tl_esm_team']['comment'],
159
+            'exclude'                 => true,
160
+            'inputType'               => 'textarea',
161
+            'eval'                    => array('mandatory'=>false, 'maxlength'=>128, 'tl_class'=>'clr'),
162
+            'sql'                     => "varchar(128) NOT NULL default ''"
163
+        ),
164
+		'division' => array
165
+		(
166
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_team']['division'],
167
+			'exclude'                 => true,
168
+			'filter'                  => true,
169
+			'inputType'               => 'select',
170
+			'options'                 => $GLOBALS['eSM_team']['divisions'],
171
+			'reference'               => &$GLOBALS['TL_LANG']['REF']['divisions'],
172
+			'eval'                    => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'),
173
+			'sql'                     => "varchar(128) NOT NULL default ''"
174
+		),
175
+		'singleSRC' => array
176
+		(
177
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_team']['singleSRC'],
178
+			'exclude'                 => true,
179
+			'inputType'               => 'fileTree',
180
+			'eval'                    => array('filesOnly'=>true, 'extensions'=>Config::get('validImageTypes'), 'fieldType'=>'radio', 'mandatory'=>true),
181
+			'sql'                     => "binary(16) NULL"
182
+		),
183
+		'published' => array
184
+		(
185
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_team']['published'],
186
+			'exclude'                 => true,
187
+			'filter'                  => true,
188
+			'inputType'               => 'checkbox',
189
+			'default'                 => '1',
190
+			'eval'                    => array('doNotCopy'=>true),
191
+			'sql'                     => "char(1) NOT NULL default ''"
192
+		),
193
+	)
194
+);
195
+
196
+/**
197
+ * Provide miscellaneous methods that are used by the data configuration array.
198
+ */
199
+class tl_esm_team extends Backend
200
+{
201
+
202
+	/**
203
+	 * Import the back end user object
204
+	 */
205
+	public function __construct()
206
+	{
207
+		parent::__construct();
208
+		$this->import('BackendUser', 'User');
209
+	}
210
+
211
+  /**
212
+   * Add the type of input field
213
+   *
214
+   * @param array $arrRow
215
+   *
216
+   * @return string
217
+   */
218
+  public function listMembers($arrRow)
219
+  {
220
+    return '
221
+<div style="float: left; width: 35%;">' . $arrRow['firstname'] . ' ' . $arrRow['lastname'] . '</div>
222
+<div style="font-size: .625rem; color: #c6c6c6;"><strong>[' . $arrRow['position'] . ']</strong></div>' . "\n";
223
+  }
224
+
225
+	/**
226
+	 * Return the "toggle visibility" button
227
+	 *
228
+	 * @param array  $row
229
+	 * @param string $href
230
+	 * @param string $label
231
+	 * @param string $title
232
+	 * @param string $icon
233
+	 * @param string $attributes
234
+	 *
235
+	 * @return string
236
+	 */
237
+	public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
238
+	{
239
+		if (strlen(Input::get('tid')))
240
+		{
241
+			$this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1), (@func_get_arg(12) ?: null));
242
+			$this->redirect($this->getReferer());
243
+		}
244
+
245
+		// Check permissions AFTER checking the tid, so hacking attempts are logged
246
+		if (!$this->User->hasAccess('tl_esm_team::published', 'alexf'))
247
+		{
248
+			return '';
249
+		}
250
+
251
+		$href .= '&amp;tid='.$row['id'].'&amp;state='.($row['published'] ? '' : 1);
252
+
253
+		if (!$row['published'])
254
+		{
255
+			$icon = 'invisible.gif';
256
+		}
257
+
258
+		return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label, 'data-state="' . ($row['published'] ? 1 : 0) . '"').'</a> ';
259
+	}
260
+
261
+
262
+	/**
263
+	 * Disable/enable a user group
264
+	 *
265
+	 * @param integer       $intId
266
+	 * @param boolean       $blnVisible
267
+	 * @param DataContainer $dc
268
+	 */
269
+	public function toggleVisibility($intId, $blnVisible, DataContainer $dc=null)
270
+	{
271
+		// Set the ID and action
272
+		Input::setGet('id', $intId);
273
+		Input::setGet('act', 'toggle');
274
+
275
+		if ($dc)
276
+		{
277
+			$dc->id = $intId; // see #8043
278
+		}
279
+
280
+		// Check the field access
281
+		if (!$this->User->hasAccess('tl_esm_team::published', 'alexf'))
282
+		{
283
+			$this->log('Not enough permissions to publish/unpublish teammember ID "'.$intId.'"', __METHOD__, TL_ERROR);
284
+			$this->redirect('contao/main.php?act=error');
285
+		}
286
+
287
+		$objVersions = new Versions('tl_esm_team', $intId);
288
+		$objVersions->initialize();
289
+
290
+		// Trigger the save_callback
291
+		if (is_array($GLOBALS['TL_DCA']['tl_news']['fields']['published']['save_callback']))
292
+		{
293
+			foreach ($GLOBALS['TL_DCA']['tl_news']['fields']['published']['save_callback'] as $callback)
294
+			{
295
+				if (is_array($callback))
296
+				{
297
+					$this->import($callback[0]);
298
+					$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, ($dc ?: $this));
299
+				}
300
+				elseif (is_callable($callback))
301
+				{
302
+					$blnVisible = $callback($blnVisible, ($dc ?: $this));
303
+				}
304
+			}
305
+		}
306
+
307
+		// Update the database
308
+		$this->Database->prepare("UPDATE tl_esm_team SET tstamp=". time() .", published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")
309
+			->execute($intId);
310
+
311
+		$objVersions->create();
312
+		$this->log('A new version of record "tl_esm_team.id='.$intId.'" has been created'.$this->getParentEntries('tl_esm_team', $intId), __METHOD__, TL_GENERAL);
313
+	}
314
+}