Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DocFam.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Family Document Class
8  *
9  * @author Anakeen
10  * @version $Id: Class.DocFam.php,v 1.31 2008/09/16 16:09:59 eric Exp $
11  * @package FDL
12  */
13 /**
14  */
15 include_once ('FDL/Class.PFam.php');
16 /**
17  * @class DocFam
18  * @method createProfileAttribute
19  */
20 class DocFam extends PFam
21 {
22 
23  var $dbtable = "docfam";
24 
25  var $sqlcreate = "
26 create table docfam (cprofid int ,
27  dfldid int,
28  cfldid int,
29  ccvid int,
30  ddocid int,
31  methods text,
32  defval text,
33  schar char,
34  param text,
35  genversion float,
36  maxrev int,
37  usedocread int,
38  tagable text,
39  configuration text) inherits (doc);
40 create unique index idx_idfam on docfam(id);";
41  var $sqltcreate = array();
42 
43  var $defDoctype = 'C';
44 
45  var $defaultview = "FDL:VIEWFAMCARD";
46 
47  var $attr;
48  public $specialmenu = "FDL:POPUPFAMDETAIL";
49  public $addfields = array(
50  "dfldid",
51  "cfldid",
52  "ccvid",
53  "cprofid",
54  "ddocid",
55  "methods",
56  "defval",
57  "param",
58  "genversion",
59  "usedocread",
60  "schar",
61  "maxrev",
62  "tagable",
63  "configuration"
64  );
65  public $genversion;
66  public $dfldid;
67  public $cfldid;
68  public $ccvid;
69  public $cprofid;
70  public $ddocid;
71  public $methods;
72  public $defval;
73  public $param;
74  public $schar;
75  public $maxrev;
77  public $tagable;
78  private $_configuration;
79  private $_xtdefval; // dynamic used by ::getParams()
80  private $_xtparam; // dynamic used by ::getDefValues()
81  private $defaultSortProperties = array(
82  'owner' => array(
83  'sort' => 'no',
84  ) ,
85  'title' => array(
86  'sort' => 'asc',
87  ) ,
88  'revision' => array(
89  'sort' => 'no',
90  ) ,
91  'initid' => array(
92  'sort' => 'desc',
93  ) ,
94  'revdate' => array(
95  'sort' => 'desc',
96  ) ,
97  'state' => array(
98  'sort' => 'asc',
99  )
100  );
101  /**
102  * @var bool bool(true) if object is "fully" instantiated using FDLGEN or bool(false) if object is instantiated
103  * without FDLGEN (e.g. when the family is imported and the FDLGEN is not yet generated).
104  */
105  private $FDLGEN_HasBeenLoaded = false;
106 
107  function __construct($dbaccess = '', $id = '', $res = '', $dbid = 0, $include = true)
108  {
109 
110  foreach ($this->addfields as $f) $this->fields[$f] = $f;
111  // specials characteristics R : revised on each modification
112  parent::__construct($dbaccess, $id, $res, $dbid);
113  $this->doctype = 'C';
114  if ($include && ($this->id > 0) && ($this->isAffected())) {
115  $adoc = "Doc" . $this->id;
116  $GEN = getGen($dbaccess);
117  if (include_once ("FDL$GEN/Class.$adoc.php")) {
118  $adoc = "ADoc" . $this->id;
119  $this->attributes = new $adoc();
120  $this->attributes->orderAttributes();
121  } else {
122  throw new Dcp\Exception(sprintf("cannot access attribute definition for %s (#%s) family", $this->name, $this->id));
123  }
124  $this->FDLGEN_HasBeenLoaded = true;
125  }
126  }
127 
128  protected function postAffect(array $data, $more, $reset)
129  {
130  $this->_xtdefval = null;
131  $this->_xtparam = null;
132  }
133 
134  function preDocDelete()
135  {
136  return _("cannot delete family");
137  }
138  /**
139  * return i18n title for family
140  * based on name
141  * @return string
142  */
143  function getCustomTitle()
144  {
145  $r = $this->name . '#title';
146  $i = _($r);
147  if ($i != $r) return $i;
148  return $this->title;
149  }
150 
151  static function getLangTitle($values)
152  {
153  $r = $values["name"] . '#title';
154  $i = _($r);
155  if ($i != $r) return $i;
156  return $values["title"];
157  }
158 
159  function postStore()
160  {
161  include_once ("FDL/Lib.Attr.php");
162  return refreshPhpPgDoc($this->dbaccess, $this->id);
163  }
164 
165  function preCreated()
166  {
167  $cdoc = $this->getFamilyDocument();
168  if ($cdoc->isAlive()) {
169  if (!$this->ccvid) $this->ccvid = $cdoc->ccvid;
170  if (!$this->cprofid) $this->cprofid = $cdoc->cprofid;
171  if (!$this->defval) $this->defval = $cdoc->defval;
172  if (!$this->schar) $this->schar = $cdoc->schar;
173  if (!$this->usefor) $this->usefor = $cdoc->usefor;
174  if (!$this->tagable) $this->tagable = $cdoc->tagable;
175  }
176  }
177  /**
178  * update attributes of workflow if needed
179  * @param array $extra
180  * @return string
181  */
182  function postImport(array $extra = array())
183  {
184  $err = '';
185  if (strstr($this->usefor, 'W')) {
186  $classw = $this->classname;
187  if ($classw) {
188  $w = new $classw();
189  if ($w) {
190  if (is_a($w, "WDoc")) {
191  /*
192  * @var WDoc $w
193  */
194  $err = $w->createProfileAttribute($this->id);
195  }
196  }
197  } else {
198  $err = "workflow need class";
199  }
200  }
201  return $err;
202  }
203  /**
204  * @templateController default values controller
205  * @param string $target
206  * @param bool $ulink
207  * @param bool $abstract
208  */
210  /* @noinspection PhpUnusedParameterInspection */
211  $target = "_self", $ulink = true, $abstract = false)
212  {
213  $d = createDoc($this->dbaccess, $this->id, false, true, false);
214  $defValues = $this->getDefValues();
215  $ownDefValues = $this->explodeX($this->defval);
216  $ownParValues = $this->explodeX($this->param);
217  $tDefVal = $tDefPar = array();
218 
219  $tp = $this->getParamAttributes();
220  $pPowns = $this->getOwnParams();
221  foreach ($tp as $aid => & $oa) {
222  if ($oa->type == "array") continue;
223  $tDefPar[$aid] = array(
224  "aid" => $aid,
225  "alabel" => $oa->getLabel() ,
226  "defown" => isset($pPowns[$aid]) ? $pPowns[$aid] : null,
227  "definh" => ($this->fromid) ? $this->getFamilyDocument()->getParameterRawValue($aid) : '',
228  "defresult" => $this->getHtmlValue($oa, $this->getFamilyParameterValue($aid))
229  );
230  }
231  $parent = null;
232  if ($this->fromid > 0) {
233  $parent = $this->getFamilyDocument();
234  }
235  foreach ($defValues as $aid => $dv) {
236  $oa = $d->getAttribute($aid);
237  $value = $d->getRawValue($aid);
238  $ownValue = isset($ownDefValues[$aid]) ? $ownDefValues[$aid] : null;
239 
240  if ($oa) {
241  $oa->setVisibility('R');
242  $label = $oa->getLabel();
243  if ($oa->usefor == 'Q') {
244  $value = $d->getFamilyParameterValue($aid);
245  if (!empty($ownParValues[$aid])) {
246  $ownValue = $ownParValues[$aid];
247  } else {
248  if ($ownValue) $ownValue.= ' <em>(' . _("default value") . ")</em>";
249  }
250  }
251  } else {
252  $label = '-';
253  }
254  $inhValue = '';
255  if ($parent) {
256  if ($oa->usefor == 'Q') {
257 
258  $inhValue = $parent->getParameterRawValue($aid);
259  } else {
260  $inhValue = $parent->getDefValue($aid);
261  }
262  }
263  $t = array(
264  "aid" => $aid,
265  "alabel" => $label,
266  "defown" => $ownValue,
267  "definh" => $inhValue,
268  "defresult" => $this->getHtmlValue($oa, $value)
269  );
270  if ($oa && $oa->usefor == 'Q') {
271 
272  $tDefPar[$aid] = $t;
273  } else {
274  $tDefVal[$aid] = $t;
275  }
276  }
277  $this->lay->set("hasAncestor", $this->fromid > 0);
278  $this->lay->set("docid", $this->id);
279  $this->lay->SetBlockData("DEFVAL", $tDefVal);
280  $this->lay->SetBlockData("DEFPAR", $tDefPar);
281  $this->lay->Set("NOVAL", count($tDefVal) == 0);
282  $this->lay->Set("NOPAR", count($tDefPar) == 0);
283  $this->lay->Set("canEdit", $this->canEdit() == "");
284  }
285  /**
286  * @templateController special default view for families
287  * @param string $target
288  * @param bool $ulink
289  * @param bool $abstract
290  */
291  function viewfamcard(
292  /* @noinspection PhpUnusedParameterInspection */
293  $target = "_self", $ulink = true, $abstract = false)
294  {
295  // -----------------------------------
296 
297  /* @var Action $action */
298  global $action;
299  //Checking if document has acls
300  simpleQuery($this->dbaccess, "SELECT count(*) FROM docperm WHERE docid=" . $this->id, $nb_acl, true, true);
301  $this->lay->set("hasAcl", ($nb_acl != "0"));
302 
303  $this->lay->set("modifyacl", ($this->control("modifyacl") == ""));
304  $this->lay->set("canInitProfil", $action->HasPermission("FREEDOM_ADMIN", "FREEDOM"));
305 
306  foreach ($this->fields as $k => $v) {
307 
308  $this->lay->set("$v", $this->$v ? $this->$v : false);
309  switch ($v) {
310  case 'cprofid':
311  if ($this->$v > 0) {
312  $tdoc = new_Doc($this->dbaccess, $this->$v);
313 
314  $this->lay->set("cmodifyacl", ($tdoc->control("modifyacl") == ""));
315 
316  $this->lay->set("cproftitle", $tdoc->title);
317  $this->lay->set("cprofdisplay", "");
318  $hascontrol = ($this->controlUserId($this->$v, $this->userid, "modifyacl") == "");
319  $this->lay->set("ca_" . $v, $hascontrol);
320  } else {
321  $this->lay->set("cprofdisplay", "none");
322  }
323  break;
324 
325  case 'cfldid':
326  if ($this->$v > 0) {
327  $tdoc = new_Doc($this->dbaccess, $this->$v);
328  $this->lay->set("cfldtitle", $tdoc->title);
329  $this->lay->set("cflddisplay", "");
330  } else {
331  $this->lay->set("cflddisplay", "none");
332  }
333  break;
334 
335  case 'dfldid':
336  if ($this->$v > 0) {
337  $tdoc = new_Doc($this->dbaccess, $this->$v);
338  $this->lay->set("dfldtitle", $tdoc->title);
339  $this->lay->set("dflddisplay", "");
340  } else {
341  $this->lay->set("dflddisplay", "none");
342  }
343  break;
344 
345  case 'wid':
346  if ($this->$v > 0) {
347  /*
348  * @var WDoc $tdoc
349  */
350  $tdoc = new_Doc($this->dbaccess, $this->$v);
351  $this->lay->set("wtitle", $tdoc->title);
352  $this->lay->set("wdisplay", true);
353  $this->lay->set("wactif", ($tdoc->profid > 0));
354  $hascontrol = ($tdoc->control("modifyacl") == "");
355  $this->lay->set("wcontrol", $hascontrol);
356  $this->lay->set("wedit", ($tdoc->control("edit") == ""));
357  $states = $tdoc->getStates();
358  $tstates = array();
359  $tnoprofilstates = array();
360  foreach ($states as $st) {
361  $pid = $tdoc->getStateProfil($st);
362  if ($pid) {
363  $pdoc = new_doc($this->dbaccess, $pid);
364  $tstates[$pid]["smodifyacl"] = ($pdoc->control("modifyacl") == "");
365  $tstates[$pid]["sactif"] = $pdoc->profid;
366  $tstates[$pid]["pstateid"] = $pid;
367  $tstates[$pid]["states"][] = _($st);
368  } else {
369  $tnoprofilstates[_($st) ] = array(
370  "pstateattrid" => $tdoc->getStateProfilAttribute($st) ,
371  "states" => _($st)
372  );
373  }
374  }
375 
376  $this->lay->set("noprofilstate", implode(", ", array_keys($tnoprofilstates)));
377  foreach ($tstates as $ka => $va) {
378  $tstates[$ka]["states"] = implode(", ", $va["states"]);
379  }
380  $this->lay->setBlockData("pstate", $tstates);
381  $this->lay->setBlockData("nopstate", $tnoprofilstates);
382  } else {
383  $this->lay->set("wdisplay", false);
384  }
385  break;
386 
387  case 'ccvid':
388  if ($this->$v > 0) {
389  $tdoc = new_Doc($this->dbaccess, $this->$v);
390  $this->lay->set("cvtitle", $tdoc->title);
391  $this->lay->set("cvdisplay", "");
392  } else {
393  $this->lay->set("cvdisplay", "none");
394  }
395  break;
396 
397  case 'maxrev':
398  if (!$this->maxrev) {
399  if ($this->schar == 'S') {
400  $this->lay->set("maxrevision", _("no revisable"));
401  } else {
402  $this->lay->set("maxrevision", _("unlimited revisions"));
403  }
404  } else {
405  $this->lay->set("maxrevision", $this->maxrev);
406  }
407 
408  break;
409  }
410  }
411  }
412  //~~~~~~~~~~~~~~~~~~~~~~~~~ PARAMETERS ~~~~~~~~~~~~~~~~~~~~~~~~
413 
414  /**
415  * return family parameter
416  *
417  * @deprecated use {@link Doc::getParameterRawValue} instead
418  * @see Doc::getParameterRawValue
419  * @param string $idp parameter identifier
420  * @param string $def default value if parameter not found or if it is null
421  * @return string parameter value
422  */
423  final public function getParamValue($idp, $def = "")
424  {
426  return $this->getParameterRawValue($idp, $def);
427  }
428  /**
429  * return family parameter
430  *
431  * @param string $idp parameter identifier
432  * @param string $def default value if parameter not found or if it is null
433  * @return string parameter value
434  */
435  final public function getParameterRawValue($idp, $def = "")
436  {
437 
438  $pValue = $this->getXValue("param", $idp);
439  if ($pValue === '') {
440  $defsys = $this->getDefValue($idp);
441  if ($defsys !== '') {
442  return $defsys;
443  }
444  return $def;
445  }
446  return $pValue;
447  }
448  /**
449  * use in Doc::getParameterFamilyValue
450  * @param string $idp
451  * @param string $def
452  * @see Doc::getParameterFamilyValue_
453  * @return bool|string
454  */
455  protected function getParameterFamilyRawValue($idp, $def)
456  {
457 
458  return $this->getParameterRawValue($idp, $def);
459  }
460  /**
461  * return all family parameter - seach in parents if parameter value is null
462  *
463  * @return array string parameter value
464  */
465  function getParams()
466  {
467  return $this->getXValues("param");
468  }
469  /**
470  * return own family parameters values - no serach in parent families
471  * @return array string parameter value
472  */
473  function getOwnParams()
474  {
475  return $this->explodeX($this->param);
476  }
477  /**
478  * return the value of an list parameter document
479  *
480  * the parameter must be in an array or of a type '*list' like enumlist or textlist
481  * @param string $idAttr identifier of list parameter
482  * @param string $def default value returned if parameter not found or if is empty
483  * @param int $index rank in case of multiple value
484  * @return array the list of parameter values
485  */
486  public function getParamTValue($idAttr, $def = "", $index = - 1)
487  {
488  $t = $this->rawValueToArray($this->getParameterRawValue("$idAttr", $def));
489  if ($index == - 1) return $t;
490  if (isset($t[$index])) return $t[$index];
491  else return $def;
492  }
493  /**
494  * set family parameter value
495  *
496  * @param string $idp parameter identifier
497  * @param string $val value of the parameter
498  * @param bool $check set to false when construct family
499  * @return string error message
500  */
501  public function setParam($idp, $val, $check = true)
502  {
503  $this->setChanged();
504  $idp = strtolower($idp);
505 
506  $oa = null;
507  if ($check) {
508  $oa = $this->getAttribute($idp); // never use getAttribute if not check
509  if (!$oa) {
510  return ErrorCode::getError('DOC0120', $idp, $this->getTitle() , $this->name);
511  }
512  }
513 
514  if (is_array($val)) {
515  if ($oa && $oa->type == 'htmltext') {
516  $val = $this->arrayToRawValue($val, "\r");
517  } else {
518  $val = $this->arrayToRawValue($val);
519  }
520  }
521  if (!empty($val) && $oa && ($oa->type == "date" || $oa->type == "timestamp")) {
522  $err = $this->convertDateToiso($oa, $val);
523  if ($err) return $err;
524  }
525 
526  $err = '';
527  if ($this->isComplete()) $err = $this->checkSyntax($idp, $val);
528  if (!$err) $this->setXValue("param", strtolower($idp) , $val);
529  return $err;
530  }
531 
532  private function convertDateToiso(BasicAttribute $oa, &$val)
533  {
534  $localeconfig = getLocaleConfig();
535  if ($localeconfig !== false) {
536  if ($oa->type == "date" || $oa->type == "timestamp") {
537  if ($oa->type == "date") {
538  $dateFormat = $localeconfig['dateFormat'];
539  } else {
540  $dateFormat = $localeconfig['dateTimeFormat'];
541  }
542 
543  $tDates = explode("\n", $val);
544  foreach ($tDates as $k => $date) {
545  $tDates[$k] = stringDateToIso($date, $dateFormat);
546  }
547  $val = implode("\n", $tDates);
548  } else {
549  return sprintf(_("local config for date not found"));
550  }
551  }
552  return '';
553  }
554  /**
555  * Verify is family is under construction
556  * @return bool
557  */
558  private function isComplete()
559  {
560  return ($this->attributes && $this->attributes->attr);
561  }
562  /**
563  * @param string $aid attribute identifier
564  * @param string $val value to test
565  * @return string error message
566  */
567  private function checkSyntax($aid, $val)
568  {
569  /*
570  * @var NormalAttribute $oa
571  */
572  $oa = $this->getAttribute($aid);
573  if (!$oa) return ''; // cannot test in this case
574  $err = '';
575  $type = $oa->type;
576  if ($oa->isMultiple()) {
577  $val = explode("\n", $val);
578  }
579 
580  if (is_array($val)) $vals = $val;
581  else $vals[] = $val;
582 
583  foreach ($vals as $ka => $av) {
584  if (!self::seemsMethod($av)) {
585  switch ($type) {
586  case 'money':
587  case 'double':
588  if (!empty($av) && (!is_numeric($av))) {
589  $err = sprintf(_("value [%s] is not a number") , $av);
590  }
591  break;
592 
593  case 'int':
594  if (!empty($av)) {
595  if ((!is_numeric($av))) {
596  $err = sprintf(_("value [%s] is not a number") , $av);
597  }
598  if (!$err && (!ctype_digit($av))) {
599  $err = sprintf(_("value [%s] is not a integer") , $av);
600  }
601  }
602  break;
603  }
604  if (!$err) {
605  // verifiy constraint
606  if ($oa->phpconstraint) {
607  //print_r2($aid."[$ka]".$oa->phpconstraint);
608  $map[$aid] = $av;
609  $err = $this->applyMethod($oa->phpconstraint, null, $oa->isMultiple() ? $ka : -1, array() , $map);
610  }
611  }
612  }
613  }
614  return $err;
615  }
616  //~~~~~~~~~~~~~~~~~~~~~~~~~ DEFAULT VALUES ~~~~~~~~~~~~~~~~~~~~~~~~
617 
618  /**
619  * return family default value
620  *
621  * @param string $idp parameter identifier
622  * @param string $def default value if parameter not found or if it is null
623  * @return string default value
624  */
625  public function getDefValue($idp, $def = "")
626  {
627  $x = $this->getXValue("defval", $idp, $def);
628 
629  return $x;
630  }
631  /**
632  * return all family default values
633  * search in parents families if value is null
634  *
635  * @return array string default value
636  */
637  public function getDefValues()
638  {
639  return $this->getXValues("defval");
640  }
641  /**
642  * return own default value not inherit default
643  *
644  * @return array string default value
645  */
646  function getOwnDefValues()
647  {
648  return $this->explodeX($this->defval);
649  }
650  /**
651  * set family default value
652  *
653  * @param string $idp parameter identifier
654  * @param string $val value of the default
655  * @param bool $check
656  * @return string error message
657  */
658  function setDefValue($idp, $val, $check = true)
659  {
660  $idp = strtolower($idp);
661  $err = '';
662  $oa = null;
663  if ($check) {
664  $oa = $this->getAttribute($idp);
665  if (!$oa) {
666  return ErrorCode::getError('DOC0123', $idp, $this->getTitle() , $this->name);
667  }
668  }
669  if (!empty($val) && $oa && ($oa->type == "date" || $oa->type == "timestamp")) {
670  $err = $this->convertDateToiso($oa, $val);
671  }
672  $this->setXValue("defval", $idp, $val);
673  return $err;
674  }
675  //~~~~~~~~~~~~~~~~~~~~~~~~~ X VALUES ~~~~~~~~~~~~~~~~~~~~~~~~
676 
677  /**
678  * return family default value
679  *
680  * @param string $X column name
681  * @param string $idp parameter identifier
682  * @param string $def default value if parameter not found or if it is null
683  * @return string default value
684  */
685  function getXValue($X, $idp, $def = "")
686  {
687  $tval = "_xt$X";
688  if (!isset($this->$tval)) $this->getXValues($X);
689 
690  $tval2 = $this->$tval;
691  $v = isset($tval2[strtolower($idp) ]) ? $tval2[strtolower($idp) ] : '';
692  if ($v == "-") return $def;
693  if ($v !== "") return $v;
694  return $def;
695  }
696  /**
697  * explode param or defval string
698  * @param string $sx
699  * @return array
700  */
701  private function explodeX($sx)
702  {
703  $txval = array();
704  $tdefattr = explode("][", substr($sx, 1, strlen($sx) - 2));
705  foreach ($tdefattr as $k => $v) {
706 
707  $aid = substr($v, 0, strpos($v, '|'));
708  $dval = substr(strstr($v, '|') , 1);
709  if ($aid) $txval[$aid] = $dval;
710  }
711  return $txval;
712  }
713  /**
714  * return all family default values
715  *
716  * @param string $X column name
717  * @return array string default value
718  */
719  function getXValues($X)
720  {
721  $Xval = "_xt$X";
722  $defval = $this->$X;
723 
724  if ($this->$Xval) return $this->$Xval;
725 
726  $XS[$this->id] = $defval;
727  $this->$Xval = array();
728  $inhIds = array();
729  if ($this->attributes !== null && isset($this->attributes->fromids) && is_array($this->attributes->fromids)) {
730  $sql = sprintf("select id,%s from docfam where id in (%s)", pg_escape_string($X) , implode(',', $this->attributes->fromids));
731  simpleQuery($this->dbaccess, $sql, $rx, false, false);
732  foreach ($rx as $r) {
733  $XS[$r["id"]] = $r[$X];
734  }
735  $inhIds = array_values($this->attributes->fromids);
736  }
737  if (!in_array($this->id, $inhIds)) $inhIds[] = $this->id;
738 
739  $txval = array();
740 
741  foreach ($inhIds as $famId) {
742  $txvalh = $this->explodeX($XS[$famId]);
743  foreach ($txvalh as $aid => $dval) {
744  $txval[$aid] = ($dval == '-') ? null : $dval;
745  }
746  }
747  if ($this->isComplete()) {
748  uksort($txval, array(
749  $this,
750  "compareXOrder"
751  ));
752  }
753  $this->$Xval = $txval;
754 
755  return $this->$Xval;
756  }
757 
758  public function compareXOrder($a1, $a2)
759  {
760  $oa1 = $this->getAttribute($a1);
761  $oa2 = $this->getAttribute($a2);
762  if ($oa1 && $oa2) {
763  if ($oa1->ordered > $oa2->ordered) return 1;
764  else if ($oa1->ordered < $oa2->ordered) return -1;
765  }
766  return 0;
767  }
768  /**
769  * set family default value
770  *
771  * @param $X
772  * @param string $idp parameter identifier
773  * @param string $val value of the default
774  * @return void
775  */
776  function setXValue($X, $idp, $val)
777  {
778  $tval = "_xt$X";
779  if (is_array($val)) $val = $this->arrayToRawValue($val);
780 
781  $txval = $this->explodeX($this->$X);
782 
783  $txval[strtolower($idp) ] = $val;
784  $this->$tval = $txval;
785 
786  $tdefattr = array();
787  foreach ($txval as $k => $v) {
788  if ($k && ($v !== '')) $tdefattr[] = "$k|$v";
789  }
790  $this->$tval = null;
791  $this->$X = "[" . implode("][", $tdefattr) . "]";
792  }
793 
794  final public function UpdateVaultIndex()
795  {
796  /*
797  * Skip processing if the family has no attributes
798  * This typically happens when the family is created for the first time at import and FDLGEN is not yet generated
799  */
800  if ((!$this->FDLGEN_HasBeenLoaded) || (!isset($this->attributes->attr))) {
801  return '';
802  }
803 
804  $point = uniqid(__METHOD__);
805  if (($err = $this->savePoint($point)) !== '') {
806  return $err;
807  }
808  $dvi = new DocVaultIndex($this->dbaccess);
809  $dvi->DeleteDoc($this->id);
810 
812 
813  foreach ($tvid as $k => $vid) {
814  $dvi->docid = $this->id;
815  $dvi->vaultid = $vid;
816  $dvi->Add();
817  }
818  if (($err = $this->commitPoint($point)) !== '') {
819  return $err;
820  }
821  return '';
822  }
823 
824  function saveVaultFile($vid, $stream)
825  {
826  $err = '';
827  if (is_resource($stream) && get_resource_type($stream) == "stream") {
828  $ext = "nop";
829  $filename = uniqid(getTmpDir() . "/_fdl") . ".$ext";
830  $tmpstream = fopen($filename, "w");
831  while (!feof($stream)) {
832  if (false === fwrite($tmpstream, fread($stream, 4096))) {
833  $err = "403 Forbidden";
834  break;
835  }
836  }
837  fclose($tmpstream);
838  if (!$err) {
839  $vf = newFreeVaultFile($this->dbaccess);
840  $info = null;
841  $err = $vf->Retrieve($vid, $info);
842  if ($err == "") $err = $vf->Save($filename, false, $vid);
843  unlink($filename);
844  }
845  return $err;
846  }
847  return '';
848  }
849  /**
850  * read xml configuration file
851  */
852  function getConfiguration()
853  {
854  if (!$this->_configuration) {
855  if ($this->name) {
856  $dxml = new DomDocument();
857  $famfile = DEFAULT_PUBDIR . sprintf("/families/%s.fam", $this->name);
858  if (!@$dxml->load($famfile)) {
859  return null;
860  } else {
861  /* @var stdClass $o */
862  $o = null;
863  $properties = $dxml->getElementsByTagName('property');
864  foreach ($properties as $prop) {
865  /* @var DOMElement $prop */
866  $name = $prop->getAttribute('name');
867  $value = $prop->nodeValue;
868  $o->properties[$name] = $value;
869  }
870  $views = $dxml->getElementsByTagName('view');
871  foreach ($views as $view) {
872  /* @var DOMElement $view */
873  $name = $view->getAttribute('name');
874  foreach ($view->attributes as $a) {
875  $o->views[$name][$a->name] = $a->value;
876  }
877  }
878  }
879  $this->_configuration = $o;
880  }
881  }
882  return $this->_configuration;
883  }
884  /**
885  * @param bool $linkInclude if false fdl.xsd is write inside else use an include directive
886  * @return string
887  */
888  function getXmlSchema($linkInclude = false)
889  {
890  $lay = new Layout(getLayoutFile("FDL", "family_schema.xml"));
891  $lay->set("famname", strtolower($this->name));
892  $lay->set("famtitle", strtolower($this->getTitle()));
893  $lay->set("include", $linkInclude);
894  if ($linkInclude) {
895  $lay->set("includefdlxsd", "");
896  } else {
897  $xsd = new DOMDocument();
898  $xsd->load(getLayoutFile("FDL", "fdl.xsd"));
899  $xsd->preserveWhiteSpace = false;
900  $xsd->formatOutput = true;
901  $innerXml = '';
902  $rootNode = $xsd->documentElement;
903  /**
904  * @var \DOMNode $node
905  */
906  foreach ($rootNode->childNodes as $subnode) {
907  $innerXml.= ($xsd->saveXML($subnode));
908  }
909 
910  $lay->set("includefdlxsd", $innerXml);
911  }
912 
913  $level1 = array();
914  $la = $this->getAttributes();
915  $tax = array();
916 
917  foreach ($la as $k => $v) {
918  if ((!$v) || ($v->getOption("autotitle") == "yes") || ($v->usefor == 'Q')) unset($la[$k]);
919  }
920  foreach ($la as $k => $v) {
921  if (($v->id != Adoc::HIDDENFIELD) && ($v->type == 'frame' || $v->type == "tab") && ((!$v->fieldSet) || $v->fieldSet->id == Adoc::HIDDENFIELD)) {
922  $level1[] = array(
923  "level1name" => $k
924  );
925  $tax[] = array(
926  "tax" => $v->getXmlSchema($la)
927  );
928  } else {
929  // if ($v) $tax[]=array("tax"=>$v->getXmlSchema());
930 
931  }
932  };
933 
934  $lay->setBlockData("ATTR", $tax);
935  $lay->setBlockData("LEVEL1", $level1);
936 
937  $xsd = new DOMDocument();
938  $xsd->preserveWhiteSpace = false;
939  $xsd->formatOutput = true;
940  $xsd->loadXML($lay->gen());
941 
942  return ($xsd->saveXML());
943  }
944  /*
945  private function loadDefaultSortProperties() {
946  $confStore = new ConfigurationStore();
947  foreach ($this->defaultSortProperties as $propName => $pValues) {
948  foreach ($pValues as $pName => $pValue) {
949  $confStore->add('sortProperties', $propName, $pName, $pValue);
950  }
951  }
952  $conf = $confStore->getText();
953  if ($conf === false) {
954  return false;
955  }
956  $this->configuration = $conf;
957  error_log(__METHOD__." ".sprintf("conf = [%s]", $conf));
958  return $this;
959  }
960  */
961  /**
962  * Reset properties configuration
963  * @return \DocFam
964  */
965  public function resetPropertiesParameters()
966  {
967  $this->configuration = '';
968  return $this;
969  }
970  /**
971  * Get a property's parameter's value
972  * @param string $propName The property's name
973  * @param string $pName The parameter's name
974  * @return bool|string boolean false on error, string containing the parameter's value
975  */
976  public function getPropertyParameter($propName, $pName)
977  {
978  $propName = strtolower($propName);
979 
980  $confStore = new ConfigurationStore();
981  if ($confStore->load($this->configuration) === false) {
982  return false;
983  }
984 
986  $pValue = $confStore->get($class, $propName, $pName);
987  if ($pValue === false) {
988  return false;
989  }
990 
991  return $pValue;
992  }
993  /**
994  * Set a parameter's value on a property
995  *
996  * Note: The value is set on the object but not saved in the
997  * database, so it's your responsibility to call modify() if you
998  * want to make the change persistent.
999  *
1000  * @param string $propName The property's name
1001  * @param string $pName The parameter's name
1002  * @param string $pValue The parameter's value
1003  * @return bool boolean false on error, or boolean true on success
1004  */
1005  public function setPropertyParameter($propName, $pName, $pValue)
1006  {
1007  $propName = strtolower($propName);
1008 
1009  $confStore = new ConfigurationStore();
1010  if ($confStore->load($this->configuration) === false) {
1011  return false;
1012  }
1013 
1015  $confStore->add($class, $propName, $pName, $pValue);
1016 
1017  $conf = $confStore->getText();
1018  if ($conf === false) {
1019  return false;
1020  }
1021 
1022  $this->configuration = $conf;
1023  return true;
1024  }
1025  /**
1026  * Get sortable properties.
1027  * @return array properties' Names with their set of parameters
1028  */
1029  public function getSortProperties()
1030  {
1031  $res = array();
1032  /*
1033  * Lookup default parameters
1034  */
1035  foreach ($this->defaultSortProperties as $propName => $params) {
1036  if (isset($params['sort']) && $params['sort'] != 'no') {
1037  $res[$propName] = $params;
1038  }
1039  }
1040  $confStore = new ConfigurationStore();
1041  if ($confStore->load($this->configuration) === false) {
1042  return $res;
1043  }
1044  /*
1045  * Lookup custom parameters
1046  */
1047  $props = $confStore->get('sortProperties', null, 'sort');
1048  if ($props === null) {
1049  return $res;
1050  }
1051  foreach ($props as $propName => $params) {
1052  if (isset($params['sort']) && $params['sort'] != 'no') {
1053  $res[$propName] = $params;
1054  }
1055  }
1056 
1057  return $res;
1058  }
1059 
1060  public function PostUpdate()
1061  {
1062  if (($err = $this->updateVaultIndex()) !== '') {
1063  return $err;
1064  }
1065  return parent::PostUpdate();
1066  }
1067  /**
1068  * Inhibit search values : no need and must not be use when import family
1069  * @param bool $withLocale
1070  * @return string
1071  */
1072  protected function getExtraSearchableDisplayValues($withLocale = true)
1073  {
1074  return "";
1075  }
1076 }
Layout is a template generator.
$classname
Definition: Class.Doc.php:446
compareXOrder($a1, $a2)
setPropertyParameter($propName, $pName, $pValue)
$tdoc
getXValues($X)
global $action
newFreeVaultFile($dbaccess)
Definition: Lib.Util.php:17
& getAttribute($idAttr, &$oa=null, $useMask=true)
Definition: Class.Doc.php:2152
stringDateToIso($date, $format=false, $withT=false)
Definition: Lib.Util.php:246
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
getConfiguration()
print $fam getTitle() $fam name
static rawValueToArray($v)
Definition: Class.Doc.php:6228
Exception class use exceptionCode to identifiy correctly exception.
Definition: exceptions.php:19
refreshPhpPgDoc($dbaccess, $docid)
Definition: Lib.Attr.php:18
getParameterFamilyRawValue($idp, $def)
getFamilyDocument()
Definition: Class.Doc.php:1482
canEdit($verifyDomain=true)
Definition: Class.Doc.php:1364
$filename
getParamTValue($idAttr, $def="", $index=-1)
saveVaultFile($vid, $stream)
resetPropertiesParameters()
getParamAttributes()
Definition: Class.Doc.php:2515
getDefValue($idp, $def="")
if($dbaccess=="") $dvi
static getError($code, $args=null)
Definition: ErrorCode.php:27
isAffected()
getLocaleConfig($core_lang= '')
Definition: Lib.Common.php:853
$d
Definition: dav.php:77
viewfamcard($target="_self", $ulink=true, $abstract=false)
getFamilyParameterValue($idp, $def="")
Definition: Class.Doc.php:1538
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
savePoint($point)
setChanged()
Definition: Class.Doc.php:844
applyMethod($method, $def="", $index=-1, array $bargs=array(), array $mapArgs=array(), &$err= '')
Definition: Class.Doc.php:4511
getLayoutFile($app, $layfile)
Definition: Lib.Common.php:258
setXValue($X, $idp, $val)
static getParameterClassMap($key=null)
Definition: CheckProp.php:109
$views
Definition: Class.Doc.php:416
__construct($dbaccess= '', $id= '', $res= '', $dbid=0, $include=true)
$title
Definition: Class.Doc.php:346
getXValue($X, $idp, $def="")
$fromid
Definition: Class.Doc.php:366
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
if($updateExistingTable) $point
Definition: updateclass.php:88
getOwnParams()
getTitle($id="-1", $def="", $latest=false)
Definition: Class.Doc.php:8715
getHtmlValue($oattr, $value, $target="_self", $htmllink=true, $index=-1, $entities=true, $abstract=false)
Definition: Class.Doc.php:6457
postImport(array $extra=array())
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
deprecatedFunction($msg= '')
Definition: Lib.Common.php:86
getOwnDefValues()
if($dbaccess=="") $o
getCustomTitle()
new_Doc($dbaccess, $id= '', $latest=false)
$values
Definition: Class.Doc.php:546
postAffect(array $data, $more, $reset)
commitPoint($point)
& getAttributes($useMask=true)
Definition: Class.Doc.php:2174
static getLangTitle($values)
getExtraSearchableDisplayValues($withLocale=true)
static arrayToRawValue($v, $br= '< BR >')
Definition: Class.Doc.php:6252
$vf
Definition: geticon.php:28
viewDefaultValues($target="_self", $ulink=true, $abstract=false)
$info
Definition: geticon.php:30
setDefValue($idp, $val, $check=true)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
getPropertyParameter($propName, $pName)
if($file) if($subject==""&&$file) if($subject=="") $err
$class
Definition: updateclass.php:38
getDefValues()
setParam($idp, $val, $check=true)
getParamValue($idp, $def="")
UpdateVaultIndex()
$value
controlUserId($docid, $uid, $aclname)
control($aclname, $strict=false)
Definition: Class.Doc.php:6593
getSortProperties()
getParameterRawValue($idp, $def="")
preDocDelete()
updateVaultIndex()
Definition: Class.Doc.php:9024
$data
getGen($dbaccess)
Definition: Lib.Util.php:27
← centre documentaire © anakeen