ILIAS  Release_5_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 ceven 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 
45 
46  private $member_obj = null;
47  private $members_obj = null;
49 
50  private $latitude = '';
51  private $longitude = '';
52  private $locationzoom = 0;
53  private $enablemap = 0;
54 
55  private $session_limit = 0;
56  private $session_prev = -1;
57  private $session_next = -1;
58 
59  private $reg_access_code = '';
60  private $reg_access_code_enabled = false;
61  private $status_dt = null;
62 
64 
73  private $auto_notification = true;
74 
81  function ilObjCourse($a_id = 0,$a_call_by_reference = true)
82  {
83 
84  #define("ILIAS_MODULE","course");
85  #define("KEEP_IMAGE_PATH",1);
86 
87  $this->SUBSCRIPTION_DEACTIVATED = 1;
88  $this->SUBSCRIPTION_CONFIRMATION = 2;
89  $this->SUBSCRIPTION_DIRECT = 3;
90  $this->SUBSCRIPTION_PASSWORD = 4;
91  $this->SUBSCRIPTION_AUTOSUBSCRIPTION = 5;
92  $this->ARCHIVE_DISABLED = 1;
93  $this->ARCHIVE_READ = 2;
94  $this->ARCHIVE_DOWNLOAD = 3;
95  $this->ABO_ENABLED = 1;
96  $this->ABO_DISABLED = 0;
97  $this->SHOW_MEMBERS_ENABLED = 1;
98  $this->SHOW_MEMBERS_DISABLED = 0;
99  $this->setStatusDetermination(self::STATUS_DETERMINATION_LP);
100 
101  $this->type = "crs";
102 
103  parent::__construct($a_id,$a_call_by_reference);
104 
105  }
106 
112  public static function lookupShowMembersEnabled($a_obj_id)
113  {
114  $query = 'SELECT show_members FROM crs_settings '.
115  'WHERE obj_id = '.$GLOBALS['ilDB']->quote($a_obj_id,'integer');
116  $res = $GLOBALS['ilDB']->query($query);
117  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
118  {
119  return (bool) $row->show_members;
120  }
121  return false;
122  }
123 
128  public function getRegistrationAccessCode()
129  {
130  return $this->reg_access_code;
131  }
132 
138  public function setRegistrationAccessCode($a_code)
139  {
140  $this->reg_access_code = $a_code;
141  }
142 
148  {
149  return (bool) $this->reg_access_code_enabled;
150  }
151 
157  public function enableRegistrationAccessCode($a_status)
158  {
159  $this->reg_access_code_enabled = $a_status;
160  }
161 
163  {
164  return $this->important;
165  }
166  function setImportantInformation($a_info)
167  {
168  $this->important = $a_info;
169  }
170  function getSyllabus()
171  {
172  return $this->syllabus;
173  }
174  function setSyllabus($a_syllabus)
175  {
176  $this->syllabus = $a_syllabus;
177  }
178  function getContactName()
179  {
180  return $this->contact_name;
181  }
182  function setContactName($a_cn)
183  {
184  $this->contact_name = $a_cn;
185  }
187  {
188  return $this->contact_consultation;
189  }
190  function setContactConsultation($a_value)
191  {
192  $this->contact_consultation = $a_value;
193  }
194  function getContactPhone()
195  {
196  return $this->contact_phone;
197  }
198  function setContactPhone($a_value)
199  {
200  $this->contact_phone = $a_value;
201  }
202  function getContactEmail()
203  {
204  return $this->contact_email;
205  }
206  function setContactEmail($a_value)
207  {
208  $this->contact_email = $a_value;
209  }
211  {
212  return $this->contact_responsibility;
213  }
214  function setContactResponsibility($a_value)
215  {
216  $this->contact_responsibility = $a_value;
217  }
218  function getActivationType()
219  {
220  return (int) $this->activation_type;
221  }
222  function setActivationType($a_type)
223  {
224  // offline is separate property now
225  if($a_type == IL_CRS_ACTIVATION_OFFLINE)
226  {
227  $this->setOfflineStatus(true);
228  $a_type = IL_CRS_ACTIVATION_UNLIMITED;
229  }
230 
231  $this->activation_type = $a_type;
232  }
234  {
235  return $this->activation_type == IL_CRS_ACTIVATION_UNLIMITED;
236  }
238  {
239  return $this->activation_start ? $this->activation_start : time();
240  }
241  function setActivationStart($a_value)
242  {
243  $this->activation_start = $a_value;
244  }
245  function getActivationEnd()
246  {
247  return $this->activation_end ? $this->activation_end : mktime(0,0,0,12,12,date("Y",time())+2);
248  }
249  function setActivationEnd($a_value)
250  {
251  $this->activation_end = $a_value;
252  }
253  function getOfflineStatus()
254  {
255  return (bool)$this->activation_offline;
256  }
257  function setOfflineStatus($a_value)
258  {
259  $this->activation_offline = (bool) $a_value;
260  }
261  function setActivationVisibility($a_value)
262  {
263  $this->activation_visibility = (bool) $a_value;
264  }
266  {
267  return $this->activation_visibility;
268  }
269 
271  {
272  return $this->subscription_limitation_type;
273  }
275  {
276  $this->subscription_limitation_type = $a_type;
277  }
279  {
280  return $this->subscription_limitation_type == IL_CRS_SUBSCRIPTION_UNLIMITED;
281  }
283  {
284  return $this->subscription_start ? $this->subscription_start : time();
285  }
286  function setSubscriptionStart($a_value)
287  {
288  $this->subscription_start = $a_value;
289  }
291  {
292  return $this->subscription_end ? $this->subscription_end : mktime(0,0,0,12,12,date("Y",time())+2);
293  }
294  function setSubscriptionEnd($a_value)
295  {
296  $this->subscription_end = $a_value;
297  }
299  {
300  return $this->subscription_type ? $this->subscription_type : IL_CRS_SUBSCRIPTION_DIRECT;
301  #return $this->subscription_type ? $this->subscription_type : $this->SUBSCRIPTION_DEACTIVATED;
302  }
303  function setSubscriptionType($a_value)
304  {
305  $this->subscription_type = $a_value;
306  }
308  {
309  return $this->subscription_password;
310  }
311  function setSubscriptionPassword($a_value)
312  {
313  $this->subscription_password = $a_value;
314  }
316  {
317  return $this->view_mode == IL_CRS_VIEW_OBJECTIVE;
318  }
319 
321  {
322  return (bool) $this->waiting_list;
323  }
324 
325  function enableWaitingList($a_status)
326  {
327  $this->waiting_list = (bool) $a_status;
328  }
329 
331  {
332  if($this->getSubscriptionUnlimitedStatus())
333  {
334  return true;
335  }
336  if(time() > $this->getSubscriptionStart() and time() < $this->getSubscriptionEnd())
337  {
338  return true;
339  }
340  return false;
341  }
342 
348  public function enableSessionLimit($a_status)
349  {
350  $this->session_limit = $a_status;
351  }
352 
353  public function isSessionLimitEnabled()
354  {
355  return (bool) $this->session_limit;
356  }
357 
365  public function enableSubscriptionMembershipLimitation($a_status)
366  {
367  $this->subscription_membership_limitation = $a_status;
368  }
369 
375  public function setNumberOfPreviousSessions($a_num)
376  {
377  $this->session_prev = $a_num;
378  }
379 
384  public function getNumberOfPreviousSessions()
385  {
386  return $this->session_prev;
387  }
388 
394  public function setNumberOfNextSessions($a_num)
395  {
396  $this->session_next = $a_num;
397  }
398 
403  public function getNumberOfNextSessions()
404  {
405  return $this->session_next;
406  }
415  {
416  return (bool) $this->subscription_membership_limitation;
417  }
418 
420  {
421  return $this->subscription_max_members;
422  }
423  function setSubscriptionMaxMembers($a_value)
424  {
425  $this->subscription_max_members = $a_value;
426  }
427 
436  public static function _isSubscriptionNotificationEnabled($a_course_id)
437  {
438  global $ilDB;
439 
440  $query = "SELECT * FROM crs_settings ".
441  "WHERE obj_id = ".$ilDB->quote($a_course_id ,'integer')." ".
442  "AND sub_notify = 1";
443  $res = $ilDB->query($query);
444  return $res->numRows() ? true : false;
445  }
446 
453  public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
454  {
455  global $ilUser;
456 
457  // Caching
458  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]))
459  {
460  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
461  }
462 
463  // Results are stored in $this->items
464  parent::getSubItems($a_admin_panel_enabled,$a_include_side_block);
465 
466  $limit_sess = false;
467  if(!$a_admin_panel_enabled &&
468  !$a_include_side_block &&
469  $this->items['sess'] &&
470  is_array($this->items['sess']) &&
471  $this->isSessionLimitEnabled() &&
472  $this->getViewMode() == ilContainer::VIEW_SESSIONS) // #16686
473  {
474  $limit_sess = true;
475  }
476 
477  if(!$limit_sess)
478  {
479  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
480  }
481 
482 
483  // do session limit
484 
485  // @todo move to gui class
486  if(isset($_GET['crs_prev_sess']))
487  {
488  $ilUser->writePref('crs_sess_show_prev_'.$this->getId(), (string) (int) $_GET['crs_prev_sess']);
489  }
490  if(isset($_GET['crs_next_sess']))
491  {
492  $ilUser->writePref('crs_sess_show_next_'.$this->getId(), (string) (int) $_GET['crs_next_sess']);
493  }
494 
495  $sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
496  $today = new ilDate(date('Ymd',time()),IL_CAL_DATE);
497  $previous = $current = $next = array();
498  foreach($sessions as $key => $item)
499  {
500  $start = new ilDateTime($item['start'],IL_CAL_UNIX);
501  $end = new ilDateTime($item['end'],IL_CAL_UNIX);
502 
503  if(ilDateTime::_within($today, $start, $end, IL_CAL_DAY))
504  {
505  $current[] = $item;
506  }
507  elseif(ilDateTime::_before($start, $today, IL_CAL_DAY))
508  {
509  $previous[] = $item;
510  }
511  elseif(ilDateTime::_after($start, $today, IL_CAL_DAY))
512  {
513  $next[] = $item;
514  }
515  }
516  $num_previous_remove = max(
517  count($previous) - $this->getNumberOfPreviousSessions(),
518  0
519  );
520  while($num_previous_remove--)
521  {
522  if(!$ilUser->getPref('crs_sess_show_prev_'.$this->getId()))
523  {
524  array_shift($previous);
525  }
526  $this->items['sess_link']['prev']['value'] = 1;
527  }
528 
529  $num_next_remove = max(
530  count($next) - $this->getNumberOfNextSessions(),
531  0
532  );
533  while($num_next_remove--)
534  {
535  if(!$ilUser->getPref('crs_sess_show_next_'.$this->getId()))
536  {
537  array_pop($next);
538  }
539  // @fixme
540  $this->items['sess_link']['next']['value'] = 1;
541  }
542 
543  $sessions = array_merge($previous,$current,$next);
544  $this->items['sess'] = $sessions;
545 
546  // #15389 - see ilContainer::getSubItems()
547  include_once('Services/Container/classes/class.ilContainerSorting.php');
548  $sort = ilContainerSorting::_getInstance($this->getId());
549  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $sort->sortItems($this->items);
550 
551  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
552  }
553 
555  {
556  return true;
557  return $this->subscription_notify ? true : false;
558  }
559  function setSubscriptionNotify($a_value)
560  {
561  $this->subscription_notify = $a_value ? true : false;
562  }
563 
564  function setViewMode($a_mode)
565  {
566  $this->view_mode = $a_mode;
567  }
568  function getViewMode()
569  {
570  return $this->view_mode;
571  }
572 
573  function _lookupViewMode($a_id)
574  {
575  global $ilDB;
576 
577  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
578  $res = $ilDB->query($query);
579  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
580  {
581  return $row->view_mode;
582  }
583  return false;
584  }
585 
586  function _lookupAboStatus($a_id)
587  {
588  global $ilDB;
589 
590  $query = "SELECT abo FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
591  $res = $ilDB->query($query);
592  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
593  {
594  return $row->abo;
595  }
596  return false;
597  }
598 
599  function getArchiveStart()
600  {
601  return $this->archive_start ? $this->archive_start : time();
602  }
603  function setArchiveStart($a_value)
604  {
605  $this->archive_start = $a_value;
606  }
607  function getArchiveEnd()
608  {
609  return $this->archive_end ? $this->archive_end : mktime(0,0,0,12,12,date("Y",time())+2);
610  }
611  function setArchiveEnd($a_value)
612  {
613  $this->archive_end = $a_value;
614  }
615  function getArchiveType()
616  {
617  return $this->archive_type ? IL_CRS_ARCHIVE_DOWNLOAD : IL_CRS_ARCHIVE_NONE;
618  }
619  function setArchiveType($a_value)
620  {
621  $this->archive_type = $a_value;
622  }
623  function setAboStatus($a_status)
624  {
625  $this->abo = $a_status;
626  }
627  function getAboStatus()
628  {
629  return $this->abo;
630  }
631  function setShowMembers($a_status)
632  {
633  $this->show_members = $a_status;
634  }
635  function getShowMembers()
636  {
637  return $this->show_members;
638  }
639 
645  public function setMailToMembersType($a_type)
646  {
647  $this->mail_members = $a_type;
648  }
649 
654  public function getMailToMembersType()
655  {
656  return $this->mail_members;
657  }
658 
659  function getMessage()
660  {
661  return $this->message;
662  }
663  function setMessage($a_message)
664  {
665  $this->message = $a_message;
666  }
667  function appendMessage($a_message)
668  {
669  if($this->getMessage())
670  {
671  $this->message .= "<br /> ";
672  }
673  $this->message .= $a_message;
674  }
675 
676  function isActivated($a_check_archive = false)
677  {
678  if($a_check_archive)
679  {
680  if($this->isArchived())
681  {
682  return true;
683  }
684  }
685  if($this->getOfflineStatus())
686  {
687  return false;
688  }
689  if($this->getActivationUnlimitedStatus())
690  {
691  return true;
692  }
693  if(time() < $this->getActivationStart() or
694  time() > $this->getActivationEnd())
695  {
696  return false;
697  }
698  return true;
699  }
700 
707  function _isActivated($a_obj_id)
708  {
709  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
710  return ilObjCourseAccess::_isActivated($a_obj_id);
711  }
712 
719  function _registrationEnabled($a_obj_id)
720  {
721  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
722  return ilObjCourseAccess::_registrationEnabled($a_obj_id);
723  }
724 
725  function isArchived()
726  {
727  if($this->getViewMode() != IL_CRS_VIEW_ARCHIVE)
728  {
729  return false;
730  }
731  if(time() < $this->getArchiveStart() or time() > $this->getArchiveEnd())
732  {
733  return false;
734  }
735  return true;
736  }
737 
738  function allowAbo()
739  {
740  return $this->ABO == $this->ABO_ENABLED;
741  }
742 
743  function read($a_force_db = false)
744  {
745  parent::read($a_force_db);
746 
747  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
749 
750  $this->__readSettings();
751  }
752  function create($a_upload = false)
753  {
754  global $ilAppEventHandler;
755 
756  parent::create($a_upload);
757 
758  if(!$a_upload)
759  {
760  $this->createMetaData();
761  }
762  $this->__createDefaultSettings();
763 
764  $ilAppEventHandler->raise('Modules/Course',
765  'create',
766  array('object' => $this,
767  'obj_id' => $this->getId(),
768  'appointments' => $this->prepareAppointments('create')));
769 
770  }
771 
777  function setLatitude($a_latitude)
778  {
779  $this->latitude = $a_latitude;
780  }
781 
787  function getLatitude()
788  {
789  return $this->latitude;
790  }
791 
797  function setLongitude($a_longitude)
798  {
799  $this->longitude = $a_longitude;
800  }
801 
807  function getLongitude()
808  {
809  return $this->longitude;
810  }
811 
817  function setLocationZoom($a_locationzoom)
818  {
819  $this->locationzoom = $a_locationzoom;
820  }
821 
827  function getLocationZoom()
828  {
829  return $this->locationzoom;
830  }
831 
837  function setEnableCourseMap($a_enablemap)
838  {
839  $this->enablemap = $a_enablemap;
840  }
841 
848  {
849  return $this->enablemap;
850  }
851 
860  public function cloneObject($a_target_id,$a_copy_id = 0)
861  {
862  global $ilDB,$ilUser;
863 
864  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
865 
866  $this->cloneAutoGeneratedRoles($new_obj);
867  $this->cloneMetaData($new_obj);
868 
869  // Assign admin
870  $new_obj->getMemberObject()->add($ilUser->getId(),IL_CRS_ADMIN);
871 
872  // #14596
873  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
874  if($cwo->isRootNode($this->getRefId()))
875  {
876  $this->setOfflineStatus(true);
877  }
878 
879  // Copy settings
880  $this->cloneSettings($new_obj);
881 
882  // Course Defined Fields
883  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
884  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
885 
886  // Clone course files
887  include_once('Modules/Course/classes/class.ilCourseFile.php');
888  ilCourseFile::_cloneFiles($this->getId(),$new_obj->getId());
889 
890  // Copy learning progress settings
891  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
892  $obj_settings = new ilLPObjSettings($this->getId());
893  $obj_settings->cloneSettings($new_obj->getId());
894  unset($obj_settings);
895 
896  // clone icons
897  global $ilLog;
898  $ilLog->write(__METHOD__.': '.$this->getBigIconPath().' '.$this->getSmallIconPath());
899  $new_obj->saveIcons($this->getBigIconPath(),
900  $this->getSmallIconPath(),
901  $this->getTinyIconPath());
902 
903  // clone certificate (#11085)
904  include_once "./Services/Certificate/classes/class.ilCertificate.php";
905  include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
906  $cert = new ilCertificate(new ilCourseCertificateAdapter($this));
907  $newcert = new ilCertificate(new ilCourseCertificateAdapter($new_obj));
908  $cert->cloneCertificate($newcert);
909 
910  return $new_obj;
911  }
912 
921  public function cloneDependencies($a_target_id,$a_copy_id)
922  {
923  parent::cloneDependencies($a_target_id,$a_copy_id);
924 
925  // Clone course start objects
926  include_once('Services/Container/classes/class.ilContainerStartObjects.php');
927  $start = new ilContainerStartObjects($this->getRefId(),$this->getId());
928  $start->cloneDependencies($a_target_id,$a_copy_id);
929 
930  // Clone course item settings
931  include_once('Services/Object/classes/class.ilObjectActivation.php');
932  ilObjectActivation::cloneDependencies($this->getRefId(),$a_target_id,$a_copy_id);
933 
934  include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
935  ilLOSettings::cloneSettings($a_copy_id, $this->getId(), ilObject::_lookupObjId($a_target_id));
936 
937  // Clone course learning objectives
938  include_once('Modules/Course/classes/class.ilCourseObjective.php');
939  $crs_objective = new ilCourseObjective($this);
940  $crs_objective->ilClone($a_target_id,$a_copy_id);
941 
942  return true;
943  }
944 
952  public function cloneAutoGeneratedRoles($new_obj)
953  {
954  global $ilLog,$rbacadmin,$rbacreview;
955 
956  $admin = $this->getDefaultAdminRole();
957  $new_admin = $new_obj->getDefaultAdminRole();
958 
959  if(!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId())
960  {
961  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_admin');
962  }
963  $rbacadmin->copyRolePermissions($admin,$this->getRefId(),$new_obj->getRefId(),$new_admin,true);
964  $ilLog->write(__METHOD__.' : Finished copying of role crs_admin.');
965 
966  $tutor = $this->getDefaultTutorRole();
967  $new_tutor = $new_obj->getDefaultTutorRole();
968  if(!$tutor || !$new_tutor)
969  {
970  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_tutor');
971  }
972  $rbacadmin->copyRolePermissions($tutor,$this->getRefId(),$new_obj->getRefId(),$new_tutor,true);
973  $ilLog->write(__METHOD__.' : Finished copying of role crs_tutor.');
974 
975  $member = $this->getDefaultMemberRole();
976  $new_member = $new_obj->getDefaultMemberRole();
977  if(!$member || !$new_member)
978  {
979  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_member');
980  }
981  $rbacadmin->copyRolePermissions($member,$this->getRefId(),$new_obj->getRefId(),$new_member,true);
982  $ilLog->write(__METHOD__.' : Finished copying of role crs_member.');
983 
984  return true;
985  }
986 
987 
988  function validate()
989  {
990  $this->setMessage('');
991 
992  #if(($this->getSubscriptionLimitationType() != IL_CRS_SUBSCRIPTION_DEACTIVATED) and
993  # $this->getSubscriptionType() == )
994  #{
995  # $this->appendMessage($this->lng->txt('crs_select_registration_type'));
996  #}
997 
998  if(($this->getActivationType() == IL_CRS_ACTIVATION_LIMITED) and
999  $this->getActivationEnd() < $this->getActivationStart())
1000  {
1001  $this->appendMessage($this->lng->txt("activation_times_not_valid"));
1002  }
1004  $this->getSubscriptionStart() > $this->getSubscriptionEnd())
1005  {
1006  $this->appendMessage($this->lng->txt("subscription_times_not_valid"));
1007  }
1008  #if((!$this->getActivationUnlimitedStatus() and
1009  # !$this->getSubscriptionUnlimitedStatus()) and
1010  # ($this->getSubscriptionStart() > $this->getActivationEnd() or
1011  # $this->getSubscriptionStart() < $this->getActivationStart() or
1012  # $this->getSubscriptionEnd() > $this->getActivationEnd() or
1013  # $this->getSubscriptionEnd() < $this->getActivationStart()))
1014  #
1015  #{
1016  # $this->appendMessage($this->lng->txt("subscription_time_not_within_activation"));
1017  #}
1019  {
1020  $this->appendMessage($this->lng->txt("crs_password_required"));
1021  }
1022  if($this->isSubscriptionMembershipLimited() and ($this->getSubscriptionMaxMembers() <= 0 or !is_numeric($this->getSubscriptionMaxMembers())))
1023  {
1024  $this->appendMessage($this->lng->txt("max_members_not_numeric"));
1025  }
1026  if(($this->getViewMode() == IL_CRS_VIEW_ARCHIVE) and
1027  $this->getArchiveStart() > $this->getArchiveEnd())
1028  {
1029  $this->appendMessage($this->lng->txt("archive_times_not_valid"));
1030  }
1031  if(!$this->getTitle() || !$this->getStatusDetermination())
1032  {
1033  $this->appendMessage($this->lng->txt('err_check_input'));
1034  }
1035 
1036 
1037  return $this->getMessage() ? false : true;
1038  }
1039 
1041  {
1042  global $ilErr;
1043  $error = false;
1044  if($this->getContactEmail()) {
1045  $emails = split(",",$this->getContactEmail());
1046 
1047  foreach ($emails as $email) {
1048  $email = trim($email);
1049  if (!(ilUtil::is_email($email) or ilObjUser::getUserIdByLogin($email)))
1050  {
1051  $ilErr->appendMessage($this->lng->txt('contact_email_not_valid')." '".$email."'");
1052  $error = true;
1053  }
1054  }
1055  }
1056  return !$error;
1057  }
1058 
1059  function hasContactData()
1060  {
1061  return strlen($this->getContactName()) or
1062  strlen($this->getContactResponsibility()) or
1063  strlen($this->getContactEmail()) or
1064  strlen($this->getContactPhone()) or
1065  strlen($this->getContactConsultation());
1066  }
1067 
1068 
1075  function delete()
1076  {
1077  global $ilAppEventHandler;
1078 
1079  // always call parent delete function first!!
1080  if (!parent::delete())
1081  {
1082  return false;
1083  }
1084 
1085  // delete meta data
1086  $this->deleteMetaData();
1087 
1088  // put here course specific stuff
1089 
1090  $this->__deleteSettings();
1091 
1092  include_once('Modules/Course/classes/class.ilCourseParticipants.php');
1094 
1095  $this->initCourseArchiveObject();
1096  $this->archives_obj->deleteAll();
1097 
1098  include_once './Modules/Course/classes/class.ilCourseObjective.php';
1100 
1101  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
1103 
1104  include_once './Modules/Course/classes/class.ilCourseFile.php';
1106 
1107  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
1109 
1110  $ilAppEventHandler->raise('Modules/Course',
1111  'delete',
1112  array('object' => $this,
1113  'obj_id' => $this->getId(),
1114  'appointments' => $this->prepareAppointments('delete')));
1115 
1116 
1117  return true;
1118  }
1119 
1120 
1121 
1125  function update()
1126  {
1127  global $ilAppEventHandler,$ilLog;
1128 
1129  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1130  $sorting = new ilContainerSortingSettings($this->getId());
1131  $sorting->setSortMode($this->getOrderType());
1132  $sorting->update();
1133 
1134  $this->updateMetaData();
1135  $this->updateSettings();
1136  parent::update();
1137 
1138  $ilAppEventHandler->raise('Modules/Course',
1139  'update',
1140  array('object' => $this,
1141  'obj_id' => $this->getId(),
1142  'appointments' => $this->prepareAppointments('update')));
1143 
1144  }
1145 
1146  function updateSettings()
1147  {
1148  global $ilDB;
1149 
1150  // Due to a bug 3.5.alpha maybe no settings exist. => create default settings
1151 
1152  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1153  $res = $ilDB->query($query);
1154 
1155  if(!$res->numRows())
1156  {
1157  $this->__createDefaultSettings();
1158  }
1159 
1160  $query = "UPDATE crs_settings SET ".
1161  "syllabus = ".$ilDB->quote($this->getSyllabus() ,'text').", ".
1162  "contact_name = ".$ilDB->quote($this->getContactName() ,'text').", ".
1163  "contact_responsibility = ".$ilDB->quote($this->getContactResponsibility() ,'text').", ".
1164  "contact_phone = ".$ilDB->quote($this->getContactPhone() ,'text').", ".
1165  "contact_email = ".$ilDB->quote($this->getContactEmail() ,'text').", ".
1166  "contact_consultation = ".$ilDB->quote($this->getContactConsultation() ,'text').", ".
1167  "activation_type = ".$ilDB->quote(!$this->getOfflineStatus() ,'integer').", ".
1168  "sub_limitation_type = ".$ilDB->quote($this->getSubscriptionLimitationType() ,'integer').", ".
1169  "sub_start = ".$ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1170  "sub_end = ".$ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1171  "sub_type = ".$ilDB->quote($this->getSubscriptionType() ,'integer').", ".
1172  "sub_password = ".$ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1173  "sub_mem_limit = ".$ilDB->quote((int) $this->isSubscriptionMembershipLimited() ,'integer').", ".
1174  "sub_max_members = ".$ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1175  "sub_notify = ".$ilDB->quote($this->getSubscriptionNotify() ,'integer').", ".
1176  "view_mode = ".$ilDB->quote($this->getViewMode() ,'integer').", ".
1177  "archive_start = ".$ilDB->quote($this->getArchiveStart() ,'integer').", ".
1178  "archive_end = ".$ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1179  "archive_type = ".$ilDB->quote($this->getArchiveType() ,'integer').", ".
1180  "abo = ".$ilDB->quote($this->getAboStatus() ,'integer').", ".
1181  "waiting_list = ".$ilDB->quote($this->enabledWaitingList() ,'integer').", ".
1182  "important = ".$ilDB->quote($this->getImportantInformation() ,'text').", ".
1183  "show_members = ".$ilDB->quote($this->getShowMembers() ,'integer').", ".
1184  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
1185  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
1186  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
1187  "enable_course_map = ".$ilDB->quote((int) $this->getEnableCourseMap() ,'integer').", ".
1188  'session_limit = '.$ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1189  'session_prev = '.$ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1190  'session_next = '.$ilDB->quote($this->getNumberOfNextSessions(),'integer').', '.
1191  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1192  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1193  'auto_notification = '.$ilDB->quote( (int)$this->getAutoNotification(), 'integer').', '.
1194  'status_dt = '.$ilDB->quote((int) $this->getStatusDetermination()).', '.
1195  'mail_members_type = '.$ilDB->quote((int) $this->getMailToMembersType(),'integer').' '.
1196  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1197 
1198 
1199  $res = $ilDB->manipulate($query);
1200 
1201  // moved activation to ilObjectActivation
1202  if($this->ref_id)
1203  {
1204  include_once "./Services/Object/classes/class.ilObjectActivation.php";
1205  ilObjectActivation::getItem($this->ref_id);
1206 
1207  $item = new ilObjectActivation;
1208  if($this->getActivationUnlimitedStatus())
1209  {
1211  }
1212  else
1213  {
1214  $item->setTimingType(ilObjectActivation::TIMINGS_ACTIVATION);
1215  $item->setTimingStart($this->getActivationStart());
1216  $item->setTimingEnd($this->getActivationEnd());
1217  $item->toggleVisible($this->getActivationVisibility());
1218  }
1219 
1220  $item->update($this->ref_id);
1221  }
1222  }
1223 
1231  public function cloneSettings($new_obj)
1232  {
1233  $new_obj->setSyllabus($this->getSyllabus());
1234  $new_obj->setContactName($this->getContactName());
1235  $new_obj->setContactResponsibility($this->getContactResponsibility());
1236  $new_obj->setContactPhone($this->getContactPhone());
1237  $new_obj->setContactEmail($this->getContactEmail());
1238  $new_obj->setContactConsultation($this->getContactConsultation());
1239  $new_obj->setOfflineStatus($this->getOfflineStatus()); // #9914
1240  $new_obj->setActivationType($this->getActivationType());
1241  $new_obj->setActivationStart($this->getActivationStart());
1242  $new_obj->setActivationEnd($this->getActivationEnd());
1243  $new_obj->setActivationVisibility($this->getActivationVisibility());
1244  $new_obj->setSubscriptionLimitationType($this->getSubscriptionLimitationType());
1245  $new_obj->setSubscriptionStart($this->getSubscriptionStart());
1246  $new_obj->setSubscriptionEnd($this->getSubscriptionEnd());
1247  $new_obj->setSubscriptionType($this->getSubscriptionType());
1248  $new_obj->setSubscriptionPassword($this->getSubscriptionPassword());
1249  $new_obj->enableSubscriptionMembershipLimitation($this->isSubscriptionMembershipLimited());
1250  $new_obj->setSubscriptionMaxMembers($this->getSubscriptionMaxMembers());
1251  $new_obj->setSubscriptionNotify($this->getSubscriptionNotify());
1252  $new_obj->setViewMode($this->getViewMode());
1253  $new_obj->setOrderType($this->getOrderType());
1254  $new_obj->setArchiveStart($this->getArchiveStart());
1255  $new_obj->setArchiveEnd($this->getArchiveEnd());
1256  $new_obj->setArchiveType($this->getArchiveType());
1257  $new_obj->setAboStatus($this->getAboStatus());
1258  $new_obj->enableWaitingList($this->enabledWaitingList());
1259  $new_obj->setImportantInformation($this->getImportantInformation());
1260  $new_obj->setShowMembers($this->getShowMembers());
1261  $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
1262  $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
1263  $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
1264  $new_obj->setAutoNotification( $this->getAutoNotification() );
1265  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
1266  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1267  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
1268  $new_obj->setStatusDetermination($this->getStatusDetermination());
1269  $new_obj->setMailToMembersType($this->getMailToMembersType());
1270 
1271  // #10271
1272  $new_obj->setEnableCourseMap($this->getEnableCourseMap());
1273  $new_obj->setLatitude($this->getLatitude());
1274  $new_obj->setLongitude($this->getLongitude());
1275  $new_obj->setLocationZoom($this->getLocationZoom());
1276 
1277  $new_obj->update();
1278  }
1279 
1281  {
1282  global $ilDB;
1283 
1284  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1286 
1287  $query = "INSERT INTO crs_settings (obj_id,syllabus,contact_name,contact_responsibility,".
1288  "contact_phone,contact_email,contact_consultation,activation_type,activation_start,".
1289  "activation_end,sub_limitation_type,sub_start,sub_end,sub_type,sub_password,sub_mem_limit,".
1290  "sub_max_members,sub_notify,view_mode,archive_start,archive_end,archive_type,abo," .
1291  "latitude,longitude,location_zoom,enable_course_map,waiting_list,show_members, ".
1292  "session_limit,session_prev,session_next, reg_ac_enabled, reg_ac, auto_notification, status_dt,mail_members_type) ".
1293  "VALUES( ".
1294  $ilDB->quote($this->getId() ,'integer').", ".
1295  $ilDB->quote($this->getSyllabus() ,'text').", ".
1296  $ilDB->quote($this->getContactName() ,'text').", ".
1297  $ilDB->quote($this->getContactResponsibility() ,'text').", ".
1298  $ilDB->quote($this->getContactPhone() ,'text').", ".
1299  $ilDB->quote($this->getContactEmail() ,'text').", ".
1300  $ilDB->quote($this->getContactConsultation() ,'text').", ".
1301  $ilDB->quote(0 ,'integer').", ".
1302  $ilDB->quote($this->getActivationStart() ,'integer').", ".
1303  $ilDB->quote($this->getActivationEnd() ,'integer').", ".
1304  $ilDB->quote(IL_CRS_SUBSCRIPTION_DEACTIVATED ,'integer').", ".
1305  $ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1306  $ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1307  $ilDB->quote(IL_CRS_SUBSCRIPTION_DIRECT ,'integer').", ".
1308  $ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1309  "0, ".
1310  $ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1311  "1, ".
1312  "0, ".
1313  $ilDB->quote($this->getArchiveStart() ,'integer').", ".
1314  $ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1315  $ilDB->quote(IL_CRS_ARCHIVE_NONE ,'integer').", ".
1316  $ilDB->quote($this->ABO_ENABLED ,'integer').", ".
1317  $ilDB->quote($this->getLatitude() ,'text').", ".
1318  $ilDB->quote($this->getLongitude() ,'text').", ".
1319  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
1320  $ilDB->quote($this->getEnableCourseMap() ,'integer').", ".
1321  #"objective_view = '0', ".
1322  "1, ".
1323  "1,".
1324  $ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1325  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1326  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1327  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1328  $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1329  $ilDB->quote((int)$this->getAutoNotification(),'integer').', '.
1330  $ilDB->quote((int)$this->getStatusDetermination(),'integer').', '.
1331  $ilDB->quote((int) $this->getMailToMembersType(),'integer').' '.
1332  ")";
1333 
1334  $res = $ilDB->manipulate($query);
1335  $this->__readSettings();
1336 
1337  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1338  $sorting = new ilContainerSortingSettings($this->getId());
1339  $sorting->setSortMode(ilContainer::SORT_MANUAL);
1340  $sorting->update();
1341  }
1342 
1343 
1344  function __readSettings()
1345  {
1346  global $ilDB;
1347 
1348  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1349 
1350  $res = $ilDB->query($query);
1351  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1352  {
1353  $this->setSyllabus($row->syllabus);
1354  $this->setContactName($row->contact_name);
1355  $this->setContactResponsibility($row->contact_responsibility);
1356  $this->setContactPhone($row->contact_phone);
1357  $this->setContactEmail($row->contact_email);
1358  $this->setContactConsultation($row->contact_consultation);
1359  $this->setOfflineStatus(!(bool)$row->activation_type); // see below
1360  $this->setSubscriptionLimitationType($row->sub_limitation_type);
1361  $this->setSubscriptionStart($row->sub_start);
1362  $this->setSubscriptionEnd($row->sub_end);
1363  $this->setSubscriptionType($row->sub_type);
1364  $this->setSubscriptionPassword($row->sub_password);
1365  $this->enableSubscriptionMembershipLimitation($row->sub_mem_limit);
1366  $this->setSubscriptionMaxMembers($row->sub_max_members);
1367  $this->setSubscriptionNotify($row->sub_notify);
1368  $this->setViewMode($row->view_mode);
1369  $this->setArchiveStart($row->archive_start);
1370  $this->setArchiveEnd($row->archive_end);
1371  $this->setArchiveType($row->archive_type);
1372  $this->setAboStatus($row->abo);
1373  $this->enableWaitingList($row->waiting_list);
1374  $this->setImportantInformation($row->important);
1375  $this->setShowMembers($row->show_members);
1376  $this->setLatitude($row->latitude);
1377  $this->setLongitude($row->longitude);
1378  $this->setLocationZoom($row->location_zoom);
1379  $this->setEnableCourseMap($row->enable_course_map);
1380  $this->enableSessionLimit($row->session_limit);
1381  $this->setNumberOfPreviousSessions($row->session_prev);
1382  $this->setNumberOfNextSessions($row->session_next);
1383  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
1384  $this->setRegistrationAccessCode($row->reg_ac);
1385  $this->setAutoNotification($row->auto_notification == 1 ? true : false);
1386  $this->setStatusDetermination((int) $row->status_dt);
1387  $this->setMailToMembersType($row->mail_members_type);
1388  }
1389 
1390  // moved activation to ilObjectActivation
1391  if($this->ref_id)
1392  {
1393  include_once "./Services/Object/classes/class.ilObjectActivation.php";
1394  $activation = ilObjectActivation::getItem($this->ref_id);
1395  switch($activation["timing_type"])
1396  {
1399  $this->setActivationStart($activation["timing_start"]);
1400  $this->setActivationEnd($activation["timing_end"]);
1401  $this->setActivationVisibility($activation["visible"]);
1402  break;
1403 
1404  default:
1406  break;
1407  }
1408  }
1409  else
1410  {
1411  // #13176 - there should always be default
1413  }
1414 
1415  return true;
1416  }
1417 
1418  function initWaitingList()
1419  {
1420  include_once "./Modules/Course/classes/class.ilCourseWaitingList.php";
1421 
1422  if(!is_object($this->waiting_list_obj))
1423  {
1424  $this->waiting_list_obj = new ilCourseWaitingList($this->getId());
1425  }
1426  return true;
1427  }
1428 
1429 
1435  protected function initCourseMemberObject()
1436  {
1437  global $ilUser;
1438 
1439  include_once "./Modules/Course/classes/class.ilCourseParticipant.php";
1440  $this->member_obj = ilCourseParticipant::_getInstanceByObjId($this->getId(),$ilUser->getId());
1441  return true;
1442  }
1443 
1449  protected function initCourseMembersObject()
1450  {
1451  global $ilUser;
1452 
1453  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1454  $this->members_obj = ilCourseParticipants::_getInstanceByObjId($this->getId());
1455  return true;
1456  }
1457 
1462  public function getMemberObject()
1463  {
1464  if(!$this->member_obj instanceof ilCourseParticipant)
1465  {
1466  $this->initCourseMemberObject();
1467  }
1468  return $this->member_obj;
1469  }
1470 
1475  public function getMembersObject()
1476  {
1477  if(!$this->members_obj instanceof ilCourseParticipants)
1478  {
1479  $this->initCourseMembersObject();
1480  }
1481  return $this->members_obj;
1482  }
1483 
1485  {
1486  include_once "./Modules/Course/classes/class.ilCourseArchives.php";
1487 
1488  if(!is_object($this->archives_obj))
1489  {
1490  $this->archives_obj =& new ilCourseArchives($this);
1491  }
1492  return true;
1493  }
1494 
1495 
1496 
1497  // RBAC METHODS
1498  function initDefaultRoles()
1499  {
1500  global $rbacadmin,$rbacreview,$ilDB;
1501 
1502  include_once './Services/AccessControl/classes/class.ilObjRole.php';
1504  'il_crs_admin_'.$this->getRefId(),
1505  "Admin of crs obj_no.".$this->getId(),
1506  'il_crs_admin',
1507  $this->getRefId()
1508  );
1510  'il_crs_tutor_'.$this->getRefId(),
1511  "Tutor of crs obj_no.".$this->getId(),
1512  'il_crs_tutor',
1513  $this->getRefId()
1514  );
1516  'il_crs_member_'.$this->getRefId(),
1517  "Member of crs obj_no.".$this->getId(),
1518  'il_crs_member',
1519  $this->getRefId()
1520  );
1521 
1522  return array();
1523  }
1524 
1534  public function setParentRolePermissions($a_parent_ref)
1535  {
1536  global $rbacadmin, $rbacreview;
1537 
1538  $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1539  foreach((array) $parent_roles as $parent_role)
1540  {
1541  $rbacadmin->initIntersectionPermissions(
1542  $this->getRefId(),
1543  $parent_role['obj_id'],
1544  $parent_role['parent'],
1545  $this->__getCrsNonMemberTemplateId(),
1546  ROLE_FOLDER_ID
1547  );
1548  }
1549  }
1550 
1558  {
1559  global $ilDB;
1560 
1561  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
1562  $res = $this->ilias->db->query($q);
1563  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1564 
1565  return $row["obj_id"];
1566  }
1567 
1572  public static function lookupCourseNonMemberTemplatesId()
1573  {
1574  global $ilDB;
1575 
1576  $query = 'SELECT obj_id FROM object_data WHERE type = '.$ilDB->quote('rolt','text').' AND title = '.$ilDB->quote('il_crs_non_member','text');
1577  $res = $ilDB->query($query);
1578  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1579 
1580  return isset($row['obj_id']) ? $row['obj_id'] : 0;
1581  }
1582 
1589  public function getLocalCourseRoles($a_translate = false)
1590  {
1591  global $rbacadmin,$rbacreview;
1592 
1593  if (empty($this->local_roles))
1594  {
1595  $this->local_roles = array();
1596  $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1597 
1598  foreach ($role_arr as $role_id)
1599  {
1600  if ($rbacreview->isAssignable($role_id,$this->getRefId()) == true)
1601  {
1602  $role_Obj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
1603 
1604  if ($a_translate)
1605  {
1606  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1607  }
1608  else
1609  {
1610  $role_name = $role_Obj->getTitle();
1611  }
1612  $this->local_roles[$role_name] = $role_Obj->getId();
1613  }
1614  }
1615  }
1616 
1617  return $this->local_roles;
1618  }
1619 
1620 
1621 
1631  public function getDefaultCourseRoles($a_crs_id = "")
1632  {
1633  global $rbacadmin, $rbacreview;
1634 
1635  if (strlen($a_crs_id) > 0)
1636  {
1637  $crs_id = $a_crs_id;
1638  }
1639  else
1640  {
1641  $crs_id = $this->getRefId();
1642  }
1643 
1644  $role_arr = $rbacreview->getRolesOfRoleFolder($crs_id);
1645 
1646  foreach ($role_arr as $role_id)
1647  {
1648  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1649 
1650  $crs_Member ="il_crs_member_".$crs_id;
1651  $crs_Admin ="il_crs_admin_".$crs_id;
1652  $crs_Tutor ="il_crs_tutor_".$crs_id;
1653 
1654  if (strcmp($role_Obj->getTitle(), $crs_Member) == 0 )
1655  {
1656  $arr_crsDefaultRoles["crs_member_role"] = $role_Obj->getId();
1657  }
1658 
1659  if (strcmp($role_Obj->getTitle(), $crs_Admin) == 0)
1660  {
1661  $arr_crsDefaultRoles["crs_admin_role"] = $role_Obj->getId();
1662  }
1663 
1664  if (strcmp($role_Obj->getTitle(), $crs_Tutor) == 0)
1665  {
1666  $arr_crsDefaultRoles["crs_tutor_role"] = $role_Obj->getId();
1667  }
1668  }
1669 
1670  return $arr_crsDefaultRoles;
1671  }
1672 
1673  function __getLocalRoles()
1674  {
1675  global $rbacreview;
1676 
1677  // GET role_objects of predefined roles
1678 
1679  return $rbacreview->getRolesOfRoleFolder($this->getRefId(),false);
1680  }
1681 
1682  function __deleteSettings()
1683  {
1684  global $ilDB;
1685 
1686  $query = "DELETE FROM crs_settings ".
1687  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1688  $res = $ilDB->manipulate($query);
1689 
1690  return true;
1691  }
1692 
1693 
1695  {
1696  $local_roles = $this->__getLocalRoles();
1697 
1698  foreach($local_roles as $role_id)
1699  {
1700  $title = ilObject::_lookupTitle($role_id);
1701  if(substr($title,0,8) == 'il_crs_m')
1702  {
1703  return $role_id;
1704  }
1705  }
1706  return 0;
1707  }
1709  {
1710  $local_roles = $this->__getLocalRoles();
1711 
1712  foreach($local_roles as $role_id)
1713  {
1714  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1715  {
1716  if(!strcmp($tmp_role->getTitle(),"il_crs_tutor_".$this->getRefId()))
1717  {
1718  return $role_id;
1719  }
1720  }
1721  }
1722  return false;
1723  }
1725  {
1726  $local_roles = $this->__getLocalRoles();
1727 
1728  foreach($local_roles as $role_id)
1729  {
1730  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1731  {
1732  if(!strcmp($tmp_role->getTitle(),"il_crs_admin_".$this->getRefId()))
1733  {
1734  return $role_id;
1735  }
1736  }
1737  }
1738  return false;
1739  }
1740 
1741  function _deleteUser($a_usr_id)
1742  {
1743  // Delete all user related data
1744  // delete lm_history
1745  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
1746  ilCourseLMHistory::_deleteUser($a_usr_id);
1747 
1748  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
1750 
1751  // Course objectives
1752  include_once "Modules/Course/classes/Objectives/class.ilLOUserResults.php";
1754  }
1755 
1762  public function MDUpdateListener($a_element)
1763  {
1764  global $ilLog;
1765 
1766  parent::MDUpdateListener($a_element);
1767 
1768  switch($a_element)
1769  {
1770  case 'General':
1771  // Update ecs content
1772  include_once 'Modules/Course/classes/class.ilECSCourseSettings.php';
1773  $ecs = new ilECSCourseSettings($this);
1774  $ecs->handleContentUpdate();
1775  break;
1776 
1777  default:
1778  return true;
1779  }
1780  }
1781 
1786  function addAdditionalSubItemInformation(&$a_item_data)
1787  {
1788  include_once './Services/Object/classes/class.ilObjectActivation.php';
1790  }
1791 
1799  protected function prepareAppointments($a_mode = 'create')
1800  {
1801  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1802  include_once('./Services/Calendar/classes/class.ilDateTime.php');
1803 
1804  switch($a_mode)
1805  {
1806  case 'create':
1807  case 'update':
1808  if(!$this->getActivationUnlimitedStatus() and !$this->getOfflineStatus())
1809  {
1810  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_START);
1811  $app->setTitle($this->getTitle());
1812  $app->setSubtitle('crs_cal_activation_start');
1813  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1814  $app->setDescription($this->getLongDescription());
1815  $app->setStart(new ilDateTime($this->getActivationStart(),IL_CAL_UNIX));
1816  $apps[] = $app;
1817 
1818  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_END);
1819  $app->setTitle($this->getTitle());
1820  $app->setSubtitle('crs_cal_activation_end');
1821  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1822  $app->setDescription($this->getLongDescription());
1823  $app->setStart(new ilDateTime($this->getActivationEnd(),IL_CAL_UNIX));
1824  $apps[] = $app;
1825  }
1827  {
1828  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1829  $app->setTitle($this->getTitle());
1830  $app->setSubtitle('crs_cal_reg_start');
1831  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1832  $app->setDescription($this->getLongDescription());
1833  $app->setStart(new ilDateTime($this->getSubscriptionStart(),IL_CAL_UNIX));
1834  $apps[] = $app;
1835 
1836  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1837  $app->setTitle($this->getTitle());
1838  $app->setSubtitle('crs_cal_reg_end');
1839  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1840  $app->setDescription($this->getLongDescription());
1841  $app->setStart(new ilDateTime($this->getSubscriptionEnd(),IL_CAL_UNIX));
1842  $apps[] = $app;
1843  }
1844 
1845  return $apps ? $apps : array();
1846 
1847  case 'delete':
1848  // Nothing to do: The category and all assigned appointments will be deleted.
1849  return array();
1850  }
1851  }
1852 
1853  ###### Interface ilMembershipRegistrationCodes
1854 
1858  public static function lookupObjectsByCode($a_code)
1859  {
1860  global $ilDB;
1861 
1862  $query = "SELECT obj_id FROM crs_settings ".
1863  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1864  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1865  $res = $ilDB->query($query);
1866 
1867  $obj_ids = array();
1868  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1869  {
1870  $obj_ids[] = $row->obj_id;
1871  }
1872  return $obj_ids;
1873  }
1874 
1881  public function register($a_user_id,$a_role = ilCourseConstants::CRS_MEMBER, $a_force_registration = false)
1882  {
1883  global $ilCtrl, $tree;
1884  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1885  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1887 
1888  if($part->isAssigned($a_user_id))
1889  {
1890  return true;
1891  }
1892 
1893  if(!$a_force_registration)
1894  {
1895  // Availability
1897  {
1898  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1899 
1901  {
1902  throw new ilMembershipRegistrationException('Cant registrate to course '.$this->getId().
1903  ', course subscription is deactivated.', '456');
1904  }
1905  }
1906 
1907  // Time Limitation
1909  {
1910  if( !$this->inSubscriptionTime() )
1911  {
1912  throw new ilMembershipRegistrationException('Cant registrate to course '.$this->getId().
1913  ', course is out of registration time.', '789');
1914  }
1915  }
1916 
1917  // Max members
1918  if($this->isSubscriptionMembershipLimited())
1919  {
1920  $free = max(0,$this->getSubscriptionMaxMembers() - $part->getCountMembers());
1921  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
1922  $waiting_list = new ilCourseWaitingList($this->getId());
1923  if($this->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
1924  {
1925  $waiting_list->addToList($a_user_id);
1926  $this->lng->loadLanguageModule("crs");
1927  $info = sprintf($this->lng->txt('crs_added_to_list'),
1928  $waiting_list->getPosition($a_user_id));
1929  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
1930  $participants = ilCourseParticipants::_getInstanceByObjId($this->getId());
1931  $participants->sendNotification($participants->NOTIFY_WAITING_LIST,$a_user_id);
1932 
1933  throw new ilMembershipRegistrationException($info, '124');
1934  }
1935 
1936  if(!$this->enabledWaitingList() && !$free)
1937  {
1938  throw new ilMembershipRegistrationException('Cant registrate to course '.$this->getId().
1939  ', membership is limited.', '123');
1940  }
1941  }
1942  }
1943 
1944  $part->add($a_user_id,$a_role);
1945  $part->sendNotification($part->NOTIFY_ACCEPT_USER, $a_user_id);
1946  $part->sendNotification($part->NOTIFY_ADMINS,$a_user_id);
1947 
1948 
1949  include_once './Modules/Forum/classes/class.ilForumNotification.php';
1951 
1952  return true;
1953  }
1954 
1961  public function getAutoNotification()
1962  {
1963  return $this->auto_notification;
1964  }
1965 
1966 
1973  public function setAutoNotification($value)
1974  {
1975  $this->auto_notification = $value;
1976  }
1977 
1983  public function setStatusDetermination($a_value)
1984  {
1985  $a_value = (int)$a_value;
1986 
1987  // #13905
1988  if($a_value == self::STATUS_DETERMINATION_LP)
1989  {
1990  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
1992  {
1994  }
1995  }
1996 
1997  $this->status_dt = $a_value;
1998  }
1999 
2005  public function getStatusDetermination()
2006  {
2007  return $this->status_dt;
2008  }
2009 
2013  public function syncMembersStatusWithLP()
2014  {
2015  include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
2016  foreach($this->getMembersObject()->getParticipants() as $user_id)
2017  {
2018  // #15529 - force raise on sync
2019  ilLPStatusWrapper::_updateStatus($this->getId(), $user_id, null, false, false, true);
2020  }
2021  }
2022 
2030  public function checkLPStatusSync($a_member_id)
2031  {
2032  // #11113
2033  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
2036  {
2037  include_once("Services/Tracking/classes/class.ilLPStatus.php");
2038  // #13811 - we need to suppress creation if status entry
2039  $has_completed = (ilLPStatus::_lookupStatus($this->getId(), $a_member_id, false) == ilLPStatus::LP_STATUS_COMPLETED_NUM);
2040  $this->getMembersObject()->updatePassed($a_member_id, $has_completed, false, true);
2041  }
2042  }
2043 
2044  function getOrderType()
2045  {
2046  if($this->enabledObjectiveView())
2047  {
2048  return ilContainer::SORT_MANUAL;
2049  }
2050  return parent::getOrderType();
2051  }
2052 
2053 } //END class.ilObjCourse
2054 ?>