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_objekte::toggleVisibility()   C

Complexity

Conditions 15
Paths 72

Size

Total Lines 50
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
eloc 33
nc 72
nop 3
dl 0
loc 50
rs 5.3624
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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_objekte
17
 */
18
$GLOBALS['TL_DCA']['tl_belegungsplan_objekte'] = array(
19
	'config' => array(
20
		'dataContainer'               => 'Table',
21
		'ptable'                      => 'tl_belegungsplan_category',
22
		'ctable'                      => array('tl_belegungsplan_calender'),
23
		'switchToEdit'                => true,
24
		'enableVersioning'            => true,
25
		'sql' => array(
26
			'keys' => array(
27
				'id' => 'primary',
28
				'pid,published,sorting' => 'index'
29
			)
30
		)
31
	),
32
	// List
33
	'list' => array(
34
		'sorting' => array(
35
			'mode'                    => 4,
36
			'fields'                  => array('sorting'),
37
			'panelLayout'             => 'filter;sort,search,limit',
38
			'headerFields'            => array('title'),
39
			'child_record_callback'   => array('tl_belegungsplan_objekte', 'listQuestions')
40
		),
41
		'global_operations' => array(
42
			'all' => array(
43
				'label'               => &$GLOBALS['TL_LANG']['MSC']['all'],
44
				'href'                => 'act=select',
45
				'class'               => 'header_edit_all',
46
				'attributes'          => 'onclick="Backend.getScrollOffset()" accesskey="e"'
47
			)
48
		),
49
		'operations' => array(
50
			'edit' => array(
51
				'label'               => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['edit'],
52
				'href'                => 'table=tl_belegungsplan_calender',
53
				'icon'                => 'cssimport.svg'
54
			),
55
			'editheader' => array(
56
				'label'               => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['editheader'],
57
				'href'                => 'act=edit',
58
				'icon'                => 'edit.svg',
59
				'button_callback'     => array('tl_belegungsplan_objekte', 'editHeader')
60
			),
61
			'delete' => array(
62
				'label'               => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['delete'],
63
				'href'                => 'act=delete',
64
				'icon'                => 'delete.svg',
65
				'attributes'          => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
66
			),
67
			'toggle' => array(
68
				'label'               => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['toggle'],
69
				'icon'                => 'visible.svg',
70
				'attributes'          => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
71
				'button_callback'     => array('tl_belegungsplan_objekte', 'toggleIcon')
72
			),
73
			'show' => array(
74
				'label'               => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['show'],
75
				'href'                => 'act=show',
76
				'icon'                => 'show.svg'
77
			)
78
		)
79
	),
80
	// Palettes
81
	'palettes' => array(
82
		'__selector__'                => array(),
83
		'default'                     => '{title_legend},name,author,infotext;{publish_legend},published'
84
	),
85
	// Subpalettes
86
	'subpalettes' => array(),
87
	// Fields
88
	'fields' => array(
89
		'id' => array(
90
			'sql'                     => "int(10) unsigned NOT NULL auto_increment"
91
		),
92
		'pid' => array(
93
			'foreignKey'              => 'tl_belegungsplan_category.title',
94
			'sql'                     => "int(10) unsigned NOT NULL default '0'",
95
			'relation'                => array('type'=>'belongsTo', 'load'=>'eager')
96
		),
97
		'sorting' => array(
98
			'label'                   => &$GLOBALS['TL_LANG']['MSC']['sorting'],
99
			'sorting'                 => true,
100
			'flag'                    => 11,
101
			'sql'                     => "int(10) unsigned NOT NULL default '0'"
102
		),
103
		'tstamp' => array(
104
			'sql'                     => "int(10) unsigned NOT NULL default '0'"
105
		),
106
		'name' => array(
107
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['name'],
108
			'exclude'                 => true,
109
			'search'                  => true,
110
			'inputType'               => 'text',
111
			'eval'                    => array('mandatory'=>true, 'unique'=>true, 'maxlength'=>128, 'tl_class'=>'w50'),
112
			'sql'                     => "varchar(128) NOT NULL default ''"
113
		),
114
		'author' => array(
115
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['author'],
116
			'default'                 => BackendUser::getInstance()->id,
117
			'exclude'                 => true,
118
			'search'                  => true,
119
			'filter'                  => true,
120
			'sorting'                 => true,
121
			'flag'                    => 11,
122
			'inputType'               => 'select',
123
			'foreignKey'              => 'tl_user.name',
124
			'eval'                    => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
125
			'sql'                     => "int(10) unsigned NOT NULL default '0'",
126
			'relation'                => array('type'=>'belongsTo', 'load'=>'eager')
127
		),
128
		'infotext' => array(
129
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['infotext'],
130
			'exclude'                 => true,
131
			'search'                  => true,
132
			'inputType'               => 'text',
133
			'eval'                    => array('maxlength'=>255, 'tl_class'=>'long'),
134
			'sql'                     => "varchar(255) NOT NULL default ''"
135
		),
136
		'published' => array(
137
			'label'                   => &$GLOBALS['TL_LANG']['tl_belegungsplan_objekte']['published'],
138
			'exclude'                 => true,
139
			'filter'                  => true,
140
			'flag'                    => 2,
141
			'inputType'               => 'checkbox',
142
			'eval'                    => array('doNotCopy'=>true),
143
			'sql'                     => "char(1) NOT NULL default ''"
144
		)
145
	)
146
);
147
/**
148
 * Provide miscellaneous methods that are used by the data configuration array.
149
 *
150
 * @author Jan Karai <https://www.sachsen-it.de>
151
 */
