ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseStart.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2005 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  var $db;
36 
37  var $ref_id;
38  var $id;
39  var $start_objs = array();
40 
47  function ilCourseStart($a_course_ref_id,$a_course_obj_id)
48  {
49  global $ilDB;
50 
51  $this->db =& $ilDB;
52 
53  $this->ref_id = $a_course_ref_id;
54  $this->id = $a_course_obj_id;
55 
56  $this->__read();
57  }
58  function setId($a_id)
59  {
60  $this->id = $a_id;
61  }
62  function getId()
63  {
64  return $this->id;
65  }
66  function setRefId($a_ref_id)
67  {
68  $this->ref_id = $a_ref_id;
69  }
70  function getRefId()
71  {
72  return $this->ref_id;
73  }
74  function getStartObjects()
75  {
76  return $this->start_objs ? $this->start_objs : array();
77  }
78 
87  public function cloneDependencies($a_target_id,$a_copy_id)
88  {
89  global $ilObjDataCache,$ilLog;
90 
91  $ilLog->write(__METHOD__.': Begin course start objects...');
92 
93  $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
94  $start = new ilCourseStart($a_target_id,$new_obj_id);
95 
96  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
97  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
98  $mappings = $cwo->getMappings();
99  foreach($this->getStartObjects() as $start_id => $data)
100  {
101  $item_ref_id = $data['item_ref_id'];
102  if(isset($mappings[$item_ref_id]) and $mappings[$item_ref_id])
103  {
104  $ilLog->write(__METHOD__.': Clone start object nr. '.$item_ref_id);
105  $start->add($mappings[$item_ref_id]);
106  }
107  else
108  {
109  $ilLog->write(__METHOD__.': No mapping found for start object nr. '.$item_ref_id);
110  }
111  }
112  $ilLog->write(__METHOD__.': ... end course start objects');
113  return true;
114  }
115 
116  function delete($a_crs_start_id)
117  {
118  global $ilDB;
119 
120  $query = "DELETE FROM crs_start ".
121  "WHERE crs_start_id = ".$ilDB->quote($a_crs_start_id)." ".
122  "AND crs_id = ".$ilDB->quote($this->getId())." ";
123 
124  $this->db->query($query);
125 
126  return true;
127  }
128 
129  function exists($a_item_ref_id)
130  {
131  global $ilDB;
132 
133  $query = "SELECT * FROM crs_start ".
134  "WHERE crs_id = ".$ilDB->quote($this->getId())." ".
135  "AND item_ref_id = ".$a_item_ref_id." ";
136 
137  $res = $this->db->query($query);
138 
139  return $res->numRows() ? true : false;
140  }
141 
142  function add($a_item_ref_id)
143  {
144  global $ilDB;
145 
146  if($a_item_ref_id)
147  {
148  $query = "INSERT INTO crs_start ".
149  "SET crs_id = ".$ilDB->quote($this->getId()).", ".
150  "item_ref_id = ".$ilDB->quote($a_item_ref_id)." ";
151 
152  $this->db->query($query);
153 
154  return true;
155  }
156  return false;
157  }
158 
159  function __deleteAll()
160  {
161  global $ilDB;
162 
163  $query = "DELETE FROM crs_start ".
164  "WHERE crs_id = ".$ilDB->quote($this->getId())." ";
165 
166 
167  $this->db->query($query);
168 
169  return true;
170  }
171 
172  function getPossibleStarters(&$item_obj)
173  {
174  foreach($item_obj->getItems() as $node)
175  {
176  switch($node['type'])
177  {
178  case 'lm':
179  case 'sahs':
180  case 'svy':
181  case 'tst':
182  $poss_items[] = $node['ref_id'];
183  break;
184  }
185  }
186  return $poss_items ? $poss_items : array();
187  }
188 
189  function allFullfilled($user_id)
190  {
191  foreach($this->getStartObjects() as $item)
192  {
193  if(!$this->isFullfilled($user_id,$item['item_ref_id']))
194  {
195  return false;
196  }
197  }
198  return true;
199  }
200 
201 
202  function isFullfilled($user_id,$item_id)
203  {
204  global $ilObjDataCache;
205 
206  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
207  $lm_continue =& new ilCourseLMHistory($this->getRefId(),$user_id);
208  $continue_data = $lm_continue->getLMHistory();
209 
210  $obj_id = $ilObjDataCache->lookupObjId($item_id);
211  $type = $ilObjDataCache->lookupType($obj_id);
212 
213  switch($type)
214  {
215  case 'tst':
216  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
217 
218  if(!ilObjTestAccess::_checkCondition($obj_id,'finished',''))
219  {
220  return false;
221  }
222  break;
223  case 'svy':
224  include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
225  if(!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id))
226  {
227  return false;
228  }
229  break;
230  case 'sahs':
231  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
232  $completed = ilLPStatusWrapper::_getCompleted($obj_id);
233  if(!in_array($user_id,$completed))
234  {
235  return false;
236  }
237  break;
238 
239  default:
240  if(!isset($continue_data[$item_id]))
241  {
242  return false;
243  }
244  }
245  return true;
246  }
247 
248 
249  // PRIVATE
250  function __read()
251  {
252  global $tree,$ilDB;
253 
254  $this->start_objs = array();
255 
256  $query = "SELECT * FROM crs_start ".
257  "WHERE crs_id = ".$ilDB->quote($this->getId())." ";
258 
259  $res = $this->db->query($query);
260  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
261  {
262  if($tree->isInTree($row->item_ref_id))
263  {
264  $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
265  }
266  else
267  {
268  $this->delete($row->item_ref_id);
269  }
270  }
271  return true;
272  }
273 
274 
275 
276 
277 } // END class.ilObjCourseGrouping
278 ?>