1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* EGroupware eTemplate extension - InfoLog widget |
4
|
|
|
* |
5
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
6
|
|
|
* @package etemplate |
7
|
|
|
* @subpackage extensions |
8
|
|
|
* @link http://www.egroupware.org |
9
|
|
|
* @author Ralf Becker <[email protected]> |
10
|
|
|
* @version $Id$ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
use EGroupware\Api; |
14
|
|
|
use EGroupware\Api\Etemplate; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Infolog widget et2 representation: |
18
|
|
|
* Both infolog-value and infolog-fields widgets are using client-side et2_widget_entry |
19
|
|
|
* and the format to address them in template is as follows: |
20
|
|
|
* |
21
|
|
|
* <infolog-value id="fieldname" or value="@fieldname" |
22
|
|
|
* options="[field(e.g. sum), compare, alternate_fields(e.g. (-)#customfileds, use '-' if we need subtraction)]" |
23
|
|
|
* /> |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* eTemplate extension: InfoLog widget |
29
|
|
|
* |
30
|
|
|
* This widget can be used to display data from an InfoLog specified by it's id |
31
|
|
|
* |
32
|
|
|
* The infolog-value widget takes 3 comma-separated arguments (beside the name) in the options/size field: |
33
|
|
|
* 1) name of the field (as provided by the infolog-fields widget) |
34
|
|
|
* 2) an optional compare value: if given the selected field is compared with its value and an X is printed on equality, nothing otherwise |
35
|
|
|
* 3) colon (:) separted list of alternative fields: the first non-empty one is used if the selected value is empty |
36
|
|
|
* There's a special field "sum" in 1), which sums up all fields given in alternatives. |
37
|
|
|
*/ |
38
|
|
|
class infolog_widget extends Etemplate\Widget\Entry |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Array with a transformation description, based on attributes to modify. |
43
|
|
|
* @see etemplate_widget_transformer |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected static $transformation = array( |
48
|
|
|
'type' => array( |
49
|
|
|
'infolog-fields' => array( |
50
|
|
|
'sel_options' => array('__callback__' => '_get_fields'), |
51
|
|
|
'type' => 'select', |
52
|
|
|
'no_lang' => true, |
53
|
|
|
'options' => 'None', |
54
|
|
|
), |
55
|
|
|
'__default__' => array( |
56
|
|
|
'options' => array( |
57
|
|
|
'' => array('id' => '@value[@id]'), |
58
|
|
|
// Others added automatically in constructor |
59
|
|
|
'__default__' => array('type' => 'label', 'options' => ''), |
60
|
|
|
), |
61
|
|
|
'no_lang' => 1, |
62
|
|
|
), |
63
|
|
|
), |
64
|
|
|
); |
65
|
|
|
/** |
66
|
|
|
* exported methods of this class |
67
|
|
|
* |
68
|
|
|
* @var array $public_functions |
69
|
|
|
*/ |
70
|
|
|
var $public_functions = array( |
71
|
|
|
'pre_process' => True, |
72
|
|
|
); |
73
|
|
|
/** |
74
|
|
|
* availible extensions and there names for the editor |
75
|
|
|
* |
76
|
|
|
* @var string/array $human_name |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
var $human_name = array( |
79
|
|
|
'infolog-value' => 'InfoLog', |
80
|
|
|
'infolog-fields' => 'InfoLog fields', |
81
|
|
|
); |
82
|
|
|
/** |
83
|
|
|
* Instance of the infolog_bo class |
84
|
|
|
* |
85
|
|
|
* @var infolog_bo |
86
|
|
|
*/ |
87
|
|
|
var $infolog; |
88
|
|
|
/** |
89
|
|
|
* Cached infolog |
90
|
|
|
* |
91
|
|
|
* @var array |
92
|
|
|
*/ |
93
|
|
|
var $data; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Constructor of the extension |
97
|
|
|
*/ |
98
|
|
|
function __construct($xml) |
99
|
|
|
{ |
100
|
|
|
parent::__construct($xml); |
101
|
|
|
|
102
|
|
|
$this->infolog = new infolog_bo(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function get_entry($value, array $attrs) |
106
|
|
|
{ |
107
|
|
|
unset($attrs); // not used |
108
|
|
|
|
109
|
|
|
// Already done |
110
|
|
|
if (is_array($value) && !(array_key_exists('app',$value) && array_key_exists('id', $value))) return $value; |
111
|
|
|
|
112
|
|
|
// Link entry, already in array format |
113
|
|
|
if(is_array($value) && array_key_exists('app', $value) && array_key_exists('id', $value)) $value = $value['id']; |
114
|
|
|
|
115
|
|
|
// Link entry, in string format |
116
|
|
|
if (substr($value,0,8) == 'infolog:') $value = substr($value,8); |
117
|
|
|
if($value) |
118
|
|
|
{ |
119
|
|
|
return $this->infolog->read($value); |
120
|
|
|
} |
121
|
|
|
return array(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function _get_fields() |
125
|
|
|
{ |
126
|
|
|
static $fields=null; |
127
|
|
|
|
128
|
|
|
if (!isset($fields)) |
129
|
|
|
{ |
130
|
|
|
$fields = array( |
131
|
|
|
'' => lang('Sum'), |
132
|
|
|
'info_type' => lang('Type'), |
133
|
|
|
'info_subject' => lang('Subject'), |
134
|
|
|
'info_des' => lang('Description'), |
135
|
|
|
'info_cat' => lang('Category'), |
136
|
|
|
'info_from' => lang('Contact'), |
137
|
|
|
'info_responsible' => lang('Responsible'), |
138
|
|
|
'info_startdate' => lang('Startdate'), |
139
|
|
|
'info_enddate' => lang('Enddate'), |
140
|
|
|
'info_status' => lang('Status'), |
141
|
|
|
'info_priority' => lang('Priority'), |
142
|
|
|
'info_location' => lang('Location'), |
143
|
|
|
'info_percent' => lang('Completed'), |
144
|
|
|
'info_datecompleted' => lang('Date completed'), |
145
|
|
|
// meta data |
146
|
|
|
// PM fields |
147
|
|
|
'info_planned_time' => lang('planned time'), |
148
|
|
|
'info_used_time' => lang('used time'), |
149
|
|
|
'pl_id' => lang('Pricelist'), |
150
|
|
|
'info_price' => lang('Price'), |
151
|
|
|
// other |
152
|
|
|
'info_owner' => lang('Owner'), |
153
|
|
|
'info_access' => lang('Access'), |
154
|
|
|
'info_id' => lang('Id#'), |
155
|
|
|
'info_link_id' => lang('primary link'), |
156
|
|
|
'info_modifier' => lang('Modifierer'), |
157
|
|
|
'info_datemodified' => lang('Last modified'), |
158
|
|
|
// 'info_id_parent' => lang('Parent'), |
159
|
|
|
// 'info_confirm' => lang('Confirm'), |
160
|
|
|
// 'info_custom_from' => lang('Custom from'), |
161
|
|
|
); |
162
|
|
|
foreach(Api\Storage\Customfields::get('infolog') as $name => $data) |
163
|
|
|
{ |
164
|
|
|
$fields['#'.$name] = lang($data['label']); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
return $fields; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// register widgets for etemplate2 |
172
|
|
|
Etemplate\Widget::registerWidget('infolog_widget',array('infolog-value', 'infolog-fields')); |
173
|
|
|
|