1: <?php
2: /**
3: * This file contains Plugin Manager Relations recipient class.
4: *
5: * @package Plugin
6: * @subpackage PluginManager
7: * @author Frederic Schneider
8: * @copyright four for business AG <www.4fb.de>
9: * @license http://www.contenido.org/license/LIZENZ.txt
10: * @link http://www.4fb.de
11: * @link http://www.contenido.org
12: */
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: /**
17: * Plugin Manager Relations recipient class.
18: *
19: * @package Plugin
20: * @subpackage PluginManager
21: * @author Frederic Schneider
22: * @method PimPluginRelations createNewItem
23: * @method PimPluginRelations next
24: */
25: class PimPluginRelationsCollection extends ItemCollection {
26: /**
27: * Constructor Function
28: *
29: * @throws cInvalidArgumentException
30: */
31: public function __construct() {
32: global $cfg;
33: parent::__construct($cfg['tab']['plugins_rel'], 'idpluginrelation');
34: $this->_setItemClass('PimPluginRelations');
35: }
36:
37: /**
38: * Create a new plugin
39: *
40: * @param $idItem int Is equivalent to idarea or idnavm
41: * @param $idPlugin int Plugin Id
42: * @param $type string Relation to tables *_area and *_nav_main
43: *
44: * @return Item
45: *
46: * @throws cDbException
47: * @throws cException
48: * @throws cInvalidArgumentException
49: */
50: public function create($idItem, $idPlugin, $type) {
51:
52: // create a new entry
53: $item = $this->createNewItem();
54: $item->set('iditem', $idItem);
55: $item->set('idplugin', $idPlugin);
56: $item->set('type', $type);
57:
58: $item->store();
59:
60: return $item;
61: }
62:
63: }
64:
65: /**
66: * Single Plugin Manager Relations Item
67: */
68: class PimPluginRelations extends Item {
69:
70: /**
71: * @var string Error storage
72: */
73: protected $_sError;
74:
75: /**
76: * Constructor Function
77: *
78: * @param mixed $id Specifies the id of item to load
79: *
80: * @throws cDbException
81: * @throws cException
82: */
83: public function __construct($id = false) {
84: global $cfg;
85: parent::__construct($cfg['tab']['plugins_rel'], 'idpluginrelation');
86: $this->_sError = '';
87: if ($id !== false) {
88: $this->loadByPrimaryKey($id);
89: }
90: }
91:
92: /**
93: * Userdefined setter for pim relations fields.
94: *
95: * @param string $name
96: * @param mixed $value
97: * @param bool $bSafe Flag to run defined inFilter on passed value
98: *
99: * @return bool
100: */
101: public function setField($name, $value, $bSafe = true) {
102: switch ($name) {
103: case 'iditem':
104: $value = (int) $value;
105: break;
106: case 'idplugin':
107: $value = (int) $value;
108: break;
109: }
110:
111: return parent::setField($name, $value, $bSafe);
112: }
113:
114: }
115: