ILIAS  Release_4_1_x_branch Revision 61804
 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 ,'integer')." ".
122  "AND crs_id = ".$ilDB->quote($this->getId(),'integer')." ";
123  $res = $ilDB->manipulate($query);
124  return true;
125  }
126 
127  function exists($a_item_ref_id)
128  {
129  global $ilDB;
130 
131  $query = "SELECT * FROM crs_start ".
132  "WHERE crs_id = ".$ilDB->quote($this->getId() ,'integer')." ".
133  "AND item_ref_id = ".$ilDB->quote($a_item_ref_id ,'integer')." ";
134  $res = $this->db->query($query);
135 
136  return $res->numRows() ? true : false;
137  }
138 
139  function add($a_item_ref_id)
140  {
141  global $ilDB;
142 
143  if($a_item_ref_id)
144  {
145  $next_id = $ilDB->nextId('crs_start');
146  $query = "INSERT INTO crs_start (crs_start_id,crs_id,item_ref_id) ".
147  "VALUES( ".
148  $ilDB->quote($next_id, 'integer').", ".
149  $ilDB->quote($this->getId() ,'integer').", ".
150  $ilDB->quote($a_item_ref_id ,'integer')." ".
151  ")";
152  $res = $ilDB->manipulate($query);
153  return true;
154  }
155  return false;
156  }
157 
158  function __deleteAll()
159  {
160  global $ilDB;
161 
162  $query = "DELETE FROM crs_start ".
163  "WHERE crs_id = ".$ilDB->quote($this->getId() ,'integer')." ";
164  $res = $ilDB->manipulate($query);
165 
166  return true;
167  }
168 
169  function getPossibleStarters(&$item_obj)
170  {
171  foreach($item_obj->getItems() as $node)
172  {
173  switch($node['type'])
174  {
175  case 'lm':
176  case 'sahs':
177  case 'svy':
178  case 'tst':
179  $poss_items[] = $node['ref_id'];
180  break;
181  }
182  }
183  return $poss_items ? $poss_items : array();
184  }
185 
186  function allFullfilled($user_id)
187  {
188  foreach($this->getStartObjects() as $item)
189  {
190  if(!$this->isFullfilled($user_id,$item['item_ref_id']))
191  {
192  return false;
193  }
194  }
195  return true;
196  }
197 
198 
199  function isFullfilled($user_id,$item_id)
200  {
201  global $ilObjDataCache;
202 
203  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
204  $lm_continue =& new ilCourseLMHistory($this->getRefId(),$user_id);
205  $continue_data = $lm_continue->getLMHistory();
206 
207  $obj_id = $ilObjDataCache->lookupObjId($item_id);
208  $type = $ilObjDataCache->lookupType($obj_id);
209 
210  switch($type)
211  {
212  case 'tst':
213  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
214 
215  if(!ilObjTestAccess::_checkCondition($obj_id,'finished',''))
216  {
217  return false;
218  }
219  break;
220  case 'svy':
221  include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
222  if(!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id))
223  {
224  return false;
225  }
226  break;
227  case 'sahs':
228  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
229  $completed = ilLPStatusWrapper::_getCompleted($obj_id);
230  if(!in_array($user_id,$completed))
231  {
232  return false;
233  }
234  break;
235 
236  default:
237  if(!isset($continue_data[$item_id]))
238  {
239  return false;
240  }
241  }
242  return true;
243  }
244 
245 
246  // PRIVATE
247  function __read()
248  {
249  global $tree,$ilDB;
250 
251  $this->start_objs = array();
252 
253  $query = "SELECT * FROM crs_start ".
254  "WHERE crs_id = ".$ilDB->quote($this->getId() ,'integer')." ";
255 
256  $res = $this->db->query($query);
257  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
258  {
259  if($tree->isInTree($row->item_ref_id))
260  {
261  $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
262  }
263  else
264  {
265  $this->delete($row->item_ref_id);
266  }
267  }
268  return true;
269  }
270 
271 
272 
273 
274 } // END class.ilObjCourseGrouping
275 ?>