Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Report.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * document to present a report on one family document
8  */
9 namespace Dcp\Core;
10 
11 use \Dcp\AttributeIdentifiers\Report as MyAttributes;
13 {
14 
15  public $defaultedit = "FREEDOM:EDITREPORT";
16  public $defaultview = "FREEDOM:VIEWREPORT";
17 
18  public $cviews = array(
19  "FREEDOM:VIEWREPORT",
20  "FREEDOM:VIEWMINIREPORT:T"
21  );
22  public $eviews = array(
23  "FREEDOM:EDITREPORT"
24  );
25 
26  protected $attributeGrants = array();
27  /**
28  * public because use in RSS
29  *
30  */
31  public function _getInternals()
32  {
33  return array(
34  "title" => _("doctitle") ,
35  "revdate" => _("revdate") ,
36  "id" => _("document id") ,
37  "revision" => _("revision") ,
38  "state" => _("step") ,
39  "owner" => _("owner")
40  );
41  }
42  /**
43  * Compute the values fo the edit display
44  * @templateController
45  *
46  */
47  public function editreport()
48  {
49  global $action;
50  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/selectbox.js");
51  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FREEDOM/Layout/editreport.js");
52 
53  $rfamid = GetHttpVars("sfamid", $this->getRawValue("SE_FAMID", 1));
54  $rdoc = createDoc($this->dbaccess, $rfamid, false);
55  if ($rdoc === false) {
56  $rdoc = new_Doc('');
57  }
58  $lattr = $rdoc->GetNormalAttributes();
59  $tcolumn1 = array();
60  $tcolumn2 = array();
61  /**
62  * @var \NormalAttribute $v
63  */
64  foreach ($lattr as $k => $v) {
65  // if ($v->visibility=="H") continue;
66  $tcolumn1[$v->id] = array(
67  "aid" => $v->id,
68  "alabel" => $v->getLabel()
69  );
70  }
71  $tinternals = $this->_getInternals();
72  // reconstruct internals for layout
73  reset($tinternals);
74  foreach ($tinternals as $k => $v) {
75  $tinternals[$k] = array(
76  "aid" => $k,
77  "alabel" => $v
78  );
79  }
80  // display selected column
81  $tcols = $this->getMultipleRawValues("REP_IDCOLS");
82 
83  foreach ($tcols as $k => $vx) {
84  if (isset($tcolumn1[$vx])) {
85  $tcolumn2[$vx] = $tcolumn1[$vx];
86  unset($tcolumn1[$vx]);
87  }
88  if (isset($tinternals[$vx])) {
89  $tcolumn2[$vx] = $tinternals[$vx];
90  unset($tinternals[$vx]);
91  }
92  }
93 
94  $this->lay->setBlockData("COLUMN1", $tcolumn1);
95  $this->lay->setBlockData("INTERNALS", $tinternals);
96 
97  $this->lay->setBlockData("COLUMN2", $tcolumn2);
98  }
99  /**
100  * Secondary view to choose columns
101  * @templateController
102  */
103  public function reportchoosecolumns($target = "_self", $ulink = true, $abstract = false)
104  {
105  global $action;
106 
107  $action->parent->addJsRef("lib/jquery/jquery.js");
108 
109  $doc = new_doc($this->dbaccess, $this->getRawValue(MyAttributes::se_famid));
110  $toa = $doc->getNormalAttributes();
111  $tattr = array();
112 
113  $colums = getReportColumns($this->dbaccess, $doc->id);
114 
115  $proFrame = new \FieldSetAttribute("_prop", $doc->id, _("Document Properties"));
116  $proAttr = array();
117  foreach ($colums as $k => $col) {
118  $colId = $col[1];
119  if (isset(\Doc::$infofields[$colId])) {
120  $proAttr[$colId] = new \NormalAttribute($colId, $doc->id, _(\Doc::$infofields[$colId]["label"]) , "text", "", false, $k, "", "R", false, false, false, $proFrame, "", "", "");
121  }
122  }
123  $toa = array_merge($proAttr, $toa);
124  $relTypes = array(
125  "docid",
126  "account",
127  "thesaurus"
128  );
129 
130  $currentArray = '';
131  $currentTab = '';
132  $currentFrame = '';
133  $currentStruct = '';
134 
135  $structArray = '';
136  $structTab = '';
137  $structFrame = '';
138  /**
139  * @var \NormalAttribute $oa
140  */
141  foreach ($toa as $oa) {
142 
143  if ($oa->type == "array") continue;
144 
145  $struct = $oa->fieldSet->id;
146 
147  $structTab = $structFrame = $structArray = '';
148  if ($struct) {
149  $soa = $doc->getAttribute($struct);
150  if ($struct == '_prop') {
151  $soa = $proFrame;
152  }
153  $structArray = $structFrame = $structTab = '';
154  if ($soa->type == "array") {
155  $structArray = $soa->id;
156  } else if ($soa->type == "frame") {
157  $structFrame = $soa->id;
158  }
159  if (isset($soa->fieldSet) && $soa->fieldSet->id != \Adoc::HIDDENFIELD) {
160  if ($soa->fieldSet->type == "tab") {
161  $structTab = $soa->fieldSet->id;
162  }
163  if ($soa->fieldSet->type == "frame") {
164  $structFrame = $soa->fieldSet->id;
165  if (isset($soa->fieldSet->fieldSet) && $soa->fieldSet->fieldSet->type == "tab") {
166  $structTab = $soa->fieldSet->fieldSet->id;
167  }
168  }
169  }
170  }
171  if ($currentStruct) {
172  $soa = $doc->getAttribute($currentStruct);
173  if ($currentStruct == '_prop') {
174  $soa = $proFrame;
175  }
176  $currentArray = $currentFrame = $currentTab = '';
177  if ($soa->type == "array") {
178  $currentArray = $soa->id;
179  } else if ($soa->type == "frame") {
180  $currentFrame = $soa->id;
181  }
182  if (isset($soa->fieldSet) && $soa->fieldSet->id != \Adoc::HIDDENFIELD) {
183  if ($soa->fieldSet->type == "tab") {
184  $currentTab = $soa->fieldSet->id;
185  }
186  if ($soa->fieldSet->type == "frame") {
187  $currentFrame = $soa->fieldSet->id;
188  if (isset($soa->fieldSet->fieldSet) && $soa->fieldSet->fieldSet->type == "tab") {
189  $currentTab = $soa->fieldSet->fieldSet->id;
190  }
191  }
192  }
193  }
194  if ($struct) {
195  if ($structArray != $currentArray && $currentArray) {
196  $tattr[] = $this->getColumnBlockItem($doc, $currentArray, false);
197  }
198  if ($structFrame != $currentFrame && $currentFrame) {
199  $tattr[] = $this->getColumnBlockItem($doc, $currentFrame, false);
200  }
201  if ($structTab != $currentTab && $currentTab) {
202  $tattr[] = $this->getColumnBlockItem($doc, $currentTab, false);
203  }
204  if ($structTab != $currentTab && $structTab) {
205 
206  $tattr[] = $this->getColumnBlockItem($doc, $structTab, true);
207  }
208  if ($structFrame != $currentFrame && $structFrame) {
209  $tattr[] = $this->getColumnBlockItem($doc, $structFrame, true);
210  }
211  if ($structArray != $currentArray && $structArray) {
212  $tattr[] = $this->getColumnBlockItem($doc, $structArray, true);
213  }
214  $tattr[] = array(
215  "attrid" => $oa->id,
216  "doption" => '',
217  "newframe" => false,
218  "newtab" => false,
219  "newarray" => false,
220  "endframe" => false,
221  "goodattr" => true,
222  "endtab" => false,
223  "endarray" => false,
224  "need" => $oa->needed,
225  "hidden" => $oa->visibility == 'H',
226  "attrname" => htmlspecialchars($oa->getLabel())
227  );
228  if (in_array($oa->type, $relTypes)) {
229  $tattr[] = array(
230  "attrid" => $oa->id,
231  "doption" => 'docid',
232  "newframe" => false,
233  "newtab" => false,
234  "newarray" => false,
235  "endframe" => false,
236  "goodattr" => true,
237  "endtab" => false,
238  "endarray" => false,
239  "need" => $oa->needed,
240  "hidden" => $oa->visibility == 'H',
241  "attrname" => htmlspecialchars($oa->getLabel()) . '<i> (' . _("report:docid") . ')</i>'
242  );
243  }
244  }
245 
246  $currentStruct = $struct;
247  }
248 
249  if ($structArray) {
250  $tattr[] = $this->getColumnBlockItem($doc, $structArray, false);
251  }
252  if ($structFrame) {
253  $tattr[] = $this->getColumnBlockItem($doc, $structFrame, false);
254  }
255  if ($structTab) {
256  $tattr[] = $this->getColumnBlockItem($doc, $structTab, false);
257  }
258 
259  $this->lay->setBlockData("ATTRS", $tattr);
260  $this->lay->set("famid", $doc->id);
261  $this->lay->set("famtitle", $doc->getHtmlTitle());
262  $this->lay->set("famicon", $doc->getIcon("", 48));
263  }
264 
265  protected function getColumnBlockItem(\Doc & $doc, $attrid, $isNew)
266  {
267  /**
268  * @var \NormalAttribute $soa
269  */
270  $soa = $doc->getAttribute($attrid);
271  if ($attrid == "_prop") {
272  $soa = new \FieldSetAttribute("_prop", $doc->id, _("Document Properties"));
273  }
274  return array(
275  "attrid" => $soa->id,
276  "goodattr" => false,
277  "doption" => '',
278  "newframe" => $isNew && $soa->type == "frame",
279  "newtab" => $isNew && $soa->type == "tab",
280  "newarray" => $isNew && $soa->type == "array",
281  "endframe" => (!$isNew) && $soa->type == "frame",
282  "endtab" => (!$isNew) && $soa->type == "tab",
283  "endarray" => (!$isNew) && $soa->type == "array",
284  "need" => isset($soa->needed) && $soa->needed,
285  "hidden" => $soa->visibility == 'H',
286  "selected" => false,
287  "attrname" => $soa->getLabel()
288  );
289  }
290  /**
291  * Compute the values for the view display
292  * @templateController
293  *
294  * @param string $target window target name for hyperlink destination
295  * @param bool $ulink if false hyperlink are not generated
296  * @param bool $abstract if true only abstract attribute are generated
297  */
298  public function viewreport($target = "_self", $ulink = true, $abstract = false)
299  {
300  global $action;
301  $this->viewattr($target, $ulink, $abstract);
302  $this->viewprop($target, $ulink, $abstract);
303  $action->parent->AddCssRef("FREEDOM:viewreport.css", true);
304  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FREEDOM/Layout/sorttable.js");
305  // --------------------------
306  // display headers column
307  $rfamid = $this->getRawValue("SE_FAMID", 1);
308  $rdoc = createDoc($this->dbaccess, $rfamid, false);
309  if ($rdoc === false) {
310  $err = sprintf(_('Family [%s] not found') , $rfamid);
311  $this->lay->template = htmlspecialchars($err, ENT_QUOTES);
312  $this->lay->noparse = true;
313  return $err;
314  }
315  $lattr = $rdoc->GetNormalAttributes();
316  $tcolumn1 = array();
317  $tcolumn2 = array();
318  foreach ($lattr as $k => $v) {
319  // if ($v->visibility=="H") continue;
320  $tcolumn1[$v->id] = array(
321  "colid" => $v->id,
322  "collabel" => mb_ucfirst($v->getLabel()) ,
323  "rightfornumber" => ($v->type == "money") ? "right" : "left"
324  );
325  }
326 
327  $tinternals = $this->_getInternals();
328  foreach ($tinternals as $k => $v) {
329  $tcolumn1[$k] = array(
330  "colid" => $k,
331  "collabel" => mb_ucfirst($v) ,
332  "rightfornumber" => "left"
333  );
334  }
335 
336  $tcols = $this->getMultipleRawValues("REP_IDCOLS");
337  $tDisplayOption = $this->getMultipleRawValues("REP_DISPLAYOPTION");
338  foreach ($tcols as $k => & $vcol) {
339  if ($vcol) {
340  $tcolumn2[$k] = isset($tcolumn1[$vcol]) ? $tcolumn1[$vcol] : null;
341  if ($tDisplayOption[$k] == "docid") {
342  $tcolumn2[$k]["collabel"].= ' (' . _("report:docid") . ')';
343  }
344  }
345  }
346 
347  $tcols[] = "cvid";
348  $tcols[] = "wid";
349  $tcols[] = "state";
350  $this->lay->setBlockData("COLS", $tcolumn2);
351  $this->lay->set("HASCOLS", count($tcolumn2) > 0);
352  include_once ("FDL/Lib.Dir.php");
353 
354  $this->lay->set("reportstyle", $this->getRawValue("REP_STYLE", "perso"));
355  $this->lay->set("isperso", ($this->getRawValue("REP_STYLE", "perso") == "perso"));
356  if ($this->isParameterizable() && $ulink) {
357  $this->lay->setBlockData("PARAMS", array(
358  array(
359  "zou"
360  )
361  ));
362  }
363  // --------------------------
364  // display body
365  $limit = $this->getRawValue("REP_LIMIT", "ALL");
366  $order = $this->getRawValue("REP_IDSORT", "title");
367  $oa = $rdoc->getAttribute($order);
368  if ($oa) {
369  if (($oa->type == "docid") && ($oa->getOption("doctitle") != "")) {
370  $order = $oa->getOption("doctitle");
371  if ($order == 'auto') $order = $oa->id . '_title';
372  }
373  }
374  $order.= " " . $this->getRawValue("REP_ORDERSORT");
375  $s = new \SearchDoc($this->dbaccess, $this->getRawValue("se_famid"));
376  $s->useCollection($this->initid);
377  $s->setOrder($order);
378  $s->returnsOnly($tcols);
379  $s->setObjectReturn();
380  $limit = intval($limit);
381  $maxDisplayLimit = intval($this->getFamilyParameterValue("rep_maxdisplaylimit", 1000)) + 1;
382  if ($limit == 0) $limit = $maxDisplayLimit;
383  else $limit = min($limit, $maxDisplayLimit);
384  $s->setSlice($limit);
385  try {
386  $s->search();
387  }
388  catch(\Exception $e) {
389  /*
390  * Prevent exception from stopping the view's composition
391  * The error will be handled and reported with the getError() method below
392  */
393  }
394  $err = $s->getError();
395  if ($err) {
397  return $err;
398  }
399  $needRemoveLast = false;
400  if ($s->count() >= $maxDisplayLimit) {
401  addWarningMsg(sprintf(_("Max display limit %s reached. Use export to see all") , $maxDisplayLimit - 1));
402  $needRemoveLast = true;
403  }
404  $trodd = false;
405  $tcolor = $this->getMultipleRawValues("REP_COLORS");
406  $trow = array();
407  $k = 0;
409  while ($rdoc = $s->getNextDoc()) {
410  $k++;
411  $trow[$k] = array(
412  "CELLS" => "row$k",
413  "docid" => $rdoc->id,
414  "troddoreven" => $trodd ? "trodd" : "treven"
415  );
416  $trodd = !$trodd;
417  $tdodd = false;
418  $tcell = array();
419  reset($tcolumn2);
420  reset($tcolor);
421 
422  foreach ($tcolumn2 as $ki => $vc) {
423  $kc = $vc["colid"];
424  if ($rdoc->getRawValue($kc) == "") $tcell[$ki] = array(
425  "cellval" => ""
426  );
427  else {
428  $visible = true;
429  switch ($kc) {
430  case "revdate":
431  // $cval= (date("Y-m-d H:i:s", $rdoc->getRawValue($kc)));
432  $cval = (date("Y-m-d H:i:s", $rdoc->getRawValue($kc)));
433  // $cval = strftime("%d/%m/%Y %T", $rdoc->getRawValue($kc));
434  // $cval = strftime ("%x %T",$rdoc->getRawValue($kc]);
435  break;
436 
437  case "state":
438  $cval = $rdoc->getStatelabel();
439  break;
440 
441  case "title":
442  if ($ulink) {
443  $cval = $rdoc->getDocAnchor($rdoc->id, 'rdoc' . $rdoc->id, true, false, true, "fixed");
444  } else {
445  $cval = $rdoc->getHtmlTitle();
446  }
447  break;
448 
449  default:
450  if ($tDisplayOption[$ki] == "docid") {
451  $visible = \Dcp\VerifyAttributeAccess::isAttributeAccessGranted($rdoc, $lattr[$kc]);
452  $cval = $rdoc->getRawValue($kc);
453  } else {
454  $cval = $rdoc->getPropertyValue($kc);
455  if ($cval === false) {
456  $visible = \Dcp\VerifyAttributeAccess::isAttributeAccessGranted($rdoc, $lattr[$kc]);
457  $cval = $rdoc->getHtmlValue($lattr[$kc], $rdoc->getRawValue($kc) , $target, $ulink);
458  }
459  }
460  if (isset($lattr[$kc]) && $lattr[$kc]->type == "image") {
461  $cval = "<img width=\"40px\" src=\"$cval\">";
462  }
463  }
464  if ($visible) {
465  $tcell[$ki] = array(
466  "cellval" => $cval,
467  "rawval" => $rdoc->getRawValue($kc)
468  );
469  } else {
470  $tcell[$ki] = array(
471  "cellval" => $this->getFamilyParameterValue(MyAttributes::rep_noaccesstext) ,
472  "rawval" => ""
473  );
474  }
475  }
476  $tcell[$ki]["bgcell"] = current($tcolor);
477  next($tcolor);
478  $tcell[$ki]["tdoddoreven"] = $tdodd ? "tdodd" : "tdeven";
479  $tcell[$ki]["rightfornumber"] = (isset($lattr[$kc]) && $lattr[$kc]->type == "money") ? "right" : "left";
480  $tdodd = !$tdodd;
481  }
482  $this->lay->setBlockData("row$k", $tcell);
483  }
484 
485  if ($needRemoveLast) array_pop($trow);
486  $this->lay->setBlockData("ROWS", $trow);
487  // ---------------------
488  // footer
489  $tfoots = $this->getMultipleRawValues("REP_FOOTS");
490  $tlfoots = array();
491  foreach ($tfoots as $k => $v) {
492  switch ($v) {
493  case "CARD":
494  $val = count($trow);
495  break;
496 
497  case "MOY":
498  case "SUM":
499  reset($trow);
500  $val = 0;
501  foreach ($trow as $kr => $vr) {
502  $ctr = $this->lay->getBlockData($vr["CELLS"]);
503  if (isset($ctr[$k]["rawval"])) $val+= $ctr[$k]["rawval"];
504  }
505  if ($v == "MOY") $val = $val / count($trow);
506  if (!$rdoc) {
507  $rdoc = createTmpDoc($this->dbaccess, $this->getRawValue("se_famid"));
508  }
509  if (isset($lattr[$tcols[$k]])) {
510  $val = $rdoc->getHtmlValue($lattr[$tcols[$k]], $val, $target, $ulink);
511  }
512  break;
513 
514  default:
515  $val = "-";
516  }
517  $footRight = '';
518  if (isset($tcolumn2[$k])) {
519  $footRight = $tcolumn2[$k]["rightfornumber"];
520  }
521  $tlfoots[] = array(
522  "footval" => $val,
523  "rightfornumber" => $footRight
524  );
525  }
526  $this->lay->setBlockData("TFOOT", $tlfoots);
527  $this->lay->set("TITLE", $this->getHTMLTitle());
528  return $err;
529  }
530  /**
531  * Generate data struct to csv export of a report
532  *
533  * @param boolean $refresh true to refresh the doc before export
534  * @param boolean $isPivotExport if is pivot true
535  * @param string $pivotElement id of the pivot element
536  *
537  * @return array
538  */
539  public function generateCSVReportStruct($isPivotExport = false, $pivotId = "id", $separator = ".", $dateFormat = "US", $refresh = true, $stripHtmlTags = false, $renderNumber = "format")
540  {
541  require_once 'WHAT/Class.twoDimensionalArray.php';
542  require_once 'FDL/Class.SearchDoc.php';
543 
544  $famId = $this->getRawValue("se_famid", 1);
545  $limit = $this->getRawValue("rep_limit", "ALL");
546  $order = $this->getRawValue("rep_idsort", "title");
547 
548  $mb0 = microtime(true);
549  $this->setStatus(_("Doing search request"));
550  $search = new \SearchDoc($this->dbaccess, $famId);
551  $search->dirid = $this->initid;
552  $search->slice = $limit;
553  $search->orderby = trim($order . " " . $this->getRawValue("rep_ordersort"));
554  $search->setObjectReturn();
555  // print_r($search->getSearchInfo());
556  $famDoc = createDoc($this->dbaccess, $famId, false);
557  $tcols = $this->getMultipleRawValues("rep_idcols");
558  $tcolsOption = $this->getMultipleRawValues("rep_displayoption");
559  $searchCols = $tcols;
560  $searchCols[] = "cvid";
561  $searchCols[] = "wid";
562  $search->returnsOnly($searchCols);
563 
564  if ($isPivotExport) {
565  $search->search();
566  $this->setStatus(_("Doing render"));
567  return $this->generatePivotCSV($search, $tcols, $famDoc, $pivotId, $refresh, $separator, $dateFormat, $stripHtmlTags, $renderNumber);
568  } else {
569  $this->setStatus(_("Doing render"));
570  return $this->generateBasicCSV($search, $tcols, $tcolsOption, $famDoc, $refresh, $separator, $dateFormat, $stripHtmlTags, $renderNumber);
571  }
572  }
573 
574  public static function setStatus($s)
575  {
576  global $action;
577  $expVarName = $action->getParam("exportSession");
578  if ($expVarName) $action->Register($expVarName, array(
579  "status" => $s
580  ));
581  }
582 
583  protected function generatePivotCSV(\SearchDoc $search, Array $columns, \Doc $famDoc, $pivotId, $refresh, $separator, $dateFormat, $stripHtmlTags, $renderNumber = "format")
584  {
585  $convertFormat = array(
586  "dateFormat" => $dateFormat,
587  'decimalSeparator' => $separator,
588  'stripHtmlTags' => $stripHtmlTags,
589  'renderNumber' => $renderNumber
590  );
591 
592  $pivotColumnName = uniqid();
593 
594  $singleAttributes = array();
595  $multipleAttributes = array();
596  $resultSingleArray = array();
597  $resultMultipleArray = array();
598 
599  $internals = $this->_getInternals();
600  //Generate column organisation
601  $resultSingleArray[$pivotColumnName] = array();
602 
603  foreach ($columns as $currentColumnID) {
604  $attributeObject = $famDoc->getAttribute($currentColumnID);
605  if (!$attributeObject) {
606  $singleAttributes[] = $currentColumnID;
607  $resultSingleArray[$currentColumnID] = array();
608  } elseif ($attributeObject->isMultiple()) {
609  if ($attributeObject->getOption('multiple') == "yes" && !$attributeObject->inArray()) {
610  $multipleAttributes[$currentColumnID] = array();
611  $multipleAttributes[$currentColumnID][] = $currentColumnID;
612  $resultMultipleArray[$currentColumnID] = array();
613  $resultMultipleArray[$currentColumnID][$pivotColumnName] = array();
614  $resultMultipleArray[$currentColumnID][$currentColumnID] = array();
615  } else {
616  $arrayID = $attributeObject->fieldSet->id;
617  if (!isset($multipleAttributes[$arrayID])) {
618  $multipleAttributes[$arrayID] = array();
619  $resultMultipleArray[$arrayID] = array();
620  $resultMultipleArray[$arrayID][$pivotColumnName] = array();
621  }
622  $multipleAttributes[$arrayID][] = $currentColumnID;
623  $resultMultipleArray[$arrayID][$currentColumnID] = array();
624  }
625  } else {
626  $singleAttributes[] = $currentColumnID;
627  $resultSingleArray[$currentColumnID] = array();
628  }
629  }
630  //Get Value
631  $nbDoc = $search->count();
632  $k = 0;
633  while ($currentDoc = $search->getNextDoc()) {
634  $k++;
635  if ($k % 10 == 0) $this->setStatus(sprintf(_("Pivot rendering %d/%d") , $k, $nbDoc));
636  if ($refresh) {
637  $currentDoc->refresh();
638  }
639  $pivotAttribute = $famDoc->getAttribute($pivotId);
640  $pivotValue = $pivotAttribute ? $this->getCellValue($currentDoc, $pivotAttribute, $convertFormat) : $this->convertInternalElement($pivotId, $currentDoc);
641  $resultSingleArray[$pivotColumnName][] = $pivotValue;
642  foreach ($singleAttributes as $currentColumnID) {
643  $currentAttribute = $famDoc->getAttribute($currentColumnID);
644  $resultSingleArray[$currentColumnID][] = $currentAttribute ? $this->getCellValue($currentDoc, $currentAttribute, $convertFormat) : $this->convertInternalElement($currentColumnID, $currentDoc);
645  }
646  $nbElement = 0;
647  foreach ($multipleAttributes as $currentKey => $currentArrayID) {
648  foreach ($currentArrayID as $currentColumnID) {
649  $currentAttribute = $famDoc->getAttribute($currentColumnID);
650  $nbElement = count($currentDoc->getMultipleRawValues($currentColumnID));
651  for ($i = 0; $i < $nbElement; $i++) {
652  $resultMultipleArray[$currentKey][$currentColumnID][] = $this->getCellValue($currentDoc, $currentAttribute, $convertFormat, $i);
653  }
654  }
655  for ($i = 0; $i < $nbElement; $i++) {
656  $resultMultipleArray[$currentKey][$pivotColumnName][] = $pivotValue;
657  }
658  }
659  }
660  //Generate result array
661  $firstRow = array();
662  $twoDimStruct = new \TwoDimensionStruct();
663  //Generate first line
664  $firstRow[] = _("REPORT_pivot");
665  $twoDimStruct->addColumn($resultSingleArray[$pivotColumnName]);
666 
667  foreach ($singleAttributes as $currentColumnID) {
668  $currentAttribute = $famDoc->getAttribute($currentColumnID);
669  $firstRow[] = $currentAttribute ? $currentAttribute->getLabel() : $internals[$currentColumnID];
670  $twoDimStruct->addColumn($resultSingleArray[$currentColumnID]);
671  }
672  //Generate content
673  foreach ($multipleAttributes as $currentKey => $currentArrayID) {
674  $firstRow[] = "";
675  $emptyArray = array(
676  ""
677  );
678  $twoDimStruct->addColumn($emptyArray);
679  $firstRow[] = _("REPORT_pivot");
680  $twoDimStruct->addColumn($resultMultipleArray[$currentKey][$pivotColumnName]);
681  foreach ($currentArrayID as $currentColumnID) {
682  $currentAttribute = $famDoc->getAttribute($currentColumnID);
683  $firstRow[] = $currentAttribute ? $currentAttribute->getLabel() : $internals[$currentColumnID];
684  $twoDimStruct->addColumn($resultMultipleArray[$currentKey][$currentColumnID]);
685  }
686  }
687 
688  if ($twoDimStruct->insertRow(0, $firstRow, true) == null) {
689  var_export($twoDimStruct->getLastErrorMessage());
690  }
691 
692  return $twoDimStruct->getArray();
693  }
694 
695  protected function getCellValue(\Doc $doc, \BasicAttribute $oa, $format, $index = - 1)
696  {
697  return $oa->getTextualValue($doc, $index, $format);
698  }
699  /**
700  * Generate a basic CSV export
701  *
702  * @param \SearchDoc $search the result of the report
703  * @param array $columns an array of id
704  * @param \Doc $famDoc the associated family doc
705  *
706  * @return array
707  */
708  protected function generateBasicCSV(\SearchDoc $search, Array $columns, Array $displayOptions, \Doc $famDoc, $refresh, $separator, $dateFormat, $stripHtmlFormat = true, $renderNumber = "format")
709  {
710  $fc = new \FormatCollection();
711  $dl = $search->getDocumentList();
712  $fc->useCollection($dl);
713 
714  $htmlNoAccess = new \DOMDocument();
715  $htmlNoAccess->loadHTML($this->getFamilyParameterValue(MyAttributes::rep_noaccesstext));
716 
717  $fc->setNoAccessText(trim($htmlNoAccess->textContent));
718  if ($separator) $fc->setDecimalSeparator($separator);
719  $fc->relationIconSize = 0;
720  $fc->stripHtmlTags($stripHtmlFormat);
721  switch ($dateFormat) {
722  case 'US':
723  $fc->setDateStyle(\DateAttributeValue::isoWTStyle);
724  break;
725 
726  case 'FR':
727  $fc->setDateStyle(\DateAttributeValue::frenchStyle);
728  break;
729 
730  case 'ISO':
731  $fc->setDateStyle(\DateAttributeValue::isoStyle);
732  break;
733  }
734  $isAttrInArray = array();
735  foreach ($columns as $k => $col) {
736  if (empty($col)) {
737  unset($columns[$k]);
738  } else {
739  if ($famDoc->getAttribute($col)) {
740  $fc->addAttribute($col);
741  $isAttrInArray[$col] = $famDoc->getAttribute($col)->inArray();
742  } else {
743  $fc->addProperty($col);
744  }
745  }
746  }
747 
748  $fc->setLongtextMultipleBrToCr(" "); // longtext are in a single line if multiple
749  $fc->setNc('-');
750  $fc->setHookAdvancedStatus(function ($s)
751  {
753  });
754  $r = $fc->render();
755  $this->setStatus(_("Doing csv render"));
756  $out = array();
757  $line = array();
758  foreach ($columns as $kc => $col) {
759  if (isset(\Doc::$infofields[$col]["label"])) {
760  $line[$kc] = _(\Doc::$infofields[$col]["label"]);
761  } else {
762  $line[$kc] = $famDoc->getLabel($col);
763  if ($displayOptions[$kc] == "docid") $line[$kc].= ' (' . _("report:docid") . ')';
764  }
765  }
766  $out[] = $line;
767  foreach ($r as $k => $render) {
768  $line = array();
769  foreach ($columns as $kc => $col) {
770  $cellValue = '';
771  if (isset($render["attributes"][$col])) {
772  $oa = $famDoc->getAttribute($col);
773  $cellValue = \FormatCollection::getDisplayValue($render["attributes"][$col], $oa, -1, array(
774  'displayDocId' => ($displayOptions[$kc] == "docid") ,
775  'stripHtmlTags' => $stripHtmlFormat
776  ));
777  if ($renderNumber === "raw" && in_array($oa->type, array(
778  "int",
779  "double",
780  "money"
781  ))) {
782  if (is_array($render["attributes"][$col])) {
783  $numValues = [];
784  foreach ($render["attributes"][$col] as $arender) {
785  $oneValue = $arender->value;
786  if ($separator) {
787  $oneValue = str_replace(".", $separator, $oneValue);
788  }
789  $numValues[] = $oneValue;
790  }
791  $cellValue = implode("\n", $numValues);
792  } else {
793  $cellValue = $render["attributes"][$col]->value;
794  if ($separator) {
795  $cellValue = str_replace(".", $separator, $cellValue);
796  }
797  }
798  }
799  } else {
800  if (isset($render["properties"][$col])) {
801  $cellValue = $render["properties"][$col];
802  if (is_object($cellValue)) {
803  $cellValue = $cellValue->displayValue;
804  }
805  }
806  }
807  $line[] = $cellValue;
808  }
809  $out[] = $line;
810  }
811 
812  return $out;
813  }
814  protected function convertInternalElement($internalName, \Doc $doc)
815  {
816  switch ($internalName) {
817  case "revdate":
818  return strftime("%x %T", $doc->getRawValue($internalName));
819  case "state":
820  return $doc->getStatelabel();
821  case "title":
822  return $doc->getHTMLTitle();
823  case "id":
824  return $doc->id;
825  case "owner":
826  return $doc->owner;
827  default:
828  return $doc->getRawValue($internalName);
829  }
830  }
831  /**
832  * Compute the values for the mini view display (portal)
833  * @templateController
834  *
835  * @param string $target window target name for hyperlink destination
836  * @param bool $ulink if false hyperlink are not generated
837  * @param bool $abstract if true only abstract attribute are generated
838  */
839  public function viewminireport($target = "_self", $ulink = true, $abstract = false)
840  {
841  $this->viewreport($target, $ulink, $abstract);
842  }
843 }
static $infofields
Definition: Class.Doc.php:105
global $action
& getAttribute($idAttr, &$oa=null, $useMask=true)
Definition: Class.Doc.php:2152
convertInternalElement($internalName,\Doc $doc)
addWarningMsg($msg)
Definition: Lib.Common.php:95
static isAttributeAccessGranted(\Doc $doc,\BasicAttribute $attribute)
getStatelabel()
Definition: Class.Doc.php:5404
if($famId) $s
generateCSVReportStruct($isPivotExport=false, $pivotId="id", $separator=".", $dateFormat="US", $refresh=true, $stripHtmlTags=false, $renderNumber="format")
viewattr($target="_self", $ulink=true, $abstract=false, $viewhidden=false)
Definition: Class.Doc.php:7695
getReportColumns($dbaccess, $famid, $name="")
getCellValue(\Doc $doc,\BasicAttribute $oa, $format, $index=-1)
getFamilyParameterValue($idp, $def="")
Definition: Class.Doc.php:1538
generatePivotCSV(\SearchDoc $search, Array $columns,\Doc $famDoc, $pivotId, $refresh, $separator, $dateFormat, $stripHtmlTags, $renderNumber="format")
generateBasicCSV(\SearchDoc $search, Array $columns, Array $displayOptions,\Doc $famDoc, $refresh, $separator, $dateFormat, $stripHtmlFormat=true, $renderNumber="format")
viewprop($target="_self", $ulink=true, $abstract=false)
Definition: Class.Doc.php:7781
viewminireport($target="_self", $ulink=true, $abstract=false)
$search
viewreport($target="_self", $ulink=true, $abstract=false)
static setStatus($s)
getMultipleRawValues($idAttr, $def="", $index=-1)
Definition: Class.Doc.php:3240
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getHTMLTitle($id="-1", $def="", $latest=false)
Definition: Class.Doc.php:8754
mb_ucfirst($s)
Definition: Lib.Common.php:105
getTextualValue(Doc $doc, $index=-1, Array $configuration=array())
new_Doc($dbaccess, $id= '', $latest=false)
static getDisplayValue($info, $oAttr, $index=-1, $configuration=array())
getLabel($idAttr)
Definition: Class.Doc.php:2091
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
if($file) if($subject==""&&$file) if($subject=="") $err
getRawValue($idAttr, $def="")
Definition: Class.Doc.php:3117
$initid
Definition: Class.Doc.php:361
← centre documentaire © anakeen