1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
6
|
|
|
* @package MShop |
7
|
|
|
* @subpackage Common |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\MShop\Common\Manager\PropertyRef; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Common trait for managers retrieving/storing property items |
16
|
|
|
* |
17
|
|
|
* @package MShop |
18
|
|
|
* @subpackage Common |
19
|
|
|
*/ |
20
|
|
|
trait Traits |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Returns the property items for the given parent IDs |
24
|
|
|
* |
25
|
|
|
* @param array $parentIds List of parent IDs |
26
|
|
|
* @param string $domain Domain of the calling manager |
27
|
|
|
* @return array Associative list of parent IDs / property IDs as keys and items implementing |
28
|
|
|
* \Aimeos\MShop\Common\Item\Property\Iface as values |
29
|
|
|
*/ |
30
|
|
|
protected function getPropertyItems( array $parentIds, $domain ) |
31
|
|
|
{ |
32
|
|
|
$list = []; |
33
|
|
|
|
34
|
|
|
if( !empty( $parentIds ) ) |
35
|
|
|
{ |
36
|
|
|
$propManager = $this->getObject()->getSubManager( 'property' ); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$propSearch = $propManager->createSearch(); |
39
|
|
|
$propSearch->setConditions( $propSearch->compare( '==', $domain . '.property.parentid', $parentIds ) ); |
40
|
|
|
$propSearch->setSortations( [$propSearch->sort( '+', $domain . '.property.type.position' )] ); |
41
|
|
|
$propSearch->setSlice( 0, 0x7fffffff ); |
42
|
|
|
|
43
|
|
|
foreach( $propManager->searchItems( $propSearch ) as $id => $propItem ) { |
44
|
|
|
$list[$propItem->getParentId()][$id] = $propItem; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $list; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Adds new, updates existing and deletes removed property items |
54
|
|
|
* |
55
|
|
|
* @param \Aimeos\MShop\Common\Item\ListRef\Iface $item Item with referenced items |
|
|
|
|
56
|
|
|
* @param string $domain Domain of the calling manager |
57
|
|
|
* @return \Aimeos\MShop\Common\Item\ListRef\Iface Item with saved referenced items |
|
|
|
|
58
|
|
|
*/ |
59
|
|
|
protected function savePropertyItems( \Aimeos\MShop\Common\Item\PropertyRef\Iface $item, $domain ) |
60
|
|
|
{ |
61
|
|
|
$propManager = $this->getObject()->getSubManager( 'property' ); |
|
|
|
|
62
|
|
|
$propManager->deleteItems( array_keys( $item->getPropertyItemsDeleted() ) ); |
63
|
|
|
|
64
|
|
|
foreach( $item->getPropertyItems( null, false ) as $propItem ) |
65
|
|
|
{ |
66
|
|
|
if( $propItem->getParentId() != $item->getId() ) { |
67
|
|
|
$propItem->setId( null ); //create new property item if copied |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$propItem->setParentId( $item->getId() ); |
71
|
|
|
$propManager->saveItem( $propItem ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $item; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.