Completed
Push — master ( 8ea274...4857d6 )
by Vitaly
03:56
created

Material::idsByFieldValue()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 31
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 31
rs 8.439
cc 5
eloc 14
nc 12
nop 5
1
<?php
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>
4
 * on 07.08.14 at 17:11
5
 */
6
namespace samsoncms\api;
7
8
use \samsonframework\orm\Condition;
9
use \samsonframework\orm\QueryInterface;
10
11
/**
12
 * SamsonCMS Material database record object.
13
 * This class extends default ActiveRecord material table record functionality.
14
 * @package samson\cms
15
 * @author Vitaly Egorov <[email protected]>
16
 */
17
class Material extends \samson\activerecord\material
18
{
19
    /** Override table attributes for late static binding */
20
    public static $_attributes = array();
21
    public static $_sql_select = array();
22
    public static $_sql_from = array();
23
    public static $_own_group = array();
24
    public static $_map = array();
25
26
    /**
27
     * Get identifiers collection by field identifier and its value.
28
     * Method is optimized for performance.
29
     *
30
     * @param QueryInterface $query Database query instance
31
     * @param string $fieldID Additional field identifier
32
     * @param string $fieldValue Additional field value for searching
33
     * @param array|null $return Variable where request result would be returned
34
     * @param array $materialIDs Collection of material identifiers for filtering query
35
     * @return bool|array True if material entities has been found and $return is passed
36
     *                      or identifiers collection if only two parameters is passed.
37
     */
38
    public static function idsByFieldValue(QueryInterface $query, $fieldID, $fieldValue, &$return = array(), $materialIDs = null)
39
    {
40
        /** @var array $fields Collection for storing fields data */
41
        static $fields;
42
43
        /** @var Field $fieldRecord Cache field object */
44
        $fieldRecord = isset($fields[$fieldID]) ? $fields[$fieldID] : Field::byID($query, $fieldID);
45
46
        // We need to have field record
47
        if (isset($fieldRecord)) {
48
            $materials = array();
49
50
            // Get material identifiers by field
51
            $query->entity('samson\activerecord\materialfield')
52
                ->where('MaterialID', $materials)
0 ignored issues
show
Documentation introduced by
$materials is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
                ->where('Active', 1)
54
                ->where('FieldID', $fieldID)
55
                ->where($fieldRecord->valueFieldName(), $fieldValue);
56
57
            // Add material identifier filter if passed
58
            if (isset($materialIDs)) {
59
                $query->where('MaterialID', $materialIDs);
0 ignored issues
show
Documentation introduced by
$materialIDs is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
            }
61
62
            // Perform database query and get only material identifiers collection
63
            $return = $query->fields($materials);
0 ignored issues
show
Documentation introduced by
$materials is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
        }
65
66
        // If only one argument is passed - return null, otherwise bool
67
        return func_num_args() > 3 ? $return == null : $return;
68
    }
69
70
    /**
71
     * Get current entity identifiers collection by navigation identifier.
72
     *
73
     * @param QueryInterface $query Database query
74
     * @param string $navigationID Navigation identifier
75
     * @param array $return Variable where request result would be returned
76
     * @param array $materialIDs Collection of material identifiers for filtering query
77
     * @return bool|array True if material entities has been found and $return is passed
78
     *                      or collection of identifiers if only two parameters is passed.
79
     */
80
    public static function idsByNavigationID(QueryInterface $query, $navigationID, &$return = array(), $materialIDs = null)
81
    {
82
        // Prepare query
83
         $query->entity('\samson\activerecord\structurematerial')
84
            ->where('StructureID', $navigationID)
85
            ->where('Active', 1);
86
87
        // Add material identifier filter if passed
88
        if (isset($materialIDs)) {
89
            $query->where('MaterialID', $materialIDs);
0 ignored issues
show
Documentation introduced by
$materialIDs is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
        }
91
92
        // Perform database query and get only material identifiers collection
93
        $return = $query->fields('MaterialID');
94
95
        // If only one argument is passed - return null, otherwise bool
96
        return func_num_args() > 2 ? $return == null : $return;
97
    }
98
99
    /**
100
     * Get self[] by field identifier and its value.
101
     * Method is optimized for performance.
102
     *
103
     * @param QueryInterface $query Database query instance
104
     * @param string $fieldID Additional field identifier
105
     * @param string $fieldValue Additional field value for searching
106
     * @param self[]|array|null $return Variable where request result would be returned
107
     * @return bool|self[] True if material entities has been found and $return is passed
108
     *                      or self[] if only two parameters is passed.
109
     */
110 View Code Duplication
    public static function byFieldValue(QueryInterface $query, $fieldID, $fieldValue, &$return = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112
        /** @var array $materialIds Collection of entity identifiers filtered by additional field */
113
        $materialIds = null;
114
        if (static::idsByFieldValue($query, $fieldID, $fieldValue, $materialIds)) {
115
            // Get material instances
116
            $return = $query->entity(get_called_class())
117
                ->where('MaterialID', $materialIds)
0 ignored issues
show
Bug introduced by
It seems like $materialIds can also be of type array; however, samsonframework\orm\QueryInterface::where() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
118
                ->exec();
119
        }
120
121
        // If only one argument is passed - return null, otherwise bool
122
        return func_num_args() > 3 ? $return == null : $return;
123
    }
124
125
    /**
126
     * Get current entity instances collection by navigation identifier.
127
     *
128
     * @param QueryInterface $query Database query
129
     * @param string $navigationID Navigation identifier
130
     * @param self[]|array|null $return Variable where request result would be returned
131
     * @return bool|self[] True if material entities has been found and $return is passed
132
     *                      or self[] if only two parameters is passed.
133
     */
134 View Code Duplication
    public static function byNavigationID(QueryInterface $query, $navigationID, &$return = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
    {
136
        /** @var array $materialIds Collection of entity identifiers filtered by additional field */
137
        $materialIds = null;
138
        if (static::idsByNavigationID($query, $navigationID, $materialIds)) {
139
            $return = $query->entity(get_called_class())
140
                ->where('MaterialID', $materialIds)
0 ignored issues
show
Documentation introduced by
$materialIds is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
                ->where('Active', 1)
142
                ->where('Published', 1)
143
                ->exec();
144
        }
145
146
        // If only one argument is passed - return null, otherwise bool
147
        return func_num_args() > 2 ? $return == null : $return;
148
    }
149
150 View Code Duplication
    public static function byNavigationIdAndFieldValue(QueryInterface $query, $navigationID, $fieldID, $fieldValue, &$return = array())
0 ignored issues
show
Unused Code introduced by
The parameter $fieldID is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $fieldValue is not used and could be removed.

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

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
151
    {
152
        /** @var array $materialIds Collection of entity identifiers filtered by additional field */
153
        $materialIds = null;
154
        if (static::idsByNavigationID($query, $navigationID, $materialIds)) {
155
156
            $return = $query->entity(get_called_class())
157
                ->where('MaterialID', $materialIds)
0 ignored issues
show
Documentation introduced by
$materialIds is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
158
                ->exec();
159
        }
160
161
        // If only one argument is passed - return null, otherwise bool
162
        return func_num_args() > 3 ? $return == null : $return;
163
    }
164
165
    /**
166
     * Get material entities collection by URL(s).
167
     * @param QueryInterface $query Object for performing database queries
168
     * @param array|string $url Material URL or collection of material URLs
169
     * @param self[]|array|null $return Variable where request result would be returned
170
     * @return bool|self[] True if material entities has been found
171
     */
172 View Code Duplication
    public static function byUrl(QueryInterface $query, $url, & $return = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
173
    {
174
        // Get field record by identifier column
175
        $return = static::collectionByColumn($query, 'Url', $url);
0 ignored issues
show
Bug introduced by
It seems like $url defined by parameter $url on line 172 can also be of type array; however, samsonframework\orm\Record::collectionByColumn() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
176
177
        // If only one argument is passed - return null, otherwise bool
178
        return func_num_args() > 1 ? $return == null : $return;
179
    }
180
181
    /**
182
     * Set additional material field value by field identifier
183
     * @param string $fieldID Field identifier
184
     * @param string $value Value to be stored
185
     * @param string $locale Locale identifier
186
     */
187
    public function setFieldByID($fieldID, $value, $locale = DEFAULT_LOCALE)
188
    {
189
        // TODO: This should be removed
190
        /** @var QueryInterface $query This should be removed to use $this->database*/
191
        $query = dbQuery();
0 ignored issues
show
Bug introduced by
The call to dbQuery() misses a required argument $class_name.

This check looks for function calls that miss required arguments.

Loading history...
192
193
        /** @var Field $fieldRecord Try to find this additional field */
194
        $fieldRecord = null;
195
        if (Field::byID($query, $fieldID, $fieldRecord)) {
0 ignored issues
show
Documentation introduced by
$fieldRecord is of type object<samsoncms\api\Field>, but the function expects a null|object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
196
            /** @var MaterialField $materialFieldRecord Try to find additional field value */
197
            $materialFieldRecord = null;
198
            if (!MaterialField::byFieldIDAndMaterialID($query, $this->id, $fieldRecord->id, $materialFieldRecord)) {
199
                // Create new additional field value record if it does not exists
200
                $materialFieldRecord = new MaterialField();
201
                $materialFieldRecord->FieldID = $fieldRecord->id;
202
                $materialFieldRecord->MaterialID = $this->id;
203
                $materialFieldRecord->Active = 1;
204
                $materialFieldRecord->locale = $locale;
205
            }
206
207
            // Define which field should be filled
208
            switch ($fieldRecord->Type) {
209
                case 1:
210
                    $valueFieldName = 'numeric_value';
211
                    break;
212
                case 2:
213
                    $valueFieldName = 'key_value';
214
                    break;
215
                default:
216
                    $valueFieldName = 'Value';
217
            }
218
219
            // At this point we already have database record instance
220
            $fieldRecord->$valueFieldName = $value;
221
            $fieldRecord->save();
222
        }
223
    }
224
225
    /**
226
     * Get select additional field text value
227
     * TODO: Find where do we use it
228
     * @return string Select field text
229
     */
230
    public function selectText($fieldID)
231
    {
232
        /** @var \samson\activerecord\field $field */
233
        $field = null;
234
        if (dbQuery('field')->id($fieldID)->first($field)) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::id() has been deprecated with message: Use direct query with where('PRIMARY_FIELD',...)

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
235
            // If this entity has this field set
236
            if (isset($this[$field->Name]{0})) {
237
                $types = array();
238
                foreach (explode(',', $field->Value) as $typeValue) {
239
                    $typeValue = explode(':', $typeValue);
240
                    $types[$typeValue[0]] = $typeValue[1];
241
                }
242
                return $types[$this[$field->Name]];
243
            }
244
        }
245
246
        // Value not set
247
        return '';
248
    }
249
250
    /**
251
     * Get collection of images for material by gallery additional field selector. If none is passed
252
     * all images from gallery table would be returned for this material entity.
253
     *
254
     * @param string|null $fieldSelector Additional field selector value
255
     * @param string $selector Additional field field name to search for
256
     * @return \samson\activerecord\gallery[] Collection of images in this gallery additional field for material
257
     */
258
    public function &gallery($fieldSelector = null, $selector = 'FieldID')
259
    {
260
        /** @var \samson\activerecord\gallery[] $images Get material images for this gallery */
261
        $images = array();
262
263
        /* @var \samson\activerecord\field Get field object if we need to search it by other fields */
264
        $field = null;
0 ignored issues
show
Unused Code introduced by
$field is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
265
        if ($selector != 'FieldID') {
266
            $field = dbQuery('field')->cond($selector, $fieldSelector)->first();
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
267
            $fieldSelector = $field->id;
268
        }
269
270
        // Create query
271
        $query = dbQuery('materialfield');
272
273
        // Add field filter if present
274
        if (isset($fieldSelector)) {
275
            $query->cond("FieldID", $fieldSelector);
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
276
        }
277
278
        /** @var \samson\activerecord\materialfield $dbMaterialField Find material field gallery record */
279
        $dbMaterialField = null;
280
        if ($query->cond('MaterialID', $this->id)->first($dbMaterialField)) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
281
            // Get material images for this materialfield
282
            if (dbQuery('gallery')->cond('materialFieldId', $dbMaterialField->id)->exec($images)) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
283
284
            }
285
        }
286
287
        return $images;
288
    }
