ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilLPCollection.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14abstract class ilLPCollection
15{
16 protected $obj_id; // [int]
17 protected $mode; // [int]
18 protected $items; // [array]
19
20 public function __construct($a_obj_id, $a_mode)
21 {
22 $this->obj_id = $a_obj_id;
23 $this->mode = $a_mode;
24
25 if($a_obj_id)
26 {
27 $this->read($a_obj_id);
28 }
29 }
30
31 public function hasSelectableItems()
32 {
33 return true;
34 }
35
36 public function cloneCollection($a_target_id, $a_copy_id)
37 {
38 global $ilLog;
39
40 $target_obj_id = ilObject::_lookupObjId($a_target_id);
41
42 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
43 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
44 $mappings = $cwo->getMappings();
45
46 // #12067
47 $new_collection = new static($target_obj_id, $this->mode);
48 foreach($this->items as $item)
49 {
50 if(!isset($mappings[$item]) or !$mappings[$item])
51 {
52 continue;
53 }
54
55 $new_collection->addEntry($mappings[$item]);
56 }
57
58 $ilLog->write(__METHOD__.': cloned learning progress collection.');
59 }
60
61
62 //
63 // CRUD
64 //
65
66 public function getItems()
67 {
68 return $this->items;
69 }
70
71 protected function read()
72 {
73 global $ilDB;
74
75 $items = array();
76
77 $res = $ilDB->query("SELECT * FROM ut_lp_collections".
78 " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer"));
79 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
80 {
81 if($this->validateEntry($row->item_id))
82 {
83 $items[] = $row->item_id;
84 }
85 else
86 {
87 $this->deleteEntry($row->item_id);
88 }
89 }
90
91 $this->items = $items;
92 }
93
94 public function delete()
95 {
96 global $ilDB;
97
98 $query = "DELETE FROM ut_lp_collections".
99 " WHERE obj_id = ".$ilDB->quote($this->obj_id ,"integer");
100 $ilDB->manipulate($query);
101
102 $query = "DELETE FROM ut_lp_coll_manual".
103 " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer");
104 $ilDB->manipulate($query);
105
106 // #15462 - reset internal data
107 $this->items = array();
108
109 return true;
110 }
111
112 //
113 // ENTRIES
114 //
115
116 protected function validateEntry($a_item_id)
117 {
118 return true;
119 }
120
121 public function isAssignedEntry($a_item_id)
122 {
123 if(is_array($this->items))
124 {
125 return (bool)in_array($a_item_id, $this->items);
126 }
127 return false;
128 }
129
130 protected function addEntry($a_item_id)
131 {
132 global $ilDB;
133
134 if(!$this->isAssignedEntry($a_item_id))
135 {
136 $query = "INSERT INTO ut_lp_collections".
137 " (obj_id, lpmode, item_id)".
138 " VALUES (".$ilDB->quote($this->obj_id , "integer").
139 ", ".$ilDB->quote($this->mode, "integer").
140 ", ".$ilDB->quote($a_item_id , "integer").
141 ")";
142 $ilDB->manipulate($query);
143 $this->items[] = $a_item_id;
144 }
145 return true;
146 }
147
148 protected function deleteEntry($a_item_id)
149 {
150 global $ilDB;
151
152 $query = "DELETE FROM ut_lp_collections".
153 " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer").
154 " AND item_id = ".$ilDB->quote($a_item_id, "integer");
155 $ilDB->manipulate($query);
156 return true;
157 }
158
159 public function deactivateEntries(array $a_item_ids)
160 {
161 foreach($a_item_ids as $item_id)
162 {
163 $this->deleteEntry($item_id);
164 }
165 }
166
167 public function activateEntries(array $a_item_ids)
168 {
169 foreach($a_item_ids as $item_id)
170 {
171 $this->addEntry($item_id);
172 }
173 }
174}
175
176?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _getInstance($a_copy_id)
Get instance of copy wizard options.
LP collection base class.
isAssignedEntry($a_item_id)
activateEntries(array $a_item_ids)
cloneCollection($a_target_id, $a_copy_id)
__construct($a_obj_id, $a_mode)
deactivateEntries(array $a_item_ids)
static _lookupObjId($a_id)
global $ilDB