152
class tl_belegungsplan_objekte extends Backend
153
{
154
	/**
155
	 * Import the back end user object
156
	 */
157
	public function __construct()
158
	{
159
		parent::__construct();
160
		$this->import('BackendUser', 'User');
161
	}
162
	/**
163
	 * Return the edit header button
164
	 *
165
	 * @param array  $row
166
	 * @param string $href
167
	 * @param string $label
168
	 * @param string $title
169
	 * @param string $icon
170
	 * @param string $attributes
171
	 *
172
	 * @return string
173
	 */
174
	public function editHeader($row, $href, $label, $title, $icon, $attributes)
175
	{
176
		return '<a href="' . $this->addToUrl($href . '&amp;id=' . $row['id']) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label) . '</a> ';
177
	}
178
	/**
179
	 * Add the type of input field
180
	 *
181
	 * @param array $arrRow
182
	 *
183
	 * @return string
184
	 */
185
	public function listQuestions($arrRow)
186
	{
187
		$key = $arrRow['published'] ? 'published' : 'unpublished';
188
		$date = Date::parse(Config::get('datimFormat'), $arrRow['tstamp']);
189
		return '
190
<div class="cte_type ' . $key . '">' . $date . '</div>
191
<div class="limit_height' . (!Config::get('doNotCollapse') ? ' h40' : '') . '">
192
' . StringUtil::insertTagToSrc($arrRow['name']) . 
193
(!empty($arrRow['infotext']) ? '<span style="color:#b3b3b3;padding-left:3px">[' . StringUtil::insertTagToSrc($arrRow['infotext']) . ']</span>' : '') . '
194
</div>' . "\n";
195
	}
196
	/**
197
	 * Return the "toggle visibility" button
198
	 *
199
	 * @param array  $row
200
	 * @param string $href
201
	 * @param string $label
202
	 * @param string $title
203
	 * @param string $icon
204
	 * @param string $attributes
205
	 *
206
	 * @return string
207
	 */
208
	public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
209
	{
210
		if (strlen(Input::get('tid')))
211
		{
212
			$this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1), (@func_get_arg(12) ?: null));
213
			$this->redirect($this->getReferer());
214
		}
215
		
216
		$href .= '&amp;tid=' . $row['id'] . '&amp;state=' . ($row['published'] ? '' : 1);
217
		if (!$row['published'])
218
		{
219
			$icon = 'invisible.svg';
220
		}
221
		return '<a href="' . $this->addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label, 'data-state="' . ($row['published'] ? 1 : 0) . '"') . '</a> ';
222
	}
223
	/**
224
	 * Disable/enable a user group
225
	 *
226
	 * @param integer       $intId
227
	 * @param boolean       $blnVisible
228
	 * @param DataContainer $dc
229
	 *
230
	 * @throws Contao\CoreBundle\Exception\AccessDeniedException
231
	 */
232
	public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null) {
233
		// Set the ID and action
234
		Input::setGet('id', $intId);
235
		Input::setGet('act', 'toggle');
236
		if ($dc) {
237
			$dc->id = $intId; // see #8043
238
		}
239
		
240
		// Set the current record
241
		if ($dc) {
242
			$objRow = $this->Database->prepare("SELECT * FROM tl_belegungsplan_objekte WHERE id=?")
243
									 ->limit(1)
244
									 ->execute($intId);
245
			if ($objRow->numRows) {
246
				$dc->activeRecord = $objRow;
247
			}
248
		}
249
		$objVersions = new Versions('tl_belegungsplan_objekte', $intId);
250
		$objVersions->initialize();
251
		// Trigger the save_callback
252
		if (is_array($GLOBALS['TL_DCA']['tl_belegungsplan_objekte']['fields']['published']['save_callback'])) {
253
			foreach ($GLOBALS['TL_DCA']['tl_belegungsplan_objekte']['fields']['published']['save_callback'] as $callback) {
254
				if (is_array($callback)) {
255
					$this->import($callback[0]);
256
					$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc);
257
				} elseif (is_callable($callback)) {
258
					$blnVisible = $callback($blnVisible, $dc);
259
				}
260
			}
261
		}
262
		$time = time();
263
		// Update the database
264
		$this->Database->prepare("UPDATE tl_belegungsplan_objekte SET tstamp=$time, published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")
265
					   ->execute($intId);
266
		if ($dc) {
267
			$dc->activeRecord->tstamp = $time;
268
			$dc->activeRecord->published = ($blnVisible ? '1' : '');
269
		}
270
		// Trigger the onsubmit_callback
271
		if (is_array($GLOBALS['TL_DCA']['tl_belegungsplan_objekte']['config']['onsubmit_callback'])) {
272
			foreach ($GLOBALS['TL_DCA']['tl_belegungsplan_objekte']['config']['onsubmit_callback'] as $callback) {
273
				if (is_array($callback)) {
274
					$this->import($callback[0]);
275
					$this->{$callback[0]}->{$callback[1]}($dc);
276
				} elseif (is_callable($callback)) {
277
					$callback($dc);
278
				}
279
			}
280
		}
281
		$objVersions->create();
282
	}
283
}
284