289
290
    /**
291
     * Create copy of current object
292
     * @param mixed $clone Material for cloning
293
     * @param array $excludedFields excluded from materialfield fields identifiers
294
     * @returns void
295
     */
296
    public function &copy(& $clone = null, $excludedFields = array())
297
    {
298
        // Create new instance by copying
299
        $clone = parent::copy($clone);
300
301
        /** @var \samson\activerecord\structurematerial[] $objects Create structure material relations */
302
        $objects = array();
303 View Code Duplication
        if (dbQuery('structurematerial')->cond('MaterialID', $this->MaterialID)->exec($objects)) {
0 ignored issues
show
Bug introduced by
The property MaterialID does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
304
            foreach ($objects as $cmsNavigation) {
305
                /** @var \samson\activerecord\Record $copy */
306
                $copy = $cmsNavigation->copy();
307
                $copy->MaterialID = $clone->id;
308
                $copy->save();
309
            }
310
        }
311
        /** @var \samson\activerecord\materialfield[] $objects Create material field relations */
312
        $objects = array();
313
        if (dbQuery('materialfield')->cond('MaterialID', $this->MaterialID)->exec($objects)) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
314
            foreach ($objects as $pMaterialField) {
315
                // Check if field is NOT excluded from copying
316
                if (!in_array($pMaterialField->FieldID, $excludedFields)) {
317
                    /** @var \samson\activerecord\dbRecord $copy Copy instance */
318
                    $copy = $pMaterialField->copy();
319
                    $copy->MaterialID = $clone->id;
0 ignored issues
show
Bug introduced by
The property MaterialID does not seem to exist in samson\activerecord\dbRecord.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
320
                    $copy->save();
321
                }
322
            }
323
        }
