Offline Server  1.6
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DomainViewApi.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Return offline domains where current user is affected
4  *
5  * @author Anakeen
6  * @version $Id: $
7  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
8  * @package OFFLINE
9  */
10 /**
11  */
12 
13 include_once ("DATA/Class.Collection.php");
14 include_once ("OFFLINE/Class.ExceptionCode.php");
15 include_once ("FDL/Class.DocWaitManager.php");
16 
18 {
19 
20  /**
21  * internal domain document
22  * @var _OFFLINEDOMAIN
23  */
24  private $domain = null;
25  /**
26  * parent object
27  * @var DomainApi
28  */
29  private $domainApi = null;
30  public function __construct(Dir &$domain = null, DomainApi &$domainApi = null)
31  {
32  $this->domain = $domain;
33  $this->domainApi = $domainApi;
34  }
35  private static function setError($err)
36  {
37  throw new Exception($err);
38  }
39 
40  public function getFamiliesBindings($config)
41  {
42  include_once ("FDL/Class.DocumentList.php");
43  $families = $this->domain->getFamilies();
44  $list = new DocumentList();
45  $list->addDocumentIdentificators($families);
46 
47  $domain = $this->domain;
48  $callback = function (&$family) use($domain)
49  {
50  $maskId = $domain->getOfflineMask($family->id);
51  if ($maskId) {
52  $family->applyMask($maskId, true);
53  } else {
54  $family->applyMask();
55  }
56  };
57  $list->listMap($callback); // apply specific offline mask
58 
59 
60  $out = '';
61  foreach ( $list as $family ) {
62  $out->bindings[$family->getProperty('name')] = $this->getFamilyBindings($family);
63  }
64  return $out;
65  }
66 
67  public function getFamilyBindings(DocFam &$family)
68  {
69  $lay = new Layout(getLayoutFile("OFFLINE", "familyBinding.xml"));
70  $lay->set("FAMNAME", $family->name);
71  $lay->set("FAMID", $family->id);
72  $oas = $family->getAttributes();
73  // need cause defval is not declared as attribute
74  simpleQuery($family->dbaccess, sprintf("select defval from docfam where id=%d", $family->id), $defval, true, true);
75  $family->defval=$defval;
76  $this->_defaultValues=$family->getDefValues($defval);
77  $tree = array();
78  $node = array();
79  foreach ( $oas as $aid => &$oa ) {
80  if (($oa->usefor != "Q") && ($oa->type == 'tab')) {
81  $node[$aid] = array();
82  $tree[$aid] = &$node[$aid];
83  if ($oa->ordered === null) {
84  $oa->ordered = $this->getNodeOrder($oa, $oas);
85  }
86  }
87  }
88  foreach ( $oas as $aid => &$oa ) {
89  if (($oa->usefor != "Q") && ($oa->type == 'frame')) {
90  $fid = $oa->fieldSet->id;
91  if ($fid && $fid != "FIELD_HIDDENS") {
92  $node[$aid] = array();
93  //$tree[$aid] = &$node[$aid];
94  $node[$fid][$aid] = &$node[$aid];
95  } else {
96  $node[$aid] = array();
97  $tree[$aid] = &$node[$aid];
98  }
99  if ($oa->ordered === null) {
100  $oa->ordered = $this->getNodeOrder($oa, $oas);
101  }
102  }
103  }
104 
105  foreach ( $oas as $aid => &$oa ) {
106  if (($oa->usefor != "Q") && ($oa->type == 'array')) {
107  $fid = $oa->fieldSet->id;
108  if ($fid && $fid != "FIELD_HIDDENS") {
109  $node[$aid] = array();
110  // $tree[$aid] = &$node[$aid];
111  $node[$fid][$aid] = &$node[$aid];
112  } else {
113  $node[$aid] = array();
114  $tree[$aid] = &$node[$aid];
115  }
116  if ($oa->ordered === null) {
117  $oa->ordered = $this->getNodeOrder($oa, $oas);
118  }
119  }
120  }
121 
122  foreach ( $oas as $aid => &$oa ) {
123  if (($oa->usefor != "Q") && ($oa->type != 'menu') && ($oa->type != 'action')&& ($oa->type != 'array') && ($oa->type != 'frame') && ($oa->type != 'tab')) {
124  $fid = $oa->fieldSet->id;
125  if ($fid && $fid != "FIELD_HIDDENS") {
126  $node[$aid] = '';
127  $node[$fid][$aid] = $node[$aid];
128  } else {
129  $node[$aid] = array();
130  $tree[$aid] = &$node[$aid];
131  }
132  }
133  }
134  unset($tree["FIELD_HIDDENS"]);
135  //print_r2($tree);
136  $lay->set("viewContent", $this->bindingViewNodeAttribute($tree, $oas));
137 
138  $lay->set("editContent", $this->bindingEditNodeAttribute($tree, $oas));
139 
140  //print_r2($viewbinding);
141  $binding = $lay->gen();
142  return $binding;
143  }
144 
145  private function getNodeOrder(BasicAttribute &$noa, array &$oas)
146  {
147  if ($noa->ordered === null) {
148  foreach ( $oas as $aid => &$oa ) {
149  $fid = $oa->fieldSet->id;
150  if ($fid == $noa->id) {
151  $noa->ordered = intval($this->getNodeOrder($oa, $oas)) - 1;
152  break;
153  }
154  }
155  }
156  return intval($noa->ordered);
157  }
158  private function bindingViewNodeAttribute(array &$node, array &$oas, BasicAttribute &$oa = null)
159  {
160  $out = '';
161  if ($oa) {
162  $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
163  }
164  if ((!$oa) || (($visibility != 'I') && ($visibility != 'H') && ($visibility != 'O'))) {
165 
166  if ($oa) {
167  $label = $oa->encodeXml($oa->getLabel(), true);
168  $out .= sprintf('<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view">', $label, $oa->type, $oa->id);
169 
170  }
171  $callback = function ($a, $b) use(&$oas)
172  {
173  //print "\n$a:".$oas[$a]->ordered. " - $b:".$oas[$b]->ordered;
174  if ($oas[$a]->type=="tab" && $oas[$b]->type!="tab") return 1;
175  else if ($oas[$a]->type!="tab" && $oas[$b]->type=="tab") return -1;
176  if ($oas[$a]->ordered > $oas[$b]->ordered) return 1;
177  else if ($oas[$a]->ordered < $oas[$b]->ordered) return -1;
178  return 0;
179  };
180  uksort($node, $callback);
181 
182  $tabbox = false;
183  /*
184  print_r2(array_keys($node));
185  foreach ( $node as $k => $v ) {
186  print "<br/>$k:".$oas[$k]->ordered;
187  }*/
188  foreach ( $node as $k => $v ) {
189  if ((!$tabbox) && ($oas[$k]->type == "tab")) {
190  $tabbox = true;
191  $out .= "<xul:tabbox><xul:tabs/><xul:tabpanels>";
192  }
193  if (is_array($v)) {
194  $out .= $this->bindingViewNodeAttribute($v, $oas, $oas[$k]);
195  } else {
196  $out .= $this->bindingViewLeafAttribute($oas[$k]) . "\n";
197  }
198  if ($tabbox && ($oas[$k]->type != "tab")) {
199  $tabbox = false;
200  $out .= "</xul:tabpanels></xul:tabbox>";
201 
202  }
203  }
204  if ($tabbox) {
205  $out .= "</xul:tabpanels></xul:tabbox>";
206  }
207  if ($oa) {
208  $out .= sprintf('</xul:dcpAttribute>');
209  }
210  }
211 
212  return $out;
213  }
214 
215  private function bindingViewLeafAttribute(BasicAttribute &$oa)
216  {
217  $out = '';
218  $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
219  if (($visibility != "I") && ($visibility != "H")) {
220  $label = $oa->encodeXml($oa->getLabel(), true);
221  switch ($oa->type) {
222  case 'docid' :
223  $out = sprintf('<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view" relationFamily="%s" multiple="%s"/>', $label, $oa->type, $oa->id, trim($oa->format), ($oa->getOption("multiple") == "yes") ? "true" : "false");
224  break;
225  case 'enum' :
226  $out = sprintf('<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view" multiple="%s"/>', $label, $oa->type, $oa->id, ($oa->getOption("multiple") == "yes") ? "true" : "false");
227  break;
228  default :
229  $out = sprintf('<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view"/>', $label, $oa->type, $oa->id);
230  }
231  }
232  return $out;
233  }
234 
235  private function bindingEditNodeAttribute(array &$node, array &$oas, BasicAttribute &$oa = null)
236  {
237  $out = '';
238  $visibility = "";
239  if ($oa) {
240  $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
241  }
242  if ((!$oa) || ($visibility != 'I')) {
243  if ($oa) {
244  $label = $oa->encodeXml($oa->getLabel(), true);
245  $out = sprintf('<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="edit" visibility="%s">', $label, $oa->type, $oa->id, $visibility);
246  }
247  $callback = function ($a, $b) use(&$oas)
248  {
249  //print "\n$a:".$oas[$a]->ordered. " - $b:".$oas[$b]->ordered;
250  if ($oas[$a]->type=="tab" && $oas[$b]->type!="tab") return 1;
251  else if ($oas[$a]->type!="tab" && $oas[$b]->type=="tab") return -1;
252  if ($oas[$a]->ordered > $oas[$b]->ordered) return 1;
253  else if ($oas[$a]->ordered < $oas[$b]->ordered) return -1;
254  return 0;
255  };
256  uksort($node, $callback);
257  $tabbox = false;
258  foreach ( $node as $k => $v ) {
259 
260  if ((!$tabbox) && ($oas[$k]->type == "tab")) {
261  $tabbox = true;
262  $out .= "<xul:tabbox><xul:tabs/><xul:tabpanels>";
263  }
264  if (is_array($v)) {
265  $out .= $this->bindingEditNodeAttribute($v, $oas, $oas[$k]);
266  } else {
267  $out .= $this->bindingEditLeafAttribute($oas[$k]) . "\n";
268  }
269  if ($tabbox && ($oas[$k]->type != "tab")) {
270  $tabbox = false;
271  $out .= "</xul:tabpanels></xul:tabbox>";
272  }
273 
274  }
275  if ($tabbox) {
276  $out .= "</xul:tabpanels></xul:tabbox>";
277  }
278  if ($oa) {
279  $out .= sprintf('</xul:dcpAttribute>');
280  }
281  }
282 
283  return $out;
284  }
285 
286  private function getDefaultValue($aid) {
287  if (is_array($this->_defaultValues)) {
288  $def=$this->_defaultValues[$aid];
289  if (strtolower($def)=="::getuserid()") $def=Doc::getUserId();
290  elseif (strtolower($def)=="::userdocid()") $def=Doc::userDocId();
291  elseif (substr($def,0,2)=="::") $def='';
292  return $def;
293  }
294  return '';
295  }
296 
297  private function bindingEditLeafAttribute(BasicAttribute &$oa)
298  {
299  $out = '';
300  $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
301  if ($visibility != 'I') {
302  $options = array(
303  'esize',
304  'elabel',
305  'cwidth'
306  );
307  $opt = '';
308  foreach ( $options as $option ) {
309  if ($oa->getOption($option)) {
310  $opt .= $option . '="';
311  $opt .= $oa->encodeXml($oa->getOption($option), true);
312  $opt .= '" ';
313  }
314  }
315  $label = $oa->encodeXml($oa->getLabel(), true);
316  $common=sprintf(' label="%s" type="%s" attrid="%s" mode="edit" visibility="%s" required="%s" defaultValue="%s" %s', $label, $oa->type, $oa->id, $visibility, $oa->needed?'true':'false', $this->getDefaultValue($oa->id), $opt);
317  switch ($oa->type) {
318  case 'docid' :
319  $out = sprintf('<xul:dcpAttribute %s relationFamily="%s" multiple="%s"/>', $common, trim($oa->format), ($oa->getOption("multiple") == "yes") ? "true" : "false");
320  break;
321  case 'enum' :
322  $out = sprintf('<xul:dcpAttribute %s multiple="%s"/>', $common, ($oa->getOption("multiple") == "yes") ? "true" : "false");
323  break;
324  default :
325  $out = sprintf('<xul:dcpAttribute %s/>', $common);
326  }
327  }
328  return $out;
329  }
330 }
331 
332 ?>
getFamilyBindings(DocFam &$family)
__construct(Dir &$domain=null, DomainApi &$domainApi=null)
getFamiliesBindings($config)
← centre documentaire © anakeen - published under CC License - Dynacase