Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.FormatCollection.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Document list class
8  *
9  * @author Anakeen
10  * @version $Id: $
11  * @package FDL
12  */
13 /**
14  * Format document list to be easily used in
15  * @class FormatCollection
16  * @code
17  * $s = new \SearchDoc(self::$dbaccess, $this->famName);
18  $s->setObjectReturn();
19  $dl = $s->search()->getDocumentList();
20  $fc = new \FormatCollection();
21  $fc->useCollection($dl);
22  $fc->addProperty($fc::propName);
23  $fc->addAttribute(('tst_x'));
24  $fc->setNc($nc);
25  $r = $fc->render();
26  * @endcode
27  */
29 {
30  const noAccessText = "N.C.";
31  /*
32  * @var DocumentList $dl
33  */
34  protected $dl = null;
35  public $debug = array();
36  protected $propsKeys = array();
37  protected $fmtProps = array(
38  self::propId,
39  self::title
40  );
41  protected $fmtAttrs = array();
42  protected $ncAttribute = '';
43 
44  protected $noAccessText = self::noAccessText;
45  /**
46  * @var int family icon size in pixel
47  */
48  public $familyIconSize = 24;
49  /**
50  * @var int relation icon size in pixel
51  */
52  public $relationIconSize = 14;
53  /**
54  * @var int mime type icon size in pixel
55  */
56  public $mimeTypeIconSize = 14;
57  /**
58  * @var int thumbnail width in pixel
59  */
60  public $imageThumbnailSize = 48;
61  /**
62  * @var string text in case of no access in relation target
63  */
64  public $relationNoAccessText = "";
65  /**
66  * @var bool if true set showempty option in displayValue when value is empty
67  */
68  public $useShowEmptyOption = true;
69 
70  protected $attributeGrants = array();
71 
72  protected $decimalSeparator = ',';
73 
75 
76  protected $propDateStyle = null;
77 
78  protected $stripHtmlTag = false;
79 
80  protected $longtextMultipleBrToCr = "\n";
81  /**
82  * Verify attribute visibility "I"
83  * @var bool
84  */
85  protected $verifyAttributeAccess = true;
86  /**
87  * @var closure
88  */
89  protected $hookStatus = null;
90  /**
91  * @var bool
92  */
93  protected $singleDocument = false;
94  /**
95  * @var closure
96  */
97  protected $renderAttributeHook = null;
98  /**
99  * @var closure
100  */
101  protected $renderDocumentHook = null;
102  /**
103  * @var closure
104  */
105  protected $renderPropertyHook = null;
106 
107  const title = "title";
108  /**
109  * name property
110  */
111  const propName = "name";
112  /**
113  * id property
114  */
115  const propId = "id";
116  /**
117  * icon property
118  */
119  const propIcon = "icon";
120  /**
121  * locked property
122  */
123  const propLocked = "locked";
124  /**
125  * initid property
126  */
127  const propInitid = "initid";
128  /**
129  * revision property
130  */
131  const propRevision = "revision";
132  /**
133  * url access to document
134  */
135  const propUrl = "url";
136  /**
137  * family information
138  */
139  const propFamily = "family";
140  /**
141  * Last access date
142  */
143  const propLastAccessDate = "lastAccessDate";
144  /**
145  * Last modification date
146  */
147  const propLastModificationDate = "lastModificationDate";
148  /**
149  * Some informations about revision
150  */
151  const propRevisionData = "revisionData";
152  /**
153  * View Controller information
154  */
155  const propViewController = "viewController";
156  /**
157  * Workflow information
158  */
159  const propWorkflow = "workflow";
160  /**
161  * allocated information
162  */
163  const propAffected = "affected";
164  /**
165  * status information : alive, deleted, fixed
166  */
167  const propStatus = "status";
168  /**
169  * note information
170  */
171  const propNote = "note";
172  /**
173  * usefor information
174  */
175  const propUsage = "usage";
176  /**
177  * doctype information
178  */
179  const propType = "type";
180  /**
181  * Applictaion Tags list
182  * @see \Doc::addAtag()
183  */
184  const propTags = "tags";
185  /**
186  * Security information (lock, profil)
187  */
188  const propSecurity = "security";
189  /**
190  * Creation date (of revision 0)
191  */
192  const propCreationDate = "creationDate";
193  /**
194  * Creation user (of revision 0)
195  */
196  const propCreatedBy = "createdBy";
197  /**
198  * state property
199  */
200  const propState = "state";
201  /**
202  * revision date
203  */
204  const revdate = "revdate";
205  /**
206  * access date
207  */
208  const adate = "adate";
209  /**
210  * creation date
211  */
212  const cdate = "cdate";
213 
214  public function __construct($doc = null)
215  {
216  $this->propsKeys = self::getAvailableProperties();
217  if ($doc !== null) {
218  $this->dl = array(
219  $doc
220  );
221  $this->singleDocument = true;
222  }
223  }
224 
225  public static function getAvailableProperties()
226  {
227  $keys = array_keys(Doc::$infofields);
228  $keys[] = self::propFamily;
229  $keys[] = self::propLastAccessDate;
230  $keys[] = self::propLastModificationDate;
231  $keys[] = self::propCreationDate;
232  $keys[] = self::propCreatedBy;
233  $keys[] = self::propRevisionData;
234  $keys[] = self::propViewController;
235  $keys[] = self::propWorkflow;
236  $keys[] = self::propTags;
237  $keys[] = self::propSecurity;
238  $keys[] = self::propAffected;
239  $keys[] = self::propStatus;
240  $keys[] = self::propNote;
241  $keys[] = self::propUsage;
242  $keys[] = self::propType;
243  return $keys;
244  }
245  /**
246  * @param string $propDateStyle
247  * @return $this
248  * @throws \Dcp\Fmtc\Exception
249  */
251  {
252  if (!in_array($propDateStyle, array(
257  ))) {
258  throw new \Dcp\Fmtc\Exception("FMTC0003", $propDateStyle);
259  }
260  $this->propDateStyle = $propDateStyle;
261  return $this;
262  }
263  /**
264  * If false, attribute with "I" visibility are returned
265  * @param boolean $verifyAttributeAccess
266  */
268  {
269  $this->verifyAttributeAccess = $verifyAttributeAccess;
270  }
271  /**
272  * Use when cannot access attribut value
273  * Due to visibility "I"
274  * @param string $noAccessText
275  */
277  {
278  $this->noAccessText = $noAccessText;
279  }
280  /**
281  * default value returned when attribute not found in document
282  * @param $s
283  * @return \FormatCollection
284  */
285  public function setNc($s)
286  {
287  $this->ncAttribute = $s;
288  return $this;
289  }
290  /**
291  * document list to format
292  * @param DocumentList $l
293  * @return FormatCollection
294  */
295  public function useCollection(DocumentList & $l)
296  {
297  $this->dl = $l;
298  return $this;
299  }
300  /**
301  * set decimal character character to use for double and money type
302  * @param string $s a character to separate decimal part from integer part
303  * @return FormatCollection
304  */
305  public function setDecimalSeparator($s)
306  {
307  $this->decimalSeparator = $s;
308  return $this;
309  }
310  /**
311  * display Value of htmltext content value without tags
312  * @param bool $strip
313  * @return FormatCollection
314  */
315  public function stripHtmlTags($strip = true)
316  {
317  $this->stripHtmlTag = $strip;
318  return $this;
319  }
320  /**
321  * set date style
322  * possible values are :DateAttributeValue::defaultStyle,DateAttributeValue::frenchStyle,DateAttributeValue::isoWTStyle,DateAttributeValue::isoStyle
323  * @param string $style
324  * @return $this
325  * @throws Dcp\Fmtc\Exception
326  */
327  public function setDateStyle($style)
328  {
329  if (!in_array($style, array(
334  ))) {
335  throw new \Dcp\Fmtc\Exception("FMTC0003", $style);
336  }
337  $this->dateStyle = $style;
338  return $this;
339  }
340  /**
341  * add a property to render
342  * by default id and title are rendered
343  * @param string $props
344  * @throws \Dcp\Fmtc\Exception
345  * @return FormatCollection
346  */
347  public function addProperty($props)
348  {
349  if ((!in_array($props, $this->propsKeys) && ($props != self::propUrl))) {
350  throw new \Dcp\Fmtc\Exception("FMTC0001", $props);
351  }
352  $this->fmtProps[$props] = $props;
353  return $this;
354  }
355  /**
356  * add an attribute to render
357  * by default no attributes are rendered
358  * @param string $attrid
359  * @return FormatCollection
360  */
361  public function addAttribute($attrid)
362  {
363 
364  $this->fmtAttrs[$attrid] = $attrid;
365  return $this;
366  }
367  /**
368  * apply a callback on each document
369  * if callback return false, the document is skipped from list
370  * @param Closure $hookFunction
371  * @return $this
372  */
373  public function setHookAdvancedStatus($hookFunction)
374  {
375  $this->hookStatus = $hookFunction;
376  return $this;
377  }
378  /**
379  * apply a callback on each returned value
380  * to modify render
381  * @param Closure $hookFunction
382  * @return $this
383  */
384  public function setAttributeRenderHook($hookFunction)
385  {
386  $this->renderAttributeHook = $hookFunction;
387  return $this;
388  }
389  /**
390  * apply a callback on each document returned
391  * to modify render
392  * @param Closure $hookFunction
393  * @return $this
394  */
395  public function setDocumentRenderHook($hookFunction)
396  {
397  $this->renderDocumentHook = $hookFunction;
398  return $this;
399  }
400  /**
401  * apply a callback on each returned property
402  * to modify render value
403  * @param Closure $hookFunction
404  * @return $this
405  */
406  public function setPropertyRenderHook($hookFunction)
407  {
408  $this->renderPropertyHook = $hookFunction;
409  return $this;
410  }
411  protected function callHookStatus($s)
412  {
413  if ($this->hookStatus) {
414  // call_user_func($function, $this->currentDoc);
415  $h = $this->hookStatus;
416  return $h($s);
417  }
418  return true;
419  }
420  /**
421  * @param StandardAttributeValue|null $info
422  * @param BasicAttribute|null $oa
423  * @param Doc $doc
424  * @return StandardAttributeValue
425  */
426  protected function callAttributeRenderHook($info, $oa, \Doc $doc)
427  {
428  if ($this->renderAttributeHook) {
430  return $h($info, $oa, $doc);
431  }
432  return $info;
433  }
434  /**
435  * @param array $info
436  * @param Doc $doc
437  * @return StandardAttributeValue
438  */
439  protected function callDocumentRenderHook(array $info, \Doc $doc)
440  {
441  if ($this->renderDocumentHook) {
443  return $h($info, $doc);
444  }
445  return $info;
446  }
447  /**
448  * @param StandardAttributeValue|string|null $info
449  * @param string $propId
450  * @param Doc $doc
451  * @return StandardAttributeValue
452  */
453  protected function callPropertyRenderHook($info, $propId, \Doc $doc)
454  {
455  if ($this->renderPropertyHook) {
457  return $h($info, $propId, $doc);
458  }
459  return $info;
460  }
461  /**
462  * return formatted document list to be easily exported in other format
463  * @throws \Dcp\Fmtc\Exception
464  * @return array
465  */
466  public function render()
467  {
468  /*
469  * @var Doc $doc
470  */
471  $r = array();
472  $kdoc = 0;
473  $countDoc = count($this->dl);
475  foreach ($this->dl as $docid => $doc) {
476  if ($kdoc % 10 == 0) $this->callHookStatus(sprintf(_("Doc Render %d/%d") , $kdoc, $countDoc));
477  $renderDoc = array();
478  foreach ($this->fmtProps as $propName) {
479  $renderDoc["properties"][$propName] = $this->callPropertyRenderHook($this->getPropInfo($propName, $doc) , $propName, $doc);
480  }
481 
482  foreach ($this->fmtAttrs as $attrid) {
483  $oa = $doc->getAttribute($attrid);
484  if ($oa) {
485  if (($oa->type == "array") || ($oa->type == "tab") || ($oa->type == "frame")) throw new \Dcp\Fmtc\Exception("FMTC0002", $attrid);
486 
487  $value = $doc->getRawValue($oa->id);
488  if ($value === '') {
489  if ($this->verifyAttributeAccess === true && !\Dcp\VerifyAttributeAccess::isAttributeAccessGranted($doc, $oa)) {
490  $attributeInfo = new noAccessAttributeValue($this->noAccessText);
491  } else {
492  if ($this->useShowEmptyOption && $empty = $oa->getOption("showempty")) {
493  $attributeInfo = new StandardAttributeValue($oa, null);
494  $attributeInfo->displayValue = $empty;
495  } else {
496  $attributeInfo = null;
497  }
498  }
499  } else {
500  $attributeInfo = $this->getInfo($oa, $value, $doc);
501  }
502  $renderDoc["attributes"][$oa->id] = $this->callAttributeRenderHook($attributeInfo, $oa, $doc);
503  } else {
504  $renderDoc["attributes"][$attrid] = $this->callAttributeRenderHook(new UnknowAttributeValue($this->ncAttribute) , null, $doc);
505  }
506  }
507 
508  $r[$kdoc] = $this->callDocumentRenderHook($renderDoc, $doc);
509 
510  $kdoc++;
511  }
512  return $r;
513  }
514  protected function getPropInfo($propName, Doc $doc)
515  {
516  switch ($propName) {
517  case self::title:
518  return $doc->getTitle();
519  case self::propIcon:
520  return $doc->getIcon('', $this->familyIconSize);
521  case self::propId:
522  return intval($doc->id);
523  case self::propInitid:
524  return intval($doc->initid);
525  case self::propRevision:
526  return intval($doc->revision);
527  case self::propLocked:
528  return intval($doc->locked);
529  case self::propState:
530  return $this->getState($doc);
531  case self::propUrl:
532  return sprintf("?app=FDL&amp;action=OPENDOC&amp;mode=view&amp;id=%d", $doc->id);
533  case self::revdate:
534  return $this->getFormatDate(date("Y-m-d H:i:s", intval($doc->$propName)) , $this->propDateStyle);
535  case self::cdate:
536  case self::adate:
537  return $this->getFormatDate($doc->$propName, $this->propDateStyle);
538  case self::propFamily:
539  return $this->getFamilyInfo($doc);
540  case self::propLastAccessDate:
541  return $this->getFormatDate($doc->adate, $this->propDateStyle);
542  case self::propLastModificationDate:
543  return $this->getFormatDate(date("Y-m-d H:i:s", $doc->revdate) , $this->propDateStyle);
544  case self::propCreationDate:
545  if ($doc->revision == 0) {
546  return $this->getFormatDate($doc->cdate, $this->propDateStyle);
547  } else {
548  $sql = sprintf("select cdate from docread where initid=%d and revision = 0", $doc->initid);
549  simpleQuery($doc->dbaccess, $sql, $cdate, true, true);
550  return $this->getFormatDate($cdate, $this->propDateStyle);
551  }
552  case self::propCreatedBy:
553  return $this->getCreatedByData($doc);
554  case self::propRevisionData:
555  return $this->getRevisionData($doc);
556  case self::propViewController:
557  return $this->getViewControllerData($doc);
558  case self::propWorkflow:
559  return $this->getWorkflowData($doc);
560  case self::propTags:
561  return $this->getApplicationTagsData($doc);
562  case self::propSecurity:
563  return $this->getSecurityData($doc);
564  case self::propAffected:
565  return $this->getAllocatedData($doc);
566  case self::propStatus:
567  return $this->getStatusData($doc);
568  case self::propNote:
569  return $this->getNoteData($doc);
570  case self::propUsage:
571  return $this->getUsageData($doc);
572  case self::propType:
573  return $this->getTypeData($doc);
574  default:
575  return $doc->$propName;
576  }
577  }
578 
579  protected function getCreatedByData(\Doc $doc)
580  {
581  if ($doc->revision == 0) {
582  $ownerId = $doc->owner;
583  } else {
584  $sql = sprintf("select owner from docread where initid=%d and revision = 0", $doc->initid);
585  simpleQuery($doc->dbaccess, $sql, $ownerId, true, true);
586  }
587  return $this->getAccountData(abs($ownerId) , $doc);
588  }
589 
590  protected function getStatusData(\Doc $doc)
591  {
592  if ($doc->doctype == "Z") {
593  return "deleted";
594  } elseif ($doc->locked == - 1) {
595  return "fixed";
596  } else {
597  return "alive";
598  }
599  }
600 
601  protected function getUsageData(\Doc $doc)
602  {
603  if (strstr($doc->usefor, "S")) {
604  return "system";
605  } else {
606  return "normal";
607  }
608  }
609  protected function getTypeData(\Doc $doc)
610  {
611  switch ($doc->defDoctype) {
612  case 'F':
613  return "document";
614  case 'D':
615  return "folder";
616  case "S":
617  return "search";
618  case "C":
619  return "family";
620  case "P":
621  return "profil";
622  case "W":
623  return "workflow";
624  default:
625  return $doc->defDoctype;
626  }
627  }
628 
629  protected function getNoteData(\Doc $doc)
630  {
631  if ($doc->postitid > 0) {
632  $note = new_doc($doc->dbaccess, $doc->postitid);
633  return array(
634  "id" => intval($note->initid) ,
635  "title" => $note->getTitle() ,
636  "icon" => $note->getIcon("", $this->familyIconSize)
637  );
638  } else {
639  return array(
640  "id" => 0,
641  "title" => ""
642  );
643  }
644  }
645  protected function getWorkflowData(\Doc $doc)
646  {
647  if ($doc->wid > 0) {
648  $workflow = new_doc($doc->dbaccess, $doc->wid);
649  return array(
650  "id" => intval($workflow->initid) ,
651  "title" => $workflow->getTitle() ,
652  "icon" => $workflow->getIcon("", $this->familyIconSize)
653  );
654  } else {
655  return array(
656  "id" => 0,
657  "title" => ""
658  );
659  }
660  }
661  protected function getApplicationTagsData(\Doc $doc)
662  {
663  if ($doc->atags) {
664  return explode("\n", $doc->atags);
665  } else {
666  return array();
667  }
668  }
669 
670  protected function getAllocatedData(\Doc $doc)
671  {
672  if ($doc->allocated > 0) {
673  return $this->getAccountData($doc->allocated, $doc);
674  } else {
675  return array(
676  "id" => 0,
677  "title" => ""
678  );
679  }
680  }
681 
682  protected function getAccountData($accountId, \Doc $doc)
683  {
684  $sql = sprintf("select initid, icon, title from doc128 where us_whatid='%d' and locked != -1", $accountId);
685  simpleQuery("", $sql, $result, false, true);
686  if ($result) {
687  return array(
688  "id" => intval($result["initid"]) ,
689  "title" => $result["title"],
690  "icon" => $doc->getIcon($result["icon"], $this->familyIconSize)
691  );
692  } else {
693  return array(
694  "id" => 0,
695  "title" => "",
696  "icon" => ""
697  );
698  }
699  }
700  protected function getSecurityData(\Doc $doc)
701  {
702  $info = array();
703  if ($doc->locked) {
704  if ($doc->locked == - 1) {
705  $info["lock"] = array(
706  "id" => - 1,
707  "temporary" => false
708  );
709  } else {
710  $info["lock"] = array(
711  "lockedBy" => $this->getAccountData(abs($doc->locked) , $doc) ,
712  "temporary" => ($doc->locked < - 1)
713  );
714  }
715  } else {
716  $info["lock"] = array(
717  "id" => 0
718  );
719  }
720  $info["readOnly"] = ($doc->canEdit() != "");
721  $info["fixed"] = ($doc->locked == - 1);
722  if ($doc->profid != 0) {
723 
724  if ($doc->profid == $doc->id) {
725  $info["profil"] = array(
726  "id" => intval($doc->initid) ,
727  "icon" => $doc->getIcon("", $this->familyIconSize) ,
728  "private" => true,
729  "activated" => true,
730  "type" => "private",
731  "title" => $doc->getTitle()
732  );
733  if ($doc->dprofid > 0) {
734  $profil = new_doc($doc->dbaccess, $doc->dprofid);
735  $info["profil"]["reference"] = array(
736  "id" => intval($profil->initid) ,
737  "icon" => $profil->getIcon("", $this->familyIconSize) ,
738  "activated" => ($profil->id == $profil->profid) ,
739  "title" => $profil->getTitle()
740  );
741  $info["profil"]["type"] = "dynamic";
742  }
743  } else {
744  $profil = new_doc($doc->dbaccess, abs($doc->profid));
745  $info["profil"] = array(
746  "id" => intval($profil->initid) ,
747  "icon" => $profil->getIcon("", $this->familyIconSize) ,
748  "type" => "linked",
749  "activated" => ($profil->id == $profil->profid) ,
750  "title" => $profil->getTitle()
751  );
752  }
753  } else {
754  $info["profil"] = array(
755  "id" => 0,
756  "title" => ""
757  );
758  }
759 
760  $info["confidentiality"] = ($doc->confidential > 0) ? "private" : "public";
761  return $info;
762  }
763 
764  protected function getViewControllerData(\Doc $doc)
765  {
766  if ($doc->cvid > 0) {
767  $cv = new_doc($doc->dbaccess, $doc->cvid);
768  return array(
769  "id" => intval($cv->initid) ,
770 
771  "title" => $cv->getTitle() ,
772  "icon" => $cv->getIcon("", $this->familyIconSize)
773  );
774  } else {
775  return array(
776  "id" => 0,
777  "title" => ""
778  );
779  }
780  }
781  protected function getRevisionData(\Doc $doc)
782  {
783  return array(
784  "isModified" => ($doc->lmodify == "Y") ,
785  "id" => intval($doc->id) ,
786  "number" => intval($doc->revision) ,
787  "createdBy" => $this->getAccountData(abs($doc->owner) , $doc)
788  );
789  }
790 
791  protected function getFamilyInfo(\Doc $doc)
792  {
793  $family = $doc->getFamilyDocument();
794  return array(
795  "title" => $family->getTitle() ,
796  "name" => $family->name,
797  "id" => intval($family->id) ,
798  "icon" => $family->getIcon("", $this->familyIconSize)
799  );
800  }
801  protected function getFormatDate($v, $dateStyle = '')
802  {
803  if (!$dateStyle) {
805  }
807  else if ($dateStyle === DateAttributeValue::isoStyle) return stringDateToIso($v, false, true);
808  else if ($dateStyle === DateAttributeValue::isoWTStyle) return stringDateToIso($v, false, false);
810 
811  $ldate = stringDateToLocaleDate($v, '%d/%m/%Y %H:%M');
812  if (strlen($v) < 11) return substr($ldate, 0, strlen($v));
813  else return $ldate;
814  }
815  return stringDateToLocaleDate($v);
816  }
817  protected function getState(Doc $doc)
818  {
819  $s = new StatePropertyValue();
820  if ($doc->state) {
821  $s->reference = $doc->state;
822  $s->stateLabel = _($doc->state);
823 
824  if ($doc->locked != - 1) {
825  $s->activity = $doc->getStateActivity();
826  if ($s->activity) $s->displayValue = $s->activity;
827  else $s->displayValue = $s->stateLabel;
828  } else {
829  $s->displayValue = $s->stateLabel;
830  }
831 
832  $s->color = $doc->getStateColor();
833  }
834  return $s;
835  }
836  /**
837  * delete last null values
838  * @param array $t
839  * @return array
840  */
841  protected static function rtrimNull(array $t)
842  {
843  $i = count($t) - 1;
844  for ($k = $i; $k >= 0; $k--) {
845  if ($t[$k] === null) unset($t[$k]);
846  else break;
847  }
848  return $t;
849  }
850  public function getInfo(NormalAttribute $oa, $value, $doc = null)
851  {
852  $info = null;
853  if ($oa->isMultiple()) {
854  if ($oa->isMultipleInArray()) {
855  // double level multiple
857  if (count($tv) == 1 && $tv[0] == "\t") {
858  $tv[0] = '';
859  }
860  foreach ($tv as $k => $av) {
861  if ($av !== '') {
862  if (is_array($av)) {
863  $tvv = $this->rtrimNull($av);
864  } else {
865  $tvv = explode('<BR>', $av); // second level multiple
866 
867  }
868  if (count($tvv) == 0) {
869  $info[$k] = array();
870  } else {
871  foreach ($tvv as $avv) {
872  $info[$k][] = $this->getSingleInfo($oa, $avv, $doc);
873  }
874  }
875  } else {
876  $info[$k] = array();
877  }
878  }
879  } else {
880  // single level multiple
882  if ($oa->inArray() && count($tv) == 1 && $tv[0] == "\t") {
883  $tv[0] = '';
884  }
885 
886  foreach ($tv as $k => $av) {
887  $info[] = $this->getSingleInfo($oa, $av, $doc, $k);
888  }
889  }
890 
891  return $info;
892  } else {
893 
894  return $this->getSingleInfo($oa, $value, $doc);
895  }
896  }
897 
898  protected function getSingleInfo(NormalAttribute $oa, $value, $doc = null, $index = - 1)
899  {
900  $info = null;
901 
902  if ($this->verifyAttributeAccess === true && !\Dcp\VerifyAttributeAccess::isAttributeAccessGranted($doc, $oa)) {
904  } else {
905 
906  switch ($oa->type) {
907  case 'text':
908  $info = new TextAttributeValue($oa, $value);
909  break;
910 
911  case 'longtext':
912  $info = new LongtextAttributeValue($oa, $value, $this->longtextMultipleBrToCr);
913  break;
914 
915  case 'int':
916  $info = new IntAttributeValue($oa, $value);
917  break;
918 
919  case 'money':
920  $info = new MoneyAttributeValue($oa, $value);
921  break;
922 
923  case 'double':
924  $info = new DoubleAttributeValue($oa, $value, $this->decimalSeparator);
925  break;
926 
927  case 'enum':
928  $info = new EnumAttributeValue($oa, $value);
929  break;
930 
931  case 'thesaurus':
932  $info = new ThesaurusAttributeValue($oa, $value, $doc, $this->relationIconSize, $this->relationNoAccessText);
933  break;
934 
935  case 'docid':
936  case 'account':
937  $info = new DocidAttributeValue($oa, $value, $doc, $this->relationIconSize, $this->relationNoAccessText);
938  break;
939 
940  case 'file':
941  $info = new FileAttributeValue($oa, $value, $doc, $index, $this->mimeTypeIconSize);
942  break;
943 
944  case 'image':
945  $info = new ImageAttributeValue($oa, $value, $doc, $index, $this->imageThumbnailSize);
946  break;
947 
948  case 'timestamp':
949  case 'date':
950  $info = new DateAttributeValue($oa, $value, $this->dateStyle);
951  break;
952 
953  case 'htmltext':
954  $info = new HtmltextAttributeValue($oa, $value, $this->stripHtmlTag);
955  break;
956 
957  default:
958  $info = new StandardAttributeValue($oa, $value);
959  break;
960  }
961  }
962  return $info;
963  }
964  /**
965  * @param string $longtextMultipleBrToCr
966  */
968  {
969  $this->longtextMultipleBrToCr = $longtextMultipleBrToCr;
970  }
971  /**
972  * get some stat to estimate time cost
973  * @return array
974  */
975  public function getDebug()
976  {
977  $average = $cost = $sum = array();
978  foreach ($this->debug as $type => $time) {
979  $average[$type] = sprintf("%0.3fus", array_sum($time) / count($time) * 1000000);
980  $cost[$type] = sprintf("%0.3fms", array_sum($time) * 1000);
981  $sum[$type] = sprintf("%d", count($time));
982  }
983 
984  return array(
985  "average" => $average,
986  "cost" => $cost,
987  "count" => $sum
988  );
989  }
990  /**
991  * @param array|stdClass $info
992  * @param NormalAttribute $oAttr
993  * @param int $index
994  * @param array $configuration
995  * @return string
996  */
997  public static function getDisplayValue($info, $oAttr, $index = - 1, $configuration = array())
998  {
999  $attrInArray = ($oAttr->inArray());
1000  $attrIsMultiple = ($oAttr->getOption('multiple') == 'yes');
1001  $sepRow = isset($configuration['multipleSeparator'][0]) ? $configuration['multipleSeparator'][0] : "\n";
1002  $sepMulti = isset($configuration['multipleSeparator'][1]) ? $configuration['multipleSeparator'][1] : ", ";
1003  $displayDocId = (isset($configuration['displayDocId']) && $configuration['displayDocId'] === true) && (!isset($info->visible));
1004 
1005  if (is_array($info) && $index >= 0) {
1006  $info = array(
1007  $info[$index]
1008  );
1009  }
1010  if ($displayDocId && is_array($info) && count($info) > 0) {
1011  $displayDocId = (!isset($info[0]->visible));
1012  }
1013 
1014  if (!$attrInArray) {
1015  if ($attrIsMultiple) {
1016  $multiList = array();
1017  if (empty($info)) {
1018  $info = array();
1019  }
1020  foreach ($info as $data) {
1021  $multiList[] = $displayDocId ? $data->value : $data->displayValue;
1022  }
1023  $result = join($sepMulti, $multiList);
1024  } else {
1025  $result = $displayDocId ? $info->value : $info->displayValue;
1026  }
1027  } else {
1028  $rowList = array();
1029  if ($attrIsMultiple) {
1030  if (empty($info)) {
1031  $info = array();
1032  }
1033  foreach ($info as $multiData) {
1034  $multiList = array();
1035  foreach ($multiData as $data) {
1036  $multiList[] = $displayDocId ? $data->value : $data->displayValue;
1037  }
1038  $rowList[] = join($sepMulti, $multiList);
1039  }
1040  } else {
1041  if (!is_array($info)) {
1042  $info = array(
1043  $info
1044  );
1045  }
1046  foreach ($info as $data) {
1047  $rowList[] = $displayDocId ? $data->value : $data->displayValue;
1048  }
1049  }
1050  $result = join($sepRow, $rowList);
1051  }
1052  return $result;
1053  }
1054 }
1055 
1057 {
1058  public $value;
1060  /**
1061  * @param NormalAttribute $oa
1062  * @param $v
1063  */
1064  public function __construct($oa, $v)
1065  {
1066  $this->value = ($v === '') ? null : $v;
1067  $this->displayValue = $v;
1068  }
1069 }
1071 {
1072  /**
1073  * noAccessAttributeValue constructor.
1074  * @param string $v
1075  */
1076  public function __construct($v)
1077  {
1078  $this->value = ($v === '') ? null : $v;
1079  $this->displayValue = $v;
1080  }
1081 }
1083 {
1084  public $visible = true;
1085  /**
1086  * noAccessAttributeValue constructor.
1087  * @param string $v
1088  */
1089  public function __construct($v)
1090  {
1091  $this->value = '';
1092  $this->displayValue = $v;
1093  }
1094 }
1095 
1097 {
1098  public $reference;
1099  public $color;
1100  public $activity;
1101  public $stateLabel;
1103 }
1104 
1106 {
1107  public function __construct(NormalAttribute $oa, $v)
1108  {
1109  $this->value = ($v === '') ? null : $v;
1110  if ($oa->format) $this->displayValue = sprintf($oa->format, $v);
1111  else $this->displayValue = $v;
1112  }
1113 }
1114 
1116 {
1117 }
1118 
1120 {
1121  public function __construct(NormalAttribute $oa, $v, $multipleLongtextCr = "\n")
1122  {
1123  if ($oa->inArray()) {
1124  $v = str_replace("<BR>", $multipleLongtextCr, $v);
1125  }
1126  parent::__construct($oa, $v);
1127  }
1128 }
1129 
1131 {
1132  public function __construct(NormalAttribute $oa, $v)
1133  {
1134  parent::__construct($oa, $v);
1135  $this->value = intval($v);
1136  }
1137 }
1138 
1140 {
1141  const defaultStyle = 'D';
1142  /**
1143  * ISO with T : YYYY-MM-DDTHH:MM:SS
1144  */
1145  const isoStyle = 'I';
1146  /**
1147  * ISO without T : YYYY-MM-DD HH:MM:SS
1148  */
1149  const isoWTStyle = 'U';
1150  const frenchStyle = 'F';
1151  public function __construct(NormalAttribute $oa, $v, $dateStyle = self::defaultStyle)
1152  {
1153  parent::__construct($oa, $v);
1154  if ($oa->format != "") {
1155  $this->displayValue = strftime($oa->format, stringDateToUnixTs($v));
1156  } else {
1157  if ($dateStyle === self::defaultStyle) $this->displayValue = stringDateToLocaleDate($v);
1158  else if ($dateStyle === self::isoStyle) $this->displayValue = stringDateToIso($v, false, true);
1159  else if ($dateStyle === self::isoWTStyle) $this->displayValue = stringDateToIso($v, false, false);
1160  else if ($dateStyle === self::frenchStyle) {
1161 
1162  $ldate = stringDateToLocaleDate($v, '%d/%m/%Y %H:%M');
1163  if (strlen($v) < 11) $this->displayValue = substr($ldate, 0, strlen($v));
1164  else $this->displayValue = $ldate;
1165  } else $this->displayValue = stringDateToLocaleDate($v);
1166  }
1167  }
1168 }
1169 
1171 {
1172  const defaultStyle = 'D';
1173  const isoStyle = 'I';
1174  const isoWTStyle = 'U';
1175  const frenchStyle = 'F';
1176  public function __construct(NormalAttribute $oa, $v, $stripHtmlTag = false)
1177  {
1178  parent::__construct($oa, $v);
1179  if ($stripHtmlTag) {
1180  $this->displayValue = html_entity_decode(strip_tags($this->displayValue) , ENT_NOQUOTES, 'UTF-8');
1181  }
1182  }
1183 }
1185 {
1186 
1187  public function __construct(NormalAttribute $oa, $v, $decimalSeparator = ',')
1188  {
1189  parent::__construct($oa, $v);
1190  $lang = getParam("CORE_LANG");
1191  if ($lang == "fr_FR") {
1192  if (is_array($this->displayValue)) {
1193  foreach ($this->displayValue as $k => $v) {
1194  $this->displayValue[$k] = str_replace('.', $decimalSeparator, $v);
1195  }
1196  } else {
1197  $this->displayValue = str_replace('.', $decimalSeparator, $this->displayValue);
1198  }
1199  }
1200  if (is_array($this->value)) {
1201  /** @noinspection PhpWrongForeachArgumentTypeInspection */
1202  foreach ($this->value as $k => $v) {
1203  $this->value[$k] = doubleval($v);
1204  }
1205  } else {
1206  $this->value = doubleval($this->value);
1207  }
1208  }
1209 }
1210 
1212 {
1213 
1214  public function __construct(NormalAttribute $oa, $v)
1215  {
1216  parent::__construct($oa, $v);
1217 
1218  $lang = getParam("CORE_LANG");
1219  if ($lang == "fr_FR") {
1220  }
1221  if (is_array($this->displayValue)) {
1222  foreach ($this->displayValue as $k => $dv) {
1223  $this->displayValue[$k] = money_format('%!.2n', doubleval($dv));
1224  if ($oa->format) {
1225  $this->displayValue[$k] = sprintf($oa->format, $this->displayValue[$k]);
1226  }
1227  }
1228  } else {
1229  $this->displayValue = money_format('%!.2n', doubleval($v));
1230  if ($oa->format) {
1231  $this->displayValue = sprintf($oa->format, $this->displayValue);
1232  }
1233  }
1234 
1235  if (is_array($this->value)) {
1236  /** @noinspection PhpWrongForeachArgumentTypeInspection */
1237  foreach ($this->value as $k => $v) {
1238  $this->value[$k] = doubleval($v);
1239  }
1240  } else {
1241  $this->value = doubleval($this->value);
1242  }
1243  }
1244 }
1246 {
1247  public $exists = true;
1248  public function __construct(NormalAttribute $oa, $v)
1249  {
1250  $this->value = ($v === '') ? null : $v;
1251  if ($v !== null && $v !== '') {
1252  $this->displayValue = $oa->getEnumLabel($v);
1253  $this->exists = $oa->existEnum($v, false);
1254  }
1255  }
1256 }
1257 
1259 {
1260  public $size = 0;
1261  public $creationDate = '';
1262  public $fileName = '';
1263  public $url = '';
1264  public $mime = '';
1265  public $icon = '';
1266 
1267  public function __construct(NormalAttribute $oa, $v, Doc $doc, $index, $iconMimeSize = 24)
1268  {
1269 
1270  $this->value = ($v === '') ? null : $v;
1271  if ($v) {
1272  $finfo = $doc->getFileInfo($v, "", "object");
1273  if ($finfo) {
1274  $this->size = $finfo->size;
1275  $this->creationDate = $finfo->cdate;
1276  $this->fileName = $finfo->name;
1277  $this->mime = $finfo->mime_s;
1278  $this->displayValue = $this->fileName;
1279 
1280  $iconFile = getIconMimeFile($this->mime);
1281  if ($iconFile) $this->icon = $doc->getIcon($iconFile, $iconMimeSize);
1282  $this->url = $doc->getFileLink($oa->id, $index, false, true, $v, $finfo);
1283  }
1284  }
1285  }
1286 }
1288 {
1289  public $thumbnail = '';
1290  public function __construct(NormalAttribute $oa, $v, Doc $doc, $index, $thumbnailSize = 48)
1291  {
1292  parent::__construct($oa, $v, $doc, $index);
1293  $fileLink = $doc->getFileLink($oa->id, $index, false, true, $v);
1294  if ($fileLink) {
1295  if ($thumbnailSize > 0) {
1296  $this->thumbnail = sprintf('%s&width=%d', $fileLink, $thumbnailSize);
1297  } else {
1298  $this->thumbnail = $fileLink;
1299  }
1300  } elseif ($v) {
1301  global $action;
1302  $localImage = $action->parent->getImageLink($v);
1303  if ($localImage) {
1304  $this->displayValue = basename($v);
1305  $this->url = $localImage;
1306  if ($thumbnailSize > 0) {
1307  $this->thumbnail = $action->parent->getImageLink($v, null, $thumbnailSize);
1308  } else {
1309  $this->thumbnail = $localImage;
1310  }
1311  }
1312  }
1313  }
1314 }
1316 {
1318 
1319  public $url;
1320  public $icon = null;
1321  public $revision = - 1;
1322  public $initid;
1323  public $fromid;
1324  protected $visible = true;
1325 
1326  public function __construct(NormalAttribute $oa, $v, Doc & $doc, $iconsize = 24, $relationNoAccessText = '')
1327  {
1328  $this->familyRelation = $oa->format;
1329  $this->value = ($v === '') ? null : $v;
1330  $info = array();
1331  $docRevOption = $oa->getOption("docrev", "latest");
1332  $this->displayValue = DocTitle::getRelationTitle($v, $docRevOption == "latest", $doc, $docRevOption, $info);
1333  if ($this->displayValue !== false) {
1334  if ($v !== '' && $v !== null) {
1335  if ($iconsize > 0) {
1336  if (!empty($info["icon"])) {
1337  $this->icon = $doc->getIcon($info["icon"], $iconsize, $info["initid"]);
1338  } else {
1339  $this->icon = $doc->getIcon("doc.png", $iconsize);
1340  }
1341  }
1342  $this->url = $this->getDocUrl($v, $docRevOption);
1343  if ($docRevOption === "fixed") {
1344  $this->revision = intval($info["revision"]);
1345  } else if (preg_match('/^state\(([^\)]+)\)/', $docRevOption, $matches)) {
1346  $this->revision = array(
1347  "state" => $matches[1]
1348  );
1349  }
1350  if (isset($info["initid"])) {
1351  $this->initid = intval($info["initid"]);
1352  }
1353  if (isset($info["fromid"])) {
1354  $this->fromid = intval($info["fromid"]);
1355  }
1356  }
1357  } else {
1358  $this->visible = false;
1359  if ($relationNoAccessText) $this->displayValue = $relationNoAccessText;
1360  else $this->displayValue = $oa->getOption("noaccesstext", _("information access deny"));
1361  }
1362  }
1363 
1364  protected function getDocUrl($v, $docrev)
1365  {
1366  if (!$v) return '';
1367  $ul = "?app=FDL&amp;action=OPENDOC&amp;mode=view&amp;id=" . $v;
1368 
1369  if ($docrev == "latest" || $docrev == "" || !$docrev) $ul.= "&amp;latest=Y";
1370  elseif ($docrev != "fixed") {
1371  // validate that docrev looks like state(xxx)
1372  if (preg_match('/^state\(([a-zA-Z0-9_:-]+)\)/', $docrev, $matches)) {
1373  $ul.= "&amp;state=" . $matches[1];
1374  }
1375  }
1376  return $ul;
1377  }
1378 }
1380 {
1381  static $thcDoc = null;
1382  static $thcDocTitle = array();
1383  public function __construct(NormalAttribute $oa, $v, Doc & $doc, $iconsize = 24, $relationNoAccessText = '')
1384  {
1385  parent::__construct($oa, $v, $doc, $iconsize, $relationNoAccessText);
1386  if ($this->visible) {
1387  if (isset(self::$thcDocTitle[$this->value])) {
1388  // use local cache
1389  $this->displayValue = self::$thcDocTitle[$this->value];
1390  } else {
1391  if (self::$thcDoc === null) {
1392  self::$thcDoc = createTmpDoc("", "THCONCEPT");
1393  }
1394  $rawValue = getTDoc("", $this->value);
1395  self::$thcDoc->affect($rawValue);
1396  $this->displayValue = self::$thcDoc->getTitle();
1397  // set local cache
1398  self::$thcDocTitle[$this->value] = $this->displayValue;
1399  }
1400  }
1401  }
1402 }
1403 
static $infofields
Definition: Class.Doc.php:105
getInfo(NormalAttribute $oa, $value, $doc=null)
getAccountData($accountId,\Doc $doc)
__construct(NormalAttribute $oa, $v, $decimalSeparator= ',')
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
global $action
setHookAdvancedStatus($hookFunction)
stringDateToIso($date, $format=false, $withT=false)
Definition: Lib.Util.php:246
static rawValueToArray($v)
Definition: Class.Doc.php:6228
callAttributeRenderHook($info, $oa,\Doc $doc)
stringDateToLocaleDate($fdate, $format= '')
Definition: Lib.Util.php:98
__construct(NormalAttribute $oa, $v, Doc $doc, $index, $iconMimeSize=24)
__construct(NormalAttribute $oa, $v, $stripHtmlTag=false)
getFamilyDocument()
Definition: Class.Doc.php:1482
canEdit($verifyDomain=true)
Definition: Class.Doc.php:1364
__construct(NormalAttribute $oa, $v)
getIcon($idicon="", $size=null, $otherId=null)
Definition: Class.Doc.php:5817
if($famId) $s
getEnumLabel($enumid=null, $returnDisabled=true)
$lang
Definition: lang.php:18
__construct(NormalAttribute $oa, $v, Doc &$doc, $iconsize=24, $relationNoAccessText= '')
getSingleInfo(NormalAttribute $oa, $value, $doc=null, $index=-1)
static getRelationTitle($docid, $latest=true, Doc $doc, $docrevOption="", array &$info=array())
getIconMimeFile($sysmime)
getStateColor($def="")
Definition: Class.Doc.php:5359
setNoAccessText($noAccessText)
setPropDateStyle($propDateStyle)
setLongtextMultipleBrToCr($longtextMultipleBrToCr)
__construct(NormalAttribute $oa, $v)
__construct(NormalAttribute $oa, $v, $multipleLongtextCr="\n")
$docid
Definition: cleanFamily.php:13
setAttributeRenderHook($hookFunction)
callDocumentRenderHook(array $info,\Doc $doc)
__construct(NormalAttribute $oa, $v)
getFormatDate($v, $dateStyle= '')
useCollection(DocumentList &$l)
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
revision(Action &$action)
Definition: revision.php:22
getFileLink($attrid, $index=-1, $cache=false, $inline=false, $otherValue= '', $info=null)
Definition: Class.Doc.php:6293
getPropInfo($propName, Doc $doc)
getTitle($id="-1", $def="", $latest=false)
Definition: Class.Doc.php:8715
getFileInfo($filesvalue, $key="", $returnType="array")
Definition: Class.Doc.php:8253
existEnum($key, $completeKey=true)
__construct(NormalAttribute $oa, $v)
static rtrimNull(array $t)
setVerifyAttributeAccess($verifyAttributeAccess)
stringDateToUnixTs($isodate, $utc=false)
Definition: Lib.Util.php:217
__construct(NormalAttribute $oa, $v, Doc $doc, $index, $thumbnailSize=48)
static getDisplayValue($info, $oAttr, $index=-1, $configuration=array())
$info
Definition: geticon.php:30
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
getStateActivity($def="")
Definition: Class.Doc.php:5383
__construct(NormalAttribute $oa, $v, Doc &$doc, $iconsize=24, $relationNoAccessText= '')
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
callPropertyRenderHook($info, $propId,\Doc $doc)
setDocumentRenderHook($hookFunction)
setPropertyRenderHook($hookFunction)
$value
getOption($x, $def="")
__construct(NormalAttribute $oa, $v, $dateStyle=self::defaultStyle)
$data
← centre documentaire © anakeen