1
|
|
|
<?php
|
2
|
|
|
//-------------------------------------------------------------------------
|
3
|
|
|
// OVIDENTIA http://www.ovidentia.org
|
4
|
|
|
// Ovidentia is free software; you can redistribute it and/or modify
|
5
|
|
|
// it under the terms of the GNU General Public License as published by
|
6
|
|
|
// the Free Software Foundation; either version 2, or (at your option)
|
7
|
|
|
// any later version.
|
8
|
|
|
//
|
9
|
|
|
// This program is distributed in the hope that it will be useful, but
|
10
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
|
|
// See the GNU General Public License for more details.
|
13
|
|
|
//
|
14
|
|
|
// You should have received a copy of the GNU General Public License
|
15
|
|
|
// along with this program; if not, write to the Free Software
|
16
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
17
|
|
|
// USA.
|
18
|
|
|
//-------------------------------------------------------------------------
|
19
|
|
|
/**
|
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
|
21
|
|
|
* @copyright Copyright (c) 2019 by CapWelton ({@link http://www.capwelton.com})
|
22
|
|
|
*/
|
23
|
|
|
|
24
|
|
|
require_once dirname(__FILE__). '/record.ctrl.php';
|
25
|
|
|
|
26
|
|
|
class app_Component
|
27
|
|
|
{
|
28
|
|
|
const ENTRY = 'Entry';
|
29
|
|
|
const COUNTRY = 'Country';
|
30
|
|
|
const ADDRESS = 'Address';
|
31
|
|
|
|
32
|
|
|
private $app;
|
33
|
|
|
|
34
|
|
|
private $set;
|
35
|
|
|
private $controller;
|
36
|
|
|
private $ui;
|
37
|
|
|
|
38
|
|
|
private $controllerObject;
|
39
|
|
|
private $uiObject;
|
40
|
|
|
|
41
|
|
|
public function __construct(Func_App $app, $set = null, $controller = null, $ui = null)
|
42
|
|
|
{
|
43
|
|
|
$this->app = $app;
|
44
|
|
|
$this->set = $set;
|
45
|
|
|
$this->controller = $controller;
|
46
|
|
|
$this->ui = $ui;
|
47
|
|
|
}
|
48
|
|
|
|
49
|
|
|
/**
|
50
|
|
|
* Returns a multidimensional array with information about required and optional components.
|
51
|
|
|
* The returned array may have 0, 1 or 2 keys : 'requiredComponents' and 'optionalComponents'.
|
52
|
|
|
* Each of these keys is associated to an array of strings for each component name.
|
53
|
|
|
* @return array
|
54
|
|
|
*/
|
55
|
|
|
public function checkDependencies()
|
56
|
|
|
{
|
57
|
|
|
$main = new ReflectionClass($this->set);
|
58
|
|
|
$dependencies = array();
|
59
|
|
|
if($main->hasMethod('getRequiredComponents')){
|
60
|
|
|
$requiredComponents = $this->recordSet()->getRequiredComponents();
|
61
|
|
|
foreach ($requiredComponents as $requiredComponent){
|
62
|
|
|
$dependencies['requiredComponents'][] = $requiredComponent;
|
63
|
|
|
}
|
64
|
|
|
}
|
65
|
|
|
if($main->hasMethod('getOptionalComponents')){
|
66
|
|
|
$optionalComponents = $this->recordSet()->getOptionalComponents();
|
67
|
|
|
foreach ($optionalComponents as $optionalComponent){
|
68
|
|
|
$dependencies['optionalComponents'][] = $optionalComponent;
|
69
|
|
|
}
|
70
|
|
|
}
|
71
|
|
|
|
72
|
|
|
return $dependencies;
|
73
|
|
|
}
|
74
|
|
|
|
75
|
|
|
/**
|
76
|
|
|
* If the component record set has a method onUpdate, this method is called.
|
77
|
|
|
* This method should only be called in the synchronizeComponentsSql method of the addon.
|
78
|
|
|
*/
|
79
|
|
|
public function onUpdate()
|
80
|
|
|
{
|
81
|
|
|
$main = new ReflectionClass($this->set);
|
82
|
|
|
if($main->hasMethod('onUpdate')){
|
83
|
|
|
$this->recordSet()->onUpdate();
|
84
|
|
|
}
|
85
|
|
|
}
|
86
|
|
|
|
87
|
|
|
/**
|
88
|
|
|
* @return app_ComponentCtrlRecord
|
89
|
|
|
*/
|
90
|
|
|
public function controller($proxy = true)
|
91
|
|
|
{
|
92
|
|
|
if(!isset($this->controllerObject)){
|
93
|
|
|
$this->app->includeRecordController();
|
94
|
|
|
$ctrl = $this->controller;
|
95
|
|
|
$this->controllerObject = new $ctrl($this->app, $this);
|
96
|
|
|
}
|
97
|
|
|
if($proxy){
|
98
|
|
|
return $this->controllerObject->proxy();
|
99
|
|
|
}
|
100
|
|
|
return $this->controllerObject;
|
101
|
|
|
}
|
102
|
|
|
|
103
|
|
|
/**
|
104
|
|
|
* @return app_ComponentCtrlRecord
|
105
|
|
|
*/
|
106
|
|
|
public function proxy()
|
107
|
|
|
{
|
108
|
|
|
return $this->controller();
|
109
|
|
|
}
|
110
|
|
|
|
111
|
|
|
/**
|
112
|
|
|
* @return app_ComponentUi
|
113
|
|
|
*/
|
114
|
|
|
public function ui()
|
115
|
|
|
{
|
116
|
|
|
if(!isset($this->uiObject)){
|
117
|
|
|
$ui = $this->ui;
|
118
|
|
|
$this->uiObject = new $ui($this->app);
|
119
|
|
|
}
|
120
|
|
|
return $this->uiObject;
|
121
|
|
|
}
|
122
|
|
|
|
123
|
|
|
public function recordSet()
|
124
|
|
|
{
|
125
|
|
|
$set = $this->set;
|
126
|
|
|
return new $set($this->app);
|
127
|
|
|
}
|
128
|
|
|
|
129
|
|
|
public function getSetClassName()
|
130
|
|
|
{
|
131
|
|
|
$reflectionClass = new ReflectionClass($this->set);
|
132
|
|
|
return $this->app->classPrefix . $reflectionClass->getShortName();
|
133
|
|
|
}
|
134
|
|
|
|
135
|
|
|
public function getRecordClassName()
|
136
|
|
|
{
|
137
|
|
|
return substr($this->getSetClassName(), 0, -3);
|
138
|
|
|
}
|
139
|
|
|
}
|
140
|
|
|
|
141
|
|
|
interface app_ComponentUi
|
142
|
|
|
{
|
143
|
|
|
public function tableView($id = null);
|
144
|
|
|
|
145
|
|
|
public function editor($id = null, \Widget_Layout $layout = null);
|
146
|
|
|
}
|
147
|
|
|
|
148
|
|
|
class app_ComponentCtrlRecord extends app_CtrlRecord
|
149
|
|
|
{
|
150
|
|
|
private $component;
|
151
|
|
|
|
152
|
|
|
/**
|
153
|
|
|
* @param Func_App $app
|
154
|
|
|
* @isComponentController
|
155
|
|
|
*/
|
156
|
|
|
public function __construct(Func_App $app = null, app_Component $component = null)
|
157
|
|
|
{
|
158
|
|
|
$this->setApp($app);
|
159
|
|
|
$this->setComponent($component);
|
160
|
|
|
}
|
161
|
|
|
|
162
|
|
|
public function setComponent(app_Component $component = null)
|
163
|
|
|
{
|
164
|
|
|
$this->component = $component;
|
165
|
|
|
return $this;
|
166
|
|
|
}
|
167
|
|
|
|
168
|
|
|
public function getComponent()
|
169
|
|
|
{
|
170
|
|
|
return $this->component;
|
171
|
|
|
}
|
172
|
|
|
|
173
|
|
|
protected function getRecordSet()
|
174
|
|
|
{
|
175
|
|
|
return $this->getComponent()->recordSet();
|
176
|
|
|
}
|
177
|
|
|
|
178
|
|
|
protected function getRecordClassName()
|
179
|
|
|
{
|
180
|
|
|
return $this->getComponent()->getRecordClassName();
|
181
|
|
|
}
|
182
|
|
|
} |