Passed
Push — master ( 873a62...e4a92d )
by Aimeos
04:13
created

Base   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 37
dl 0
loc 94
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 1
A filter() 0 16 2
A prefix() 0 3 1
A getSaveAttributes() 0 27 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2024
6
 * @package MShop
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\MShop\Common\Manager\Property;
12
13
14
/**
15
 * Abstract property manager implementation.
16
 *
17
 * @package MShop
18
 * @subpackage Common
19
 */
20
abstract class Base
21
	extends \Aimeos\MShop\Common\Manager\Base
22
	implements \Aimeos\MShop\Common\Manager\Property\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
23
{
24
	/**
25
	 * Creates a new empty item instance
26
	 *
27
	 * @param array $values Values the item should be initialized with
28
	 * @return \Aimeos\MShop\Common\Item\Property\Iface New property item object
29
	 */
30
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
31
	{
32
		$prefix = $this->prefix();
33
		$locale = $this->context()->locale();
34
35
		$values['.languageid'] = $locale->getLanguageId();
36
		$values[$prefix . 'siteid'] = $values[$prefix . 'siteid'] ?? $locale->getSiteId();
37
38
		return new \Aimeos\MShop\Common\Item\Property\Standard( $prefix, $values );
39
	}
40
41
42
	/**
43
	 * Creates a filter object.
44
	 *
45
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
46
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
47
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
48
	 */
49
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
50
	{
51
		$filter = parent::filter();
52
53
		if( $default !== false )
54
		{
55
			$prefix = $this->prefix();
56
			$langid = $this->context()->locale()->getLanguageId();
57
58
			$filter->add( $filter->or( [
59
				$filter->compare( '==', $prefix . 'languageid', null ),
60
				$filter->compare( '==', $prefix . 'languageid', $langid ),
61
			] ) );
62
		}
63
64
		return $filter;
65
	}
66
67
68
	/**
69
	 * Returns the attributes that can be used for saving.
70
	 *
71
	 * @param bool $withsub Return also attributes of sub-managers if true
72
	 * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items
73
	 */
74
	public function getSaveAttributes( bool $withsub = true ) : array
75
	{
76
		$prefix = $this->prefix();
77
78
		return $this->createAttributes( [
79
			$prefix . 'parentid' => [
80
				'internalcode' => 'parentid',
81
				'label' => 'Property parent ID',
82
				'type' => 'int',
83
				'public' => false,
84
			],
85
			$prefix . 'key' => [
86
				'internalcode' => 'key',
87
				'label' => 'Property key',
88
				'public' => false,
89
			],
90
			$prefix . 'type' => [
91
				'internalcode' => 'type',
92
				'label' => 'Property type',
93
			],
94
			$prefix . 'value' => [
95
				'internalcode' => 'value',
96
				'label' => 'Property value',
97
			],
98
			$prefix . 'languageid' => [
99
				'internalcode' => 'langid',
100
				'label' => 'Property language ID',
101
			],
102
		] );
103
	}
104
105
106
	/**
107
	 * Returns the domain prefix.
108
	 *
109
	 * @return string Domain prefix with sub-domains separated by "."
110
	 */
111
	protected function prefix() : string
112
	{
113
		return $this->getDomain() . '.property.';
114
	}
115
}
116