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.
Test Failed
Push — master ( 79866d...70b5f4 )
by Jan
24:35 queued 17:10
created

tl_belegungsplan_calender::listCalender()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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(),
86
		'default'                     => '{title_legend},gast,author;{date_legend},startDate,endDate'
87
	),
88
	// Subpalettes
89
	'subpalettes' => array(
90
	),
91
	// Fields
92
	'fields' => array
93
	(
94
		'id' => array
95
		(
96
			'sql'                     => "int(10) unsigned NOT NULL auto_increment"
97
		),
98
		'pid' => array
99
		(
100
			'foreignKey'              => 'tl_belegungsplan_objekte.name',
101
			'sql'                     => "int(10) unsigned NOT NULL default '0'",
102
			'relation'                => array('type'=>'belongsTo', 'load'=>'eager')
103
		),
104
		'tstamp' => array
105
		(
106
			'sql'                     => "int(10) unsigned NOT NULL default '0'"
107
		),
108
		'gast' => array
109
		(
110
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['gast'],
111
			'exclude'                 => true,
112
			'search'                  => true,
113
			'filter'                  => true,
114
			'inputType'               => 'text',
115
			'eval'                    => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'long'),
116
			'sql'                     => "varchar(255) NOT NULL default ''"
117
		),
118
		'author' => array
119
		(
120
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['author'],
121
			'default'                 => BackendUser::getInstance()->id,
122
			'exclude'                 => true,
123
			'search'                  => true,
124
			'filter'                  => true,
125
			'sorting'                 => true,
126
			'flag'                    => 11,
127
			'inputType'               => 'select',
128
			'foreignKey'              => 'tl_user.name',
129
			'eval'                    => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
130
			'sql'                     => "int(10) unsigned NOT NULL default '0'",
131
			'relation'                => array('type'=>'belongsTo', 'load'=>'eager')
132
		),
133
		'startDate' => array
134
		(
135
			'label'			=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['startDate'],
136
			'exclude'		=> true,
137
			'search'		=> true,
138
			'filter'		=> true,
139
			'sorting'		=> true,
140
			'flag'			=> 8,
141
			'inputType'		=> 'text',
142
			'eval'			=> array('rgxp'=>'date', 'mandatory'=>true, 'doNotCopy'=>true, 'datepicker'=>true, 'tl_class'=>'w50 wizard'),
143
			'sql'			=> "int(10) unsigned NULL"
144
		),
145
		'endDate' => array
146
		(
147
			'label'			=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDate'],
148
			'exclude'		=> true,
149
			'search'		=> true,
150
			'filter'		=> true,
151
			'sorting'		=> true,
152
			'flag'			=> 8,
153
			'inputType'		=> 'text',
154
			'eval'			=> array('rgxp'=>'date', 'mandatory'=>true, 'doNotCopy'=>true, 'datepicker'=>true, 'tl_class'=>'w50 wizard'),
155
			'save_callback'	=> array(array('tl_belegungsplan_calender','loadEndDate')),
156
			'sql'			=> "int(10) unsigned NULL"
157
		),
158
		'ueberschneidung' => array
159
		(
160
			'label'			=> &$GLOBALS['TL_LANG']['tl_belegungsplan_calender']['ueberschneidung'],
161
			'exclude'		=> true,
162
			'inputType'		=> 'text',
163
			'sql'			=> "text NOT NULL default ''"
164
		)
165
	)
166
);
167
168
 /**
169
 * Provide miscellaneous methods that are used by the data configuration array.
170
 *
171
 * @author Jan Karai <https://www.sachsen-it.de>
172
 */
