ILIAS  Release_4_1_x_branch Revision 61804
 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 include_once './Services/Membership/interfaces/interface.ilMembershipRegistrationCodes.php';
27 
36 {
37 
38  const CAL_REG_START = 1;
39  const CAL_REG_END = 2;
41  const CAL_ACTIVATION_END = 4;
42 
46 
47 
48  private $latitude = '';
49  private $longitude = '';
50  private $locationzoom = 0;
51  private $enablemap = 0;
52 
53  private $session_limit = 0;
54  private $session_prev = -1;
55  private $session_next = -1;
56 
57  private $reg_access_code = '';
58  private $reg_access_code_enabled = false;
59 
66  function ilObjCourse($a_id = 0,$a_call_by_reference = true)
67  {
68 
69  #define("ILIAS_MODULE","course");
70  #define("KEEP_IMAGE_PATH",1);
71 
72  $this->SUBSCRIPTION_DEACTIVATED = 1;
73  $this->SUBSCRIPTION_CONFIRMATION = 2;
74  $this->SUBSCRIPTION_DIRECT = 3;
75  $this->SUBSCRIPTION_PASSWORD = 4;
76  $this->SUBSCRIPTION_AUTOSUBSCRIPTION = 5;
77  $this->ARCHIVE_DISABLED = 1;
78  $this->ARCHIVE_READ = 2;
79  $this->ARCHIVE_DOWNLOAD = 3;
80  $this->ABO_ENABLED = 1;
81  $this->ABO_DISABLED = 0;
82  $this->SHOW_MEMBERS_ENABLED = 1;
83  $this->SHOW_MEMBERS_DISABLED = 0;
84 
85  $this->type = "crs";
86 
87  parent::__construct($a_id,$a_call_by_reference);
88 
89  if($a_id)
90  {
91  #$this->__initMetaObject();
92  $this->initCourseMemberObject();
93  }
94  else
95  {
96 
97  }
98  }
99 
104  public function getRegistrationAccessCode()
105  {
106  return $this->reg_access_code;
107  }
108 
114  public function setRegistrationAccessCode($a_code)
115  {
116  $this->reg_access_code = $a_code;
117  }
118 
124  {
125  return (bool) $this->reg_access_code_enabled;
126  }
127 
133  public function enableRegistrationAccessCode($a_status)
134  {
135  $this->reg_access_code_enabled = $a_status;
136  }
137 
139  {
140  return $this->important;
141  }
142  function setImportantInformation($a_info)
143  {
144  $this->important = $a_info;
145  }
146  function getSyllabus()
147  {
148  return $this->syllabus;
149  }
150  function setSyllabus($a_syllabus)
151  {
152  $this->syllabus = $a_syllabus;
153  }
154  function getContactName()
155  {
156  return $this->contact_name;
157  }
158  function setContactName($a_cn)
159  {
160  $this->contact_name = $a_cn;
161  }
163  {
164  return $this->contact_consultation;
165  }
166  function setContactConsultation($a_value)
167  {
168  $this->contact_consultation = $a_value;
169  }
170  function getContactPhone()
171  {
172  return $this->contact_phone;
173  }
174  function setContactPhone($a_value)
175  {
176  $this->contact_phone = $a_value;
177  }
178  function getContactEmail()
179  {
180  return $this->contact_email;
181  }
182  function setContactEmail($a_value)
183  {
184  $this->contact_email = $a_value;
185  }
187  {
188  return $this->contact_responsibility;
189  }
190  function setContactResponsibility($a_value)
191  {
192  $this->contact_responsibility = $a_value;
193  }
194 
195  function getActivationType()
196  {
197  return (int) $this->activation_type;
198  }
199  function setActivationType($a_type)
200  {
201  $this->activation_type = $a_type;
202  }
204  {
205  return $this->activation_type == IL_CRS_ACTIVATION_UNLIMITED;
206 
207  }
208 
210  {
211  return $this->activation_start ? $this->activation_start : time();
212  }
213  function setActivationStart($a_value)
214  {
215  $this->activation_start = $a_value;
216  }
217  function getActivationEnd()
218  {
219  return $this->activation_end ? $this->activation_end : mktime(0,0,0,12,12,date("Y",time())+2);
220  }
221  function setActivationEnd($a_value)
222  {
223  $this->activation_end = $a_value;
224  }
225  function getOfflineStatus()
226  {
227  return $this->activation_type == IL_CRS_ACTIVATION_OFFLINE;
228  }
229 
230 
232  {
233  return $this->subscription_limitation_type;
234  }
236  {
237  $this->subscription_limitation_type = $a_type;
238  }
240  {
241  return $this->subscription_limitation_type == IL_CRS_SUBSCRIPTION_UNLIMITED;
242  }
244  {
245  return $this->subscription_start ? $this->subscription_start : time();
246  }
247  function setSubscriptionStart($a_value)
248  {
249  $this->subscription_start = $a_value;
250  }
252  {
253  return $this->subscription_end ? $this->subscription_end : mktime(0,0,0,12,12,date("Y",time())+2);
254  }
255  function setSubscriptionEnd($a_value)
256  {
257  $this->subscription_end = $a_value;
258  }
260  {
261  return $this->subscription_type ? $this->subscription_type : IL_CRS_SUBSCRIPTION_DIRECT;
262  #return $this->subscription_type ? $this->subscription_type : $this->SUBSCRIPTION_DEACTIVATED;
263  }
264  function setSubscriptionType($a_value)
265  {
266  $this->subscription_type = $a_value;
267  }
269  {
270  return $this->subscription_password;
271  }
272  function setSubscriptionPassword($a_value)
273  {
274  $this->subscription_password = $a_value;
275  }
277  {
278  return $this->view_mode == IL_CRS_VIEW_OBJECTIVE;
279  }
280 
282  {
283  return (bool) $this->waiting_list;
284  }
285 
286  function enableWaitingList($a_status)
287  {
288  $this->waiting_list = (bool) $a_status;
289  }
290 
292  {
293  if($this->getSubscriptionUnlimitedStatus())
294  {
295  return true;
296  }
297  if(time() > $this->getSubscriptionStart() and time() < $this->getSubscriptionEnd())
298  {
299  return true;
300  }
301  return false;
302  }
303 
309  public function enableSessionLimit($a_status)
310  {
311  $this->session_limit = $a_status;
312  }
313 
314  public function isSessionLimitEnabled()
315  {
316  return (bool) $this->session_limit;
317  }
318 
326  public function enableSubscriptionMembershipLimitation($a_status)
327  {
328  $this->subscription_membership_limitation = $a_status;
329  }
330 
336  public function setNumberOfPreviousSessions($a_num)
337  {
338  $this->session_prev = $a_num;
339  }
340 
345  public function getNumberOfPreviousSessions()
346  {
347  return $this->session_prev;
348  }
349 
355  public function setNumberOfNextSessions($a_num)
356  {
357  $this->session_next = $a_num;
358  }
359 
364  public function getNumberOfNextSessions()
365  {
366  return $this->session_next;
367  }
376  {
377  return (bool) $this->subscription_membership_limitation;
378  }
379 
381  {
382  return $this->subscription_max_members;
383  }
384  function setSubscriptionMaxMembers($a_value)
385  {
386  $this->subscription_max_members = $a_value;
387  }
388 
397  public static function _isSubscriptionNotificationEnabled($a_course_id)
398  {
399  global $ilDB;
400 
401  $query = "SELECT * FROM crs_settings ".
402  "WHERE obj_id = ".$ilDB->quote($a_course_id ,'integer')." ".
403  "AND sub_notify = 1";
404  $res = $ilDB->query($query);
405  return $res->numRows() ? true : false;
406  }
407 
414  public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
415  {
416  // Caching
417  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]))
418  {
419  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
420  }
421 
422  // Results are stored in $this->items
423  parent::getSubItems($a_admin_panel_enabled,$a_include_side_block);
424 
425  // No sessions
426  if(!is_array($this->items['sess']) or !$this->items['sess'])
427  {
428  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
429  }
430  // No session limit
431  if(!$this->isSessionLimitEnabled() or $a_admin_panel_enabled)
432  {
433  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
434  }
435 
436  // Search key of next appointment
437  $sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
438 
439  $num = 0;
440  $today = new ilDate(date('Ymd',time()),IL_CAL_DATE);
441  $today = $today->get(IL_CAL_UNIX);
442  foreach($sessions as $key => $item)
443  {
444  if($item['start'] >= $today)
445  {
446  break;
447  }
448  $num++;
449  }
450 
451  $previous = $sessions;
452  $next = $sessions;
453 
454  // Cut previous sessions
455  $previous = array_slice($previous, 0, $num);
456  if($this->getNumberOfPreviousSessions() >= 0)
457  {
458  $to_remove = (count($previous) - $this->getNumberOfPreviousSessions() > 0) ?
459  count($previous) - $this->getNumberOfPreviousSessions() :
460  0;
461  array_splice($previous, 0, $to_remove);
462  }
463 
464  // Cut next sessions
465  $next = array_slice($next, $num);
466  if($this->getNumberOfNextSessions() >= 0)
467  {
468  $next = array_splice($next, 0, $this->getNumberOfNextSessions());
469  }
470 
471  $sessions = array_merge($previous,$next);
472  $this->items['sess'] = $sessions;
473  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $this->items;
474  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
475  }
476 
478  {
479  return true;
480  return $this->subscription_notify ? true : false;
481  }
482  function setSubscriptionNotify($a_value)
483  {
484  $this->subscription_notify = $a_value ? true : false;
485  }
486 
487  function setViewMode($a_mode)
488  {
489  $this->view_mode = $a_mode;
490  }
491  function getViewMode()
492  {
493  return $this->view_mode;
494  }
495 
496  function _lookupViewMode($a_id)
497  {
498  global $ilDB;
499 
500  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
501  $res = $ilDB->query($query);
502  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
503  {
504  return $row->view_mode;
505  }
506  return false;
507  }
508 
509  function _lookupAboStatus($a_id)
510  {
511  global $ilDB;
512 
513  $query = "SELECT abo FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
514  $res = $ilDB->query($query);
515  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
516  {
517  return $row->abo;
518  }
519  return false;
520  }
521 
522  function getArchiveStart()
523  {
524  return $this->archive_start ? $this->archive_start : time();
525  }
526  function setArchiveStart($a_value)
527  {
528  $this->archive_start = $a_value;
529  }
530  function getArchiveEnd()
531  {
532  return $this->archive_end ? $this->archive_end : mktime(0,0,0,12,12,date("Y",time())+2);
533  }
534  function setArchiveEnd($a_value)
535  {
536  $this->archive_end = $a_value;
537  }
538  function getArchiveType()
539  {
540  return $this->archive_type ? IL_CRS_ARCHIVE_DOWNLOAD : IL_CRS_ARCHIVE_NONE;
541  }
542  function setArchiveType($a_value)
543  {
544  $this->archive_type = $a_value;
545  }
546  function setAboStatus($a_status)
547  {
548  $this->abo = $a_status;
549  }
550  function getAboStatus()
551  {
552  return $this->abo;
553  }
554  function setShowMembers($a_status)
555  {
556  $this->show_members = $a_status;
557  }
558  function getShowMembers()
559  {
560  return $this->show_members;
561  }
562 
563  function getMessage()
564  {
565  return $this->message;
566  }
567  function setMessage($a_message)
568  {
569  $this->message = $a_message;
570  }
571  function appendMessage($a_message)
572  {
573  if($this->getMessage())
574  {
575  $this->message .= "<br /> ";
576  }
577  $this->message .= $a_message;
578  }
579 
580  function getMembers()
581  {
582  return $this->members_obj->getMembers();
583  }
584 
585 
586  function isActivated($a_check_archive = false)
587  {
588  if($a_check_archive)
589  {
590  if($this->isArchived())
591  {
592  return true;
593  }
594  }
595  if($this->getOfflineStatus())
596  {
597  return false;
598  }
599  if($this->getActivationUnlimitedStatus())
600  {
601  return true;
602  }
603  if(time() < $this->getActivationStart() or
604  time() > $this->getActivationEnd())
605  {
606  return false;
607  }
608  return true;
609  }
610 
617  function _isActivated($a_obj_id)
618  {
619  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
620  return ilObjCourseAccess::_isActivated($a_obj_id);
621  }
622 
629  function _registrationEnabled($a_obj_id)
630  {
631  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
632  return ilObjCourseAccess::_registrationEnabled($a_obj_id);
633  }
634 
635  function isArchived()
636  {
637  if($this->getViewMode() != IL_CRS_VIEW_ARCHIVE)
638  {
639  return false;
640  }
641  if(time() < $this->getArchiveStart() or time() > $this->getArchiveEnd())
642  {
643  return false;
644  }
645  return true;
646  }
647 
648  function allowAbo()
649  {
650  return $this->ABO == $this->ABO_ENABLED;
651  }
652 
653  function read($a_force_db = false)
654  {
655  parent::read($a_force_db);
656 
657  $this->__readSettings();
658  }
659  function create($a_upload = false)
660  {
661  global $ilAppEventHandler;
662 
663  parent::create($a_upload);
664 
665  if(!$a_upload)
666  {
667  $this->createMetaData();
668  }
669  $this->__createDefaultSettings();
670 
671  $ilAppEventHandler->raise('Modules/Course',
672  'create',
673  array('object' => $this,
674  'obj_id' => $this->getId(),
675  'appointments' => $this->prepareAppointments('create')));
676 
677  }
678 
684  function setLatitude($a_latitude)
685  {
686  $this->latitude = $a_latitude;
687  }
688 
694  function getLatitude()
695  {
696  return $this->latitude;
697  }
698 
704  function setLongitude($a_longitude)
705  {
706  $this->longitude = $a_longitude;
707  }
708 
714  function getLongitude()
715  {
716  return $this->longitude;
717  }
718 
724  function setLocationZoom($a_locationzoom)
725  {
726  $this->locationzoom = $a_locationzoom;
727  }
728 
734  function getLocationZoom()
735  {
736  return $this->locationzoom;
737  }
738 
744  function setEnableCourseMap($a_enablemap)
745  {
746  $this->enablemap = $a_enablemap;
747  }
748 
755  {
756  return $this->enablemap;
757  }
758 
767  public function cloneObject($a_target_id,$a_copy_id = 0)
768  {
769  global $ilDB,$ilUser;
770 
771  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
772 
773  $this->cloneAutoGeneratedRoles($new_obj);
774  $this->cloneMetaData($new_obj);
775 
776  // Assign admin
777  $new_obj->initCourseMemberObject();
778  $new_obj->members_obj->add($ilUser->getId(),IL_CRS_ADMIN);
779 
780  // Copy settings
781  $this->cloneSettings($new_obj);
782 
783  // Course Defined Fields
784  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
785  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
786 
787  // Clone course files
788  include_once('Modules/Course/classes/class.ilCourseFile.php');
789  ilCourseFile::_cloneFiles($this->getId(),$new_obj->getId());
790 
791  // Copy learning progress settings
792  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
793  $obj_settings = new ilLPObjSettings($this->getId());
794  $obj_settings->cloneSettings($new_obj->getId());
795  unset($obj_settings);
796 
797  // clone icons
798  global $ilLog;
799  $ilLog->write(__METHOD__.': '.$this->getBigIconPath().' '.$this->getSmallIconPath());
800  $new_obj->saveIcons($this->getBigIconPath(),
801  $this->getSmallIconPath(),
802  $this->getTinyIconPath());
803 
804  return $new_obj;
805  }
806 
815  public function cloneDependencies($a_target_id,$a_copy_id)
816  {
817  global $ilObjDataCache;
818 
819  parent::cloneDependencies($a_target_id,$a_copy_id);
820 
821  // Clone course start objects
822  include_once('Modules/Course/classes/class.ilCourseStart.php');
823  $start = new ilCourseStart($this->getRefId(),$this->getId());
824  $start->cloneDependencies($a_target_id,$a_copy_id);
825 
826  // Clone course item settings
827  $this->initCourseItemObject();
828  $this->items_obj->cloneDependencies($a_target_id,$a_copy_id);
829 
830  // Clone course learning objectives
831  include_once('Modules/Course/classes/class.ilCourseObjective.php');
832  $crs_objective = new ilCourseObjective($this);
833  $crs_objective->ilClone($a_target_id,$a_copy_id);
834 
835  include_once('Services/Tracking/classes/class.ilLPCollections.php');
836  $lp_collection = new ilLPCollections($this->getId());
837  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
838 
839  return true;
840  }
841 
849  public function cloneAutoGeneratedRoles($new_obj)
850  {
851  global $ilLog,$rbacadmin,$rbacreview;
852 
853  $admin = $this->getDefaultAdminRole();
854  $new_admin = $new_obj->getDefaultAdminRole();
855  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
856  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
857 
858  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
859  {
860  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_admin');
861  }
862  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
863  $ilLog->write(__METHOD__.' : Finished copying of role crs_admin.');
864 
865  $tutor = $this->getDefaultTutorRole();
866  $new_tutor = $new_obj->getDefaultTutorRole();
867  if(!$tutor || !$new_tutor)
868  {
869  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_tutor');
870  }
871  $rbacadmin->copyRolePermissions($tutor,$source_rolf,$target_rolf,$new_tutor,true);
872  $ilLog->write(__METHOD__.' : Finished copying of role crs_tutor.');
873 
874  $member = $this->getDefaultMemberRole();
875  $new_member = $new_obj->getDefaultMemberRole();
876  if(!$member || !$new_member)
877  {
878  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_member');
879  }
880  $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
881  $ilLog->write(__METHOD__.' : Finished copying of role crs_member.');
882 
883  return true;
884  }
885 
886 
887  function validate()
888  {
889  $this->initCourseMemberObject();
890 
891  $this->setMessage('');
892 
893  #if(($this->getSubscriptionLimitationType() != IL_CRS_SUBSCRIPTION_DEACTIVATED) and
894  # $this->getSubscriptionType() == )
895  #{
896  # $this->appendMessage($this->lng->txt('crs_select_registration_type'));
897  #}
898 
899  if(($this->getActivationType() == IL_CRS_ACTIVATION_LIMITED) and
900  $this->getActivationEnd() < $this->getActivationStart())
901  {
902  $this->appendMessage($this->lng->txt("activation_times_not_valid"));
903  }
905  $this->getSubscriptionStart() > $this->getSubscriptionEnd())
906  {
907  $this->appendMessage($this->lng->txt("subscription_times_not_valid"));
908  }
909  #if((!$this->getActivationUnlimitedStatus() and
910  # !$this->getSubscriptionUnlimitedStatus()) and
911  # ($this->getSubscriptionStart() > $this->getActivationEnd() or
912  # $this->getSubscriptionStart() < $this->getActivationStart() or
913  # $this->getSubscriptionEnd() > $this->getActivationEnd() or
914  # $this->getSubscriptionEnd() < $this->getActivationStart()))
915  #
916  #{
917  # $this->appendMessage($this->lng->txt("subscription_time_not_within_activation"));
918  #}
920  {
921  $this->appendMessage($this->lng->txt("crs_password_required"));
922  }
923  if($this->isSubscriptionMembershipLimited() and ($this->getSubscriptionMaxMembers() <= 0 or !is_numeric($this->getSubscriptionMaxMembers())))
924  {
925  $this->appendMessage($this->lng->txt("max_members_not_numeric"));
926  }
927  if(($this->getViewMode() == IL_CRS_VIEW_ARCHIVE) and
928  $this->getArchiveStart() > $this->getArchiveEnd())
929  {
930  $this->appendMessage($this->lng->txt("archive_times_not_valid"));
931  }
932  if(!$this->getTitle())
933  {
934  $this->appendMessage($this->lng->txt('err_check_input'));
935  }
936 
937 
938  return $this->getMessage() ? false : true;
939  }
940 
942  {
943  global $ilErr;
944  $error = false;
945  if($this->getContactEmail()) {
946  $emails = split(",",$this->getContactEmail());
947 
948  foreach ($emails as $email) {
949  $email = trim($email);
950  if (!(ilUtil::is_email($email) or ilObjUser::getUserIdByLogin($email)))
951  {
952  $ilErr->appendMessage($this->lng->txt('contact_email_not_valid')." '".$email."'");
953  $error = true;
954  }
955  }
956  }
957  return !$error;
958  }
959 
960  function hasContactData()
961  {
962  return strlen($this->getContactName()) or
963  strlen($this->getContactResponsibility()) or
964  strlen($this->getContactEmail()) or
965  strlen($this->getContactPhone()) or
966  strlen($this->getContactConsultation());
967  }
968 
969 
976  function delete()
977  {
978  global $ilAppEventHandler;
979 
980  // always call parent delete function first!!
981  if (!parent::delete())
982  {
983  return false;
984  }
985 
986  // delete meta data
987  $this->deleteMetaData();
988 
989  // put here course specific stuff
990 
991  $this->__deleteSettings();
992 
993  $this->initCourseItemObject();
994  $this->items_obj->deleteAllEntries();
995 
996  include_once('Modules/Course/classes/class.ilCourseParticipants.php');
998 
999  $this->initCourseArchiveObject();
1000  $this->archives_obj->deleteAll();
1001 
1002  include_once './Modules/Course/classes/class.ilCourseObjective.php';
1004 
1005  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
1007 
1008  include_once './Modules/Course/classes/class.ilCourseFile.php';
1010 
1011  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
1013 
1014  $ilAppEventHandler->raise('Modules/Course',
1015  'delete',
1016  array('object' => $this,
1017  'obj_id' => $this->getId(),
1018  'appointments' => $this->prepareAppointments('delete')));
1019 
1020 
1021  return true;
1022  }
1023 
1024 
1025 
1029  function update()
1030  {
1031  global $ilAppEventHandler,$ilLog;
1032 
1033  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1034  $sorting = new ilContainerSortingSettings($this->getId());
1035  $sorting->setSortMode($this->getOrderType());
1036  $sorting->update();
1037 
1038  $this->updateMetaData();
1039  $this->updateSettings();
1040  parent::update();
1041 
1042  $ilAppEventHandler->raise('Modules/Course',
1043  'update',
1044  array('object' => $this,
1045  'obj_id' => $this->getId(),
1046  'appointments' => $this->prepareAppointments('update')));
1047 
1048  }
1049 
1050  function updateSettings()
1051  {
1052  global $ilDB;
1053 
1054  // Due to a bug 3.5.alpha maybe no settings exist. => create default settings
1055 
1056  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1057  $res = $ilDB->query($query);
1058 
1059  if(!$res->numRows())
1060  {
1061  $this->__createDefaultSettings();
1062  }
1063 
1064  $query = "UPDATE crs_settings SET ".
1065  "syllabus = ".$ilDB->quote($this->getSyllabus() ,'text').", ".
1066  "contact_name = ".$ilDB->quote($this->getContactName() ,'text').", ".
1067  "contact_responsibility = ".$ilDB->quote($this->getContactResponsibility() ,'text').", ".
1068  "contact_phone = ".$ilDB->quote($this->getContactPhone() ,'text').", ".
1069  "contact_email = ".$ilDB->quote($this->getContactEmail() ,'text').", ".
1070  "contact_consultation = ".$ilDB->quote($this->getContactConsultation() ,'text').", ".
1071  "activation_type = ".$ilDB->quote($this->getActivationType() ,'integer').", ".
1072  "activation_start = ".$ilDB->quote($this->getActivationStart() ,'integer').", ".
1073  "activation_end = ".$ilDB->quote($this->getActivationEnd() ,'integer').", ".
1074  "sub_limitation_type = ".$ilDB->quote($this->getSubscriptionLimitationType() ,'integer').", ".
1075  "sub_start = ".$ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1076  "sub_end = ".$ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1077  "sub_type = ".$ilDB->quote($this->getSubscriptionType() ,'integer').", ".
1078  "sub_password = ".$ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1079  "sub_mem_limit = ".$ilDB->quote((int) $this->isSubscriptionMembershipLimited() ,'integer').", ".
1080  "sub_max_members = ".$ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1081  "sub_notify = ".$ilDB->quote($this->getSubscriptionNotify() ,'integer').", ".
1082  "view_mode = ".$ilDB->quote($this->getViewMode() ,'integer').", ".
1083  "archive_start = ".$ilDB->quote($this->getArchiveStart() ,'integer').", ".
1084  "archive_end = ".$ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1085  "archive_type = ".$ilDB->quote($this->getArchiveType() ,'integer').", ".
1086  "abo = ".$ilDB->quote($this->getAboStatus() ,'integer').", ".
1087  "waiting_list = ".$ilDB->quote($this->enabledWaitingList() ,'integer').", ".
1088  "important = ".$ilDB->quote($this->getImportantInformation() ,'text').", ".
1089  "show_members = ".$ilDB->quote($this->getShowMembers() ,'integer').", ".
1090  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
1091  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
1092  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
1093  "enable_course_map = ".$ilDB->quote((int) $this->getEnableCourseMap() ,'integer').", ".
1094  'session_limit = '.$ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1095  'session_prev = '.$ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1096  'session_next = '.$ilDB->quote($this->getNumberOfNextSessions(),'integer').', '.
1097  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1098  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').' '.
1099  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1100 
1101  $res = $ilDB->manipulate($query);
1102  }
1103 
1111  public function cloneSettings($new_obj)
1112  {
1113  $new_obj->setSyllabus($this->getSyllabus());
1114  $new_obj->setContactName($this->getContactName());
1115  $new_obj->setContactResponsibility($this->getContactResponsibility());
1116  $new_obj->setContactPhone($this->getContactPhone());
1117  $new_obj->setContactEmail($this->getContactEmail());
1118  $new_obj->setContactConsultation($this->getContactConsultation());
1119  $new_obj->setActivationType($this->getActivationType());
1120  $new_obj->setActivationStart($this->getActivationStart());
1121  $new_obj->setActivationEnd($this->getActivationEnd());
1122  $new_obj->setSubscriptionLimitationType($this->getSubscriptionLimitationType());
1123  $new_obj->setSubscriptionStart($this->getSubscriptionStart());
1124  $new_obj->setSubscriptionEnd($this->getSubscriptionEnd());
1125  $new_obj->setSubscriptionType($this->getSubscriptionType());
1126  $new_obj->setSubscriptionPassword($this->getSubscriptionPassword());
1127  $new_obj->enableSubscriptionMembershipLimitation($this->isSubscriptionMembershipLimited());
1128  $new_obj->setSubscriptionMaxMembers($this->getSubscriptionMaxMembers());
1129  $new_obj->setSubscriptionNotify($this->getSubscriptionNotify());
1130  $new_obj->setViewMode($this->getViewMode());
1131  $new_obj->setOrderType($this->getOrderType());
1132  $new_obj->setArchiveStart($this->getArchiveStart());
1133  $new_obj->setArchiveEnd($this->getArchiveEnd());
1134  $new_obj->setArchiveType($this->getArchiveType());
1135  $new_obj->setAboStatus($this->getAboStatus());
1136  $new_obj->enableWaitingList($this->enabledWaitingList());
1137  $new_obj->setImportantInformation($this->getImportantInformation());
1138  $new_obj->setShowMembers($this->getShowMembers());
1139  $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
1140  $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
1141  $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
1142 
1143  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
1144  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1145  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
1146 
1147  $new_obj->update();
1148  }
1149 
1151  {
1152  global $ilDB;
1153 
1154  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1156 
1157  $query = "INSERT INTO crs_settings (obj_id,syllabus,contact_name,contact_responsibility,".
1158  "contact_phone,contact_email,contact_consultation,activation_type,activation_start,".
1159  "activation_end,sub_limitation_type,sub_start,sub_end,sub_type,sub_password,sub_mem_limit,".
1160  "sub_max_members,sub_notify,view_mode,archive_start,archive_end,archive_type,abo," .
1161  "latitude,longitude,location_zoom,enable_course_map,waiting_list,show_members, ".
1162  "session_limit,session_prev,session_next, reg_ac_enabled, reg_ac) ".
1163  "VALUES( ".
1164  $ilDB->quote($this->getId() ,'integer').", ".
1165  $ilDB->quote($this->getSyllabus() ,'text').", ".
1166  $ilDB->quote($this->getContactName() ,'text').", ".
1167  $ilDB->quote($this->getContactResponsibility() ,'text').", ".
1168  $ilDB->quote($this->getContactPhone() ,'text').", ".
1169  $ilDB->quote($this->getContactEmail() ,'text').", ".
1170  $ilDB->quote($this->getContactConsultation() ,'text').", ".
1171  $ilDB->quote(IL_CRS_ACTIVATION_OFFLINE ,'integer').", ".
1172  $ilDB->quote($this->getActivationStart() ,'integer').", ".
1173  $ilDB->quote($this->getActivationEnd() ,'integer').", ".
1174  $ilDB->quote(IL_CRS_SUBSCRIPTION_DEACTIVATED ,'integer').", ".
1175  $ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1176  $ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1177  $ilDB->quote(IL_CRS_SUBSCRIPTION_DIRECT ,'integer').", ".
1178  $ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1179  "0, ".
1180  $ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1181  "1, ".
1182  "0, ".
1183  $ilDB->quote($this->getArchiveStart() ,'integer').", ".
1184  $ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1185  $ilDB->quote(IL_CRS_ARCHIVE_NONE ,'integer').", ".
1186  $ilDB->quote($this->ABO_ENABLED ,'integer').", ".
1187  $ilDB->quote($this->getLatitude() ,'text').", ".
1188  $ilDB->quote($this->getLongitude() ,'text').", ".
1189  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
1190  $ilDB->quote($this->getEnableCourseMap() ,'integer').", ".
1191  #"objective_view = '0', ".
1192  "1, ".
1193  "1,".
1194  $ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1195  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1196  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1197  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1198  $ilDB->quote($this->getRegistrationAccessCode(),'text').' '.
1199  ")";
1200 
1201  $res = $ilDB->manipulate($query);
1202  $this->__readSettings();
1203 
1204  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1205  $sorting = new ilContainerSortingSettings($this->getId());
1206  $sorting->setSortMode(ilContainer::SORT_MANUAL);
1207  $sorting->update();
1208  }
1209 
1210 
1211  function __readSettings()
1212  {
1213  global $ilDB;
1214 
1215  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1216 
1217  $res = $ilDB->query($query);
1218  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1219  {
1220  $this->setSyllabus($row->syllabus);
1221  $this->setContactName($row->contact_name);
1222  $this->setContactResponsibility($row->contact_responsibility);
1223  $this->setContactPhone($row->contact_phone);
1224  $this->setContactEmail($row->contact_email);
1225  $this->setContactConsultation($row->contact_consultation);
1226  $this->setActivationType($row->activation_type);
1227  $this->setActivationStart($row->activation_start);
1228  $this->setActivationEnd($row->activation_end);
1229  $this->setSubscriptionLimitationType($row->sub_limitation_type);
1230  $this->setSubscriptionStart($row->sub_start);
1231  $this->setSubscriptionEnd($row->sub_end);
1232  $this->setSubscriptionType($row->sub_type);
1233  $this->setSubscriptionPassword($row->sub_password);
1234  $this->enableSubscriptionMembershipLimitation($row->sub_mem_limit);
1235  $this->setSubscriptionMaxMembers($row->sub_max_members);
1236  $this->setSubscriptionNotify($row->sub_notify);
1237  $this->setViewMode($row->view_mode);
1238  $this->setArchiveStart($row->archive_start);
1239  $this->setArchiveEnd($row->archive_end);
1240  $this->setArchiveType($row->archive_type);
1241  $this->setAboStatus($row->abo);
1242  $this->enableWaitingList($row->waiting_list);
1243  $this->setImportantInformation($row->important);
1244  $this->setShowMembers($row->show_members);
1245  $this->setLatitude($row->latitude);
1246  $this->setLongitude($row->longitude);
1247  $this->setLocationZoom($row->location_zoom);
1248  $this->setEnableCourseMap($row->enable_course_map);
1249  $this->enableSessionLimit($row->session_limit);
1250  $this->setNumberOfPreviousSessions($row->session_prev);
1251  $this->setNumberOfNextSessions($row->session_next);
1252  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
1253  $this->setRegistrationAccessCode($row->reg_ac);
1254  }
1255 
1256  return true;
1257  }
1258 
1259  function initWaitingList()
1260  {
1261  include_once "./Modules/Course/classes/class.ilCourseWaitingList.php";
1262 
1263  if(!is_object($this->waiting_list_obj))
1264  {
1265  $this->waiting_list_obj = new ilCourseWaitingList($this->getId());
1266  }
1267  return true;
1268  }
1269 
1270 
1272  {
1273  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1274  $this->members_obj = ilCourseParticipants::_getInstanceByObjId($this->getId());
1275  return true;
1276  }
1277 
1278  function initCourseItemObject($a_child_id = 0)
1279  {
1280  include_once "./Modules/Course/classes/class.ilCourseItems.php";
1281 
1282  if(!is_object($this->items_obj))
1283  {
1284  $this->items_obj = new ilCourseItems($this->getRefId(),$a_child_id);
1285  }
1286  return true;
1287  }
1288 
1296  public function getCourseItemObject()
1297  {
1298  if(is_object($this->items_obj))
1299  {
1300  return $this->items_obj;
1301  }
1302  $this->initCourseItemObject();
1303  return $this->items_obj;
1304  }
1305 
1306 
1308  {
1309  include_once "./Modules/Course/classes/class.ilCourseArchives.php";
1310 
1311  if(!is_object($this->archives_obj))
1312  {
1313  $this->archives_obj =& new ilCourseArchives($this);
1314  }
1315  return true;
1316  }
1317 
1318 
1319 
1320  // RBAC METHODS
1321  function initDefaultRoles()
1322  {
1323  global $rbacadmin,$rbacreview,$ilDB;
1324 
1325  $rolf_obj = $this->createRoleFolder();
1326 
1327  // CREATE ADMIN ROLE
1328  $role_obj = $rolf_obj->createRole("il_crs_admin_".$this->getRefId(),"Admin of course obj_no.".$this->getId());
1329  $admin_id = $role_obj->getId();
1330 
1331  // SET PERMISSION TEMPLATE OF NEW LOCAL ADMIN ROLE
1332  $query = "SELECT obj_id FROM object_data ".
1333  " WHERE type='rolt' AND title='il_crs_admin'";
1334 
1335  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1336  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1337 
1338  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1339  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1340  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1341 
1342  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1343  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1344  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1345 
1346  // CREATE TUTOR ROLE
1347  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1348  $role_obj = $rolf_obj->createRole("il_crs_tutor_".$this->getRefId(),"Tutors of course obj_no.".$this->getId());
1349  $member_id = $role_obj->getId();
1350 
1351  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1352  $query = "SELECT obj_id FROM object_data ".
1353  " WHERE type='rolt' AND title='il_crs_tutor'";
1354  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1355  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1356 
1357  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1358  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1359  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1360 
1361  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1362  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1363  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1364 
1365  // CREATE MEMBER ROLE
1366  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1367  $role_obj = $rolf_obj->createRole("il_crs_member_".$this->getRefId(),"Member of course obj_no.".$this->getId());
1368  $member_id = $role_obj->getId();
1369 
1370  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1371  $query = "SELECT obj_id FROM object_data ".
1372  " WHERE type='rolt' AND title='il_crs_member'";
1373  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1374  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1375 
1376  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1377  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1378  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1379 
1380  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1381  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1382  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1383 
1384  unset($role_obj);
1385  unset($rolf_obj);
1386 
1387  // Break inheritance, create local roles and initialize permission
1388  // settings depending on course status.
1389  $this->__setCourseStatus();
1390 
1391  return true;
1392  }
1393 
1411  {
1412  global $rbacadmin, $rbacreview, $rbacsystem;
1413 
1414  //get Rolefolder of course
1415  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1416 
1417  //define all relevant roles for which rights are needed to be changed
1418  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1419  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultCourseRoles());
1420 
1421  $template_id = $this->__getCrsNonMemberTemplateId();
1422 
1423  //get defined operations from template
1424  if (is_null($template_id))
1425  {
1426  $template_ops = array();
1427  } else {
1428  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'crs', ROLE_FOLDER_ID);
1429  }
1430 
1431  foreach ($arr_relevantParentRoleIds as $parentRole)
1432  {
1433  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1434  {
1435  continue;
1436  }
1437 
1438  $granted_permissions = array();
1439 
1440  // Delete the linked role for the parent role
1441  // (just in case if it already exists).
1442  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1443 
1444  // Grant permissions on the course object for
1445  // the parent role. In the foreach loop we
1446  // compute the intersection of the role
1447  // template il_crs_non_member and the
1448  // permission template of the parent role.
1449  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1450  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1451  foreach ($template_ops as $template_op)
1452  {
1453  if (in_array($template_op,$current_ops))
1454  {
1455  array_push($granted_permissions,$template_op);
1456  }
1457  }
1458  if (!empty($granted_permissions))
1459  {
1460  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1461  }
1462 
1463  // Create a linked role for the parent role and
1464  // initialize it with the intersection of
1465  // il_crs_non_member and the permission
1466  // template of the parent role
1467  if (! is_null($template_id))
1468  {
1469  $rbacadmin->copyRolePermissionIntersection(
1470  $template_id, ROLE_FOLDER_ID,
1471  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1472  $rolf_data["child"], $parentRole
1473  );
1474  }
1475  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1476  }//END foreach
1477  }
1478 
1486  {
1487  global $ilDB;
1488 
1489  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
1490  $res = $this->ilias->db->query($q);
1491  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1492 
1493  return $row["obj_id"];
1494  }
1495 
1502  public function getLocalCourseRoles($a_translate = false)
1503  {
1504  global $rbacadmin,$rbacreview;
1505 
1506  if (empty($this->local_roles))
1507  {
1508  $this->local_roles = array();
1509  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1510  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1511 
1512  foreach ($role_arr as $role_id)
1513  {
1514  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1515  {
1516  $role_Obj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
1517 
1518  if ($a_translate)
1519  {
1520  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1521  }
1522  else
1523  {
1524  $role_name = $role_Obj->getTitle();
1525  }
1526  $this->local_roles[$role_name] = $role_Obj->getId();
1527  }
1528  }
1529  }
1530 
1531  return $this->local_roles;
1532  }
1533 
1534 
1535 
1545  public function getDefaultCourseRoles($a_crs_id = "")
1546  {
1547  global $rbacadmin, $rbacreview;
1548 
1549  if (strlen($a_crs_id) > 0)
1550  {
1551  $crs_id = $a_crs_id;
1552  }
1553  else
1554  {
1555  $crs_id = $this->getRefId();
1556  }
1557 
1558  $rolf = $rbacreview->getRoleFolderOfObject($crs_id);
1559  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1560 
1561  foreach ($role_arr as $role_id)
1562  {
1563  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1564 
1565  $crs_Member ="il_crs_member_".$crs_id;
1566  $crs_Admin ="il_crs_admin_".$crs_id;
1567  $crs_Tutor ="il_crs_tutor_".$crs_id;
1568 
1569  if (strcmp($role_Obj->getTitle(), $crs_Member) == 0 )
1570  {
1571  $arr_crsDefaultRoles["crs_member_role"] = $role_Obj->getId();
1572  }
1573 
1574  if (strcmp($role_Obj->getTitle(), $crs_Admin) == 0)
1575  {
1576  $arr_crsDefaultRoles["crs_admin_role"] = $role_Obj->getId();
1577  }
1578 
1579  if (strcmp($role_Obj->getTitle(), $crs_Tutor) == 0)
1580  {
1581  $arr_crsDefaultRoles["crs_tutor_role"] = $role_Obj->getId();
1582  }
1583  }
1584 
1585  return $arr_crsDefaultRoles;
1586  }
1587 
1588  function __getLocalRoles()
1589  {
1590  global $rbacreview;
1591 
1592  // GET role_objects of predefined roles
1593 
1594  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1595 
1596  return $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1597  }
1598 
1599  function __deleteSettings()
1600  {
1601  global $ilDB;
1602 
1603  $query = "DELETE FROM crs_settings ".
1604  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1605  $res = $ilDB->manipulate($query);
1606 
1607  return true;
1608  }
1609 
1610 
1611 
1613  {
1614  $local_roles = $this->__getLocalRoles();
1615 
1616  foreach($local_roles as $role_id)
1617  {
1618  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1619  {
1620  if(!strcmp($tmp_role->getTitle(),"il_crs_member_".$this->getRefId()))
1621  {
1622  return $role_id;
1623  }
1624  }
1625  }
1626  return false;
1627  }
1629  {
1630  $local_roles = $this->__getLocalRoles();
1631 
1632  foreach($local_roles as $role_id)
1633  {
1634  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1635  {
1636  if(!strcmp($tmp_role->getTitle(),"il_crs_tutor_".$this->getRefId()))
1637  {
1638  return $role_id;
1639  }
1640  }
1641  }
1642  return false;
1643  }
1645  {
1646  $local_roles = $this->__getLocalRoles();
1647 
1648  foreach($local_roles as $role_id)
1649  {
1650  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1651  {
1652  if(!strcmp($tmp_role->getTitle(),"il_crs_admin_".$this->getRefId()))
1653  {
1654  return $role_id;
1655  }
1656  }
1657  }
1658  return false;
1659  }
1660 
1661  // static method for condition handler
1662  function _checkCondition($a_obj_id,$a_operator,$a_value,$a_usr_id = 0)
1663  {
1664  global $ilUser;
1665 
1666  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
1667 
1668  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1669 
1670  switch($a_operator)
1671  {
1672  case 'passed':
1673  return ilCourseParticipants::_hasPassed($a_obj_id,$a_usr_id);
1674 
1675  default:
1676  return true;
1677  }
1678  }
1679 
1680  function _deleteUser($a_usr_id)
1681  {
1682  // Delete all user related data
1683  // delete lm_history
1684  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
1685  ilCourseLMHistory::_deleteUser($a_usr_id);
1686 
1687  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
1689 
1690  // Course objectives
1691  include_once './Modules/Course/classes/class.ilCourseObjectiveResult.php';
1693  }
1694 
1704  public function handleECSSettings($a_export,$a_owner,$a_mids)
1705  {
1706  try
1707  {
1708  include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
1709 
1710  $writer = new ilECSContentWriter($this);
1711  $writer->setExportable($a_export);
1712  $writer->setOwnerId($a_owner);
1713  $writer->setParticipantIds((array) $a_mids);
1714  $writer->refresh();
1715  }
1716  catch(ilECSConnectorException $exc)
1717  {
1718  throw $exc;
1719  }
1720  catch(ilECSContentWriterException $exc)
1721  {
1722  throw $exc;
1723  }
1724  }
1725 
1732  public function MDUpdateListener($a_element)
1733  {
1734  global $ilLog;
1735 
1736  parent::MDUpdateListener($a_element);
1737 
1738  switch($a_element)
1739  {
1740  case 'General':
1741  $this->updateECSContent();
1742  break;
1743  default:
1744  return true;
1745  }
1746  }
1747 
1755  public function updateECSContent()
1756  {
1757  global $ilLog;
1758 
1759  include_once('./Services/WebServices/ECS/classes/class.ilECSSettings.php');
1760  $settings = ilECSSettings::_getInstance();
1761  if(!$settings->isEnabled())
1762  {
1763  return true;
1764  }
1765  try
1766  {
1767  // Update ECS EContent
1768  include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
1769  $writer = new ilECSContentWriter($this);
1770  $writer->refreshSettings();
1771  }
1772  catch(ilException $exc)
1773  {
1774  $ilLog->write(__METHOD__.': Cannot save ECS settings. '.$exc->getMessage());
1775  return false;
1776  }
1777  return true;
1778  }
1779 
1784  function addAdditionalSubItemInformation(&$a_item_data)
1785  {
1786  global $ilBench;
1787 
1788  $ilBench->start("Course", "initCourseItemObject");
1789  $this->initCourseItemObject();
1790  $ilBench->stop("Course", "initCourseItemObject");
1791 
1792  $ilBench->start("Course", "addAdditionalSubItemInformation");
1793  $this->items_obj->addAdditionalSubItemInformation($a_item_data);
1794  $ilBench->stop("Course", "addAdditionalSubItemInformation");
1795  }
1796 
1804  protected function prepareAppointments($a_mode = 'create')
1805  {
1806  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1807  include_once('./Services/Calendar/classes/class.ilDateTime.php');
1808 
1809  switch($a_mode)
1810  {
1811  case 'create':
1812  case 'update':
1813  if(!$this->getActivationUnlimitedStatus() and !$this->getOfflineStatus())
1814  {
1815  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_START);
1816  $app->setTitle($this->getTitle());
1817  $app->setSubtitle('crs_cal_activation_start');
1818  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1819  $app->setDescription($this->getLongDescription());
1820  $app->setStart(new ilDateTime($this->getActivationStart(),IL_CAL_UNIX));
1821  $apps[] = $app;
1822 
1823  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_END);
1824  $app->setTitle($this->getTitle());
1825  $app->setSubtitle('crs_cal_activation_end');
1826  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1827  $app->setDescription($this->getLongDescription());
1828  $app->setStart(new ilDateTime($this->getActivationEnd(),IL_CAL_UNIX));
1829  $apps[] = $app;
1830  }
1832  {
1833  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1834  $app->setTitle($this->getTitle());
1835  $app->setSubtitle('crs_cal_reg_start');
1836  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1837  $app->setDescription($this->getLongDescription());
1838  $app->setStart(new ilDateTime($this->getSubscriptionStart(),IL_CAL_UNIX));
1839  $apps[] = $app;
1840 
1841  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1842  $app->setTitle($this->getTitle());
1843  $app->setSubtitle('crs_cal_reg_end');
1844  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1845  $app->setDescription($this->getLongDescription());
1846  $app->setStart(new ilDateTime($this->getSubscriptionEnd(),IL_CAL_UNIX));
1847  $apps[] = $app;
1848  }
1849 
1850  return $apps ? $apps : array();
1851 
1852  case 'delete':
1853  // Nothing to do: The category and all assigned appointments will be deleted.
1854  return array();
1855  }
1856  }
1857 
1858  ###### Interface ilMembershipRegistrationCodes
1859 
1863  public static function lookupObjectsByCode($a_code)
1864  {
1865  global $ilDB;
1866 
1867  $query = "SELECT obj_id FROM crs_settings ".
1868  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1869  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1870  $res = $ilDB->query($query);
1871 
1872  $obj_ids = array();
1873  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1874  {
1875  $obj_ids[] = $row->obj_id;
1876  }
1877  return $obj_ids;
1878  }
1879 
1886  public function register($a_user_id,$a_role = ilCourseConstants::CRS_MEMBER, $a_force_registration = false)
1887  {
1888  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1889  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1891 
1892  if($part->isAssigned($a_user_id))
1893  {
1894  return true;
1895  }
1896 
1897  if(!$a_force_registration)
1898  {
1899  // Availability
1900  if(!self::_registrationEnabled($this->getId()))
1901  {
1902  $this->lng->loadLanguageModule('crs');
1903  throw new ilMembershipRegistrationException($this->lng->txt('crs_info_reg_deactivated'),$this->getRefId());
1904  }
1905  // Max members
1906  if($this->isSubscriptionMembershipLimited())
1907  {
1908  $free = max(0,$this->getSubscriptionMaxMembers() - $part->getCountMembers());
1909  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
1910  $waiting_list = new ilCourseWaitingList($this->getId());
1911  if($this->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
1912  {
1913  throw new ilMembershipRegistrationException('',$this->getRefId());
1914  }
1915  }
1916  }
1917 
1918  $part->add($a_user_id,$a_role);
1919  $part->sendNotification($part->NOTIFY_ACCEPT_USER, $a_user_id);
1920 
1921  include_once './Modules/Forum/classes/class.ilForumNotification.php';
1923 
1924  return true;
1925  }
1926 } //END class.ilObjCourse
1927 ?>