ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExportOptions.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  private static $instance = null;
16 
17  const EXPORT_EXISTING = 1;
18  const EXPORT_BUILD = 2;
19  const EXPORT_OMIT = 3;
20 
21  const KEY_INIT = 1;
22  const KEY_ITEM_MODE = 2;
23  const KEY_ROOT = 3;
24 
25  private $export_id = 0;
26  private $ref_options = array();
27  private $obj_options = array();
28  private $options = array();
29 
34  private function __construct($a_export_id)
35  {
36  $this->export_id = $a_export_id;
37  $this->read();
38  }
39 
44  public static function getInstance()
45  {
46  if (self::$instance) {
47  return self::$instance;
48  }
49  }
50 
56  public static function newInstance($a_export_id)
57  {
58  return self::$instance = new ilExportOptions($a_export_id);
59  }
60 
65  public static function allocateExportId()
66  {
67  global $DIC;
68 
69  $ilDB = $DIC['ilDB'];
70 
71  // get last export id
72  $query = 'SELECT MAX(export_id) exp FROM export_options ' .
73  'GROUP BY export_id ';
74  $res = $ilDB->query($query);
75  $exp_id = 1;
76  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
77  $exp_id = $row->exp + 1;
78  }
79  $query = 'INSERT INTO export_options (export_id,keyword,ref_id,obj_id,value) ' .
80  'VALUES( ' .
81  $ilDB->quote($exp_id, 'integer') . ', ' .
82  $ilDB->quote(self::KEY_INIT, 'integer') . ', ' .
83  $ilDB->quote(0, 'integer') . ', ' .
84  $ilDB->quote(0, 'integer') . ', ' .
85  $ilDB->quote(0, 'integer') . ' ' .
86  ')';
87  $ilDB->manipulate($query);
88 
89  return $exp_id;
90  }
91 
97  public function getSubitemsForCreation($a_source_id)
98  {
99  $refs = array();
100 
101  foreach ((array) $this->ref_options[self::KEY_ITEM_MODE] as $ref_id => $mode) {
102  if ($mode == self::EXPORT_BUILD) {
103  $refs[] = $ref_id;
104  }
105  }
106  return $refs;
107  }
108 
113  public function getSubitemsForExport()
114  {
115  $refs = array();
116  foreach ((array) $this->ref_options[self::KEY_ITEM_MODE] as $ref_id => $mode) {
117  if ($mode != self::EXPORT_OMIT) {
118  $refs[] = $ref_id;
119  }
120  }
121  return $refs;
122  }
123 
128  public function getExportId()
129  {
130  return $this->export_id;
131  }
132 
133  public function addOption($a_keyword, $a_ref_id, $a_obj_id, $a_value)
134  {
135  global $DIC;
136 
137  $ilDB = $DIC['ilDB'];
138 
139  $query = "SELECT MAX(pos) position FROM export_options";
140  $res = $ilDB->query($query);
141 
142  $pos = 0;
143  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144  $pos = $row->position;
145  }
146  $pos++;
147 
148  $query = 'INSERT INTO export_options (export_id,keyword,ref_id,obj_id,value,pos) ' .
149  'VALUES( ' .
150  $ilDB->quote($this->getExportId(), 'integer') . ', ' .
151  $ilDB->quote($a_keyword, 'integer') . ', ' .
152  $ilDB->quote($a_ref_id, 'integer') . ', ' .
153  $ilDB->quote($a_obj_id, 'integer') . ', ' .
154  $ilDB->quote($a_value, 'integer') . ', ' .
155  $ilDB->quote($pos, 'integer') . ' ' .
156  ')';
157  $ilDB->manipulate($query);
158  }
159 
165  public function getOption($a_keyword)
166  {
167  return isset($this->options[$a_keyword]) ? $this->options[$a_keyword] : null;
168  }
169 
176  public function getOptionByObjId($a_obj_id, $a_keyword)
177  {
178  return isset($this->obj_options[$a_keyword][$a_obj_id]) ? $this->obj_options[$a_keyword][$a_obj_id] : null;
179  }
180 
187  public function getOptionByRefId($a_ref_id, $a_keyword)
188  {
189  return isset($this->ref_options[$a_keyword][$a_ref_id]) ? $this->ref_options[$a_keyword][$a_ref_id] : null;
190  }
191 
196  public function delete()
197  {
198  global $DIC;
199 
200  $ilDB = $DIC['ilDB'];
201 
202  $query = "DELETE FROM export_options " .
203  "WHERE export_id = " . $ilDB->quote($this->getExportId(), 'integer');
204  $ilDB->manipulate($query);
205  return true;
206  }
207 
212  public function read()
213  {
214  global $DIC;
215 
216  $ilDB = $DIC['ilDB'];
217 
218  $this->options = array();
219  $this->obj_options = array();
220  $this->ref_options = array();
221 
222  $query = "SELECT * FROM export_options " .
223  "WHERE export_id = " . $ilDB->quote($this->getExportId(), 'integer') . ' ' .
224  "ORDER BY pos";
225  $res = $ilDB->query($query);
226  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
227  if ($row->ref_id) {
228  $this->ref_options[$row->keyword][$row->ref_id] = $row->value;
229  }
230  if ($row->obj_id) {
231  $this->obj_options[$row->keyword][$row->obj_id] = $row->value;
232  }
233  if (!$row->ref_id and !$row->obj_id) {
234  $this->options[$row->keyword] = $row->value;
235  }
236  }
237  return true;
238  }
239 }
getExportId()
Get export id.
global $DIC
Definition: saml.php:7
static getInstance()
Get singelton instance.
getOptionByRefId($a_ref_id, $a_keyword)
Get option by.
getSubitemsForExport()
Get all subitems with mode != self::EXPORT_OMIT.
static newInstance($a_export_id)
Create new instance.
getOptionByObjId($a_obj_id, $a_keyword)
Get option by.
foreach($_POST as $key=> $value) $res
$query
getSubitemsForCreation($a_source_id)
Get all subitems with mode ilExportOptions::EXPORT_BUILD
$row
addOption($a_keyword, $a_ref_id, $a_obj_id, $a_value)
global $ilDB
__construct($a_export_id)
Singleton constructor.
getOption($a_keyword)
Get option.
static allocateExportId()
Allocate a new export id.