Completed
Push — master ( 3f7cb6...83cdf5 )
by Vitaly
03:26
created

MaterialField::idsByMaterialId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 11
rs 9.4286
cc 2
eloc 6
nc 2
nop 3
1
<?php
2
namespace samsoncms\api;
3
4
use samsonframework\orm\QueryInterface;
5
6
/**
7
 * SamsonCMS additional field value table entity class
8
 * @package samson\cms
9
 */
10
class MaterialField extends \samson\activerecord\materialfield
11
{
12
    /** @var integer Primary key */
13
    public $FieldID;
14
15
    /** @var bool Internal existence flag */
16
    public $Active;
17
18
    /** @var integer Material identifier */
19
    public $MaterialID;
20
21
    /** @var string Additional field value */
22
    public $Value;
23
24
    /** @var string Additional field value */
25
    public $numeric_value;
26
27
    /** @var string Additional field value */
28
    public $key_value;
29
30
    /** @var string Additional field locale */
31
    public $locale;
32
33
34
35
    /**
36
     * Find additional field value records by its material identifiers.
37
     *
38
     * @param QueryInterface $query Query object instance
39
     * @param string $materialID Material identifier
40
     * @param self[]|null $return Variable to return found database record
41
     * @param string $locale Locale identifier
42
     * @return bool|self[]  Field instance or null if 3rd parameter not passed
43
     */
44 View Code Duplication
    public static function byMaterialID(
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...
45
        QueryInterface $query,
46
        $materialID,
47
        &$return = null,
48
        $locale = DEFAULT_LOCALE
49
    ) {
50
        $return = $query->entity(get_called_class())
51
            ->where('MaterialID', $materialID)
52
            ->where('Active', 1)
53
            ->where('locale', $locale)
54
            ->exec();
55
56
        // If only one argument is passed - return null, otherwise bool
57
        return func_num_args() > 1 ? sizeof($return) : $return;
58
    }
59
60
    /**
61
     * Find additional field value database record by its material and field identifiers.
62
     * This is generic method that should be used in nested classes to find its
63
     * records by some its primary key value.
64
     *
65
     * @param QueryInterface $query Query object instance
66
     * @param string $materialID Material identifier
67
     * @param string $fieldID Additional field identifier
68
     * @param self[]|null $return Variable to return found database record
69
     * @param string $locale Locale identifier
70
     * @return bool|null|self[]  Field instance or null if 3rd parameter not passed
71
     */
72 View Code Duplication
    public static function byFieldIDAndMaterialID(
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...
73
        QueryInterface $query,
74
        $materialID,
75
        $fieldID,
76
        &$return = null,
77
        $locale = DEFAULT_LOCALE
78
    ) {
79
        $return = $query->entity(get_called_class())
80
            ->where('MaterialID', $materialID)
81
            ->where('FieldID', $fieldID)
82
            ->where('locale', $locale)
83
            ->where('Active', 1)
84
            ->exec();
85
86
        // If only one argument is passed - return null, otherwise bool
87
        return func_num_args() > 1 ? sizeof($return): $return;
88
    }
89
}
90