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.

Issues (3647)

symphony/lib/toolkit/class.sectionmanager.php (55 issues)

1
<?php
2
3
/**
4
 * @package toolkit
5
 */
6
/**
7
 * The `SectionManager` is responsible for managing all Sections in a Symphony
8
 * installation by exposing basic CRUD operations. Sections are stored in the
9
 * database in `tbl_sections`.
10
 */
11
12
class SectionManager
13
{
14
    /**
15
     * An array of all the objects that the Manager is responsible for.
16
     *
17
     * @var array
18
     *   Defaults to an empty array.
19
     */
20
    protected static $_pool = array();
21
22
    /**
23
     * Takes an associative array of Section settings and creates a new
24
     * entry in the `tbl_sections` table, returning the ID of the Section.
25
     * The ID of the section is generated using auto_increment and returned
26
     * as the Section ID.
27
     *
28
     * @param array $settings
29
     *    An associative of settings for a section with the key being
30
     *    a column name from `tbl_sections`
31
     * @throws DatabaseException
32
     * @return integer
33
     *    The newly created Section's ID
34
     */
35
    public static function add(array $settings)
36
    {
37
        $defaults = array();
38
        $defaults['creation_date'] = $defaults['modification_date'] = DateTimeObj::get('Y-m-d H:i:s');
39
        $defaults['creation_date_gmt'] = $defaults['modification_date_gmt'] = DateTimeObj::getGMT('Y-m-d H:i:s');
40
        $defaults['author_id'] = 1;
41
        $defaults['modification_author_id'] = 1;
42
        $settings = array_replace($defaults, $settings);
43
        if (!Symphony::Database()->insert($settings, 'tbl_sections')) {
44
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type integer.
Loading history...
45
        }
46
47
        return Symphony::Database()->getInsertID();
48
    }
49
50
    /**
51
     * Updates an existing Section given it's ID and an associative
52
     * array of settings. The array does not have to contain all the
53
     * settings for the Section as there is no deletion of settings
54
     * prior to updating the Section
55
     *
56
     * @param integer $section_id
57
     *    The ID of the Section to edit
58
     * @param array $settings
59
     *    An associative of settings for a section with the key being
60
     *    a column name from `tbl_sections`
61
     * @throws DatabaseException
62
     * @return boolean
63
     */
64
    public static function edit($section_id, array $settings)
65
    {
66
        $defaults = array();
67
        $defaults['modification_date'] = DateTimeObj::get('Y-m-d H:i:s');
68
        $defaults['modification_date_gmt'] = DateTimeObj::getGMT('Y-m-d H:i:s');
69
        $defaults['author_id'] = 1;
70
        $defaults['modification_author_id'] = 1;
71
        $settings = array_replace($defaults, $settings);
72
        if (!Symphony::Database()->update($settings, 'tbl_sections', sprintf(" `id` = %d", $section_id))) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal `id` = %d does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
73
            return false;
74
        }
75
76
        return true;
77
    }
78
79
    /**
80
     * Deletes a Section by Section ID, removing all entries, fields, the
81
     * Section and any Section Associations in that order
82
     *
83
     * @param integer $section_id
84
     *    The ID of the Section to delete
85
     * @throws DatabaseException
86
     * @throws Exception
87
     * @return boolean
88
     *    Returns true when completed
89
     */
90
    public static function delete($section_id)
