Completed
Push — master ( 97a1e0...2507d2 )
by Aimeos
03:34
created

Page::getSites()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Common\Decorator;
12
13
14
/**
15
 * Page decorator for JQAdm clients
16
 *
17
 * @package Admin
18
 * @subpackage JQAdm
19
 */
20
class Page extends Base
21
{
22
	/**
23
	 * Sets the view object and adds the available sites and languages
24
	 *
25
	 * @param \Aimeos\MW\View\Iface $view The view object which generates the admin output
26
	 * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls
27
	 */
28
	public function setView( \Aimeos\MW\View\Iface $view )
29
	{
30
		$extdir = dirname( dirname( dirname( dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) ) ) );
31
		$aimeos = new \Aimeos\Bootstrap( array( $extdir ) );
32
33
		$view->pageSites = $this->getSites();
34
		$view->pageLanguages = $aimeos->getI18nList( 'admin' );
35
36
		$this->getClient()->setView( $view );
37
		return $this;
38
	}
39
40
41
	/**
42
	 * Returns the available site code/label pairs
43
	 *
44
	 * @return array Associative list of site codes as keys and site labels as values
45
	 */
46
	protected function getSites()
47
	{
48
		$list = array();
49
		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'locale/site' );
50
51
		$search = $manager->createSearch();
52
		$search->setSortations( array( $search->sort( '+', 'locale.site.label' ) ) );
53
54
		foreach( $manager->searchItems( $search ) as $item ) {
55
			$list[$item->getCode()] = $item->getLabel();
56
		}
57
58
		return $list;
59
	}
60
}
61