GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

tl_belegungsplan_calender   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 71
dl 0
loc 174
rs 10
c 0
b 0
f 0
wmc 23

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loadEndDate() 0 21 4
A listCalender() 0 7 4
A setEndDate() 0 18 3
A updateCalenders() 0 25 4
A loadUeberschneidung() 0 32 5
A calenderOndeleteCallback() 0 5 1
A updateDatabase() 0 4 1
1
<?php
2
 /**
3
  * Contao Open Source CMS
4
  *
5
  * Copyright (c) Jan Karai
6
  *
7
  * @license LGPL-3.0+
8
  */
9
10
/**
11
* Load tl_content language file
12
*/
13
System::loadLanguageFile('tl_content');
14
 
15
/**
16
 * Table tl_belegungsplan_calender
17
 */
18
$GLOBALS['TL_DCA']['tl_belegungsplan_calender'] = array
19
(
20
	// Config
21
	'config' => array
22
	(
23
		'dataContainer'			=> 'Table',
24
		'ptable'				=> 'tl_belegungsplan_objekte',
25
		'ctable'				=> array('tl_content'),
26
		'switchToEdit'			=> true,
27
		'enableVersioning'		=> true,
28
		'onsubmit_callback'		=> array(array('tl_belegungsplan_calender','loadUeberschneidung')),
29
		'ondelete_callback'		=> array(array('tl_belegungsplan_calender', 'calenderOndeleteCallback')),
30
		'sql' => array
31
		(
32
			'keys' => array
33
			(
34
				'id' => 'primary',
35
				'pid' => 'index'
36
			)
37
		)
38
	),
39
	// List
40
	'list' => array
41
	(
42
		'sorting' => array
43
		(
44
			'mode'                    => 4,
45
			'fields'                  => array('startDate DESC'),
46
			'headerFields'            => array('name'),
47
			'panelLayout'             => 'filter;sort,search,limit',
48
			'child_record_callback'   => array('tl_belegungsplan_calender', 'listCalender')
49
		),
50
		'label' => array
51
		(
52
			'fields'                  => array('gast', 'startDate', 'endDate'),
53
			'format'                  => '%s'
54
		),
55
		'global_operations' => array
56
		(
57
			'all' => array
58
			(
59
				'label'               => &$GLOBALS['TL_LANG']['MSC']['all'],
60
				'href'                => 'act=select',
61
				'class'               => 'header_edit_all',
62
				'attributes'          => 'onclick="Backend.getScrollOffset()" accesskey="e"'
63
			)
64
		),
65
		'operations' => array
66
		(
67
			'edit' => array
68
			(
69
				'label'               => &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['edit'],
70
				'href'                => 'act=edit',
71
				'icon'                => 'edit.svg'
72
			),
73
			'delete' => array
74
			(
75
				'label'               => &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['delete'],
76
				'href'                => 'act=delete',
77
				'icon'                => 'delete.svg',
78
				'attributes'          => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
79
			)
80
		)
81
	),
82
	// Palettes
83
	'palettes' => array
84
	(
85
		'__selector__'				=> array('dauer'),
86
		'default'					=> '{title_legend},gast,author;{day_legend},dauer',
87
		'oneday'					=> '{title_legend},gast,author;{day_legend},dauer;{date_legend},startDate',
88
		'moreday'					=> '{title_legend},gast,author;{day_legend},dauer;{date_legend},startDate,endDate'
89
	),
90
	// Subpalettes
91
	'subpalettes' => array(
92
	),
93
	// Fields
94
	'fields' => array
95
	(
96
		'id' => array
97
		(
98
			'sql'                     => "int(10) unsigned NOT NULL auto_increment"
99
		),
100
		'pid' => array
101
		(
102
			'foreignKey'              => 'tl_belegungsplan_objekte.name',
103
			'sql'                     => "int(10) unsigned NOT NULL default '0'",
104
			'relation'                => array('type'=>'belongsTo', 'load'=>'eager')
105
		),
106
		'tstamp' => array
107
		(
108
			'sql'                     => "int(10) unsigned NOT NULL default '0'"
109
		),
110
		'gast' => array
111
		(
112
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['gast'],
113
			'exclude'                 => true,
114
			'search'                  => true,
115
			'filter'                  => true,
116
			'inputType'               => 'text',
117
			'eval'                    => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'long'),
118
			'sql'                     => "varchar(255) NOT NULL default ''"
119
		),
120
		'author' => array
121
		(
122
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['author'],
123
			'default'                 => BackendUser::getInstance()->id,
124
			'exclude'                 => true,
125
			'search'                  => true,
126
			'filter'                  => true,
127
			'sorting'                 => true,
128
			'flag'                    => 11,
129
			'inputType'               => 'select',
130
			'foreignKey'              => 'tl_user.name',
131
			'eval'                    => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
132
			'sql'                     => "int(10) unsigned NOT NULL default '0'",
133
			'relation'                => array('type'=>'belongsTo', 'load'=>'eager')
134
		),
135
		'startDate' => array
136
		(
137
			'label'			=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['startDate'],
138
			'exclude'		=> true,
139
			'search'		=> true,
140
			'filter'		=> true,
141
			'sorting'		=> true,
142
			'flag'			=> 8,
143
			'inputType'		=> 'text',
144
			'eval'			=> array('rgxp'=>'date', 'mandatory'=>true, 'doNotCopy'=>true, 'datepicker'=>true, 'tl_class'=>'w50 wizard'),
145
			'save_callback'	=> array
146
			(
147
				array('tl_belegungsplan_calender','setEndDate')
148
			),
149
			'sql'			=> "int(10) unsigned NULL"
150
		),
151
		'endDate' => array
152
		(
153
			'label'			=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDate'],
154
			'exclude'		=> true,
155
			'search'		=> true,
156
			'filter'		=> true,
157
			'sorting'		=> true,
158
			'flag'			=> 8,
159
			'inputType'		=> 'text',
160
			'eval'			=> array('rgxp'=>'date', 'mandatory'=>true, 'doNotCopy'=>true, 'datepicker'=>true, 'tl_class'=>'w50 wizard'),
161
			'save_callback'	=> array
162
			(
163
				array('tl_belegungsplan_calender','loadEndDate')
164
			),
165
			'sql'			=> "int(10) unsigned NULL"
166
		),
167
		'ueberschneidung' => array
168
		(
169
			'label'			=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['ueberschneidung'],
170
			'exclude'		=> true,
171
			'inputType'		=> 'text',
172
			'sql'			=> "text NULL"
173
		),
174
		'dauer' => array
175
		(
176
			'label'			=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['dauer'],
177
			'inputType'		=> 'radio',
178
			'options'		=> array('oneday', 'moreday'),
179
			'default'		=> 'moreday',
180
			'reference'		=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender'],
181
			'explanation'	=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender'],
182
			'eval'			=> array('mandatory'=>true, 'submitOnChange'=>true, 'tl_class'=>'w50', 'style'=>'margin:10px'),
183
			'sql'			=> "varchar(8) NOT NULL default ''"
184
		)
185
	)
