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.
Passed
Pull Request — master (#2835)
by
unknown
06:01
created

FieldAuthor   F

Complexity

Total Complexity 104

Size/Duplication

Total Lines 666
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 666
rs 1.3705
wmc 104

28 Methods

Rating   Name   Duplication   Size   Complexity  
B commit() 0 22 6
A canFilter() 0 3 1
A getExportModes() 0 14 1
A allowDatasourceOutputGrouping() 0 4 1
A getParameterPoolValue() 0 3 1
B createTable() 0 26 1
A allowDatasourceParamOutput() 0 3 1
B processRawFieldData() 0 19 5
F displayPublishPanel() 0 68 17
A buildSortingSelectSQL() 0 12 3
B displaySettingsPanel() 0 36 5
A set() 0 7 3
A getToggleStates() 0 10 2
C buildDSRetrievalSQL() 0 112 11
B getExampleFormMarkup() 0 25 4
C groupRecords() 0 34 7
C prepareExportValue() 0 39 12
A canToggle() 0 3 2
A fetchSuggestionTypes() 0 3 1
A toggleFieldData() 0 4 1
A checkFields() 0 11 4
A __construct() 0 8 1
B appendFormattedElement() 0 26 4
A prepareTextValue() 0 4 1
A __parseFilter() 0 3 2
A buildSortingSQL() 0 16 3
A findDefaults() 0 8 3
A isSortable() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like FieldAuthor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FieldAuthor, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * @package toolkit
5
 */
6
7
/**
8
 * The Author field allows Symphony Authors to be selected in your entries.
9
 * It is a read only field, new Authors cannot be added from the Frontend using
10
 * events.
11
 *
12
 * The Author field allows filtering by Author ID or Username.
13
 * Sorting is done based on the Author's first name and last name.
14
 */
15
class FieldAuthor extends Field implements ExportableField
16
{
17
    public function __construct()
18
    {
19
        parent::__construct();
20
        $this->_name = __('Author');
0 ignored issues
show
Bug Best Practice introduced by
The property _name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
        $this->_required = true;
22
        $this->entryQueryFieldAdapter = new EntryQueryAuthorAdapter($this);
23
24
        $this->set('author_types', array());
25
    }
26
27
    /*-------------------------------------------------------------------------
28
        Definition:
29
    -------------------------------------------------------------------------*/
30
31
    public function canToggle()
32
    {
33
        return ($this->get('allow_multiple_selection') === 'yes' ? false : true);
34
    }
35
36
    public function getToggleStates()
37
    {
38
        $authors = (new AuthorManager)->select()->execute()->rows();
39
40
        $states = array();
41
        foreach ($authors as $a) {
42
            $states[$a->get('id')] = $a->getFullName();
43
        }
44
45
        return $states;
46
    }
47
48
    public function toggleFieldData(array $data, $newState, $entry_id = null)
49
    {
50
        $data['author_id'] = $newState;
51
        return $data;
52
    }
53
54
    public function canFilter()
55
    {
56
        return true;
57
    }
58
59
    public function isSortable()
60
    {
61
        return $this->canToggle();
62
    }
63
64
    public function allowDatasourceOutputGrouping()
65
    {
66
        // Grouping follows the same rule as toggling.
67
        return $this->canToggle();
68
    }
69
70
    public function allowDatasourceParamOutput()
71
    {
72
        return true;
73
    }
74
75
    public function fetchSuggestionTypes()
76
    {
77
        return array('static');
78
    }
79
80
    /*-------------------------------------------------------------------------
81
        Setup:
82
    -------------------------------------------------------------------------*/
83
84
    public function createTable()
85
    {
86
        return Symphony::Database()
87
            ->create('tbl_entries_data_' . General::intval($this->get('id')))
88
            ->ifNotExists()
89
            ->fields([
90
                'id' => [
91
                    'type' => 'int(11)',
92
                    'auto' => true,
93
                ],
94
                'entry_id' => 'int(11)',
95
                'author_id' => [
96
                    'type' => 'int(11)',
97
                    'null' => true,
98
                ]
99
            ])
100
            ->keys([
101
                'id' => 'primary',
102
                'author' => [
103
                    'type' => 'unique',
104
                    'cols' => ['entry_id', 'author_id'],
105
                ],
106
                'author_id' => 'key',
107
            ])
108
            ->execute()
109
            ->success();
110
    }
111
112
    /*-------------------------------------------------------------------------
113
        Utilities:
114
    -------------------------------------------------------------------------*/
115
116
    public function set($field, $value)
117
    {
118
        if ($field === 'author_types' && !is_array($value)) {
119
            $value = explode(',', $value);
120
        }
121
122
        $this->_settings[$field] = $value;
123
    }
124
125
    /**
126
     * Determines based on the input value whether we want to filter the Author
127
     * field by ID or by the Author's Username
128
     *
129
     * @since Symphony 2.2
130
     * @deprecated @since Symphony 3.0.0
131
     * @param string $value
132
     * @return string
133
     *  Either `author_id` or `username`
134
     */
135
    private static function __parseFilter($value)
136
    {
137
        return is_numeric($value) ? 'author_id' : 'username';
138
    }
139
140
    /*-------------------------------------------------------------------------
141
        Settings:
142
    -------------------------------------------------------------------------*/
143
144
    public function findDefaults(array &$settings)
145
    {
146
        if (!isset($settings['allow_multiple_selection'])) {
147
            $settings['allow_multiple_selection'] = 'no';
148
        }
149
150
        if (!isset($settings['author_types'])) {
151
            $settings['author_types'] = array('developer', 'manager', 'author');
152
        }
153
    }
154
155
    public function displaySettingsPanel(XMLElement &$wrapper, $errors = null)
156
    {
157
        parent::displaySettingsPanel($wrapper, $errors);
158
159
        // Author types
160
        $label = Widget::Label(__('Author types'));
161
        $types = $this->get('author_types');
162
        $options = array(
163
            array('author', empty($types) ? true : in_array('author', $types), __('Author')),
164
            array('manager', empty($types) ? true : in_array('manager', $types), __('Manager')),
165
            array('developer', empty($types) ? true : in_array('developer', $types), __('Developer'))
166
        );
167
        $label->appendChild(
168
            Widget::Select('fields['.$this->get('sortorder').'][author_types][]', $options, array(
0 ignored issues
show
Bug introduced by
Are you sure $this->get('sortorder') of type null|array|mixed can be used in concatenation? ( Ignorable by Annotation )

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

168
            Widget::Select('fields['./** @scrutinizer ignore-type */ $this->get('sortorder').'][author_types][]', $options, array(
Loading history...
169
                'multiple' => 'multiple'
170
            ))
171
        );
172
173
        if (isset($errors['author_types'])) {
174
            $wrapper->appendChild(Widget::Error($label, $errors['author_types']));
175
        } else {
176
            $wrapper->appendChild($label);
177
        }
178
179
        // Options
180
        $div = new XMLElement('div', null, array('class' => 'two columns'));
181
182
        // Allow multiple selection
183
        $this->createCheckboxSetting($div, 'allow_multiple_selection', __('Allow selection of multiple authors'));
184
185
        // Default to current logged in user
186
        $this->createCheckboxSetting($div, 'default_to_current_user', __('Select current user by default'));
187
188
        // Requirements and table display
189
        $wrapper->appendChild($div);
190
        $this->appendStatusFooter($wrapper);
191
    }
192
193
    public function checkFields(array &$errors, $checkForDuplicates = true)
194
    {
195
        parent::checkFields($errors, $checkForDuplicates);
196
197
        $types = $this->get('author_types');
198
199
        if (empty($types)) {
200
            $errors['author_types'] = __('This is a required field.');
201
        }
202
203
        return (is_array($errors) && !empty($errors) ? self::__ERROR__ : self::__OK__);
204
    }
205
206
    public function commit()
207
    {
208
        if (!parent::commit()) {
209
            return false;
210
        }
211
212
        $id = $this->get('id');
213
214
        if ($id === false) {
215
            return false;
216
        }
217
218
        $fields = array();
219
220
        $fields['allow_multiple_selection'] = ($this->get('allow_multiple_selection') ? $this->get('allow_multiple_selection') : 'no');
221
        $fields['default_to_current_user'] = ($this->get('default_to_current_user') ? $this->get('default_to_current_user') : 'no');
222
223
        if ($this->get('author_types') != '') {
224
            $fields['author_types'] = implode(',', $this->get('author_types'));
225
        }
226
227
        return FieldManager::saveSettings($id, $fields);
0 ignored issues
show
Bug introduced by
It seems like $id can also be of type array; however, parameter $field_id of FieldManager::saveSettings() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

227
        return FieldManager::saveSettings(/** @scrutinizer ignore-type */ $id, $fields);
Loading history...
228
    }
229
230
    /*-------------------------------------------------------------------------
231
        Publish:
232
    -------------------------------------------------------------------------*/
233
234
    public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
235
    {
236
        $value = isset($data['author_id']) ? $data['author_id'] : null;
237
238
        if ($this->get('default_to_current_user') === 'yes' && empty($data) && empty($_POST)) {
239
            $value = array(Symphony::Author()->get('id'));
240
        }
241
242
        if (!is_array($value)) {
243
            $value = array($value);
244
        }
245
246
        $options = array();
247
248
        if ($this->get('required') !== 'yes') {
249
            $options[] = array(null, false, null);
250
        }
251
252
        $authorQuery = (new AuthorManager)
253
            ->select()
254
            ->sort('id');
255
256
        // Custom where to only show Authors based off the Author Types setting
257
        $types = $this->get('author_types');
258
259
        if (!empty($types)) {
260
            $authorQuery->where(['user_type' => ['in' => $types]]);
261
        }
262
263
        $authors = $authorQuery->execute()->rows();
264
        $found = false;
265
266
        foreach ($authors as $a) {
267
            if (in_array($a->get('id'), $value)) {
268
                $found = true;
269
            }
270
271
            $options[] = array($a->get('id'), in_array($a->get('id'), $value), $a->getFullName());
272
        }
273
274
        // Ensure the selected Author is included in the options (incase
275
        // the settings change after the original entry was created)
276
        if (!$found && !is_null($value)) {
277
            $authors = AuthorManager::fetchByID($value);
278
279
            foreach ($authors as $a) {
280
                $options[] = array($a->get('id'), in_array($a->get('id'), $value), $a->getFullName());
281
            }
282
        }
283
284
        $fieldname = 'fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix;
0 ignored issues
show
Bug introduced by
Are you sure $this->get('element_name') of type null|array|mixed can be used in concatenation? ( Ignorable by Annotation )

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

284
        $fieldname = 'fields'.$fieldnamePrefix.'['./** @scrutinizer ignore-type */ $this->get('element_name').']'.$fieldnamePostfix;
Loading history...
285
286
        if ($this->get('allow_multiple_selection') === 'yes') {
287
            $fieldname .= '[]';
288
        }
289
290
        $label = Widget::Label($this->get('label'));
0 ignored issues
show
Bug introduced by
It seems like $this->get('label') can also be of type array; however, parameter $name of Widget::Label() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

290
        $label = Widget::Label(/** @scrutinizer ignore-type */ $this->get('label'));
Loading history...
291
292
        if ($this->get('required') !== 'yes') {
293
            $label->appendChild(new XMLElement('i', __('Optional')));
294
        }
295
296
        $label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') === 'yes' ? array('multiple' => 'multiple') : null)));
297
298
        if ($flagWithError != null) {
299
            $wrapper->appendChild(Widget::Error($label, $flagWithError));
300
        } else {
301
            $wrapper->appendChild($label);
302
        }
303
    }
304
305
    public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
306
    {
307
        $status = self::__OK__;
308
309
        if (!is_array($data) && !empty($data)) {
310
            return array('author_id' => $data);
311
        }
312
313
        if (empty($data)) {
314
            return null;
315
        }
316
317
        $result = array();
318
319
        foreach ($data as $id) {
320
            $result['author_id'][] = $id;
321
        }
322
323
        return $result;
324
    }
325
326
    /*-------------------------------------------------------------------------
327
        Output:
328
    -------------------------------------------------------------------------*/
329
330
    public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
331
    {
332
        if (!is_array($data['author_id'])) {
333
            $data['author_id'] = array($data['author_id']);
334
        }
335
336
        $list = new XMLElement($this->get('element_name'));
0 ignored issues
show
Bug introduced by
It seems like $this->get('element_name') can also be of type array; however, parameter $name of XMLElement::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

336
        $list = new XMLElement(/** @scrutinizer ignore-type */ $this->get('element_name'));
Loading history...
337
        $authors = AuthorManager::fetchByID($data['author_id']);
338
339
        foreach ($authors as $author) {
340
            if (is_null($author)) {
341
                continue;
342
            }
343
344
            $list->appendChild(new XMLElement(
345
                'item',
346
                $author->getFullName(),
347
                array(
348
                    'id' => (string)$author->get('id'),
349
                    'handle' => Lang::createHandle($author->getFullName()),
350
                    'username' => General::sanitize($author->get('username'))
351
                )
352
            ));
353
        }
354
355
        $wrapper->appendChild($list);
356
    }
357
358
    public function prepareTextValue($data, $entry_id = null)
359
    {
360
        $value = $this->prepareExportValue($data, ExportableField::LIST_OF + ExportableField::VALUE, $entry_id);
361
        return General::sanitize(implode(', ', $value));
362
    }
363
364
    public function getParameterPoolValue(array $data, $entry_id = null)
365
    {
366
        return $this->prepareExportValue($data, ExportableField::LIST_OF + ExportableField::AUTHOR, $entry_id);
367
    }
368
369
    /*-------------------------------------------------------------------------
370
        Export:
371
    -------------------------------------------------------------------------*/
372
373
    /**
374
     * Return a list of supported export modes for use with `prepareExportValue`.
375
     *
376
     * @return array
377
     */
378
    public function getExportModes()
379
    {
380
        return array(
381
            'listAuthor' =>         ExportableField::LIST_OF
382
                                    + ExportableField::AUTHOR,
383
            'listAuthorObject' =>   ExportableField::LIST_OF
384
                                    + ExportableField::AUTHOR
385
                                    + ExportableField::OBJECT,
386
            'listAuthorToValue' =>  ExportableField::LIST_OF
387
                                    + ExportableField::AUTHOR
388
                                    + ExportableField::VALUE,
389
            'listValue' =>          ExportableField::LIST_OF
390
                                    + ExportableField::VALUE,
391
            'getPostdata' =>        ExportableField::POSTDATA
392
        );
393
    }
394
395
    /**
396
     * Give the field some data and ask it to return a value using one of many
397
     * possible modes.
398
     *
399
     * @param mixed $data
400
     * @param integer $mode
401
     * @param integer $entry_id
402
     * @return array|null
403
     */
404
    public function prepareExportValue($data, $mode, $entry_id = null)
405
    {
406
        $modes = (object)$this->getExportModes();
407
408
        // Make sure we have an array to work with:
409
        if (isset($data['author_id']) && is_array($data['author_id']) === false) {
410
            $data['author_id'] = array(
411
                $data['author_id']
412
            );
413
        }
414
415
        // Return the author IDs:
416
        if ($mode === $modes->listAuthor || $mode === $modes->getPostdata) {
417
            return isset($data['author_id'])
418
                ? $data['author_id']
419
                : array();
420
        }
421
422
        // All other modes require full data:
423
        $authors = isset($data['author_id'])
424
            ? AuthorManager::fetchByID($data['author_id'])
425
            : array();
426
        $items = array();
427
428
        foreach ($authors as $author) {
429
            if (is_null($author)) {
430
                continue;
431
            }
432
433
            if ($mode === $modes->listAuthorObject) {
434
                $items[] = $author;
435
            } elseif ($mode === $modes->listValue) {
436
                $items[] = $author->getFullName();
437
            } elseif ($mode === $modes->listAuthorToValue) {
438
                $items[$data['author_id']] = $author->getFullName();
439
            }
440
        }
441
442
        return $items;
443
    }
444
445
    /*-------------------------------------------------------------------------
446
        Filtering:
447
    -------------------------------------------------------------------------*/
448
449
    /**
450
     * @deprecated @since Symphony 3.0.0
451
     * @see Field::buildDSRetrievalSQL()
452
     */
453
    public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
454
    {
455
        if (Symphony::Log()) {
456
            Symphony::Log()->pushDeprecateWarningToLog(
457
                get_called_class() . '::buildDSRetrievalSQL()',
458
                'EntryQueryFieldAdapter::filter()'
459
            );
460
        }
461
        $field_id = $this->get('id');
462
463
        if (self::isFilterRegex($data[0])) {
0 ignored issues
show
Deprecated Code introduced by
The function Field::isFilterRegex() has been deprecated: @since Symphony 3.0.0 Use EntryQueryFieldAdapter::isFilterRegex() instead ( Ignorable by Annotation )

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

463
        if (/** @scrutinizer ignore-deprecated */ self::isFilterRegex($data[0])) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
464
            $this->_key++;
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

464
            /** @scrutinizer ignore-deprecated */ $this->_key++;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
465
466
            if (preg_match('/^regexp:/i', $data[0])) {
467
                $pattern = preg_replace('/^regexp:\s*/i', null, $this->cleanValue($data[0]));
468
                $regex = 'REGEXP';
469
            } else {
470
                $pattern = preg_replace('/^not-?regexp:\s*/i', null, $this->cleanValue($data[0]));
471
                $regex = 'NOT REGEXP';
472
            }
473
474
            if (strlen($pattern) == 0) {
475
                return;
476
            }
477
478
            $joins .= "
479
                LEFT JOIN
480
                    `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

480
                    `tbl_entries_data_{$field_id}` AS t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
481
                    ON (e.id = t{$field_id}_{$this->_key}.entry_id)
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

481
                    ON (e.id = t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.entry_id)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
482
                JOIN
483
                    `tbl_authors` AS t{$field_id}_{$this->_key}_authors
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

483
                    `tbl_authors` AS t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
484
                    ON (t{$field_id}_{$this->_key}.author_id = t{$field_id}_{$this->_key}_authors.id)
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

484
                    ON (t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.author_id = t{$field_id}_{$this->_key}_authors.id)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
485
            ";
486
            $where .= "
487
                AND (
488
                    t{$field_id}_{$this->_key}.author_id {$regex} '{$pattern}'
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

488
                    t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.author_id {$regex} '{$pattern}'

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
489
                    OR t{$field_id}_{$this->_key}_authors.username {$regex} '{$pattern}'
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

489
                    OR t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.username {$regex} '{$pattern}'

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
490
                    OR CONCAT_WS(' ',
491
                        t{$field_id}_{$this->_key}_authors.first_name,
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

491
                        t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.first_name,

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
492
                        t{$field_id}_{$this->_key}_authors.last_name
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

492
                        t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.last_name

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
493
                    ) {$regex} '{$pattern}'
494
                )
495
            ";
496
        } elseif (self::isFilterSQL($data[0])) {
0 ignored issues
show
Deprecated Code introduced by
The function Field::isFilterSQL() has been deprecated: @since Symphony 3.0.0 Use EntryQueryFieldAdapter::isFilterSQL() instead ( Ignorable by Annotation )

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

496
        } elseif (/** @scrutinizer ignore-deprecated */ self::isFilterSQL($data[0])) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
497
            $this->buildFilterSQL($data[0], array('username', 'first_name', 'last_name'), $joins, $where);
0 ignored issues
show
Deprecated Code introduced by
The function Field::buildFilterSQL() has been deprecated: @since Symphony 3.0.0 Use EntryQueryFieldAdapter::createFilterSQL() instead ( Ignorable by Annotation )

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

497
            /** @scrutinizer ignore-deprecated */ $this->buildFilterSQL($data[0], array('username', 'first_name', 'last_name'), $joins, $where);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
498
        } elseif ($andOperation) {
499
            foreach ($data as $value) {
500
                $this->_key++;
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

500
                /** @scrutinizer ignore-deprecated */ $this->_key++;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
501
                $value = $this->cleanValue($value);
502
503
                if (self::__parseFilter($value) == "author_id") {
0 ignored issues
show
Deprecated Code introduced by
The function FieldAuthor::__parseFilter() has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

503
                if (/** @scrutinizer ignore-deprecated */ self::__parseFilter($value) == "author_id") {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
504
                    $where .= "
505
                        AND t{$field_id}_{$this->_key}.author_id = '{$value}'
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

505
                        AND t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.author_id = '{$value}'

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
506
                    ";
507
                    $joins .= "
508
                        LEFT JOIN
509
                            `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

509
                            `tbl_entries_data_{$field_id}` AS t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
510
                            ON (e.id = t{$field_id}_{$this->_key}.entry_id)
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

510
                            ON (e.id = t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.entry_id)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
511
                    ";
512
                } else {
513
                    $joins .= "
514
                        LEFT JOIN
515
                            `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

515
                            `tbl_entries_data_{$field_id}` AS t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
516
                            ON (e.id = t{$field_id}_{$this->_key}.entry_id)
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

516
                            ON (e.id = t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.entry_id)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
517
                        JOIN
518
                            `tbl_authors` AS t{$field_id}_{$this->_key}_authors
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

518
                            `tbl_authors` AS t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
519
                            ON (t{$field_id}_{$this->_key}.author_id = t{$field_id}_{$this->_key}_authors.id)
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

519
                            ON (t{$field_id}_{$this->_key}.author_id = t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.id)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
520
                    ";
521
                    $where .= "
522
                        AND (
523
                            t{$field_id}_{$this->_key}_authors.username = '{$value}'
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

523
                            t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.username = '{$value}'

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
524
                            OR CONCAT_WS(' ',
525
                                t{$field_id}_{$this->_key}_authors.first_name,
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

525
                                t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.first_name,

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
526
                                t{$field_id}_{$this->_key}_authors.last_name
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

526
                                t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.last_name

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
527
                            ) = '{$value}'
528
                        )
529
                    ";
530
                }
531
            }
532
        } else {
533
            if (!is_array($data)) {
534
                $data = array($data);
535
            }
536
537
            foreach ($data as &$value) {
538
                $value = $this->cleanValue($value);
539
            }
540
541
            $this->_key++;
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

541
            /** @scrutinizer ignore-deprecated */ $this->_key++;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
542
            $data = implode("', '", $data);
543
            $joins .= "
544
                LEFT JOIN
545
                    `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

545
                    `tbl_entries_data_{$field_id}` AS t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
546
                    ON (e.id = t{$field_id}_{$this->_key}.entry_id)
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

546
                    ON (e.id = t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.entry_id)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
547
                JOIN
548
                    `tbl_authors` AS t{$field_id}_{$this->_key}_authors
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

548
                    `tbl_authors` AS t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
549
                    ON (t{$field_id}_{$this->_key}.author_id = t{$field_id}_{$this->_key}_authors.id)
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

549
                    ON (t{$field_id}_{$this->_key}.author_id = t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.id)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
550
            ";
551
            $where .= "
552
                AND (
553
                    t{$field_id}_{$this->_key}.author_id IN ('{$data}')
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

553
                    t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}.author_id IN ('{$data}')

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
554
                    OR
555
                    t{$field_id}_{$this->_key}_authors.username IN ('{$data}')
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

555
                    t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.username IN ('{$data}')

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
556
                    OR CONCAT_WS(' ',
557
                        t{$field_id}_{$this->_key}_authors.first_name,
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

557
                        t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.first_name,

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
558
                        t{$field_id}_{$this->_key}_authors.last_name
0 ignored issues
show
Deprecated Code introduced by
The property Field::$_key has been deprecated: @since Symphony 3.0.0 ( Ignorable by Annotation )

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

558
                        t{$field_id}_{/** @scrutinizer ignore-deprecated */ $this->_key}_authors.last_name

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
559
                    ) IN ('{$data}')
560
                )
561
            ";
562
        }
563
564
        return true;
565
    }
566
567
    /*-------------------------------------------------------------------------
568
        Sorting:
569
    -------------------------------------------------------------------------*/
570
571
    /**
572
     * @deprecated @since Symphony 3.0.0
573
     * @see Field::buildSortingSQL()
574
     */
575
    public function buildSortingSQL(&$joins, &$where, &$sort, $order = 'ASC')
576
    {
577
        if (Symphony::Log()) {
578
            Symphony::Log()->pushDeprecateWarningToLog(
579
                get_called_class() . '::buildSortingSQL()',
580
                'EntryQueryFieldAdapter::sort()'
581
            );
582
        }
583
        if ($this->isRandomOrder($order)) {
0 ignored issues
show
Deprecated Code introduced by
The function Field::isRandomOrder() has been deprecated: @since Symphony 3.0.0 Use EntryQueryFieldAdapter::isRandomOrder() instead ( Ignorable by Annotation )

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

583
        if (/** @scrutinizer ignore-deprecated */ $this->isRandomOrder($order)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
584
            $sort = 'ORDER BY RAND()';
585
        } else {
586
            $joins .= "
587
                LEFT OUTER JOIN `tbl_entries_data_".$this->get('id')."` AS `ed` ON (`e`.`id` = `ed`.`entry_id`)
0 ignored issues
show
Bug introduced by
Are you sure $this->get('id') of type null|array|mixed can be used in concatenation? ( Ignorable by Annotation )

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

587
                LEFT OUTER JOIN `tbl_entries_data_"./** @scrutinizer ignore-type */ $this->get('id')."` AS `ed` ON (`e`.`id` = `ed`.`entry_id`)
Loading history...
588
                LEFT OUTER JOIN `tbl_authors` AS `a` ON (ed.author_id = a.id)
589
            ";
590
            $sort = sprintf('ORDER BY `a`.`first_name` %1$s, `a`.`last_name` %1$s', $order);
591
        }
592
    }
593
594
    /**
595
     * @deprecated @since Symphony 3.0.0
596
     * @see Field::buildSortingSelectSQL()
597
     */
598
    public function buildSortingSelectSQL($sort, $order = 'ASC')
599
    {
600
        if (Symphony::Log()) {
601
            Symphony::Log()->pushDeprecateWarningToLog(
602
                get_called_class() . '::buildSortingSelectSQL()',
603
                'EntryQueryFieldAdapter::sort()'
604
            );
605
        }
606
        if ($this->isRandomOrder($order)) {
0 ignored issues
show
Deprecated Code introduced by
The function Field::isRandomOrder() has been deprecated: @since Symphony 3.0.0 Use EntryQueryFieldAdapter::isRandomOrder() instead ( Ignorable by Annotation )

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

606
        if (/** @scrutinizer ignore-deprecated */ $this->isRandomOrder($order)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
607
            return null;
608
        }
609
        return '`a`.`first_name`, `a`.`last_name`';
610
    }
611
612
    /*-------------------------------------------------------------------------
613
        Events:
614
    -------------------------------------------------------------------------*/
615
616
    public function getExampleFormMarkup()
617
    {
618
        $authors = (new AuthorManager)->select()->execute()->rows();
619
        $options = array();
620
621
        foreach ($authors as $a) {
622
            $options[] = array($a->get('id'), null, $a->getFullName());
623
        }
624
625
        $fieldname = 'fields['.$this->get('element_name').']';
0 ignored issues
show
Bug introduced by
Are you sure $this->get('element_name') of type null|array|mixed can be used in concatenation? ( Ignorable by Annotation )

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

625
        $fieldname = 'fields['./** @scrutinizer ignore-type */ $this->get('element_name').']';
Loading history...
626
627
        if ($this->get('allow_multiple_selection') === 'yes') {
628
            $fieldname .= '[]';
629
        }
630
631
        $attr = array();
632
633
        if ($this->get('allow_multiple_selection') === 'yes') {
634
            $attr['multiple'] = 'multiple';
635
        }
636
637
        $label = Widget::Label($this->get('label'));
0 ignored issues
show
Bug introduced by
It seems like $this->get('label') can also be of type array; however, parameter $name of Widget::Label() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

637
        $label = Widget::Label(/** @scrutinizer ignore-type */ $this->get('label'));
Loading history...
638
        $label->appendChild(Widget::Select($fieldname, $options, $attr));
639
640
        return $label;
641
    }
642
643
    /*-------------------------------------------------------------------------
644
        Grouping:
645
    -------------------------------------------------------------------------*/
646
647
    public function groupRecords($records)
648
    {
649
        if (!is_array($records) || empty($records)) {
650
            return;
651
        }
652
653
        $groups = array($this->get('element_name') => array());
654
655
        foreach ($records as $r) {
656
            $data = $r->getData($this->get('id'));
657
            $author_id = !isset($data['author_id']) ? 0 : $data['author_id'];
658
659
            if (!isset($groups[$this->get('element_name')][$author_id])) {
660
                $author = AuthorManager::fetchByID($author_id);
661
                // If there is an author, use those values, otherwise just blank it.
662
                if ($author instanceof Author) {
663
                    $username = $author->get('username');
664
                    $full_name = $author->getFullName();
665
                } else {
666
                    $username = '';
667
                    $full_name = '';
668
                }
669
670
                $groups[$this->get('element_name')][$author_id] = array(
671
                    'attr' => array('author-id' => $author_id, 'username' => $username, 'full-name' => $full_name),
672
                    'records' => array(),
673
                    'groups' => array()
674
                );
675
            }
676
677
            $groups[$this->get('element_name')][$author_id]['records'][] = $r;
678
        }
679
680
        return $groups;
681
    }
682
}
683