ILIAS  release_4-3 Revision
 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 
170  {
171  include_once "Services/Object/classes/class.ilObjectActivation.php";
172  foreach(ilObjectActivation::getItems($this->getRefId(), false) as $node)
173  {
174  switch($node['type'])
175  {
176  case 'lm':
177  case 'sahs':
178  case 'svy':
179  case 'tst':
180  $poss_items[] = $node['ref_id'];
181  break;
182  }
183  }
184  return $poss_items ? $poss_items : array();
185  }
186 
187  function allFullfilled($user_id)
188  {
189  foreach($this->getStartObjects() as $item)
190  {
191  if(!$this->isFullfilled($user_id,$item['item_ref_id']))
192  {
193  return false;
194  }
195  }
196  return true;
197  }
198 
199 
200  function isFullfilled($user_id,$item_id)
201  {
202  global $ilObjDataCache;
203 
204  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
205  $lm_continue =& new ilCourseLMHistory($this->getRefId(),$user_id);
206  $continue_data = $lm_continue->getLMHistory();
207 
208  $obj_id = $ilObjDataCache->lookupObjId($item_id);
209  $type = $ilObjDataCache->lookupType($obj_id);
210 
211  switch($type)
212  {
213  case 'tst':
214  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
215 
216  if(!ilObjTestAccess::_checkCondition($obj_id,'finished',''))
217  {
218  return false;
219  }
220  break;
221  case 'svy':
222  include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
223  if(!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id))
224  {
225  return false;
226  }
227  break;
228  case 'sahs':
229  include_once 'Services/Tracking/classes/class.ilLPStatus.php';
230  if(ilLPStatus::_lookupStatus($obj_id, $user_id) != LP_STATUS_COMPLETED_NUM)
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 ?>