91
    {
92
        $details = Symphony::Database()->fetchRow(0, sprintf("
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n SELECT `so...ections WHERE `id` = %d does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
93
            SELECT `sortorder` FROM tbl_sections WHERE `id` = %d",
94
            $section_id
95
        ));
96
97
        // Delete all the entries
98
        $entries = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_entries` WHERE `section_id` = '$section_id'");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $section_id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
99
        EntryManager::delete($entries);
100
101
        // Delete all the fields
102
        $fields = FieldManager::fetch(null, $section_id);
103
104
        if (is_array($fields) && !empty($fields)) {
105
            foreach ($fields as $field) {
106
                FieldManager::delete($field->get('id'));
107
            }
108
        }
109
110
        // Delete the section
111
        Symphony::Database()->delete('tbl_sections', sprintf("
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n `id` = %d does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
112
            `id` = %d", $section_id
113
        ));
114
115
        // Update the sort orders
116
        Symphony::Database()->query(sprintf("
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n UPDATE tbl... WHERE `sortorder` > %d does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
117
            UPDATE tbl_sections
118
            SET `sortorder` = (`sortorder` - 1)
119
            WHERE `sortorder` > %d",
120
            $details['sortorder']
121
        ));
122
123
        // Delete the section associations
124
        Symphony::Database()->delete('tbl_sections_association', sprintf("
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n `parent_section_id` = %d does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
125
            `parent_section_id` = %d", $section_id
126
        ));
127
128
        return true;
129
    }
130
131
    /**
132
     * Returns a Section object by ID, or returns an array of Sections
133
     * if the Section ID was omitted. If the Section ID is omitted, it is
134
     * possible to sort the Sections by providing a sort order and sort
135
     * field. By default, Sections will be order in ascending order by
136
     * their name
137
     *
138
     * @param integer|array $section_id
139
     *    The ID of the section to return, or an array of ID's. Defaults to null
140
     * @param string $order
141
     *    If `$section_id` is omitted, this is the sortorder of the returned
142
     *    objects. Defaults to ASC, other options id DESC
143
     * @param string $sortfield
144
     *    The name of the column in the `tbl_sections` table to sort
145
     *    on. Defaults to name
146
     * @throws DatabaseException
147
     * @return Section|array
148
     *    A Section object or an array of Section objects
149
     */
150
    public static function fetch($section_id = null, $order = 'ASC', $sortfield = 'name')
0 ignored issues
show
Incorrect spacing between argument "$section_id" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$section_id"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$order" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$order"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$sortfield" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$sortfield"; expected 0 but found 1
Loading history...
151
    {
152
        $returnSingle = false;
153
        $section_ids = array();
154
155
        if (!is_null($section_id)) {
156
            if (!is_array($section_id)) {
157
                $returnSingle = true;
158
                $section_ids = array($section_id);
159
            } else {
160
                $section_ids = $section_id;
161
            }
162
        }
163
164
        if ($returnSingle && isset(self::$_pool[$section_id])) {
165
            return self::$_pool[$section_id];
166
        }
167
168
        // Ensure they are always an ID
169
        $section_ids = array_map('intval', $section_ids);
170
        $sql = sprintf(
171
            "SELECT `s`.*
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SELECT `s`.*\n ... %s\n %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
172
            FROM `tbl_sections` AS `s`
173
            %s
174
            %s",
175
            !empty($section_id) ? " WHERE `s`.`id` IN (" . implode(',', $section_ids) . ") " : "",
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal WHERE `s`.`id` IN ( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
176
            empty($section_id) ? " ORDER BY `s`.`$sortfield` $order" : ""
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $sortfield instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $order instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
177
        );
178
179
        if (!$sections = Symphony::Database()->fetch($sql)) {
180
            return ($returnSingle ? false : array());
0 ignored issues
show
Inline shorthand IF statement requires brackets around comparison
Loading history...
Bug Best Practice introduced by
The expression return $returnSingle ? false : array() could also return false which is incompatible with the documented return type Section|array. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
181
        }
182
183
        $ret = array();
184
185
        foreach ($sections as $s) {
186
            $obj = self::create();
187
188
            foreach ($s as $name => $value) {
189
                $obj->set($name, $value);
190
            }
191
192
            $obj->set('creation_date', DateTimeObj::get('c', $obj->get('creation_date')));
0 ignored issues
show
It seems like DateTimeObj::get('c', $obj->get('creation_date')) can also be of type false; however, parameter $value of Section::set() 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

192
            $obj->set('creation_date', /** @scrutinizer ignore-type */ DateTimeObj::get('c', $obj->get('creation_date')));
Loading history...
It seems like $obj->get('creation_date') can also be of type array; however, parameter $timestamp of DateTimeObj::get() does only seem to accept null|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

192
            $obj->set('creation_date', DateTimeObj::get('c', /** @scrutinizer ignore-type */ $obj->get('creation_date')));
Loading history...
193
194
            $modDate = $obj->get('modification_date');
195
            if (!empty($modDate)) {
196
                $obj->set('modification_date', DateTimeObj::get('c', $obj->get('modification_date')));
197
            } else {
198
                $obj->set('modification_date', $obj->get('creation_date'));
0 ignored issues
show
It seems like $obj->get('creation_date') can also be of type array; however, parameter $value of Section::set() 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

198
                $obj->set('modification_date', /** @scrutinizer ignore-type */ $obj->get('creation_date'));
Loading history...
199
            }
200
201
            self::$_pool[$obj->get('id')] = $obj;
202
203
            $ret[] = $obj;
204
        }
205
206
        return (count($ret) == 1 && $returnSingle ? $ret[0] : $ret);
0 ignored issues
show
Inline shorthand IF statement requires brackets around comparison
Loading history...
207
    }
208
209
    /**
210
     * Return a Section ID by the handle
211
     *
212
     * @param string $handle
213
     *  The handle of the section
214
     * @return integer
215
     *  The Section ID
216
     */
217
    public static function fetchIDFromHandle($handle)
218
    {
219
        $handle = Symphony::Database()->cleanValue($handle);
220
        return Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_sections` WHERE `handle` = '$handle' LIMIT 1");
0 ignored issues
show
Bug Best Practice introduced by
The expression return Symphony::Databas...''.$handle.'' LIMIT 1') also could return the type string which is incompatible with the documented return type integer.
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $handle instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
221
    }
222
223
    /**
224
     * Work out the next available sort order for a new section
225
     *
226
     * @return integer
227
     *  Returns the next sort order
228
     */
229
    public static function fetchNextSortOrder()
230
    {
231
        $next = Symphony::Database()->fetchVar(
232
            "next",
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal next does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
233
            0,
234
            "SELECT
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SELECT\n ... p\n LIMIT 1 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
235
                MAX(p.sortorder) + 1 AS `next`
236
            FROM
237
                `tbl_sections` AS p
238
            LIMIT 1"
239
        );
240
241
        return ($next ? (int)$next : 1);
0 ignored issues
show
Inline shorthand IF statement requires brackets around comparison
Loading history...
242
    }
243
244
    /**
245
     * Returns a new Section object, using the SectionManager
246
     * as the Section's $parent.
247
     *
248
     * @return Section
249
     */
250
    public static function create()
251
    {
252
        $obj = new Section;
253
        return $obj;
254
    }
255
256
    /**
257
     * Create an association between a section and a field.
258
     *
259
     * @since Symphony 2.3
260
     * @param integer $parent_section_id
261
     *    The linked section id.
262
     * @param integer $child_field_id
263
     *    The field ID of the field that is creating the association
264
     * @param integer $parent_field_id (optional)
265
     *    The field ID of the linked field in the linked section
266
     * @param boolean $show_association (optional)
267
     *    Whether of not the link should be shown on the entries table of the
268
     *    linked section. This defaults to true.
269
     * @throws DatabaseException
270
     * @throws Exception
271
     * @return boolean
272
     *    true if the association was successfully made, false otherwise.
273
     */
274
    public static function createSectionAssociation($parent_section_id = null, $child_field_id = null, $parent_field_id = null, $show_association = true, $interface = null, $editor = null)
0 ignored issues
show
Incorrect spacing between argument "$parent_section_id" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$parent_section_id"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$child_field_id" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$child_field_id"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$parent_field_id" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$parent_field_id"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$show_association" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$show_association"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$interface" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$interface"; expected 0 but found 1
Loading history...
Incorrect spacing between argument "$editor" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$editor"; expected 0 but found 1
Loading history...
275
    {
276
        if (is_null($parent_section_id) && (is_null($parent_field_id) || !$parent_field_id)) {
277
            return false;
278
        }
279
280
        if (is_null($parent_section_id)) {
281
            $parent_field = FieldManager::fetch($parent_field_id);
282
            $parent_section_id = $parent_field->get('parent_section');
283
        }
284
285
        $child_field = FieldManager::fetch($child_field_id);
286
        $child_section_id = $child_field->get('parent_section');
287
288
        $fields = array(
289
            'parent_section_id' => $parent_section_id,
290
            'parent_section_field_id' => $parent_field_id,
291
            'child_section_id' => $child_section_id,
292
            'child_section_field_id' => $child_field_id,
293
            'hide_association' => ($show_association ? 'no' : 'yes'),
0 ignored issues
show
Inline shorthand IF statement requires brackets around comparison
Loading history...
294
            'interface' => $interface,
295
            'editor' => $editor
296
        );
297
298
        return Symphony::Database()->insert($fields, 'tbl_sections_association');
299
    }
300
301
    /**
302
     * Permanently remove a section association for this field in the database.
303
     *
304
     * @since Symphony 2.3
305
     * @param integer $field_id
306
     *    the field ID of the linked section's linked field.
307
     * @throws DatabaseException
308
     * @return boolean
309
     */
310
    public static function removeSectionAssociation($field_id)
311
    {
312
        return Symphony::Database()->delete('tbl_sections_association', sprintf(
313
            '`child_section_field_id` = %1$d OR `parent_section_field_id` = %1$d',
314
            $field_id
315
        ));
316
    }
317
318
    /**
319
     * Returns the association settings for the given field id. This is to be used
320
     * when configuring the field so we can correctly show the association setting
321
     * the UI.
322
     *
323
     * @since Symphony 2.6.0
324
     * @param integer $field_id
325
     * @return string
326
     */
327
    public static function getSectionAssociationSetting($field_id)
328
    {
329
        // We must inverse the setting. The database stores 'hide', whereas the UI
330
        // refers to 'show'. Hence if the database says 'yes', it really means, hide
331
        // the association. In the UI, this needs to be flipped to 'no' so the checkbox
332
        // won't be checked.
333
        return Symphony::Database()->fetchVar('show_association', 0, sprintf('
334
            SELECT
335
            CASE hide_association WHEN "no" THEN "yes" ELSE "no" END as show_association
336
            FROM `tbl_sections_association`
337
            WHERE `child_section_field_id` = %d
338
        ', $field_id));
339
    }
340
341
    /**
342
     * Returns any section associations this section has with other sections
343
     * linked using fields. Has an optional parameter, `$respect_visibility` that
344
     * will only return associations that are deemed visible by a field that
345
     * created the association. eg. An articles section may link to the authors
346
     * section, but the field that links these sections has hidden this association
347
     * so an Articles column will not appear on the Author's Publish Index
348
     *
349
     * @deprecated This function will be removed in Symphony 3.0. Use `fetchChildAssociations` instead.
350
     * @since Symphony 2.3
351
     * @param integer $section_id
352
     *  The ID of the section
353
     * @param boolean $respect_visibility
354
     *  Whether to return all the section associations regardless of if they
355
     *  are deemed visible or not. Defaults to false, which will return all
356
     *  associations.
357
     * @return array
358
     */
359
    public static function fetchAssociatedSections($section_id, $respect_visibility = false)
0 ignored issues
show
Incorrect spacing between argument "$respect_visibility" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$respect_visibility"; expected 0 but found 1
Loading history...
360
    {
361
        if (Symphony::Log()) {
362
            Symphony::Log()->pushDeprecateWarningToLog('SectionManager::fetchAssociatedSections()', 'SectionManager::fetchChildAssociations()');
363
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
364
        self::fetchChildAssociations($section_id, $respect_visibility);
365
    }
366
367
    /**
368
     * Returns any section associations this section has with other sections
369
     * linked using fields, and where this section is the parent in the association.
370
     * Has an optional parameter, `$respect_visibility` that
371
     * will only return associations that are deemed visible by a field that
372
     * created the association. eg. An articles section may link to the authors
373
     * section, but the field that links these sections has hidden this association
374
     * so an Articles column will not appear on the Author's Publish Index
375
     *
376
     * @since Symphony 2.3.3
377
     * @param integer $section_id
378
     *    The ID of the section
379
     * @param boolean $respect_visibility
380
     *    Whether to return all the section associations regardless of if they
381
     *    are deemed visible or not. Defaults to false, which will return all
382
     *    associations.
383
     * @throws DatabaseException
384
     * @return array
385
     */
386
    public static function fetchChildAssociations($section_id, $respect_visibility = false)
0 ignored issues
show
Incorrect spacing between argument "$respect_visibility" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$respect_visibility"; expected 0 but found 1
Loading history...
387
    {
388
        return Symphony::Database()->fetch(sprintf("
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n SELECT *\n... BY `s`.`sortorder` ASC does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
389
            SELECT *
390
            FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`
391
            WHERE `sa`.`parent_section_id` = %d
392
            AND `s`.`id` = `sa`.`child_section_id`
393
            %s
394
            ORDER BY `s`.`sortorder` ASC",
395
            $section_id,
396
            ($respect_visibility) ? "AND `sa`.`hide_association` = 'no'" : ""
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
397
        ));
398
    }
399
400
    /**
401
     * Returns any section associations this section has with other sections
402
     * linked using fields, and where this section is the child in the association.
403
     * Has an optional parameter, `$respect_visibility` that
404
     * will only return associations that are deemed visible by a field that
405
     * created the association. eg. An articles section may link to the authors
406
     * section, but the field that links these sections has hidden this association
407
     * so an Articles column will not appear on the Author's Publish Index
408
     *
409
     * @since Symphony 2.3.3
410
     * @param integer $section_id
411
     *    The ID of the section
412
     * @param boolean $respect_visibility
413
     *    Whether to return all the section associations regardless of if they
414
     *    are deemed visible or not. Defaults to false, which will return all
415
     *    associations.
416
     * @throws DatabaseException
417
     * @return array
418
     */
419
    public static function fetchParentAssociations($section_id, $respect_visibility = false)
0 ignored issues
show
Incorrect spacing between argument "$respect_visibility" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$respect_visibility"; expected 0 but found 1
Loading history...
420
    {
421
        return Symphony::Database()->fetch(sprintf(
422
            "SELECT *
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SELECT *\n FR... BY `s`.`sortorder` ASC does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
423
            FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`
424
            WHERE `sa`.`child_section_id` = %d
425
            AND `s`.`id` = `sa`.`parent_section_id`
426
            %s
427
            ORDER BY `s`.`sortorder` ASC",
428
            $section_id,
429
            ($respect_visibility) ? "AND `sa`.`hide_association` = 'no'" : ""
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
430
        ));
431
    }
432
}
433