ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
48 return self::$instance;
49 }
50 }
51
57 public static function newInstance($a_export_id)
58 {
59 return self::$instance = new ilExportOptions($a_export_id);
60 }
61
66 public static function allocateExportId()
67 {
68 global $ilDB;
69
70 // get last export id
71 $query = 'SELECT MAX(export_id) exp FROM export_options '.
72 'GROUP BY export_id ';
73 $res = $ilDB->query($query);
74 $exp_id = 1;
75 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
76 {
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 {
103 if($mode == self::EXPORT_BUILD)
104 {
105 $refs[] = $ref_id;
106 }
107 }
108 return $refs;
109 }
110
115 public function getSubitemsForExport()
116 {
117 $refs = array();
118 foreach((array) $this->ref_options[self::KEY_ITEM_MODE] as $ref_id => $mode)
119 {
120 if($mode != self::EXPORT_OMIT)
121 {
122 $refs[] = $ref_id;
123 }
124 }
125 return $refs;
126 }
127
132 public function getExportId()
133 {
134 return $this->export_id;
135 }
136
137 public function addOption($a_keyword, $a_ref_id, $a_obj_id, $a_value)
138 {
139 global $ilDB;
140
141 $query = "SELECT MAX(pos) position FROM export_options";
142 $res = $ilDB->query($query);
143
144 $pos = 0;
145 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
146 {
147 $pos = $row->position;
148 }
149 $pos++;
150
151 $query = 'INSERT INTO export_options (export_id,keyword,ref_id,obj_id,value,pos) '.
152 'VALUES( '.
153 $ilDB->quote($this->getExportId(),'integer').', '.
154 $ilDB->quote($a_keyword,'integer').', '.
155 $ilDB->quote($a_ref_id,'integer').', '.
156 $ilDB->quote($a_obj_id,'integer').', '.
157 $ilDB->quote($a_value,'integer').', '.
158 $ilDB->quote($pos,'integer').' '.
159 ')';
160 $ilDB->manipulate($query);
161 }
162
168 public function getOption($a_keyword)
169 {
170 return isset($this->options[$a_keyword]) ? $this->options[$a_keyword] : null;
171 }
172
179 public function getOptionByObjId($a_obj_id,$a_keyword)
180 {
181 return isset($this->obj_options[$a_keyword][$a_obj_id]) ? $this->obj_options[$a_keyword][$a_obj_id] : null;
182 }
183
190 public function getOptionByRefId($a_ref_id,$a_keyword)
191 {
192 return isset($this->ref_options[$a_keyword][$a_ref_id]) ? $this->ref_options[$a_keyword][$a_ref_id] : null;
193 }
194
199 public function delete()
200 {
201 global $ilDB;
202
203 $query = "DELETE FROM export_options ".
204 "WHERE export_id = ".$ilDB->quote($this->getExportId(),'integer');
205 $ilDB->manipulate($query);
206 return true;
207 }
208
213 public function read()
214 {
215 global $ilDB;
216
217 $this->options = array();
218 $this->obj_options = array();
219 $this->ref_options = array();
220
221 $query = "SELECT * FROM export_options ".
222 "WHERE export_id = ".$ilDB->quote($this->getExportId(),'integer').' '.
223 "ORDER BY pos";
224 $res = $ilDB->query($query);
225 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
226 {
227 if($row->ref_id)
228 {
229 $this->ref_options[$row->keyword][$row->ref_id] = $row->value;
230 }
231 if($row->obj_id)
232 {
233 $this->obj_options[$row->keyword][$row->obj_id] = $row->value;
234 }
235 if(!$row->ref_id and !$row->obj_id)
236 {
237 $this->options[$row->keyword] = $row->value;
238 }
239
240 }
241 return true;
242 }
243}
244?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
__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.
$ref_id
Definition: sahs_server.php:39
global $ilDB