Completed
Push — master ( 4c5eea...8c1ffe )
by Aimeos
02:39
created

Standard::createFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 * @package Controller
7
 * @subpackage Frontend
8
 */
9
10
11
namespace Aimeos\Controller\Frontend\Attribute;
12
13
14
/**
15
 * Default implementation of the attribute frontend controller
16
 *
17
 * @package Controller
18
 * @subpackage Frontend
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Frontend\Base
2 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	implements Iface, \Aimeos\Controller\Frontend\Common\Iface
1 ignored issue
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
{
24
	/**
25
	 * Returns the given search filter with the conditions attached for filtering by type code
26
	 *
27
	 * @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for attribute search
28
	 * @param array $codes List of attribute type codes
29
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
30
	 * @since 2017.03
31
	 */
32
	public function addFilterTypes( \Aimeos\MW\Criteria\Iface $filter, array $codes )
33
	{
34
		if( !empty( $codes ) )
35
		{
36
			$expr = [
37
				$filter->compare( '==', 'attribute.type.code', $codes ),
38
				$filter->getConditions(),
39
			];
40
			$filter->setConditions( $filter->combine( '&&', $expr ) );
41
		}
42
43
		return $filter;
44
	}
45
46
47
	/**
48
	 * Returns the default attribute filter
49
	 *
50
	 * @param boolean True to add default criteria
51
	 * @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching
52
	 * @since 2017.03
53
	 */
54
	public function createFilter()
55
	{
56
		$filter = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' )->createSearch( true );
57
58
		$expr = array(
59
			$filter->compare( '==', 'attribute.domain', 'product' ),
60
			$filter->getConditions(),
61
		);
62
63
		$filter->setConditions( $filter->combine( '&&', $expr ) );
64
		$filter->setSortations( array( $filter->sort( '+', 'attribute.position' ) ) );
65
66
		return $filter;
67
	}
68
69
70
	/**
71
	 * Returns the attribute item for the given attribute ID
72
	 *
73
	 * @param string $id Unique attribute ID
74
	 * @param string[] $domains Domain names of items that are associated with the attributes and that should be fetched too
75
	 * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item including the referenced domains items
76
	 * @since 2017.03
77
	 */
78
	public function getItem( $id, array $domains = array( 'media', 'price', 'text' ) )
79
	{
80
		return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' )->getItem( $id, $domains );
81
	}
82
83
84
	/**
85
	 * Returns the attribute items for the given attribute IDs
86
	 *
87
	 * @param string $ids Unique attribute IDs
88
	 * @param string[] $domains Domain names of items that are associated with the attributes and that should be fetched too
89
	 * @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute item including the referenced domains items
90
	 * @since 2017.03
91
	 */
92
	public function getItems( array $ids, array $domains = array( 'media', 'price', 'text' ) )
93
	{
94
		$filter = $this->createFilter();
95
		$expr = [
96
			$filter->compare( '==', 'attribute.id', $ids ),
97
			$filter->getConditions(),
98
		];
99
		$filter->setConditions( $filter->combine( '&&', $expr ) );
100
101
		return $this->searchItems( $filter, $domains );
102
	}
103
104
105
	/**
106
	 * Returns the attributes filtered by the given criteria object
107
	 *
108
	 * @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions
109
	 * @param string[] $domains Domain names of items that are associated with the attributes and that should be fetched too
110
	 * @param integer &$total Parameter where the total number of found attributes will be stored in
111
	 * @return array Ordered list of attribute items implementing \Aimeos\MShop\Attribute\Item\Iface
112
	 * @since 2017.03
113
	 */
114
	public function searchItems( \Aimeos\MW\Criteria\Iface $filter, array $domains = array( 'media', 'price', 'text' ), &$total = null )
115
	{
116
		return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' )->searchItems( $filter, $domains, $total );
117
	}
118
}
119