Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.exportXmlFolder.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Export documents in xml
8  *
9  * @author Anakeen
10  * @package FDL
11  * @subpackage
12  */
13 /**
14  */
15 
16 include_once ("FDL/import_file.php");
17 require_once 'FDL/exportxmlfld.php';
18 
20 {
21  const zipFormat = 'X';
22  const xmlFormat = 'Y';
23  private $dbaccess;
24  private $exported = false;
25  private $outputFile = '';
26  private $useIdentificator = false;
27  /**
28  * @var string output format X or Y
29  */
30  private $format = self::xmlFormat;
31 
32  public function __construct()
33  {
34  $this->dbaccess = getDbAccess();
35  }
36  /**
37  * export format xml or zip
38  * @param string $xy
39  * @throws Dcp\Exception
40  */
41  public function setOutputFormat($xy)
42  {
43  if ($xy == self::zipFormat || $xy == self::xmlFormat) {
44  $this->format = $xy;
45  } else {
46  throw new Dcp\Exception(sprintf("format must be %s or %s") , self::zipFormat, self::xmlFormat);
47  }
48  }
49  /**
50  * export (or not) system document identifier
51  * @param bool $exportIdentificator export option
52  */
53  public function useIdentificator($exportIdentificator = true)
54  {
55  $this->useIdentificator = $exportIdentificator;
56  }
57  /**
58  * return exported file name
59  * @return string file path
60  */
61  public function getOutputFile()
62  {
63  return $this->outputFile;
64  }
65  private function setOutputFile($outputFile = '')
66  {
67  if (!$outputFile) {
68  $ext = 'nop';
69  if ($this->format == self::xmlFormat) $ext = "xml";
70  else if ($this->format == self::zipFormat) $ext = 'zip';
71  $this->outputFile = uniqid(getTmpDir() . "/export") . ".$ext";
72  } else {
73  $this->outputFile = $outputFile;
74  }
75  return $this->outputFile;
76  }
77  /**
78  * return content of xml file to be use only with xml format
79  * @return string
80  * @throws Dcp\Exception
81  */
82  public function getXmlContent()
83  {
84  if (!$this->exported) {
85  throw new Dcp\Exception(sprintf(_("nothing to export. Do export before")));
86  }
87  if ($this->format != self::xmlFormat) {
88  throw new Dcp\Exception(sprintf(_("not in XML format")));
89  }
90  return file_get_contents($this->outputFile);
91  }
92  /**
93  * export documents from search object
94  * @param SearchDoc $search search to export
95  * @param string $outputFile path to output file
96  * @return void
97  */
98  public function exportFromSearch(SearchDoc & $search, $outputFile = '')
99  {
100  global $action;
101  $this->setOutputFile($outputFile);
102  exportxmlfld($action, $folder = "0", $famid = "", $search, $this->outputFile, $this->format, $this->useIdentificator ? 'Y' : 'N');
103  }
104  /**
105  * export documents from search object
106  * @param string $folderId collection identifier
107  * @param string $outputFile path to output file
108  * @return void
109  */
110  public function exportFromFolder($folderId, $outputFile = '')
111  {
112  global $action;
113  $this->setOutputFile($outputFile);
114  exportxmlfld($action, $folderId, $famid = "", null, $this->outputFile, $this->format, $this->useIdentificator ? 'Y' : 'N');
115  }
116  /**
117  *
118  * export documents from selection object
119  * @param Fdl_DocumentSelection $selection
120  * @param string $outputFile
121  */
122  public function exportFromSelection(Fdl_DocumentSelection $selection, $outputFile = '')
123  {
124  global $action;
125  $this->setOutputFile($outputFile);
126  exportxmlfld($action, $folder = 0, $famid = "", null, $this->outputFile, $this->format, $this->useIdentificator ? 'Y' : 'N', $selection);
127  }
128 }
129 ?>
exportFromSelection(Fdl_DocumentSelection $selection, $outputFile= '')
global $action
exportxmlfld(Action &$action, $aflid="0", $famid="", SearchDoc $specSearch=null, $outputFile= '', $eformat="", $wident= 'Y', Fdl_DocumentSelection $aSelection=null, $toDownload=true)
Exception class use exceptionCode to identifiy correctly exception.
Definition: exceptions.php:19
exportFromSearch(SearchDoc &$search, $outputFile= '')
useIdentificator($exportIdentificator=true)
$search
exportFromFolder($folderId, $outputFile= '')
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
getDbAccess()
Definition: Lib.Common.php:368
← centre documentaire © anakeen