00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 define('IL_CRS_TIMINGS_ACTIVATION',0);
00035 define('IL_CRS_TIMINGS_DEACTIVATED',1);
00036 define('IL_CRS_TIMINGS_PRESETTING',2);
00037
00038 class ilCourseItems
00039 {
00040 var $course_obj;
00041 var $ilErr;
00042 var $ilDB;
00043 var $tree;
00044 var $lng;
00045
00046 var $items;
00047 var $parent;
00048
00049 var $timing_type;
00050 var $timing_start;
00051 var $timing_end;
00052
00053
00054 function ilCourseItems(&$course_obj,$a_parent = 0,$user_id = 0)
00055 {
00056 global $ilErr,$ilDB,$lng,$tree;
00057
00058 $this->ilErr =& $ilErr;
00059 $this->ilDB =& $ilDB;
00060 $this->lng =& $lng;
00061 $this->tree =& $tree;
00062
00063 $this->course_obj =& $course_obj;
00064 $this->setParentId($a_parent);
00065 $this->user_id = $user_id;
00066
00067 $this->__read();
00068 }
00069
00078 public function cloneDependencies($a_target_id,$a_copy_id)
00079 {
00080 global $ilObjDataCache,$ilLog;
00081
00082 $ilLog->write(__METHOD__.': Begin course items...');
00083
00084 $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
00085
00086 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00087 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
00088 $mappings = $cp_options->getMappings();
00089
00090 $query = "SELECT * FROM crs_items WHERE ".
00091 "parent_id = ".$this->ilDB->quote($this->getParentId())." ".
00092 "ORDER BY position DESC";
00093 $res = $this->ilDB->query($query);
00094
00095 if(!$res->numRows())
00096 {
00097 $ilLog->write(__METHOD__.': No course items found.');
00098 return true;
00099 }
00100
00101
00102 if(!is_object($new_container = ilObjectFactory::getInstanceByRefId($a_target_id,false)))
00103 {
00104 $ilLog->write(__METHOD__.': Cannot create target object.');
00105 return false;
00106 }
00107 $new_items = new ilCourseItems($this->course_obj,$a_target_id);
00108 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00109 {
00110 if(!isset($mappings[$row->parent_id]) or !$mappings[$row->parent_id])
00111 {
00112 $ilLog->write(__METHOD__.': No mapping for parent nr. '.$row->parent_id);
00113 continue;
00114 }
00115 if(!isset($mappings[$row->obj_id]) or !$mappings[$row->obj_id])
00116 {
00117 $ilLog->write(__METHOD__.': No mapping for item nr. '.$row->obj_id);
00118 continue;
00119 }
00120 $new_item_id = $mappings[$row->obj_id];
00121 $new_parent = $mappings[$row->parent_id];
00122
00123 $new_items->setItemId($new_item_id);
00124 $new_items->setParentId($new_parent);
00125 $new_items->setTimingType($row->timing_type);
00126 $new_items->setTimingStart($row->timing_start);
00127 $new_items->setTimingEnd($row->timing_end);
00128 $new_items->setSuggestionStart($row->suggestion_start);
00129 $new_items->setSuggestionEnd($row->suggestion_end);
00130 $new_items->toggleChangeable($row->changeable);
00131 $new_items->setEarliestStart($row->earliest_start);
00132 $new_items->setLatestEnd($row->latest_end);
00133 $new_items->toggleVisible($row->visible);
00134 $new_items->setPosition($row->position);
00135 $new_items->update($new_item_id);
00136 $ilLog->write(__METHOD__.': Added new entry for item nr. '.$row->obj_id);
00137 }
00138 $ilLog->write(__METHOD__.': Finished course items.');
00139 }
00140
00141 public function setItemId($a_item_id)
00142 {
00143 $this->item_id = $a_item_id;
00144 }
00145
00146 public function getItemId()
00147 {
00148 return $this->item_id;
00149 }
00150 function getUserId()
00151 {
00152 global $ilUser;
00153
00154 return $this->user_id ? $this->user_id : $ilUser->getId();
00155 }
00156
00157 function _hasCollectionTimings($a_ref_id)
00158 {
00159 global $tree,$ilDB,$ilObjDataCache;
00160
00161
00162 include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
00163
00164 $obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
00165 switch(ilLPObjSettings::_lookupMode($obj_id))
00166 {
00167 case LP_MODE_MANUAL_BY_TUTOR:
00168 case LP_MODE_COLLECTION:
00169 include_once 'Services/Tracking/classes/class.ilLPCollectionCache.php';
00170 $ids = ilLPCollectionCache::_getItems($obj_id);
00171 break;
00172 default:
00173 $ids = array($a_ref_id);
00174 break;
00175 }
00176 if(!$ids)
00177 {
00178 return false;
00179 }
00180
00181 $query = "SELECT * FROM crs_items ".
00182 "WHERE timing_type = ".$ilDB->quote(IL_CRS_TIMINGS_PRESETTING)." ".
00183 "AND obj_id IN(".implode(",",ilUtil::quoteArray($ids)).")";
00184
00185 $res = $ilDB->query($query);
00186 return $res->numRows() ? true :false;
00187 }
00188
00196 public function _hasTimings($a_ref_id)
00197 {
00198 global $tree,$ilDB;
00199
00200 $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
00201
00202 foreach($subtree as $node)
00203 {
00204 $ref_ids[] = $node['ref_id'];
00205 }
00206
00207 $query = "SELECT * FROM crs_items ".
00208 "WHERE timing_type = ".$ilDB->quote(IL_CRS_TIMINGS_PRESETTING)." ".
00209 "AND obj_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).") ".
00210 "AND parent_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).")";
00211
00212 $res = $ilDB->query($query);
00213 return $res->numRows() ? true :false;
00214 }
00215
00216 function _hasChangeableTimings($a_ref_id)
00217 {
00218 global $tree,$ilDB;
00219
00220 $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
00221
00222 foreach($subtree as $node)
00223 {
00224 $ref_ids[] = $node['ref_id'];
00225 }
00226
00227 $query = "SELECT * FROM crs_items ".
00228 "WHERE timing_type = ".$ilDB->quote(IL_CRS_TIMINGS_PRESETTING)." ".
00229 "AND changeable = '1' ".
00230 "AND obj_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).") ".
00231 "AND parent_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).")";
00232
00233 $res = $ilDB->query($query);
00234 return $res->numRows() ? true :false;
00235 }
00236
00237 function setParentId($a_parent = 0)
00238 {
00239 $this->parent = $a_parent ? $a_parent : $this->course_obj->getRefId();
00240
00241 $this->__read();
00242
00243 return true;
00244 }
00245 function getParentId()
00246 {
00247 return $this->parent;
00248 }
00249
00250 function setTimingType($a_type)
00251 {
00252 $this->timing_type = $a_type;
00253 }
00254 function getTimingType()
00255 {
00256 return $this->timing_type;
00257 }
00258
00259 function setTimingStart($a_start)
00260 {
00261 $this->timing_start = $a_start;
00262 }
00263 function getTimingStart()
00264 {
00265 return $this->timing_start;
00266 }
00267 function setTimingEnd($a_end)
00268 {
00269 $this->timing_end = $a_end;
00270 }
00271 function getTimingEnd()
00272 {
00273 return $this->timing_end;
00274 }
00275 function setSuggestionStart($a_start)
00276 {
00277 $this->suggestion_start = $a_start;
00278 }
00279 function getSuggestionStart()
00280 {
00281 return $this->suggestion_start ? $this->suggestion_start : mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
00282 }
00283 function setSuggestionEnd($a_end)
00284 {
00285 $this->suggestion_end = $a_end;
00286 }
00287 function getSuggestionEnd()
00288 {
00289 return $this->suggestion_end ? $this->suggestion_end : mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
00290 }
00291 function setEarliestStart($a_start)
00292 {
00293 $this->earliest_start = $a_start;
00294 }
00295 function getEarliestStart()
00296 {
00297 return $this->earliest_start ? $this->earliest_start : mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
00298 }
00299 function setLatestEnd($a_end)
00300 {
00301 $this->latest_end = $a_end;
00302 }
00303 function getLatestEnd()
00304 {
00305 return $this->latest_end ? $this->latest_end : mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
00306 }
00307 function toggleVisible($a_status)
00308 {
00309 $this->visible = (int) $a_status;
00310 }
00311 function enabledVisible()
00312 {
00313 return (bool) $this->visible;
00314 }
00315 function toggleChangeable($a_status)
00316 {
00317 $this->changeable = (int) $a_status;
00318 }
00319 function enabledChangeable()
00320 {
00321 return (bool) $this->changeable;
00322 }
00323
00324 function setPosition($a_pos)
00325 {
00326 $this->position = $a_pos;
00327 }
00328
00329 function getAllItems()
00330 {
00331 return $this->items ? $this->items : array();
00332 }
00333
00337 function getFilteredItems($a_container_id)
00338 {
00339 global $objDefinition;
00340
00341 include_once 'Modules/Course/classes/Event/class.ilEventItems.php';
00342
00343 $event_items = ilEventItems::_getItemsOfContainer($a_container_id);
00344
00345 foreach($this->items as $item)
00346 {
00347 if(!in_array($item['ref_id'],$event_items) &&
00348 !$objDefinition->isSideBlock($item['type']))
00349 {
00350 $filtered[] = $item;
00351 }
00352 }
00353 return $filtered ? $filtered : array();
00354 }
00355
00356 function getItemsByEvent($a_event_id)
00357 {
00358 include_once 'Modules/Course/classes/Event/class.ilEventItems.php';
00359
00360 $event_items_obj = new ilEventItems($a_event_id);
00361 $event_items = $event_items_obj->getItems();
00362 foreach($event_items as $item)
00363 {
00364 if($this->tree->isDeleted($item))
00365 {
00366 continue;
00367 }
00368 $node = $this->tree->getNodeData($item);
00369 $items[] = $this->__getItemData($node);
00370 }
00371 return $items ? $items : array();
00372 }
00373
00374
00375 function getItems()
00376 {
00377 global $rbacsystem;
00378
00379 foreach($this->items as $item)
00380 {
00381 if($item["type"] != "rolf" and
00382 ($item["timing_type"] or
00383 ($item["timing_start"] <= time() and $item["timing_end"] >= time())))
00384 {
00385 if($rbacsystem->checkAccess('visible',$item['ref_id']))
00386 {
00387 $filtered[] = $item;
00388 }
00389 }
00390 }
00391 return $filtered ? $filtered : array();
00392 }
00393 function getItem($a_item_id)
00394 {
00395 foreach($this->items as $item)
00396 {
00397 if($item["child"] == $a_item_id)
00398 {
00399 return $item;
00400 }
00401 }
00402 return array();
00403 }
00404
00405 function validateActivation()
00406 {
00407 global $ilErr;
00408
00409 $ilErr->setMessage('');
00410
00411 if($this->getTimingType() == IL_CRS_TIMINGS_ACTIVATION)
00412 {
00413 if($this->getTimingStart() > $this->getTimingEnd())
00414 {
00415 $ilErr->appendMessage($this->lng->txt("crs_activation_start_invalid"));
00416 }
00417 }
00418 if($this->getTimingType() == IL_CRS_TIMINGS_PRESETTING)
00419 {
00420 if($this->getSuggestionEnd() > $this->getLatestEnd())
00421 {
00422 $ilErr->appendMessage($this->lng->txt('crs_latest_end_not_valid'));
00423 }
00424 }
00425
00426 #if($this->getTimingType() == IL_CRS_TIMINGS_PRESETTING and
00427 # $this->enabledChangeable())
00428 #{
00429 # if($this->getSuggestionStart() < $this->getEarliestStart() or
00430 # $this->getSuggestionEnd() > $this->getLatestEnd() or
00431 # $this->getSuggestionStart() > $this->getLatestEnd() or
00432 # $this->getSuggestionEnd() < $this->getEarliestStart())
00433 # {
00434 # $ilErr->appendMessage($this->lng->txt("crs_suggestion_not_within_activation"));
00435 # }
00436 #}
00437
00438 if($ilErr->getMessage())
00439 {
00440 return false;
00441 }
00442 return true;
00443 }
00444
00451 public function save()
00452 {
00453 global $ilLog;
00454
00455 $query = "INSERT INTO crs_items SET ".
00456 "timing_type = ".$ilDB->quote($this->getTimingType()).", ".
00457 "timing_start = ".$ilDB->quote($this->getTimingStart()).", ".
00458 "timing_end = ".$ilDB->quote($this->getTimingEnd()).", ".
00459 "suggestion_start = ".$ilDB->quote($this->getSuggestionStart()).", ".
00460 "suggestion_end = ".$ilDB->quote($this->getSuggestionEnd()).", ".
00461 "changeable = ".$ilDB->quote($this->enabledChangeable()).", ".
00462 "earliest_start = ".$ilDB->quote($this->getEarliestStart()).", ".
00463 "latest_end = ".$ilDB->quote($this->getLatestEnd()).", ".
00464 "visible = ".$ilDB->quote($this->enabledVisible()).", ".
00465 "parent_id = ".$ilDB->quote($this->getParentId()).", ".
00466 "obj_id = ".$ilDB->quote($this->getItemId()).", ".
00467 "position = ".$this->ilDB->quote($this->position);
00468 $ilLog->write(__METHOD__.': '.$query);
00469
00470 $res = $this->ilDB->query($query);
00471 }
00472
00473
00474 function update($a_item_id)
00475 {
00476 global $ilDB;
00477
00478 $query = "UPDATE crs_items SET ".
00479 "timing_type = ".$ilDB->quote($this->getTimingType()).", ".
00480 "timing_start = ".$ilDB->quote($this->getTimingStart()).", ".
00481 "timing_end = ".$ilDB->quote($this->getTimingEnd()).", ".
00482 "suggestion_start = ".$ilDB->quote($this->getSuggestionStart()).", ".
00483 "suggestion_end = ".$ilDB->quote($this->getSuggestionEnd()).", ".
00484 "changeable = ".$ilDB->quote($this->enabledChangeable()).", ".
00485 "earliest_start = ".$ilDB->quote($this->getEarliestStart()).", ".
00486 "latest_end = ".$ilDB->quote($this->getLatestEnd()).", ".
00487 "visible = ".$ilDB->quote($this->enabledVisible())." ".
00488 "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ".
00489 "AND obj_id = ".$ilDB->quote($a_item_id)."";
00490
00491 $res = $this->ilDB->query($query);
00492 $this->__read();
00493
00494 return true;
00495 }
00496
00497
00498 function moveUp($item_id)
00499 {
00500 $this->__updateTop($item_id);
00501 $this->__read();
00502
00503 return true;
00504 }
00505 function moveDown($item_id)
00506 {
00507 $this->__updateBottom($item_id);
00508 $this->__read();
00509
00510 return true;
00511 }
00512
00513 function deleteAllEntries()
00514 {
00515 global $ilDB;
00516
00517 $all_items = $this->tree->getChilds($this->parent);
00518
00519 foreach($all_items as $item)
00520 {
00521 $query = "DELETE FROM crs_items ".
00522 "WHERE parent_id = ".$ilDB->quote($item["child"])."";
00523
00524 $this->ilDB->query($query);
00525 }
00526 $query = "DELETE FROM crs_items ".
00527 "WHERE parent_id = ".$ilDB->quote($this->course_obj->getRefId())." ";
00528
00529 $this->ilDB->query($query);
00530
00531 return true;
00532 }
00533
00534
00535 function __read()
00536 {
00537 $this->items = array();
00538 $all_items = $this->tree->getChilds($this->parent);
00539
00540 foreach($all_items as $item)
00541 {
00542 if($item["type"] != 'rolf')
00543 {
00544 $this->items[] = $item;
00545 }
00546 }
00547
00548 for($i = 0;$i < count($this->items); ++$i)
00549 {
00550 if($this->items[$i]["type"] == 'rolf')
00551 {
00552 unset($this->items[$i]);
00553 continue;
00554 }
00555 $this->items[$i] = $this->__getItemData($this->items[$i]);
00556 }
00557 $this->__purgeDeleted();
00558 $this->__sort();
00559
00560 return true;
00561 }
00562
00563 function __purgeDeleted()
00564 {
00565 global $tree,$ilDB;
00566
00567 $all = array();
00568
00569 $query = "SELECT obj_id FROM crs_items ".
00570 "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ";
00571
00572 $res = $this->ilDB->query($query);
00573 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00574 {
00575 if($tree->getParentId($row->obj_id) != $this->getParentId())
00576 {
00577 $this->__delete($row->obj_id);
00578 }
00579 }
00580 }
00581
00582 function __delete($a_obj_id)
00583 {
00584 global $ilDB;
00585
00586
00587 $query = "SELECT position FROM crs_items ".
00588 "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ".
00589 "AND parent_id = ".$ilDB->quote($this->getParentId())." ";
00590
00591 $res = $this->ilDB->query($query);
00592 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00593 {
00594 $position = $row->position;
00595 }
00596
00597
00598 $query = "UPDATE crs_items SET ".
00599 "position = CASE ".
00600 "WHEN position > ".$ilDB->quote($position)." ".
00601 "THEN position - 1 ".
00602 "ELSE position ".
00603 "END ".
00604 "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ";
00605
00606 $res = $this->ilDB->query($query);
00607
00608
00609 $query = "DELETE FROM crs_items ".
00610 "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ".
00611 "AND obj_id = ".$ilDB->quote($a_obj_id)." ";
00612
00613 $res = $this->ilDB->query($query);
00614
00615 return true;
00616 }
00617
00618 function __getItemData($a_item)
00619 {
00620 global $ilDB,$ilUser,$ilObjDataCache;
00621
00622 $query = "SELECT * FROM crs_items ".
00623 "WHERE obj_id = ".$ilDB->quote($a_item['child'])." ".
00624 "AND parent_id = ".$ilDB->quote($a_item['parent'])." ";
00625
00626 $res = $this->ilDB->query($query);
00627 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00628 {
00629 $a_item["timing_type"] = $row->timing_type;
00630 $a_item["timing_start"] = $row->timing_start;
00631 $a_item["timing_end"] = $row->timing_end;
00632 $a_item["suggestion_start"] = $row->suggestion_start ? $row->suggestion_start :
00633 mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
00634 $a_item["suggestion_end"] = $row->suggestion_end ? $row->suggestion_end :
00635 mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
00636 $a_item['changeable'] = $row->changeable;
00637 $a_item['earliest_start'] = $row->earliest_start ? $row->earliest_start :
00638 mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
00639 $a_item['latest_end'] = $row->latest_end ? $row->latest_end :
00640 mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
00641 $a_item['visible'] = $row->visible;
00642 $a_item["position"] = $row->position;
00643
00644 include_once 'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
00645 $data = ilTimingPlaned::_getPlanedTimings($this->getUserId(),$a_item['child']);
00646
00647
00648 if($a_item['changeable'] and
00649 $a_item['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
00650 {
00651 if($data['planed_start'])
00652 {
00653 $a_item['start'] = $data['planed_start'];
00654 $a_item['end'] = $data['planed_end'];
00655 $a_item['activation_info'] = 'crs_timings_planed_info';
00656 }
00657 else
00658 {
00659 $a_item['start'] = $row->suggestion_start;
00660 $a_item['end'] = $row->suggestion_end;
00661 $a_item['activation_info'] = 'crs_timings_suggested_info';
00662 }
00663 }
00664 elseif($a_item['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
00665 {
00666 $a_item['start'] = $row->suggestion_start;
00667 $a_item['end'] = $row->suggestion_end;
00668 $a_item['activation_info'] = 'crs_timings_suggested_info';
00669 }
00670 elseif($a_item['timing_type'] == IL_CRS_TIMINGS_ACTIVATION)
00671 {
00672 $a_item['start'] = $row->timing_start;
00673 $a_item['end'] = $row->timing_end;
00674 $a_item['activation_info'] = 'activation';
00675 }
00676 else
00677 {
00678 $a_item['start'] = 999999999;
00679 }
00680 }
00681
00682 if(!isset($a_item["position"]))
00683 {
00684 $a_item = $this->createDefaultEntry($a_item);
00685 }
00686 return $a_item;
00687 }
00688
00689 function createDefaultEntry($a_item)
00690 {
00691 global $ilDB, $objDefinition;
00692
00693 $a_item["timing_type"] = IL_CRS_TIMINGS_DEACTIVATED;
00694 $a_item["timing_start"] = time();
00695 $a_item["timing_end"] = time();
00696 $a_item["suggestion_start"] = time();
00697 $a_item["suggestion_end"] = time();
00698 if ($objDefinition->isSideBlock($a_item["type"]))
00699 {
00700 $a_item["position"] = 0;
00701 }
00702 else
00703 {
00704 $a_item["position"] = $this->__getLastPosition() + 1;
00705 }
00706 $a_item['visible'] = 0;
00707 $a_item['changeable'] = 0;
00708 $a_item['earliest_start'] = time();
00709 $a_item['latest_end'] = mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
00710 $a_item['visible'] = 0;
00711 $a_item['changeable'] = 0;
00712
00713
00714 $query = "INSERT INTO crs_items ".
00715 "VALUES(".$ilDB->quote($a_item['parent']).",".
00716 $ilDB->quote($a_item["child"]).",".
00717 $ilDB->quote($a_item["timing_type"]).",".
00718 $ilDB->quote($a_item["timing_start"]).",".
00719 $ilDB->quote($a_item["timing_end"]).",".
00720 $ilDB->quote($a_item["suggestion_start"]).",".
00721 $ilDB->quote($a_item["suggestion_end"]).",".
00722 $ilDB->quote($a_item["changeable"]).",".
00723 $ilDB->quote($a_item['earliest_start']).", ".
00724 $ilDB->quote($a_item['latest_end']).", ".
00725 $ilDB->quote($a_item["visible"]).",".
00726 $ilDB->quote($a_item["position"]).")";
00727
00728 $res = $this->ilDB->query($query);
00729
00730 return $a_item;
00731 }
00732
00733
00734 function __getLastPosition()
00735 {
00736 global $ilDB;
00737
00738 $query = "SELECT MAX(position) as last_position FROM crs_items ".
00739 "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ";
00740
00741 $res = $this->ilDB->query($query);
00742 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00743 {
00744 $max = $row->last_position;
00745 }
00746 return $max ? $max : 0;
00747 }
00748
00749 function __updateTop($item_id)
00750 {
00751 global $ilDB;
00752
00753 $query = "SELECT position,obj_id FROM crs_items ".
00754 "WHERE obj_id = ".$ilDB->quote($item_id)." ".
00755 "AND parent_id = ".$ilDB->quote($this->getParentId())."";
00756
00757 $res = $this->ilDB->query($query);
00758 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00759 {
00760 $node_a["position"] = $row->position;
00761 $node_a["obj_id"] = $row->obj_id;
00762 }
00763
00764 $query = "SELECT position, obj_id FROM crs_items ".
00765 "WHERE position < ".$ilDB->quote($node_a["position"])." ".
00766 "AND parent_id = ".$ilDB->quote($this->getParentId())." ".
00767 "ORDER BY position DESC";
00768
00769 $res = $this->ilDB->query($query);
00770 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00771 {
00772 if(!$this->__isMovable($row->obj_id))
00773 {
00774 continue;
00775 }
00776 $node_b["position"] = $row->position;
00777 $node_b["obj_id"] = $row->obj_id;
00778 break;
00779 }
00780 $this->__switchNodes($node_a,$node_b);
00781
00782 }
00783
00784 function __updateBottom($item_id)
00785 {
00786 global $ilDB;
00787
00788 $query = "SELECT position,obj_id FROM crs_items ".
00789 "WHERE obj_id = ".$ilDB->quote($item_id)." ".
00790 "AND parent_id = ".$ilDB->quote($this->getParentId())."";
00791
00792 $res = $this->ilDB->query($query);
00793 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00794 {
00795 $node_a["position"] = $row->position;
00796 $node_a["obj_id"] = $row->obj_id;
00797 break;
00798 }
00799 $query = "SELECT position ,obj_id FROM crs_items ".
00800 "WHERE position > ".$ilDB->quote($node_a["position"])." ".
00801 "AND parent_id = ".$ilDB->quote($this->getParentId())." ".
00802 "ORDER BY position ASC";
00803
00804 $res = $this->ilDB->query($query);
00805 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00806 {
00807 if(!$this->__isMovable($row->obj_id))
00808 {
00809 continue;
00810 }
00811 $node_b["position"] = $row->position;
00812 $node_b["obj_id"] = $row->obj_id;
00813 break;
00814 }
00815 $this->__switchNodes($node_a,$node_b);
00816
00817 return true;
00818 }
00819
00820 function __isMovable($a_ref_id)
00821 {
00822 include_once 'Modules/Course/classes/Event/class.ilEventItems.php';
00823
00824 global $ilObjDataCache;
00825
00826 if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_ref_id)) != 'crs')
00827 {
00828 return true;
00829 }
00830 if(ilEventItems::_isAssigned($a_ref_id))
00831 {
00832 return false;
00833 }
00834 return true;
00835 }
00836
00837 function __switchNodes($node_a,$node_b)
00838 {
00839 global $ilDB;
00840
00841 if(!$node_b["obj_id"])
00842 {
00843 return false;
00844 }
00845
00846 $query = "UPDATE crs_items SET ".
00847 "position = ".$ilDB->quote($node_a["position"])." ".
00848 "WHERE obj_id = ".$ilDB->quote($node_b["obj_id"])." ".
00849 "AND parent_id = ".$ilDB->quote($this->getParentId())."";
00850
00851 $res = $this->ilDB->query($query);
00852
00853 $query = "UPDATE crs_items SET ".
00854 "position = ".$ilDB->quote($node_b["position"])." ".
00855 "WHERE obj_id = ".$ilDB->quote($node_a["obj_id"])." ".
00856 "AND parent_id = ".$ilDB->quote($this->getParentId())."";
00857
00858 $res = $this->ilDB->query($query);
00859
00860 return true;
00861 }
00862
00863
00864 function __sort()
00865 {
00866 switch($this->course_obj->getOrderType())
00867 {
00868 case IL_CRS_SORT_MANUAL:
00869 $this->items = ilUtil::sortArray($this->items,"position","asc",true);
00870 break;
00871
00872 case IL_CRS_SORT_TITLE:
00873 $this->items = ilUtil::sortArray($this->items,"title","asc");
00874 break;
00875
00876 case IL_CRS_SORT_ACTIVATION:
00877
00878
00879 list($active,$inactive) = $this->__splitByActivation();
00880
00881 $sorted_active = ilUtil::sortArray($active,"start","asc");
00882 $sorted_inactive = ilUtil::sortArray($inactive,'title','asc');
00883
00884 $this->items = array_merge($sorted_active,$sorted_inactive);
00885 break;
00886 }
00887 return true;
00888 }
00889
00890 function __splitByActivation()
00891 {
00892 $inactive = $active = array();
00893 foreach($this->items as $item)
00894 {
00895 if($item['timing_type'] == IL_CRS_TIMINGS_DEACTIVATED)
00896 {
00897 $inactive[] = $item;
00898 }
00899 else
00900 {
00901 $active[] = $item;
00902 }
00903 }
00904 return array($active,$inactive);
00905 }
00906
00907 function _getItem($a_item_id)
00908 {
00909 include_once 'Modules/Course/classes/class.ilObjCourse.php';
00910
00911 global $ilDB,$ilUser;
00912
00913 $query = "SELECT * FROM crs_items ".
00914 "WHERE obj_id = '".$a_item_id."'";
00915 $res = $ilDB->query($query);
00916 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00917 {
00918 $data['parent_id'] = $row->parent_id;
00919 $data['obj_id'] = $row->obj_id;
00920 $data['timing_type'] = $row->timing_type;
00921 $data['timing_start'] = $row->timing_start;
00922 $data['timing_end'] = $row->timing_end;
00923 $data["suggestion_start"] = $row->suggestion_start ? $row->suggestion_start :
00924 mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
00925 $data["suggestion_end"] = $row->suggestion_end ? $row->suggestion_end :
00926 mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
00927 $data['changeable'] = $row->changeable;
00928 $data['earliest_start'] = $row->earliest_start ? $row->earliest_start :
00929 mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
00930 $data['latest_end'] = $row->latest_end ? $row->latest_end :
00931 mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
00932 $data['visible'] = $row->visible;
00933 $data['position'] = $row->position;
00934
00935
00936 include_once 'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
00937 $user_data = ilTimingPlaned::_getPlanedTimings($ilUser->getId(),$data['child']);
00938
00939
00940 if($data['changeable'] and
00941 $data['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
00942 {
00943 if($user_data['planed_start'])
00944 {
00945 $data['start'] = $user_data['planed_start'];
00946 $data['end'] = $user_data['planed_end'];
00947 $data['activation_info'] = 'crs_timings_planed_info';
00948 }
00949 else
00950 {
00951 $data['start'] = $row->suggestion_start;
00952 $data['end'] = $row->suggestion_end;
00953 $data['activation_info'] = 'crs_timings_suggested_info';
00954 }
00955 }
00956 elseif($data['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
00957 {
00958 $data['start'] = $row->suggestion_start;
00959 $data['end'] = $row->suggestion_end;
00960 $data['activation_info'] = 'crs_timings_suggested_info';
00961 }
00962 elseif($data['timing_type'] == IL_CRS_TIMINGS_ACTIVATION)
00963 {
00964 $data['start'] = $row->timing_start;
00965 $data['end'] = $row->timing_end;
00966 $data['activation_info'] = 'activation';
00967 }
00968 else
00969 {
00970 $data['start'] = 999999999;
00971 }
00972 }
00973 return $data ? $data : array();
00974 }
00975
00976 function _isActivated($a_item_id)
00977 {
00978 global $ilDB;
00979
00980 $query = "SELECT * FROM crs_items ".
00981 "WHERE obj_id = ".$ilDB->quote($a_item_id)." ";
00982
00983 $res = $ilDB->query($query);
00984 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00985 {
00986 if($row->activation_unlimited)
00987 {
00988 return true;
00989 }
00990 if(time() > $row->activation_start and time() < $row->activation_end)
00991 {
00992 return true;
00993 }
00994 }
00995 return false;
00996 }
00997
01005 public static function _readActivationTimes($a_ref_ids)
01006 {
01007 global $ilDB;
01008
01009 if(!is_array($a_ref_ids) or !$a_ref_ids)
01010 {
01011 return array();
01012 }
01013
01014 $query = "SELECT obj_id,timing_type,timing_start,timing_end,visible FROM crs_items ".
01015 "WHERE obj_id IN (".implode(',',ilUtil::quoteArray($a_ref_ids)).")";
01016 $res = $ilDB->query($query);
01017 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01018 {
01019 $ac_times[(string) $row->obj_id]['obj_id'] = $row->obj_id;
01020 $ac_times[(string) $row->obj_id]['timing_type'] = $row->timing_type;
01021 $ac_times[(string) $row->obj_id]['timing_start'] = $row->timing_start;
01022 $ac_times[(string) $row->obj_id]['timing_end'] = $row->timing_end;
01023 $ac_times[(string) $row->obj_id]['visible'] = $row->visible;
01024 }
01025
01026 return $ac_times ? $ac_times : array();
01027 }
01028 }
01029 ?>