ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
68
69 // get last export id
70 $query = 'SELECT MAX(export_id) exp FROM export_options ' .
71 'GROUP BY export_id ';
72 $res = $ilDB->query($query);
73 $exp_id = 1;
74 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
75 $exp_id = $row->exp + 1;
76 }
77 $query = 'INSERT INTO export_options (export_id,keyword,ref_id,obj_id,value) ' .
78 'VALUES( ' .
79 $ilDB->quote($exp_id, 'integer') . ', ' .
80 $ilDB->quote(self::KEY_INIT, 'integer') . ', ' .
81 $ilDB->quote(0, 'integer') . ', ' .
82 $ilDB->quote(0, 'integer') . ', ' .
83 $ilDB->quote(0, 'integer') . ' ' .
84 ')';
85 $ilDB->manipulate($query);
86
87 return $exp_id;
88 }
89
95 public function getSubitemsForCreation($a_source_id)
96 {
97 $refs = array();
98
99 foreach ((array) $this->ref_options[self::KEY_ITEM_MODE] as $ref_id => $mode) {
100 if ($mode == self::EXPORT_BUILD) {
101 $refs[] = $ref_id;
102 }
103 }
104 return $refs;
105 }
106
111 public function getSubitemsForExport()
112 {
113 $refs = array();
114 foreach ((array) $this->ref_options[self::KEY_ITEM_MODE] as $ref_id => $mode) {
115 if ($mode != self::EXPORT_OMIT) {
116 $refs[] = $ref_id;
117 }
118 }
119 return $refs;
120 }
121
126 public function getExportId()
127 {
128 return $this->export_id;
129 }
130
131 public function addOption($a_keyword, $a_ref_id, $a_obj_id, $a_value)
132 {
133 global $ilDB;
134
135 $query = "SELECT MAX(pos) position FROM export_options";
136 $res = $ilDB->query($query);
137
138 $pos = 0;
139 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
140 $pos = $row->position;
141 }
142 $pos++;
143
144 $query = 'INSERT INTO export_options (export_id,keyword,ref_id,obj_id,value,pos) ' .
145 'VALUES( ' .
146 $ilDB->quote($this->getExportId(), 'integer') . ', ' .
147 $ilDB->quote($a_keyword, 'integer') . ', ' .
148 $ilDB->quote($a_ref_id, 'integer') . ', ' .
149 $ilDB->quote($a_obj_id, 'integer') . ', ' .
150 $ilDB->quote($a_value, 'integer') . ', ' .
151 $ilDB->quote($pos, 'integer') . ' ' .
152 ')';
153 $ilDB->manipulate($query);
154 }
155
161 public function getOption($a_keyword)
162 {
163 return isset($this->options[$a_keyword]) ? $this->options[$a_keyword] : null;
164 }
165
172 public function getOptionByObjId($a_obj_id, $a_keyword)
173 {
174 return isset($this->obj_options[$a_keyword][$a_obj_id]) ? $this->obj_options[$a_keyword][$a_obj_id] : null;
175 }
176
183 public function getOptionByRefId($a_ref_id, $a_keyword)
184 {
185 return isset($this->ref_options[$a_keyword][$a_ref_id]) ? $this->ref_options[$a_keyword][$a_ref_id] : null;
186 }
187
192 public function delete()
193 {
194 global $ilDB;
195
196 $query = "DELETE FROM export_options " .
197 "WHERE export_id = " . $ilDB->quote($this->getExportId(), 'integer');
198 $ilDB->manipulate($query);
199 return true;
200 }
201
206 public function read()
207 {
208 global $ilDB;
209
210 $this->options = array();
211 $this->obj_options = array();
212 $this->ref_options = array();
213
214 $query = "SELECT * FROM export_options " .
215 "WHERE export_id = " . $ilDB->quote($this->getExportId(), 'integer') . ' ' .
216 "ORDER BY pos";
217 $res = $ilDB->query($query);
218 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
219 if ($row->ref_id) {
220 $this->ref_options[$row->keyword][$row->ref_id] = $row->value;
221 }
222 if ($row->obj_id) {
223 $this->obj_options[$row->keyword][$row->obj_id] = $row->value;
224 }
225 if (!$row->ref_id and !$row->obj_id) {
226 $this->options[$row->keyword] = $row->value;
227 }
228 }
229 return true;
230 }
231}
An exception for terminatinating execution or to throw for unit testing.
__construct($a_export_id)
Singleton constructor.
getSubitemsForCreation($a_source_id)
Get all subitems with mode ilExportOptions::EXPORT_BUILD
static getInstance()
Get singelton instance.
getOption($a_keyword)
Get option.
getSubitemsForExport()
Get all subitems with mode != self::EXPORT_OMIT.
getOptionByObjId($a_obj_id, $a_keyword)
Get option by.
addOption($a_keyword, $a_ref_id, $a_obj_id, $a_value)
static newInstance($a_export_id)
Create new instance.
getOptionByRefId($a_ref_id, $a_keyword)
Get option by.
static allocateExportId()
Allocate a new export id.
getExportId()
Get export id.
$query
foreach($_POST as $key=> $value) $res
global $ilDB