324
325
        /** @var \samson\activerecord\gallery[] $objects Create gallery field relations */
326
        $objects = array();
327 View Code Duplication
        if (dbQuery('gallery')->cond('MaterialID', $this->MaterialID)->exec($objects)) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
328
            foreach ($objects as $cmsGallery) {
329
                /** @var \samson\activerecord\Record $copy */
330
                $copy = $cmsGallery->copy();
331
                $copy->MaterialID = $clone->id;
332
                $copy->save();
333
            }
334
        }
335
336
        return $clone;
337
    }
338
339
    /**
340
     * Function to retrieve this material table by specified field
341
     * @param string $tableSelector Selector to identify table structure
342
     * @param string $selector Database field by which search is performed
343
     * @param array $tableColumns Columns names list
344
     * @param string $externalHandler External handler to perform some extra code
345
     * @param array $params External handler params
346
     * @return array Collection of collections of table cells, represented as materialfield objects
347
     */
348
    public function getTable($tableSelector, $selector = 'StructureID', &$tableColumns = null, $externalHandler = null, $params = array())
349
    {
350
        /** @var array $resultTable Collection of collections of field cells */
351
        $resultTable = array();
352
        /** @var array $dbTableFieldsIds Array of table structure column identifiers */
353
        $dbTableFieldsIds = array();
354
355
        // Get structure object if we need to search it by other fields
356
        if ($selector != 'StructureID') {
357
            $structure = dbQuery('structure')->cond($selector, $tableSelector)->first();
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
358
            $tableSelector = $structure->id;
359
        }
360
361
        /** If this table has columns */
362
        if (dbQuery('structurefield')
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
363
            ->cond("StructureID", $tableSelector)
364
            ->fields('FieldID', $dbTableFieldsIds)
0 ignored issues
show
Documentation introduced by
$dbTableFieldsIds is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
365
        ) {
366
            // Get localized and not localized fields
367
            $localizedFields = array();
368
            $unlocalizedFields = array();
369
            /** @var \samson\cms\CMSField $dbTableField Table column */
370
            foreach (dbQuery('field')->order_by('priority')->cond('FieldID', $dbTableFieldsIds)->exec() as $field) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
371
                /** Add table columns names */
372
                $tableColumns[] = $field->Name;
373
                if ($field->local == 1) {
374
                    $localizedFields[] = $field->id;
375
                } else {
376
                    $unlocalizedFields[] = $field->id;
377
                }
378
            }
379
380
            // Query to get table rows(table materials)
381
            $tableQuery = dbQuery('material')
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
382
                ->cond('parent_id', $this->MaterialID)
383
                ->cond('Active', '1')
384
                ->join('structurematerial')
385
                ->cond('structurematerial_StructureID', $tableSelector)
386
                ->order_by('priority');
387
388
            // Call user function if exists
389
            if (is_callable($externalHandler)) {
390
                // Give it query as parameter
391
                call_user_func_array($externalHandler, array_merge(array(&$tableQuery), $params));
392
            }
393
394
            // Get table row materials
395
            $tableMaterialIds = array();
396
            if ($tableQuery->fields('MaterialID', $tableMaterialIds)) {
397
                // Create field condition
398
                $localizationFieldCond = new Condition('or');
399
400
                // Create localized condition
401
                if (sizeof($localizedFields)) {
402
                    $localizedFieldCond = new Condition('and');
403
                    $localizedFieldCond->add('materialfield_FieldID', $localizedFields)
404
                        ->add('materialfield_locale', locale());
405
                    // Add this condition to condition group
406
                    $localizationFieldCond->add($localizedFieldCond);
0 ignored issues
show
Bug introduced by
The call to add() misses a required argument $value.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$localizedFieldCond is of type object<samsonframework\orm\Condition>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
407
                }
408
409
                // Create not localized condition
410
                if (sizeof($unlocalizedFields)) {
411
                    $localizationFieldCond->add('materialfield_FieldID', $unlocalizedFields);
412
                }
413
414
                // Create db query
415
                $materialFieldQuery = dbQuery('materialfield')
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
416
                    ->cond('MaterialID', $tableMaterialIds)
0 ignored issues
show
Documentation introduced by
$tableMaterialIds is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
417
                    ->cond($localizationFieldCond);
0 ignored issues
show
Documentation introduced by
$localizationFieldCond is of type object<samsonframework\orm\Condition>, but the function expects a string|object<samson\act...cord\ArgumentInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
418
419
                // Flip field identifiers as keys
420
                $tableColumnIds = array_flip($dbTableFieldsIds);
421
                $resultTable = array_flip($tableMaterialIds);
422
423
                /** @var \samson\activerecord\material $dbTableRow Material object (table row) */
424
                foreach ($materialFieldQuery->exec() as $mf) {
425
                    if (!is_array($resultTable[$mf['MaterialID']])) {
426
                        $resultTable[$mf['MaterialID']] = array();
427
                    }
428
429
                    $resultTable[$mf['MaterialID']][$tableColumnIds[$mf->FieldID]] =
430
                        !empty($mf->Value) ? $mf->Value : (!empty($mf->numeric_value) ? $mf->numeric_value : $mf->key_value);
431
                }
432
            }
433
        }
434
435
        return array_values($resultTable);
436
    }
437
}
438