173
class tl_belegungsplan_calender extends Backend
174
{
175
	 /**
176
	 * Import the back end user object
177
	 */
178
	public function __construct() {
179
		parent::__construct();
180
		$this->import('BackendUser', 'User');
181
	}
182
	/**
183
	 * Add the type of input field
184
	 *
185
	 * @param array $arrRow
186
	 *
187
	 * @return string
188
	 */
189
	public function listCalender($arrRow)
190
	{
191
		return '<div class="tl_content_left">' . $arrRow['gast'] . 
192
		' <span style="color:#999;padding-left:3px">[' . Date::parse(Config::get('dateFormat'), $arrRow['startDate']) . $GLOBALS['TL_LANG']['MSC']['cal_timeSeparator'] . Date::parse(Config::get('dateFormat'), $arrRow['endDate']) . ']</span>' . 
193
		($arrRow['endDate'] < $arrRow['startDate'] ? ' ' . Image::getHtml('error.svg', $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDateListError'], 'title="' . $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDateListError'] . '"') : '') . 
194
		($arrRow['ueberschneidung'] ? ' ' . Image::getHtml('error_404.svg', $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['ueberschneidung'][0], 'title="' . $GLOBALS['TL_LANG']['tl_belegungsplan_calender']['ueberschneidung'][0] . '"') : '') . 
195
		'</div>';
196
	}
197
	/**
198
	 * Prueft ob Enddatum kleiner Startdatum
199
	 *
200
	 * @param string $varValue
201
	 * @param DataContainer $dc
202
	 * @return string
203
	 */
204
	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

204
	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...
205
	{
206
		$dateOne = new DateTime($this->Input->post('startDate'));
207
		$dateTwo = new DateTime($this->Input->post('endDate'));
208
		try
209
		{
210
			if ($dateTwo->getTimestamp() < $dateOne->getTimestamp())
211
			{	
212
				throw new Exception($GLOBALS['TL_LANG']['tl_belegungsplan_calender']['endDateError']); 
213
			} else {
214
				return $varValue;
215
			}
216
		}
217
		catch (\OutOfBoundsException $e)
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
218
		{
219
		}
220
	}
221
	/**
222
	 * Prueft auf Terminueberschneidungen
223
	 *
224
	 * @param DataContainer $dc
225
	 */
226
	public function loadUeberschneidung(DataContainer $dc)
227
	{
228
		$intId = (int) $dc->activeRecord->id;
229
		$intPid = (int) $dc->activeRecord->pid;
230
		$intStart = (int) $dc->activeRecord->startDate;
231
		$intEnde = (int) $dc->activeRecord->endDate;
232
		// Hole alle Calenderdaten zur Auswahl
233
		$objCal = $this->Database->prepare("SELECT id, ueberschneidung
234
											FROM tl_belegungsplan_calender
235
											WHERE id <> ?
236
											AND pid = ?
237
											AND ((startDate < ? AND endDate > ?) OR (startDate >= ? AND endDate <= ?) OR (startDate < ? AND endDate > ?))")
238
						->execute($intId, $intPid, $intStart, $intStart, $intStart, $intEnde, $intEnde, $intEnde);
239
		if ($objCal->numRows > 0) {
240
			$strHelper = '';
241
			while ($objCal->next()) {
242
				$strHelper .= ',' . $objCal->id;
243
				if (empty($objCal->ueberschneidung)) {
244
					$this->updateDatabase($intId, $objCal->id);
245
				} else {
246
					$arrHelper = explode(',', $objCal->ueberschneidung);
247
					if (!in_array($intId, $arrHelper)) {
248
						$this->updateDatabase($objCal->ueberschneidung . ',' . $intId, $objCal->id);
249
					}
250
					unset($arrHelper);
251
				}
252
			}
253
			// Update am aktuellen Termin
254
			$this->updateDatabase(substr($strHelper, 1), $intId);
255
			unset($strHelper);
256
		} else {
257
			$this->updateCalenders($intId, $intPid);
258
		}		
259
	}
260
	/**
261
	 * ondelete_callback: Wird ausgefuehrt bevor ein Datensatz aus der Datenbank entfernt wird.
262
	 *
263
	 * @param DataContainer $dc
264
	 */
265
	public function calenderOndeleteCallback(DataContainer $dc)
266
	{
267
		$intId = (int) $dc->activeRecord->id;
268
		$intPid = (int) $dc->activeRecord->pid;
269
		$this->updateCalenders($intId, $intPid);
270
	}
271
	/**
272
	 * Update Datenbank
273
	 *
274
	 * @param integer $intId
275
	 * @param integer $intPid
276
	 */
277
	 public function updateCalenders($intId, $intPid)
278
	{
279
		$objCalDelete = $this->Database->prepare("SELECT id, ueberschneidung
280
											FROM tl_belegungsplan_calender
281
											WHERE id <> ?
282
											AND pid = ?
283
											AND ueberschneidung <> ''")
284
						->execute($intId, $intPid);
285
		if ($objCalDelete->numRows > 0) {
286
			$arrDelete = array($intId);
287
			$strHelper = '';
288
			while ($objCalDelete->next()) {
289
				$strHelper .= ',' . $objCalDelete->id;
290
				$arrHelper = explode(',', $objCalDelete->ueberschneidung);
291
				$arrReturn = array_diff($arrHelper, $arrDelete);
292
				$strInsert = '';
293
				if (!empty($arrReturn)) {
294
					$strInsert = implode(',', $arrReturn);
295
				} 
296
				$this->updateDatabase($strInsert, $objCalDelete->id);
297
				unset($arrHelper, $arrReturn);
298
			}
299
			// Update am aktuellen Termin
300
			$this->updateDatabase('', $intId);
301
			unset($arrHelper, $arrReturn);
302
		}
303
	}
304
	/**
305
	 * Update Datenbank
306
	 *
307
	 * @param string $strInput
308
	 * @param integer $intInput
309
	 */
310
	public function updateDatabase($strInput, $intInput)
311
	{
312
		$this->Database->prepare("UPDATE tl_belegungsplan_calender SET ueberschneidung = ? WHERE id = ?")
313
						->execute($strInput, $intInput);
314
	}
315
}
316