ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCourse.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
24 require_once "./Services/Container/classes/class.ilContainer.php";
25 include_once './Modules/Course/classes/class.ilCourseConstants.php';
26 
34 class ilObjCourse extends ilContainer
35 {
36  const CAL_REG_START = 1;
37  const CAL_REG_END = 2;
39  const CAL_ACTIVATION_END = 4;
40 
44 
45 
46  private $latitude = '';
47  private $longitude = '';
48  private $locationzoom = 0;
49  private $enablemap = 0;
50 
51  private $session_limit = 0;
52  private $session_prev = -1;
53  private $session_next = -1;
54 
61  function ilObjCourse($a_id = 0,$a_call_by_reference = true)
62  {
63 
64  #define("ILIAS_MODULE","course");
65  #define("KEEP_IMAGE_PATH",1);
66 
67  $this->SUBSCRIPTION_DEACTIVATED = 1;
68  $this->SUBSCRIPTION_CONFIRMATION = 2;
69  $this->SUBSCRIPTION_DIRECT = 3;
70  $this->SUBSCRIPTION_PASSWORD = 4;
71  $this->SUBSCRIPTION_AUTOSUBSCRIPTION = 5;
72  $this->ARCHIVE_DISABLED = 1;
73  $this->ARCHIVE_READ = 2;
74  $this->ARCHIVE_DOWNLOAD = 3;
75  $this->ABO_ENABLED = 1;
76  $this->ABO_DISABLED = 0;
77  $this->SHOW_MEMBERS_ENABLED = 1;
78  $this->SHOW_MEMBERS_DISABLED = 0;
79 
80  $this->type = "crs";
81 
82  parent::__construct($a_id,$a_call_by_reference);
83 
84  if($a_id)
85  {
86  #$this->__initMetaObject();
87  $this->initCourseMemberObject();
88  }
89  else
90  {
91 
92  }
93  }
94 
96  {
97  return $this->important;
98  }
99  function setImportantInformation($a_info)
100  {
101  $this->important = $a_info;
102  }
103  function getSyllabus()
104  {
105  return $this->syllabus;
106  }
107  function setSyllabus($a_syllabus)
108  {
109  $this->syllabus = $a_syllabus;
110  }
111  function getContactName()
112  {
113  return $this->contact_name;
114  }
115  function setContactName($a_cn)
116  {
117  $this->contact_name = $a_cn;
118  }
120  {
121  return $this->contact_consultation;
122  }
123  function setContactConsultation($a_value)
124  {
125  $this->contact_consultation = $a_value;
126  }
127  function getContactPhone()
128  {
129  return $this->contact_phone;
130  }
131  function setContactPhone($a_value)
132  {
133  $this->contact_phone = $a_value;
134  }
135  function getContactEmail()
136  {
137  return $this->contact_email;
138  }
139  function setContactEmail($a_value)
140  {
141  $this->contact_email = $a_value;
142  }
144  {
145  return $this->contact_responsibility;
146  }
147  function setContactResponsibility($a_value)
148  {
149  $this->contact_responsibility = $a_value;
150  }
151 
152  function getActivationType()
153  {
154  return (int) $this->activation_type;
155  }
156  function setActivationType($a_type)
157  {
158  $this->activation_type = $a_type;
159  }
161  {
162  return $this->activation_type == IL_CRS_ACTIVATION_UNLIMITED;
163 
164  }
165 
167  {
168  return $this->activation_start ? $this->activation_start : time();
169  }
170  function setActivationStart($a_value)
171  {
172  $this->activation_start = $a_value;
173  }
174  function getActivationEnd()
175  {
176  return $this->activation_end ? $this->activation_end : mktime(0,0,0,12,12,date("Y",time())+2);
177  }
178  function setActivationEnd($a_value)
179  {
180  $this->activation_end = $a_value;
181  }
182  function getOfflineStatus()
183  {
184  return $this->activation_type == IL_CRS_ACTIVATION_OFFLINE;
185  }
186 
187 
189  {
190  return $this->subscription_limitation_type;
191  }
193  {
194  $this->subscription_limitation_type = $a_type;
195  }
197  {
198  return $this->subscription_limitation_type == IL_CRS_SUBSCRIPTION_UNLIMITED;
199  }
201  {
202  return $this->subscription_start ? $this->subscription_start : time();
203  }
204  function setSubscriptionStart($a_value)
205  {
206  $this->subscription_start = $a_value;
207  }
209  {
210  return $this->subscription_end ? $this->subscription_end : mktime(0,0,0,12,12,date("Y",time())+2);
211  }
212  function setSubscriptionEnd($a_value)
213  {
214  $this->subscription_end = $a_value;
215  }
217  {
218  return $this->subscription_type ? $this->subscription_type : IL_CRS_SUBSCRIPTION_DIRECT;
219  #return $this->subscription_type ? $this->subscription_type : $this->SUBSCRIPTION_DEACTIVATED;
220  }
221  function setSubscriptionType($a_value)
222  {
223  $this->subscription_type = $a_value;
224  }
226  {
227  return $this->subscription_password;
228  }
229  function setSubscriptionPassword($a_value)
230  {
231  $this->subscription_password = $a_value;
232  }
234  {
235  return $this->view_mode == IL_CRS_VIEW_OBJECTIVE;
236  }
237 
239  {
240  return (bool) $this->waiting_list;
241  }
242 
243  function enableWaitingList($a_status)
244  {
245  $this->waiting_list = (bool) $a_status;
246  }
247 
249  {
250  if($this->getSubscriptionUnlimitedStatus())
251  {
252  return true;
253  }
254  if(time() > $this->getSubscriptionStart() and time() < $this->getSubscriptionEnd())
255  {
256  return true;
257  }
258  return false;
259  }
260 
266  public function enableSessionLimit($a_status)
267  {
268  $this->session_limit = $a_status;
269  }
270 
271  public function isSessionLimitEnabled()
272  {
273  return (bool) $this->session_limit;
274  }
275 
283  public function enableSubscriptionMembershipLimitation($a_status)
284  {
285  $this->subscription_membership_limitation = $a_status;
286  }
287 
293  public function setNumberOfPreviousSessions($a_num)
294  {
295  $this->session_prev = $a_num;
296  }
297 
302  public function getNumberOfPreviousSessions()
303  {
304  return $this->session_prev;
305  }
306 
312  public function setNumberOfNextSessions($a_num)
313  {
314  $this->session_next = $a_num;
315  }
316 
321  public function getNumberOfNextSessions()
322  {
323  return $this->session_next;
324  }
333  {
334  return (bool) $this->subscription_membership_limitation;
335  }
336 
338  {
339  return $this->subscription_max_members;
340  }
341  function setSubscriptionMaxMembers($a_value)
342  {
343  $this->subscription_max_members = $a_value;
344  }
345 
354  public static function _isSubscriptionNotificationEnabled($a_course_id)
355  {
356  global $ilDB;
357 
358  $query = "SELECT * FROM crs_settings ".
359  "WHERE obj_id = ".$ilDB->quote($a_course_id ,'integer')." ".
360  "AND sub_notify = 1";
361  $res = $ilDB->query($query);
362  return $res->numRows() ? true : false;
363  }
364 
371  public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
372  {
373  // Caching
374  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]))
375  {
376  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
377  }
378 
379  // Results are stored in $this->items
380  parent::getSubItems($a_admin_panel_enabled,$a_include_side_block);
381 
382  // No sessions
383  if(!is_array($this->items['sess']) or !$this->items['sess'])
384  {
385  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
386  }
387  // No session limit
388  if(!$this->isSessionLimitEnabled() or $a_admin_panel_enabled)
389  {
390  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
391  }
392 
393  // Search key of next appointment
394  $sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
395 
396  $num = 0;
397  $today = new ilDate(date('Ymd',time()),IL_CAL_DATE);
398  $today = $today->get(IL_CAL_UNIX);
399  foreach($sessions as $key => $item)
400  {
401  if($item['start'] >= $today)
402  {
403  break;
404  }
405  $num++;
406  }
407 
408  $previous = $sessions;
409  $next = $sessions;
410 
411  // Cut previous sessions
412  $previous = array_slice($previous, 0, $num);
413  if($this->getNumberOfPreviousSessions() >= 0)
414  {
415  $to_remove = (count($previous) - $this->getNumberOfPreviousSessions() > 0) ?
416  count($previous) - $this->getNumberOfPreviousSessions() :
417  0;
418  array_splice($previous, 0, $to_remove);
419  }
420 
421  // Cut next sessions
422  $next = array_slice($next, $num);
423  if($this->getNumberOfNextSessions() >= 0)
424  {
425  $next = array_splice($next, 0, $this->getNumberOfNextSessions());
426  }
427 
428  $sessions = array_merge($previous,$next);
429  $this->items['sess'] = $sessions;
430  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $this->items;
431  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
432  }
433 
435  {
436  return true;
437  return $this->subscription_notify ? true : false;
438  }
439  function setSubscriptionNotify($a_value)
440  {
441  $this->subscription_notify = $a_value ? true : false;
442  }
443 
444  function setViewMode($a_mode)
445  {
446  $this->view_mode = $a_mode;
447  }
448  function getViewMode()
449  {
450  return $this->view_mode;
451  }
452 
453  function _lookupViewMode($a_id)
454  {
455  global $ilDB;
456 
457  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
458  $res = $ilDB->query($query);
459  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
460  {
461  return $row->view_mode;
462  }
463  return false;
464  }
465 
466  function _lookupAboStatus($a_id)
467  {
468  global $ilDB;
469 
470  $query = "SELECT abo FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
471  $res = $ilDB->query($query);
472  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
473  {
474  return $row->abo;
475  }
476  return false;
477  }
478 
479  function getArchiveStart()
480  {
481  return $this->archive_start ? $this->archive_start : time();
482  }
483  function setArchiveStart($a_value)
484  {
485  $this->archive_start = $a_value;
486  }
487  function getArchiveEnd()
488  {
489  return $this->archive_end ? $this->archive_end : mktime(0,0,0,12,12,date("Y",time())+2);
490  }
491  function setArchiveEnd($a_value)
492  {
493  $this->archive_end = $a_value;
494  }
495  function getArchiveType()
496  {
497  return $this->archive_type ? IL_CRS_ARCHIVE_DOWNLOAD : IL_CRS_ARCHIVE_NONE;
498  }
499  function setArchiveType($a_value)
500  {
501  $this->archive_type = $a_value;
502  }
503  function setAboStatus($a_status)
504  {
505  $this->abo = $a_status;
506  }
507  function getAboStatus()
508  {
509  return $this->abo;
510  }
511  function setShowMembers($a_status)
512  {
513  $this->show_members = $a_status;
514  }
515  function getShowMembers()
516  {
517  return $this->show_members;
518  }
519 
520  function getMessage()
521  {
522  return $this->message;
523  }
524  function setMessage($a_message)
525  {
526  $this->message = $a_message;
527  }
528  function appendMessage($a_message)
529  {
530  if($this->getMessage())
531  {
532  $this->message .= "<br /> ";
533  }
534  $this->message .= $a_message;
535  }
536 
537  function getMembers()
538  {
539  return $this->members_obj->getMembers();
540  }
541 
542 
543  function isActivated($a_check_archive = false)
544  {
545  if($a_check_archive)
546  {
547  if($this->isArchived())
548  {
549  return true;
550  }
551  }
552  if($this->getOfflineStatus())
553  {
554  return false;
555  }
556  if($this->getActivationUnlimitedStatus())
557  {
558  return true;
559  }
560  if(time() < $this->getActivationStart() or
561  time() > $this->getActivationEnd())
562  {
563  return false;
564  }
565  return true;
566  }
567 
574  function _isActivated($a_obj_id)
575  {
576  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
577  return ilObjCourseAccess::_isActivated($a_obj_id);
578  }
579 
586  function _registrationEnabled($a_obj_id)
587  {
588  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
589  return ilObjCourseAccess::_registrationEnabled($a_obj_id);
590  }
591 
592  function isArchived()
593  {
594  if($this->getViewMode() != IL_CRS_VIEW_ARCHIVE)
595  {
596  return false;
597  }
598  if(time() < $this->getArchiveStart() or time() > $this->getArchiveEnd())
599  {
600  return false;
601  }
602  return true;
603  }
604 
605  function allowAbo()
606  {
607  return $this->ABO == $this->ABO_ENABLED;
608  }
609 
610  function read($a_force_db = false)
611  {
612  parent::read($a_force_db);
613 
614  $this->__readSettings();
615  }
616  function create($a_upload = false)
617  {
618  global $ilAppEventHandler;
619 
620  parent::create($a_upload);
621 
622  if(!$a_upload)
623  {
624  $this->createMetaData();
625  }
626  $this->__createDefaultSettings();
627 
628  $ilAppEventHandler->raise('Modules/Course',
629  'create',
630  array('object' => $this,
631  'obj_id' => $this->getId(),
632  'appointments' => $this->prepareAppointments('create')));
633 
634  }
635 
641  function setLatitude($a_latitude)
642  {
643  $this->latitude = $a_latitude;
644  }
645 
651  function getLatitude()
652  {
653  return $this->latitude;
654  }
655 
661  function setLongitude($a_longitude)
662  {
663  $this->longitude = $a_longitude;
664  }
665 
671  function getLongitude()
672  {
673  return $this->longitude;
674  }
675 
681  function setLocationZoom($a_locationzoom)
682  {
683  $this->locationzoom = $a_locationzoom;
684  }
685 
691  function getLocationZoom()
692  {
693  return $this->locationzoom;
694  }
695 
701  function setEnableCourseMap($a_enablemap)
702  {
703  $this->enablemap = $a_enablemap;
704  }
705 
712  {
713  return $this->enablemap;
714  }
715 
724  public function cloneObject($a_target_id,$a_copy_id = 0)
725  {
726  global $ilDB,$ilUser;
727 
728  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
729 
730  $this->cloneAutoGeneratedRoles($new_obj);
731  $this->cloneMetaData($new_obj);
732 
733  // Assign admin
734  $new_obj->initCourseMemberObject();
735  $new_obj->members_obj->add($ilUser->getId(),IL_CRS_ADMIN);
736 
737  // Copy settings
738  $this->cloneSettings($new_obj);
739 
740  // Course Defined Fields
741  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
742  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
743 
744  // Clone course files
745  include_once('Modules/Course/classes/class.ilCourseFile.php');
746  ilCourseFile::_cloneFiles($this->getId(),$new_obj->getId());
747 
748  // Copy learning progress settings
749  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
750  $obj_settings = new ilLPObjSettings($this->getId());
751  $obj_settings->cloneSettings($new_obj->getId());
752  unset($obj_settings);
753 
754  // clone icons
755  global $ilLog;
756  $ilLog->write(__METHOD__.': '.$this->getBigIconPath().' '.$this->getSmallIconPath());
757  $new_obj->saveIcons($this->getBigIconPath(),
758  $this->getSmallIconPath(),
759  $this->getTinyIconPath());
760 
761  return $new_obj;
762  }
763 
772  public function cloneDependencies($a_target_id,$a_copy_id)
773  {
774  global $ilObjDataCache;
775 
776  parent::cloneDependencies($a_target_id,$a_copy_id);
777 
778  // Clone course start objects
779  include_once('Modules/Course/classes/class.ilCourseStart.php');
780  $start = new ilCourseStart($this->getRefId(),$this->getId());
781  $start->cloneDependencies($a_target_id,$a_copy_id);
782 
783  // Clone course item settings
784  $this->initCourseItemObject();
785  $this->items_obj->cloneDependencies($a_target_id,$a_copy_id);
786 
787  // Clone course learning objectives
788  include_once('Modules/Course/classes/class.ilCourseObjective.php');
789  $crs_objective = new ilCourseObjective($this);
790  $crs_objective->ilClone($a_target_id,$a_copy_id);
791 
792  include_once('Services/Tracking/classes/class.ilLPCollections.php');
793  $lp_collection = new ilLPCollections($this->getId());
794  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
795 
796  return true;
797  }
798 
806  public function cloneAutoGeneratedRoles($new_obj)
807  {
808  global $ilLog,$rbacadmin,$rbacreview;
809 
810  $admin = $this->getDefaultAdminRole();
811  $new_admin = $new_obj->getDefaultAdminRole();
812  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
813  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
814 
815  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
816  {
817  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_admin');
818  }
819  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
820  $ilLog->write(__METHOD__.' : Finished copying of role crs_admin.');
821 
822  $tutor = $this->getDefaultTutorRole();
823  $new_tutor = $new_obj->getDefaultTutorRole();
824  if(!$tutor || !$new_tutor)
825  {
826  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_tutor');
827  }
828  $rbacadmin->copyRolePermissions($tutor,$source_rolf,$target_rolf,$new_tutor,true);
829  $ilLog->write(__METHOD__.' : Finished copying of role crs_tutor.');
830 
831  $member = $this->getDefaultMemberRole();
832  $new_member = $new_obj->getDefaultMemberRole();
833  if(!$member || !$new_member)
834  {
835  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_member');
836  }
837  $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
838  $ilLog->write(__METHOD__.' : Finished copying of role crs_member.');
839 
840  return true;
841  }
842 
843 
844  function validate()
845  {
846  $this->initCourseMemberObject();
847 
848  $this->setMessage('');
849 
850  #if(($this->getSubscriptionLimitationType() != IL_CRS_SUBSCRIPTION_DEACTIVATED) and
851  # $this->getSubscriptionType() == )
852  #{
853  # $this->appendMessage($this->lng->txt('crs_select_registration_type'));
854  #}
855 
856  if(($this->getActivationType() == IL_CRS_ACTIVATION_LIMITED) and
857  $this->getActivationEnd() < $this->getActivationStart())
858  {
859  $this->appendMessage($this->lng->txt("activation_times_not_valid"));
860  }
862  $this->getSubscriptionStart() > $this->getSubscriptionEnd())
863  {
864  $this->appendMessage($this->lng->txt("subscription_times_not_valid"));
865  }
866  #if((!$this->getActivationUnlimitedStatus() and
867  # !$this->getSubscriptionUnlimitedStatus()) and
868  # ($this->getSubscriptionStart() > $this->getActivationEnd() or
869  # $this->getSubscriptionStart() < $this->getActivationStart() or
870  # $this->getSubscriptionEnd() > $this->getActivationEnd() or
871  # $this->getSubscriptionEnd() < $this->getActivationStart()))
872  #
873  #{
874  # $this->appendMessage($this->lng->txt("subscription_time_not_within_activation"));
875  #}
877  {
878  $this->appendMessage($this->lng->txt("crs_password_required"));
879  }
880  if($this->isSubscriptionMembershipLimited() and ($this->getSubscriptionMaxMembers() <= 0 or !is_numeric($this->getSubscriptionMaxMembers())))
881  {
882  $this->appendMessage($this->lng->txt("max_members_not_numeric"));
883  }
884  if(($this->getViewMode() == IL_CRS_VIEW_ARCHIVE) and
885  $this->getArchiveStart() > $this->getArchiveEnd())
886  {
887  $this->appendMessage($this->lng->txt("archive_times_not_valid"));
888  }
889  return $this->getMessage() ? false : true;
890  }
891 
893  {
894  global $ilErr;
895  $error = false;
896  if($this->getContactEmail()) {
897  $emails = split(",",$this->getContactEmail());
898 
899  foreach ($emails as $email) {
900  $email = trim($email);
901  if (!(ilUtil::is_email($email) or ilObjUser::getUserIdByLogin($email)))
902  {
903  $ilErr->appendMessage($this->lng->txt('contact_email_not_valid')." '".$email."'");
904  $error = true;
905  }
906  }
907  }
908  return !$error;
909  }
910 
911  function hasContactData()
912  {
913  return strlen($this->getContactName()) or
914  strlen($this->getContactResponsibility()) or
915  strlen($this->getContactEmail()) or
916  strlen($this->getContactPhone()) or
917  strlen($this->getContactConsultation());
918  }
919 
920 
927  function delete()
928  {
929  global $ilAppEventHandler;
930 
931  // always call parent delete function first!!
932  if (!parent::delete())
933  {
934  return false;
935  }
936 
937  // delete meta data
938  $this->deleteMetaData();
939 
940  // put here course specific stuff
941 
942  $this->__deleteSettings();
943 
944  $this->initCourseItemObject();
945  $this->items_obj->deleteAllEntries();
946 
947  include_once('Modules/Course/classes/class.ilCourseParticipants.php');
949 
950  $this->initCourseArchiveObject();
951  $this->archives_obj->deleteAll();
952 
953  include_once './Modules/Course/classes/class.ilCourseObjective.php';
955 
956  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
958 
959  include_once './Modules/Course/classes/class.ilCourseFile.php';
961 
962  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
964 
965  $ilAppEventHandler->raise('Modules/Course',
966  'delete',
967  array('object' => $this,
968  'obj_id' => $this->getId(),
969  'appointments' => $this->prepareAppointments('delete')));
970 
971 
972  return true;
973  }
974 
975 
976 
980  function update()
981  {
982  global $ilAppEventHandler,$ilLog;
983 
984  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
985  $sorting = new ilContainerSortingSettings($this->getId());
986  $sorting->setSortMode($this->getOrderType());
987  $sorting->update();
988 
989  $this->updateMetaData();
990  $this->updateSettings();
991  parent::update();
992 
993  $ilAppEventHandler->raise('Modules/Course',
994  'update',
995  array('object' => $this,
996  'obj_id' => $this->getId(),
997  'appointments' => $this->prepareAppointments('update')));
998 
999  }
1000 
1001  function updateSettings()
1002  {
1003  global $ilDB;
1004 
1005  // Due to a bug 3.5.alpha maybe no settings exist. => create default settings
1006 
1007  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1008  $res = $ilDB->query($query);
1009 
1010  if(!$res->numRows())
1011  {
1012  $this->__createDefaultSettings();
1013  }
1014 
1015  $query = "UPDATE crs_settings SET ".
1016  "syllabus = ".$ilDB->quote($this->getSyllabus() ,'text').", ".
1017  "contact_name = ".$ilDB->quote($this->getContactName() ,'text').", ".
1018  "contact_responsibility = ".$ilDB->quote($this->getContactResponsibility() ,'text').", ".
1019  "contact_phone = ".$ilDB->quote($this->getContactPhone() ,'text').", ".
1020  "contact_email = ".$ilDB->quote($this->getContactEmail() ,'text').", ".
1021  "contact_consultation = ".$ilDB->quote($this->getContactConsultation() ,'text').", ".
1022  "activation_type = ".$ilDB->quote($this->getActivationType() ,'integer').", ".
1023  "activation_start = ".$ilDB->quote($this->getActivationStart() ,'integer').", ".
1024  "activation_end = ".$ilDB->quote($this->getActivationEnd() ,'integer').", ".
1025  "sub_limitation_type = ".$ilDB->quote($this->getSubscriptionLimitationType() ,'integer').", ".
1026  "sub_start = ".$ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1027  "sub_end = ".$ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1028  "sub_type = ".$ilDB->quote($this->getSubscriptionType() ,'integer').", ".
1029  "sub_password = ".$ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1030  "sub_mem_limit = ".$ilDB->quote((int) $this->isSubscriptionMembershipLimited() ,'integer').", ".
1031  "sub_max_members = ".$ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1032  "sub_notify = ".$ilDB->quote($this->getSubscriptionNotify() ,'integer').", ".
1033  "view_mode = ".$ilDB->quote($this->getViewMode() ,'integer').", ".
1034  "archive_start = ".$ilDB->quote($this->getArchiveStart() ,'integer').", ".
1035  "archive_end = ".$ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1036  "archive_type = ".$ilDB->quote($this->getArchiveType() ,'integer').", ".
1037  "abo = ".$ilDB->quote($this->getAboStatus() ,'integer').", ".
1038  "waiting_list = ".$ilDB->quote($this->enabledWaitingList() ,'integer').", ".
1039  "important = ".$ilDB->quote($this->getImportantInformation() ,'text').", ".
1040  "show_members = ".$ilDB->quote($this->getShowMembers() ,'integer').", ".
1041  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
1042  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
1043  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
1044  "enable_course_map = ".$ilDB->quote((int) $this->getEnableCourseMap() ,'integer').", ".
1045  'session_limit = '.$ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1046  'session_prev = '.$ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1047  'session_next = '.$ilDB->quote($this->getNumberOfNextSessions(),'integer').' '.
1048  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1049 
1050  $res = $ilDB->manipulate($query);
1051  }
1052 
1060  public function cloneSettings($new_obj)
1061  {
1062  $new_obj->setSyllabus($this->getSyllabus());
1063  $new_obj->setContactName($this->getContactName());
1064  $new_obj->setContactResponsibility($this->getContactResponsibility());
1065  $new_obj->setContactPhone($this->getContactPhone());
1066  $new_obj->setContactEmail($this->getContactEmail());
1067  $new_obj->setContactConsultation($this->getContactConsultation());
1068  $new_obj->setActivationType($this->getActivationType());
1069  $new_obj->setActivationStart($this->getActivationStart());
1070  $new_obj->setActivationEnd($this->getActivationEnd());
1071  $new_obj->setSubscriptionLimitationType($this->getSubscriptionLimitationType());
1072  $new_obj->setSubscriptionStart($this->getSubscriptionStart());
1073  $new_obj->setSubscriptionEnd($this->getSubscriptionEnd());
1074  $new_obj->setSubscriptionType($this->getSubscriptionType());
1075  $new_obj->setSubscriptionPassword($this->getSubscriptionPassword());
1076  $new_obj->enableSubscriptionMembershipLimitation($this->isSubscriptionMembershipLimited());
1077  $new_obj->setSubscriptionMaxMembers($this->getSubscriptionMaxMembers());
1078  $new_obj->setSubscriptionNotify($this->getSubscriptionNotify());
1079  $new_obj->setViewMode($this->getViewMode());
1080  $new_obj->setOrderType($this->getOrderType());
1081  $new_obj->setArchiveStart($this->getArchiveStart());
1082  $new_obj->setArchiveEnd($this->getArchiveEnd());
1083  $new_obj->setArchiveType($this->getArchiveType());
1084  $new_obj->setAboStatus($this->getAboStatus());
1085  $new_obj->enableWaitingList($this->enabledWaitingList());
1086  $new_obj->setImportantInformation($this->getImportantInformation());
1087  $new_obj->setShowMembers($this->getShowMembers());
1088  $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
1089  $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
1090  $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
1091  $new_obj->update();
1092  }
1093 
1095  {
1096  global $ilDB;
1097 
1098  $query = "INSERT INTO crs_settings (obj_id,syllabus,contact_name,contact_responsibility,".
1099  "contact_phone,contact_email,contact_consultation,activation_type,activation_start,".
1100  "activation_end,sub_limitation_type,sub_start,sub_end,sub_type,sub_password,sub_mem_limit,".
1101  "sub_max_members,sub_notify,view_mode,archive_start,archive_end,archive_type,abo," .
1102  "latitude,longitude,location_zoom,enable_course_map,waiting_list,show_members, ".
1103  "session_limit,session_prev,session_next ) ".
1104  "VALUES( ".
1105  $ilDB->quote($this->getId() ,'integer').", ".
1106  $ilDB->quote($this->getSyllabus() ,'text').", ".
1107  $ilDB->quote($this->getContactName() ,'text').", ".
1108  $ilDB->quote($this->getContactResponsibility() ,'text').", ".
1109  $ilDB->quote($this->getContactPhone() ,'text').", ".
1110  $ilDB->quote($this->getContactEmail() ,'text').", ".
1111  $ilDB->quote($this->getContactConsultation() ,'text').", ".
1112  $ilDB->quote(IL_CRS_ACTIVATION_OFFLINE ,'integer').", ".
1113  $ilDB->quote($this->getActivationStart() ,'integer').", ".
1114  $ilDB->quote($this->getActivationEnd() ,'integer').", ".
1115  $ilDB->quote(IL_CRS_SUBSCRIPTION_DEACTIVATED ,'integer').", ".
1116  $ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1117  $ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1118  $ilDB->quote(IL_CRS_SUBSCRIPTION_DIRECT ,'integer').", ".
1119  $ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1120  "0, ".
1121  $ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1122  "1, ".
1123  "0, ".
1124  $ilDB->quote($this->getArchiveStart() ,'integer').", ".
1125  $ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1126  $ilDB->quote(IL_CRS_ARCHIVE_NONE ,'integer').", ".
1127  $ilDB->quote($this->ABO_ENABLED ,'integer').", ".
1128  $ilDB->quote($this->getLatitude() ,'text').", ".
1129  $ilDB->quote($this->getLongitude() ,'text').", ".
1130  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
1131  $ilDB->quote($this->getEnableCourseMap() ,'integer').", ".
1132  #"objective_view = '0', ".
1133  "1, ".
1134  "1,".
1135  $ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1136  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1137  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').' '.
1138  ")";
1139 
1140  $res = $ilDB->manipulate($query);
1141  $this->__readSettings();
1142 
1143  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1144  $sorting = new ilContainerSortingSettings($this->getId());
1145  $sorting->setSortMode(ilContainer::SORT_MANUAL);
1146  $sorting->update();
1147  }
1148 
1149 
1150  function __readSettings()
1151  {
1152  global $ilDB;
1153 
1154  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1155 
1156  $res = $ilDB->query($query);
1157  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1158  {
1159  $this->setSyllabus($row->syllabus);
1160  $this->setContactName($row->contact_name);
1161  $this->setContactResponsibility($row->contact_responsibility);
1162  $this->setContactPhone($row->contact_phone);
1163  $this->setContactEmail($row->contact_email);
1164  $this->setContactConsultation($row->contact_consultation);
1165  $this->setActivationType($row->activation_type);
1166  $this->setActivationStart($row->activation_start);
1167  $this->setActivationEnd($row->activation_end);
1168  $this->setSubscriptionLimitationType($row->sub_limitation_type);
1169  $this->setSubscriptionStart($row->sub_start);
1170  $this->setSubscriptionEnd($row->sub_end);
1171  $this->setSubscriptionType($row->sub_type);
1172  $this->setSubscriptionPassword($row->sub_password);
1173  $this->enableSubscriptionMembershipLimitation($row->sub_mem_limit);
1174  $this->setSubscriptionMaxMembers($row->sub_max_members);
1175  $this->setSubscriptionNotify($row->sub_notify);
1176  $this->setViewMode($row->view_mode);
1177  $this->setArchiveStart($row->archive_start);
1178  $this->setArchiveEnd($row->archive_end);
1179  $this->setArchiveType($row->archive_type);
1180  $this->setAboStatus($row->abo);
1181  $this->enableWaitingList($row->waiting_list);
1182  $this->setImportantInformation($row->important);
1183  $this->setShowMembers($row->show_members);
1184  $this->setLatitude($row->latitude);
1185  $this->setLongitude($row->longitude);
1186  $this->setLocationZoom($row->location_zoom);
1187  $this->setEnableCourseMap($row->enable_course_map);
1188  $this->enableSessionLimit($row->session_limit);
1189  $this->setNumberOfPreviousSessions($row->session_prev);
1190  $this->setNumberOfNextSessions($row->session_next);
1191  }
1192  return true;
1193  }
1194 
1195  function initWaitingList()
1196  {
1197  include_once "./Modules/Course/classes/class.ilCourseWaitingList.php";
1198 
1199  if(!is_object($this->waiting_list_obj))
1200  {
1201  $this->waiting_list_obj = new ilCourseWaitingList($this->getId());
1202  }
1203  return true;
1204  }
1205 
1206 
1208  {
1209  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1210  $this->members_obj = ilCourseParticipants::_getInstanceByObjId($this->getId());
1211  return true;
1212  }
1213 
1214  function initCourseItemObject($a_child_id = 0)
1215  {
1216  include_once "./Modules/Course/classes/class.ilCourseItems.php";
1217 
1218  if(!is_object($this->items_obj))
1219  {
1220  $this->items_obj = new ilCourseItems($this,$a_child_id);
1221  }
1222  return true;
1223  }
1224 
1232  public function getCourseItemObject()
1233  {
1234  if(is_object($this->items_obj))
1235  {
1236  return $this->items_obj;
1237  }
1238  $this->initCourseItemObject();
1239  return $this->items_obj;
1240  }
1241 
1242 
1244  {
1245  include_once "./Modules/Course/classes/class.ilCourseArchives.php";
1246 
1247  if(!is_object($this->archives_obj))
1248  {
1249  $this->archives_obj =& new ilCourseArchives($this);
1250  }
1251  return true;
1252  }
1253 
1254 
1255 
1256  // RBAC METHODS
1257  function initDefaultRoles()
1258  {
1259  global $rbacadmin,$rbacreview,$ilDB;
1260 
1261  $rolf_obj = $this->createRoleFolder();
1262 
1263  // CREATE ADMIN ROLE
1264  $role_obj = $rolf_obj->createRole("il_crs_admin_".$this->getRefId(),"Admin of course obj_no.".$this->getId());
1265  $admin_id = $role_obj->getId();
1266 
1267  // SET PERMISSION TEMPLATE OF NEW LOCAL ADMIN ROLE
1268  $query = "SELECT obj_id FROM object_data ".
1269  " WHERE type='rolt' AND title='il_crs_admin'";
1270 
1271  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1272  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1273 
1274  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1275  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1276  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1277 
1278  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1279  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1280  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1281 
1282  // CREATE TUTOR ROLE
1283  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1284  $role_obj = $rolf_obj->createRole("il_crs_tutor_".$this->getRefId(),"Tutors of course obj_no.".$this->getId());
1285  $member_id = $role_obj->getId();
1286 
1287  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1288  $query = "SELECT obj_id FROM object_data ".
1289  " WHERE type='rolt' AND title='il_crs_tutor'";
1290  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1291  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1292 
1293  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1294  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1295  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1296 
1297  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1298  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1299  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1300 
1301  // CREATE MEMBER ROLE
1302  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1303  $role_obj = $rolf_obj->createRole("il_crs_member_".$this->getRefId(),"Member of course obj_no.".$this->getId());
1304  $member_id = $role_obj->getId();
1305 
1306  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1307  $query = "SELECT obj_id FROM object_data ".
1308  " WHERE type='rolt' AND title='il_crs_member'";
1309  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1310  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1311 
1312  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1313  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1314  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1315 
1316  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1317  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1318  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1319 
1320  unset($role_obj);
1321  unset($rolf_obj);
1322 
1323  // Break inheritance, create local roles and initialize permission
1324  // settings depending on course status.
1325  $this->__setCourseStatus();
1326 
1327  return true;
1328  }
1329 
1347  {
1348  global $rbacadmin, $rbacreview, $rbacsystem;
1349 
1350  //get Rolefolder of course
1351  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1352 
1353  //define all relevant roles for which rights are needed to be changed
1354  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1355  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultCourseRoles());
1356 
1357  $template_id = $this->__getCrsNonMemberTemplateId();
1358 
1359  //get defined operations from template
1360  if (is_null($template_id))
1361  {
1362  $template_ops = array();
1363  } else {
1364  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'crs', ROLE_FOLDER_ID);
1365  }
1366 
1367  foreach ($arr_relevantParentRoleIds as $parentRole)
1368  {
1369  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1370  {
1371  continue;
1372  }
1373 
1374  $granted_permissions = array();
1375 
1376  // Delete the linked role for the parent role
1377  // (just in case if it already exists).
1378  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1379 
1380  // Grant permissions on the course object for
1381  // the parent role. In the foreach loop we
1382  // compute the intersection of the role
1383  // template il_crs_non_member and the
1384  // permission template of the parent role.
1385  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1386  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1387  foreach ($template_ops as $template_op)
1388  {
1389  if (in_array($template_op,$current_ops))
1390  {
1391  array_push($granted_permissions,$template_op);
1392  }
1393  }
1394  if (!empty($granted_permissions))
1395  {
1396  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1397  }
1398 
1399  // Create a linked role for the parent role and
1400  // initialize it with the intersection of
1401  // il_crs_non_member and the permission
1402  // template of the parent role
1403  if (! is_null($template_id))
1404  {
1405  $rbacadmin->copyRolePermissionIntersection(
1406  $template_id, ROLE_FOLDER_ID,
1407  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1408  $rolf_data["child"], $parentRole
1409  );
1410  }
1411  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1412  }//END foreach
1413  }
1414 
1422  {
1423  global $ilDB;
1424 
1425  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
1426  $res = $this->ilias->db->query($q);
1427  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1428 
1429  return $row["obj_id"];
1430  }
1431 
1438  public function getLocalCourseRoles($a_translate = false)
1439  {
1440  global $rbacadmin,$rbacreview;
1441 
1442  if (empty($this->local_roles))
1443  {
1444  $this->local_roles = array();
1445  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1446  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1447 
1448  foreach ($role_arr as $role_id)
1449  {
1450  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1451  {
1452  $role_Obj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
1453 
1454  if ($a_translate)
1455  {
1456  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1457  }
1458  else
1459  {
1460  $role_name = $role_Obj->getTitle();
1461  }
1462  $this->local_roles[$role_name] = $role_Obj->getId();
1463  }
1464  }
1465  }
1466 
1467  return $this->local_roles;
1468  }
1469 
1470 
1471 
1481  public function getDefaultCourseRoles($a_crs_id = "")
1482  {
1483  global $rbacadmin, $rbacreview;
1484 
1485  if (strlen($a_crs_id) > 0)
1486  {
1487  $crs_id = $a_crs_id;
1488  }
1489  else
1490  {
1491  $crs_id = $this->getRefId();
1492  }
1493 
1494  $rolf = $rbacreview->getRoleFolderOfObject($crs_id);
1495  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1496 
1497  foreach ($role_arr as $role_id)
1498  {
1499  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1500 
1501  $crs_Member ="il_crs_member_".$crs_id;
1502  $crs_Admin ="il_crs_admin_".$crs_id;
1503  $crs_Tutor ="il_crs_tutor_".$crs_id;
1504 
1505  if (strcmp($role_Obj->getTitle(), $crs_Member) == 0 )
1506  {
1507  $arr_crsDefaultRoles["crs_member_role"] = $role_Obj->getId();
1508  }
1509 
1510  if (strcmp($role_Obj->getTitle(), $crs_Admin) == 0)
1511  {
1512  $arr_crsDefaultRoles["crs_admin_role"] = $role_Obj->getId();
1513  }
1514 
1515  if (strcmp($role_Obj->getTitle(), $crs_Tutor) == 0)
1516  {
1517  $arr_crsDefaultRoles["crs_tutor_role"] = $role_Obj->getId();
1518  }
1519  }
1520 
1521  return $arr_crsDefaultRoles;
1522  }
1523 
1524  function __getLocalRoles()
1525  {
1526  global $rbacreview;
1527 
1528  // GET role_objects of predefined roles
1529 
1530  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1531 
1532  return $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1533  }
1534 
1535  function __deleteSettings()
1536  {
1537  global $ilDB;
1538 
1539  $query = "DELETE FROM crs_settings ".
1540  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1541  $res = $ilDB->manipulate($query);
1542 
1543  return true;
1544  }
1545 
1546 
1547 
1549  {
1550  $local_roles = $this->__getLocalRoles();
1551 
1552  foreach($local_roles as $role_id)
1553  {
1554  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1555  {
1556  if(!strcmp($tmp_role->getTitle(),"il_crs_member_".$this->getRefId()))
1557  {
1558  return $role_id;
1559  }
1560  }
1561  }
1562  return false;
1563  }
1565  {
1566  $local_roles = $this->__getLocalRoles();
1567 
1568  foreach($local_roles as $role_id)
1569  {
1570  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1571  {
1572  if(!strcmp($tmp_role->getTitle(),"il_crs_tutor_".$this->getRefId()))
1573  {
1574  return $role_id;
1575  }
1576  }
1577  }
1578  return false;
1579  }
1581  {
1582  $local_roles = $this->__getLocalRoles();
1583 
1584  foreach($local_roles as $role_id)
1585  {
1586  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1587  {
1588  if(!strcmp($tmp_role->getTitle(),"il_crs_admin_".$this->getRefId()))
1589  {
1590  return $role_id;
1591  }
1592  }
1593  }
1594  return false;
1595  }
1596 
1597  // static method for condition handler
1598  function _checkCondition($a_obj_id,$a_operator,$a_value,$a_usr_id = 0)
1599  {
1600  global $ilUser;
1601 
1602  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
1603 
1604  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1605 
1606  switch($a_operator)
1607  {
1608  case 'passed':
1609  return ilCourseParticipants::_hasPassed($a_obj_id,$a_usr_id);
1610 
1611  default:
1612  return true;
1613  }
1614  }
1615 
1616  function _deleteUser($a_usr_id)
1617  {
1618  // Delete all user related data
1619  // delete lm_history
1620  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
1621  ilCourseLMHistory::_deleteUser($a_usr_id);
1622 
1623  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
1625 
1626  // Course objectives
1627  include_once './Modules/Course/classes/class.ilCourseObjectiveResult.php';
1629  }
1630 
1640  public function handleECSSettings($a_export,$a_owner,$a_mids)
1641  {
1642  try
1643  {
1644  include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
1645 
1646  $writer = new ilECSContentWriter($this);
1647  $writer->setExportable($a_export);
1648  $writer->setOwnerId($a_owner);
1649  $writer->setParticipantIds((array) $a_mids);
1650  $writer->refresh();
1651  }
1652  catch(ilECSConnectorException $exc)
1653  {
1654  throw $exc;
1655  }
1656  catch(ilECSContentWriterException $exc)
1657  {
1658  throw $exc;
1659  }
1660  }
1661 
1668  public function MDUpdateListener($a_element)
1669  {
1670  global $ilLog;
1671 
1672  parent::MDUpdateListener($a_element);
1673 
1674  switch($a_element)
1675  {
1676  case 'General':
1677  $this->updateECSContent();
1678  break;
1679  default:
1680  return true;
1681  }
1682  }
1683 
1691  public function updateECSContent()
1692  {
1693  global $ilLog;
1694 
1695  include_once('./Services/WebServices/ECS/classes/class.ilECSSettings.php');
1696  $settings = ilECSSettings::_getInstance();
1697  if(!$settings->isEnabled())
1698  {
1699  return true;
1700  }
1701  try
1702  {
1703  // Update ECS EContent
1704  include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
1705  $writer = new ilECSContentWriter($this);
1706  $writer->refreshSettings();
1707  }
1708  catch(ilException $exc)
1709  {
1710  $ilLog->write(__METHOD__.': Cannot save ECS settings. '.$exc->getMessage());
1711  return false;
1712  }
1713  return true;
1714  }
1715 
1720  function addAdditionalSubItemInformation(&$a_item_data)
1721  {
1722  global $ilBench;
1723 
1724  $ilBench->start("Course", "initCourseItemObject");
1725  $this->initCourseItemObject();
1726  $ilBench->stop("Course", "initCourseItemObject");
1727 
1728  $ilBench->start("Course", "addAdditionalSubItemInformation");
1729  $this->items_obj->addAdditionalSubItemInformation($a_item_data);
1730  $ilBench->stop("Course", "addAdditionalSubItemInformation");
1731  }
1732 
1740  protected function prepareAppointments($a_mode = 'create')
1741  {
1742  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1743  include_once('./Services/Calendar/classes/class.ilDateTime.php');
1744 
1745  switch($a_mode)
1746  {
1747  case 'create':
1748  case 'update':
1749  if(!$this->getActivationUnlimitedStatus() and !$this->getOfflineStatus())
1750  {
1751  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_START);
1752  $app->setTitle($this->getTitle());
1753  $app->setSubtitle('crs_cal_activation_start');
1754  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1755  $app->setDescription($this->getLongDescription());
1756  $app->setStart(new ilDateTime($this->getActivationStart(),IL_CAL_UNIX));
1757  $apps[] = $app;
1758 
1759  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_END);
1760  $app->setTitle($this->getTitle());
1761  $app->setSubtitle('crs_cal_activation_end');
1762  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1763  $app->setDescription($this->getLongDescription());
1764  $app->setStart(new ilDateTime($this->getActivationEnd(),IL_CAL_UNIX));
1765  $apps[] = $app;
1766  }
1768  {
1769  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1770  $app->setTitle($this->getTitle());
1771  $app->setSubtitle('crs_cal_reg_start');
1772  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1773  $app->setDescription($this->getLongDescription());
1774  $app->setStart(new ilDateTime($this->getSubscriptionStart(),IL_CAL_UNIX));
1775  $apps[] = $app;
1776 
1777  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1778  $app->setTitle($this->getTitle());
1779  $app->setSubtitle('crs_cal_reg_end');
1780  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1781  $app->setDescription($this->getLongDescription());
1782  $app->setStart(new ilDateTime($this->getSubscriptionEnd(),IL_CAL_UNIX));
1783  $apps[] = $app;
1784  }
1785 
1786  return $apps ? $apps : array();
1787 
1788  case 'delete':
1789  // Nothing to do: The category and all assigned appointments will be deleted.
1790  return array();
1791  }
1792  }
1793 
1794 } //END class.ilObjCourse
1795 ?>