186
);
187
188
 /**
189
  * Provide miscellaneous methods that are used by the data configuration array.
190
  *
191
  * @author Jan Karai <https://www.sachsen-it.de>
192
  */
193
class tl_belegungsplan_calender extends Backend
194
{
195
	 /**
196
	  * Import the back end user object
197
	  */
198
	public function __construct() {
199
		parent::__construct();
200
		$this->import('BackendUser', 'User');
201
	}
202
	/**
203
	 * Add the type of input field
204
	 *
205
	 * @param array $arrRow
206
	 *
207
	 * @return string
208
	 */
209
	public function listCalender($arrRow)
210
	{
211
		return '<div class="tl_content_left">' . $arrRow['gast'] . 
212
		' <span style="color:#999;padding-left:3px">[' . Date::parse(Config::get('dateFormat'), $arrRow['startDate']) .($arrRow['dauer'] == 'moreday' ? $GLOBALS['TL_LANG']['MSC']['cal_timeSeparator'] . Date::parse(Config::get('dateFormat'), $arrRow['endDate']) : '') . ']</span>' . 
213
		($arrRow['endDate'] < $arrRow['startDate'] ? ' ' . Image::getHtml('error.svg', $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDateListError'], 'title="' . $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDateListError'] . '"') : '') . 
214
		($arrRow['ueberschneidung'] ? ' ' . Image::getHtml('error_404.svg', $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['ueberschneidung'][0], 'title="' . $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['ueberschneidung'][0] . '"') : '') . 
215
		'</div>';
216
	}
217
	/**
218
	 * Prueft ob Enddatum kleiner Startdatum
219
	 *
220
	 * @param mixed $varValue
221
	 * @param DataContainer $dc
222
	 * @return mixed
223
	 */
224
	public function loadEndDate($varValue, DataContainer $dc)
0 ignored issues
show
Unused Code introduced by
The parameter $dc is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

224
	public function loadEndDate($varValue, /** @scrutinizer ignore-unused */ DataContainer $dc)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
225
	{
226
		$dateOne = new DateTime($this->Input->post('startDate'));
227
		$dateTwo = new DateTime($this->Input->post('endDate'));
228
		
229
		try
230
		{
231
			if ($dateTwo->getTimestamp() <= $dateOne->getTimestamp())
232
			{	
233
				if ($dateTwo->getTimestamp() < $dateOne->getTimestamp())
234
				{
235
					throw new Exception($GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDateError']); 
236
				} else {
237
					throw new Exception($GLOBALS['TL_LANG']['tl_belegungsplan_calender']['sameDateError']); 
238
				}
239
			} else {
240
				return $varValue;
241
			}
242
		}
243
		catch (\OutOfBoundsException $e)
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
244
		{
245
		}
246
	}
247
	/**
248
	 * Setzt das Enddatum bei eintaegigem Besuch
249
	 *
250
	 * @param mixed $varValue
251
	 * @param DataContainer $dc
252
	 *
253
	 * @return mixed
254
	 */
255
	public function setEndDate($varValue, DataContainer $dc)
256
	{
257
		// Return if there is no active record (override all)
258
		if (!$dc->activeRecord)
259
		{
260
			return;
261
		}
262
		if ($dc->Input->post('dauer') === 'oneday')
263
		{
264
			$arrSet = array();
265
			$getStartDatum = new DateTime($dc->Input->post('startDate'));
266
			$sNextDay = $getStartDatum->add(new DateInterval('P1D'));
267
			$arrSet['startDate'] = (int) $getStartDatum->getTimestamp();
268
			$arrSet['endDate'] = (int) $sNextDay->getTimestamp();
269
			
270
			$this->Database->prepare("UPDATE tl_belegungsplan_calender %s WHERE id=?")->set($arrSet)->execute($dc->id);
271
		}
272
		return $varValue;
273
	}
274
	/**
275
	 * Prueft auf Terminueberschneidungen
276
	 *
277
	 * @param DataContainer $dc
278
	 */
279
	public function loadUeberschneidung(DataContainer $dc)
280
	{
281
		$intId = (int) $dc->activeRecord->id;
282
		$intPid = (int) $dc->activeRecord->pid;
283
		$intStart = (int) $dc->activeRecord->startDate;
284
		$intEnde = (int) $dc->activeRecord->endDate;
285
		// Hole alle Calenderdaten zur Auswahl
286
		$objCal = $this->Database->prepare("SELECT id, ueberschneidung
287
											FROM tl_belegungsplan_calender
288
											WHERE id <> ?
289
											AND pid = ?
290
											AND ((startDate < ? AND endDate > ?) OR (startDate >= ? AND endDate <= ?) OR (startDate < ? AND endDate > ?))")
291
						->execute($intId, $intPid, $intStart, $intStart, $intStart, $intEnde, $intEnde, $intEnde);
292
		if ($objCal->numRows > 0) {
293
			$strHelper = '';
294
			while ($objCal->next()) {
295
				$strHelper .= ',' . $objCal->id;
296
				if (empty($objCal->ueberschneidung)) {
297
					$this->updateDatabase($intId, $objCal->id);
298
				} else {
299
					$arrHelper = explode(',', $objCal->ueberschneidung);
300
					if (!in_array($intId, $arrHelper)) {
301
						$this->updateDatabase($objCal->ueberschneidung . ',' . $intId, $objCal->id);
302
					}
303
					unset($arrHelper);
304
				}
305
			}
306
			// Update am aktuellen Termin
307
			$this->updateDatabase(substr($strHelper, 1), $intId);
308
			unset($strHelper);
309
		} else {
310
			$this->updateCalenders($intId, $intPid);
311
		}		
312
	}
313
	/**
314
	 * ondelete_callback: Wird ausgefuehrt bevor ein Datensatz aus der Datenbank entfernt wird.
315
	 *
316
	 * @param DataContainer $dc
317
	 */
318
	public function calenderOndeleteCallback(DataContainer $dc)
319
	{
320
		$intId = (int) $dc->activeRecord->id;
321
		$intPid = (int) $dc->activeRecord->pid;
322
		$this->updateCalenders($intId, $intPid);
323
	}
324
	/**
325
	 * Update Datenbank
326
	 *
327
	 * @param integer $intId
328
	 * @param integer $intPid
329
	 */
330
	 public function updateCalenders($intId, $intPid)
331
	{
332
		$objCalDelete = $this->Database->prepare("SELECT id, ueberschneidung
333
											FROM tl_belegungsplan_calender
334
											WHERE id <> ?
335
											AND pid = ?
336
											AND ueberschneidung <> ''")
337
						->execute($intId, $intPid);
338
		if ($objCalDelete->numRows > 0) {
339
			$arrDelete = array($intId);
340
			$strHelper = '';
341
			while ($objCalDelete->next()) {
342
				$strHelper .= ',' . $objCalDelete->id;
343
				$arrHelper = explode(',', $objCalDelete->ueberschneidung);
344
				$arrReturn = array_diff($arrHelper, $arrDelete);
345
				$strInsert = '';
346
				if (!empty($arrReturn)) {
347
					$strInsert = implode(',', $arrReturn);
348
				} 
349
				$this->updateDatabase($strInsert, $objCalDelete->id);
350
				unset($arrHelper, $arrReturn);
351
			}
352
			// Update am aktuellen Termin
353
			$this->updateDatabase('', $intId);
354
			unset($arrHelper, $arrReturn);
355
		}
356
	}
357
	/**
358
	 * Update Datenbank
359
	 *
360
	 * @param string $strInput
361
	 * @param integer $intInput
362
	 */
363
	public function updateDatabase($strInput, $intInput)
364
	{
365
		$this->Database->prepare("UPDATE tl_belegungsplan_calender SET ueberschneidung = ? WHERE id = ?")
366
						->execute($strInput, $intInput);
367
	}
368
}
369