-
Notifications
You must be signed in to change notification settings - Fork 17
/
Default.php
111 lines (92 loc) · 2.82 KB
/
Default.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* @copyright Copyright (c) Metaways Infosystems GmbH, 2011
* @license LGPLv3, http://www.arcavias.com/en/license
* @package Controller
* @subpackage ExtJS
*/
/**
* ExtJS plugin controller for admin interfaces.
*
* @package Controller
* @subpackage ExtJS
*/
class Controller_ExtJS_Plugin_Default
extends Controller_ExtJS_Abstract
implements Controller_ExtJS_Common_Interface
{
private $_manager = null;
private $_context = null;
/**
* Initializes the plugin controller.
*
* @param MShop_Context_Item_Interface $context MShop context object
*/
public function __construct( MShop_Context_Item_Interface $context )
{
parent::__construct( $context, 'Plugin' );
$this->_manager = MShop_Plugin_Manager_Factory::createManager( $context );
$this->_context = $context;
}
/**
* Creates a new plugin item or updates an existing one or a list thereof.
*
* @param stdClass $params Associative array containing the plugin properties
* @return array Associative list with nodes and success value
*/
public function saveItems( stdClass $params )
{
$this->_checkParams( $params, array( 'site', 'items' ) );
$this->_setLocale( $params->site );
$ids = array();
$items = ( !is_array( $params->items ) ? array( $params->items ) : $params->items );
foreach( $items as $entry )
{
$item = $this->_createItem( (array) $entry );
$this->_manager->saveItem( $item );
$ids[] = $item->getId();
}
$this->_clearCache( $ids );
$search = $this->_manager->createSearch();
$search->setConditions( $search->compare( '==', 'plugin.id', $ids ) );
$search->setSlice( 0, count( $ids ) );
$items = $this->_toArray( $this->_manager->searchItems( $search ) );
return array(
'items' => ( !is_array( $params->items ) ? reset( $items ) : $items ),
'success' => true,
);
}
/**
* Creates a new plugin item and sets the properties from the given array.
*
* @param array $entry Associative list of name and value properties using the "plugin" prefix
* @return MShop_Plugin_Item_Interface Plugin item
*/
protected function _createItem( array $entry )
{
$item = $this->_manager->createItem();
foreach( $entry as $name => $value )
{
switch( $name )
{
case 'plugin.id': $item->setId( $value ); break;
case 'plugin.code': $item->setCode( $value ); break;
case 'plugin.typeid': $item->setTypeId( $value ); break;
case 'plugin.status': $item->setStatus( $value ); break;
case 'plugin.provider': $item->setProvider( $value ); break;
case 'plugin.position': $item->setPosition( $value ); break;
case 'plugin.config': $item->setConfig( (array) $value ); break;
}
}
return $item;
}
/**
* Returns the manager the controller is using.
*
* @return MShop_Common_Manager_Interface Manager object
*/
protected function _getManager()
{
return $this->_manager;
}
}