ILIAS  Release_4_2_x_branch Revision 61807
 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 
43  private $member_obj = null;
44  private $members_obj = null;
47 
48 
49  private $latitude = '';
50  private $longitude = '';
51  private $locationzoom = 0;
52  private $enablemap = 0;
53 
54  private $session_limit = 0;
55  private $session_prev = -1;
56  private $session_next = -1;
57 
58  private $reg_access_code = '';
59  private $reg_access_code_enabled = false;
60 
69  private $auto_noti_disabled = false;
70 
77  function ilObjCourse($a_id = 0,$a_call_by_reference = true)
78  {
79 
80  #define("ILIAS_MODULE","course");
81  #define("KEEP_IMAGE_PATH",1);
82 
83  $this->SUBSCRIPTION_DEACTIVATED = 1;
84  $this->SUBSCRIPTION_CONFIRMATION = 2;
85  $this->SUBSCRIPTION_DIRECT = 3;
86  $this->SUBSCRIPTION_PASSWORD = 4;
87  $this->SUBSCRIPTION_AUTOSUBSCRIPTION = 5;
88  $this->ARCHIVE_DISABLED = 1;
89  $this->ARCHIVE_READ = 2;
90  $this->ARCHIVE_DOWNLOAD = 3;
91  $this->ABO_ENABLED = 1;
92  $this->ABO_DISABLED = 0;
93  $this->SHOW_MEMBERS_ENABLED = 1;
94  $this->SHOW_MEMBERS_DISABLED = 0;
95 
96  $this->type = "crs";
97 
98  parent::__construct($a_id,$a_call_by_reference);
99 
100  }
101 
106  public function getRegistrationAccessCode()
107  {
108  return $this->reg_access_code;
109  }
110 
116  public function setRegistrationAccessCode($a_code)
117  {
118  $this->reg_access_code = $a_code;
119  }
120 
126  {
127  return (bool) $this->reg_access_code_enabled;
128  }
129 
135  public function enableRegistrationAccessCode($a_status)
136  {
137  $this->reg_access_code_enabled = $a_status;
138  }
139 
141  {
142  return $this->important;
143  }
144  function setImportantInformation($a_info)
145  {
146  $this->important = $a_info;
147  }
148  function getSyllabus()
149  {
150  return $this->syllabus;
151  }
152  function setSyllabus($a_syllabus)
153  {
154  $this->syllabus = $a_syllabus;
155  }
156  function getContactName()
157  {
158  return $this->contact_name;
159  }
160  function setContactName($a_cn)
161  {
162  $this->contact_name = $a_cn;
163  }
165  {
166  return $this->contact_consultation;
167  }
168  function setContactConsultation($a_value)
169  {
170  $this->contact_consultation = $a_value;
171  }
172  function getContactPhone()
173  {
174  return $this->contact_phone;
175  }
176  function setContactPhone($a_value)
177  {
178  $this->contact_phone = $a_value;
179  }
180  function getContactEmail()
181  {
182  return $this->contact_email;
183  }
184  function setContactEmail($a_value)
185  {
186  $this->contact_email = $a_value;
187  }
189  {
190  return $this->contact_responsibility;
191  }
192  function setContactResponsibility($a_value)
193  {
194  $this->contact_responsibility = $a_value;
195  }
196 
197  function getActivationType()
198  {
199  return (int) $this->activation_type;
200  }
201  function setActivationType($a_type)
202  {
203  $this->activation_type = $a_type;
204  }
206  {
207  return $this->activation_type == IL_CRS_ACTIVATION_UNLIMITED;
208 
209  }
210 
212  {
213  return $this->activation_start ? $this->activation_start : time();
214  }
215  function setActivationStart($a_value)
216  {
217  $this->activation_start = $a_value;
218  }
219  function getActivationEnd()
220  {
221  return $this->activation_end ? $this->activation_end : mktime(0,0,0,12,12,date("Y",time())+2);
222  }
223  function setActivationEnd($a_value)
224  {
225  $this->activation_end = $a_value;
226  }
227  function getOfflineStatus()
228  {
229  return $this->activation_type == IL_CRS_ACTIVATION_OFFLINE;
230  }
231 
232 
234  {
235  return $this->subscription_limitation_type;
236  }
238  {
239  $this->subscription_limitation_type = $a_type;
240  }
242  {
243  return $this->subscription_limitation_type == IL_CRS_SUBSCRIPTION_UNLIMITED;
244  }
246  {
247  return $this->subscription_start ? $this->subscription_start : time();
248  }
249  function setSubscriptionStart($a_value)
250  {
251  $this->subscription_start = $a_value;
252  }
254  {
255  return $this->subscription_end ? $this->subscription_end : mktime(0,0,0,12,12,date("Y",time())+2);
256  }
257  function setSubscriptionEnd($a_value)
258  {
259  $this->subscription_end = $a_value;
260  }
262  {
263  return $this->subscription_type ? $this->subscription_type : IL_CRS_SUBSCRIPTION_DIRECT;
264  #return $this->subscription_type ? $this->subscription_type : $this->SUBSCRIPTION_DEACTIVATED;
265  }
266  function setSubscriptionType($a_value)
267  {
268  $this->subscription_type = $a_value;
269  }
271  {
272  return $this->subscription_password;
273  }
274  function setSubscriptionPassword($a_value)
275  {
276  $this->subscription_password = $a_value;
277  }
279  {
280  return $this->view_mode == IL_CRS_VIEW_OBJECTIVE;
281  }
282 
284  {
285  return (bool) $this->waiting_list;
286  }
287 
288  function enableWaitingList($a_status)
289  {
290  $this->waiting_list = (bool) $a_status;
291  }
292 
294  {
295  if($this->getSubscriptionUnlimitedStatus())
296  {
297  return true;
298  }
299  if(time() > $this->getSubscriptionStart() and time() < $this->getSubscriptionEnd())
300  {
301  return true;
302  }
303  return false;
304  }
305 
311  public function enableSessionLimit($a_status)
312  {
313  $this->session_limit = $a_status;
314  }
315 
316  public function isSessionLimitEnabled()
317  {
318  return (bool) $this->session_limit;
319  }
320 
328  public function enableSubscriptionMembershipLimitation($a_status)
329  {
330  $this->subscription_membership_limitation = $a_status;
331  }
332 
338  public function setNumberOfPreviousSessions($a_num)
339  {
340  $this->session_prev = $a_num;
341  }
342 
347  public function getNumberOfPreviousSessions()
348  {
349  return $this->session_prev;
350  }
351 
357  public function setNumberOfNextSessions($a_num)
358  {
359  $this->session_next = $a_num;
360  }
361 
366  public function getNumberOfNextSessions()
367  {
368  return $this->session_next;
369  }
378  {
379  return (bool) $this->subscription_membership_limitation;
380  }
381 
383  {
384  return $this->subscription_max_members;
385  }
386  function setSubscriptionMaxMembers($a_value)
387  {
388  $this->subscription_max_members = $a_value;
389  }
390 
399  public static function _isSubscriptionNotificationEnabled($a_course_id)
400  {
401  global $ilDB;
402 
403  $query = "SELECT * FROM crs_settings ".
404  "WHERE obj_id = ".$ilDB->quote($a_course_id ,'integer')." ".
405  "AND sub_notify = 1";
406  $res = $ilDB->query($query);
407  return $res->numRows() ? true : false;
408  }
409 
416  public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
417  {
418  global $ilUser;
419 
420  // Caching
421  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]))
422  {
423  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
424  }
425 
426  // Results are stored in $this->items
427  parent::getSubItems($a_admin_panel_enabled,$a_include_side_block);
428 
429  // No sessions
430  if(!is_array($this->items['sess']) or !$this->items['sess'])
431  {
432  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
433  }
434  // No session limit
435  if(!$this->isSessionLimitEnabled() or $a_admin_panel_enabled)
436  {
437  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
438  }
439 
440  if($a_include_side_block)
441  {
442  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
443  }
444 
445  // @todo move to gui class
446  if(isset($_GET['crs_prev_sess']))
447  {
448  $ilUser->writePref('crs_sess_show_prev_'.$this->getId(), (string) (int) $_GET['crs_prev_sess']);
449  }
450  if(isset($_GET['crs_next_sess']))
451  {
452  $ilUser->writePref('crs_sess_show_next_'.$this->getId(), (string) (int) $_GET['crs_next_sess']);
453  }
454 
455  $sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
456  $today = new ilDate(date('Ymd',time()),IL_CAL_DATE);
457  $previous = $current = $next = array();
458  foreach($sessions as $key => $item)
459  {
460  $start = new ilDateTime($item['start'],IL_CAL_UNIX);
461  $end = new ilDateTime($item['end'],IL_CAL_UNIX);
462 
463  if(ilDateTime::_within($today, $start, $end, IL_CAL_DAY))
464  {
465  $current[] = $item;
466  }
467  elseif(ilDateTime::_before($start, $today, IL_CAL_DAY))
468  {
469  $previous[] = $item;
470  }
471  elseif(ilDateTime::_after($start, $today, IL_CAL_DAY))
472  {
473  $next[] = $item;
474  }
475  }
476  $num_previous_remove = max(
477  count($previous) - $this->getNumberOfPreviousSessions(),
478  0
479  );
480  while($num_previous_remove--)
481  {
482  if(!$ilUser->getPref('crs_sess_show_prev_'.$this->getId()))
483  {
484  array_shift($previous);
485  }
486  $this->items['sess_link']['prev']['value'] = 1;
487  }
488 
489  $num_next_remove = max(
490  count($next) - $this->getNumberOfNextSessions(),
491  0
492  );
493  while($num_next_remove--)
494  {
495  if(!$ilUser->getPref('crs_sess_show_next_'.$this->getId()))
496  {
497  array_pop($next);
498  }
499  // @fixme
500  $this->items['sess_link']['next']['value'] = 1;
501  }
502 
503  $sessions = array_merge($previous,$current,$next);
504  $this->items['sess'] = $sessions;
505  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $this->items;
506  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
507  }
508 
510  {
511  return true;
512  return $this->subscription_notify ? true : false;
513  }
514  function setSubscriptionNotify($a_value)
515  {
516  $this->subscription_notify = $a_value ? true : false;
517  }
518 
519  function setViewMode($a_mode)
520  {
521  $this->view_mode = $a_mode;
522  }
523  function getViewMode()
524  {
525  return $this->view_mode;
526  }
527 
528  function _lookupViewMode($a_id)
529  {
530  global $ilDB;
531 
532  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
533  $res = $ilDB->query($query);
534  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
535  {
536  return $row->view_mode;
537  }
538  return false;
539  }
540 
541  function _lookupAboStatus($a_id)
542  {
543  global $ilDB;
544 
545  $query = "SELECT abo FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
546  $res = $ilDB->query($query);
547  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
548  {
549  return $row->abo;
550  }
551  return false;
552  }
553 
554  function getArchiveStart()
555  {
556  return $this->archive_start ? $this->archive_start : time();
557  }
558  function setArchiveStart($a_value)
559  {
560  $this->archive_start = $a_value;
561  }
562  function getArchiveEnd()
563  {
564  return $this->archive_end ? $this->archive_end : mktime(0,0,0,12,12,date("Y",time())+2);
565  }
566  function setArchiveEnd($a_value)
567  {
568  $this->archive_end = $a_value;
569  }
570  function getArchiveType()
571  {
572  return $this->archive_type ? IL_CRS_ARCHIVE_DOWNLOAD : IL_CRS_ARCHIVE_NONE;
573  }
574  function setArchiveType($a_value)
575  {
576  $this->archive_type = $a_value;
577  }
578  function setAboStatus($a_status)
579  {
580  $this->abo = $a_status;
581  }
582  function getAboStatus()
583  {
584  return $this->abo;
585  }
586  function setShowMembers($a_status)
587  {
588  $this->show_members = $a_status;
589  }
590  function getShowMembers()
591  {
592  return $this->show_members;
593  }
594 
595  function getMessage()
596  {
597  return $this->message;
598  }
599  function setMessage($a_message)
600  {
601  $this->message = $a_message;
602  }
603  function appendMessage($a_message)
604  {
605  if($this->getMessage())
606  {
607  $this->message .= "<br /> ";
608  }
609  $this->message .= $a_message;
610  }
611 
612  function isActivated($a_check_archive = false)
613  {
614  if($a_check_archive)
615  {
616  if($this->isArchived())
617  {
618  return true;
619  }
620  }
621  if($this->getOfflineStatus())
622  {
623  return false;
624  }
625  if($this->getActivationUnlimitedStatus())
626  {
627  return true;
628  }
629  if(time() < $this->getActivationStart() or
630  time() > $this->getActivationEnd())
631  {
632  return false;
633  }
634  return true;
635  }
636 
643  function _isActivated($a_obj_id)
644  {
645  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
646  return ilObjCourseAccess::_isActivated($a_obj_id);
647  }
648 
655  function _registrationEnabled($a_obj_id)
656  {
657  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
658  return ilObjCourseAccess::_registrationEnabled($a_obj_id);
659  }
660 
661  function isArchived()
662  {
663  if($this->getViewMode() != IL_CRS_VIEW_ARCHIVE)
664  {
665  return false;
666  }
667  if(time() < $this->getArchiveStart() or time() > $this->getArchiveEnd())
668  {
669  return false;
670  }
671  return true;
672  }
673 
674  function allowAbo()
675  {
676  return $this->ABO == $this->ABO_ENABLED;
677  }
678 
679  function read($a_force_db = false)
680  {
681  parent::read($a_force_db);
682 
683  $this->__readSettings();
684  }
685  function create($a_upload = false)
686  {
687  global $ilAppEventHandler;
688 
689  parent::create($a_upload);
690 
691  if(!$a_upload)
692  {
693  $this->createMetaData();
694  }
695  $this->__createDefaultSettings();
696 
697  $ilAppEventHandler->raise('Modules/Course',
698  'create',
699  array('object' => $this,
700  'obj_id' => $this->getId(),
701  'appointments' => $this->prepareAppointments('create')));
702 
703  }
704 
710  function setLatitude($a_latitude)
711  {
712  $this->latitude = $a_latitude;
713  }
714 
720  function getLatitude()
721  {
722  return $this->latitude;
723  }
724 
730  function setLongitude($a_longitude)
731  {
732  $this->longitude = $a_longitude;
733  }
734 
740  function getLongitude()
741  {
742  return $this->longitude;
743  }
744 
750  function setLocationZoom($a_locationzoom)
751  {
752  $this->locationzoom = $a_locationzoom;
753  }
754 
760  function getLocationZoom()
761  {
762  return $this->locationzoom;
763  }
764 
770  function setEnableCourseMap($a_enablemap)
771  {
772  $this->enablemap = $a_enablemap;
773  }
774 
781  {
782  return $this->enablemap;
783  }
784 
793  public function cloneObject($a_target_id,$a_copy_id = 0)
794  {
795  global $ilDB,$ilUser;
796 
797  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
798 
799  $this->cloneAutoGeneratedRoles($new_obj);
800  $this->cloneMetaData($new_obj);
801 
802  // Assign admin
803  $new_obj->getMemberObject()->add($ilUser->getId(),IL_CRS_ADMIN);
804 
805  // Copy settings
806  $this->cloneSettings($new_obj);
807 
808  // Course Defined Fields
809  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
810  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
811 
812  // Clone course files
813  include_once('Modules/Course/classes/class.ilCourseFile.php');
814  ilCourseFile::_cloneFiles($this->getId(),$new_obj->getId());
815 
816  // Copy learning progress settings
817  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
818  $obj_settings = new ilLPObjSettings($this->getId());
819  $obj_settings->cloneSettings($new_obj->getId());
820  unset($obj_settings);
821 
822  // clone icons
823  global $ilLog;
824  $ilLog->write(__METHOD__.': '.$this->getBigIconPath().' '.$this->getSmallIconPath());
825  $new_obj->saveIcons($this->getBigIconPath(),
826  $this->getSmallIconPath(),
827  $this->getTinyIconPath());
828 
829  return $new_obj;
830  }
831 
840  public function cloneDependencies($a_target_id,$a_copy_id)
841  {
842  global $ilObjDataCache;
843 
844  parent::cloneDependencies($a_target_id,$a_copy_id);
845 
846  // Clone course start objects
847  include_once('Modules/Course/classes/class.ilCourseStart.php');
848  $start = new ilCourseStart($this->getRefId(),$this->getId());
849  $start->cloneDependencies($a_target_id,$a_copy_id);
850 
851  // Clone course item settings
852  $this->initCourseItemObject();
853  $this->items_obj->cloneDependencies($a_target_id,$a_copy_id);
854 
855  // Clone course learning objectives
856  include_once('Modules/Course/classes/class.ilCourseObjective.php');
857  $crs_objective = new ilCourseObjective($this);
858  $crs_objective->ilClone($a_target_id,$a_copy_id);
859 
860  include_once('Services/Tracking/classes/class.ilLPCollections.php');
861  $lp_collection = new ilLPCollections($this->getId());
862  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
863 
864  return true;
865  }
866 
874  public function cloneAutoGeneratedRoles($new_obj)
875  {
876  global $ilLog,$rbacadmin,$rbacreview;
877 
878  $admin = $this->getDefaultAdminRole();
879  $new_admin = $new_obj->getDefaultAdminRole();
880  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
881  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
882 
883  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
884  {
885  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_admin');
886  }
887  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
888  $ilLog->write(__METHOD__.' : Finished copying of role crs_admin.');
889 
890  $tutor = $this->getDefaultTutorRole();
891  $new_tutor = $new_obj->getDefaultTutorRole();
892  if(!$tutor || !$new_tutor)
893  {
894  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_tutor');
895  }
896  $rbacadmin->copyRolePermissions($tutor,$source_rolf,$target_rolf,$new_tutor,true);
897  $ilLog->write(__METHOD__.' : Finished copying of role crs_tutor.');
898 
899  $member = $this->getDefaultMemberRole();
900  $new_member = $new_obj->getDefaultMemberRole();
901  if(!$member || !$new_member)
902  {
903  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_member');
904  }
905  $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
906  $ilLog->write(__METHOD__.' : Finished copying of role crs_member.');
907 
908  return true;
909  }
910 
911 
912  function validate()
913  {
914  $this->setMessage('');
915 
916  #if(($this->getSubscriptionLimitationType() != IL_CRS_SUBSCRIPTION_DEACTIVATED) and
917  # $this->getSubscriptionType() == )
918  #{
919  # $this->appendMessage($this->lng->txt('crs_select_registration_type'));
920  #}
921 
922  if(($this->getActivationType() == IL_CRS_ACTIVATION_LIMITED) and
923  $this->getActivationEnd() < $this->getActivationStart())
924  {
925  $this->appendMessage($this->lng->txt("activation_times_not_valid"));
926  }
928  $this->getSubscriptionStart() > $this->getSubscriptionEnd())
929  {
930  $this->appendMessage($this->lng->txt("subscription_times_not_valid"));
931  }
932  #if((!$this->getActivationUnlimitedStatus() and
933  # !$this->getSubscriptionUnlimitedStatus()) and
934  # ($this->getSubscriptionStart() > $this->getActivationEnd() or
935  # $this->getSubscriptionStart() < $this->getActivationStart() or
936  # $this->getSubscriptionEnd() > $this->getActivationEnd() or
937  # $this->getSubscriptionEnd() < $this->getActivationStart()))
938  #
939  #{
940  # $this->appendMessage($this->lng->txt("subscription_time_not_within_activation"));
941  #}
943  {
944  $this->appendMessage($this->lng->txt("crs_password_required"));
945  }
946  if($this->isSubscriptionMembershipLimited() and ($this->getSubscriptionMaxMembers() <= 0 or !is_numeric($this->getSubscriptionMaxMembers())))
947  {
948  $this->appendMessage($this->lng->txt("max_members_not_numeric"));
949  }
950  if(($this->getViewMode() == IL_CRS_VIEW_ARCHIVE) and
951  $this->getArchiveStart() > $this->getArchiveEnd())
952  {
953  $this->appendMessage($this->lng->txt("archive_times_not_valid"));
954  }
955  if(!$this->getTitle())
956  {
957  $this->appendMessage($this->lng->txt('err_check_input'));
958  }
959 
960 
961  return $this->getMessage() ? false : true;
962  }
963 
965  {
966  global $ilErr;
967  $error = false;
968  if($this->getContactEmail()) {
969  $emails = split(",",$this->getContactEmail());
970 
971  foreach ($emails as $email) {
972  $email = trim($email);
973  if (!(ilUtil::is_email($email) or ilObjUser::getUserIdByLogin($email)))
974  {
975  $ilErr->appendMessage($this->lng->txt('contact_email_not_valid')." '".$email."'");
976  $error = true;
977  }
978  }
979  }
980  return !$error;
981  }
982 
983  function hasContactData()
984  {
985  return strlen($this->getContactName()) or
986  strlen($this->getContactResponsibility()) or
987  strlen($this->getContactEmail()) or
988  strlen($this->getContactPhone()) or
989  strlen($this->getContactConsultation());
990  }
991 
992 
999  function delete()
1000  {
1001  global $ilAppEventHandler;
1002 
1003  // always call parent delete function first!!
1004  if (!parent::delete())
1005  {
1006  return false;
1007  }
1008 
1009  // delete meta data
1010  $this->deleteMetaData();
1011 
1012  // put here course specific stuff
1013 
1014  $this->__deleteSettings();
1015 
1016  $this->initCourseItemObject();
1017  $this->items_obj->deleteAllEntries();
1018 
1019  include_once('Modules/Course/classes/class.ilCourseParticipants.php');
1021 
1022  $this->initCourseArchiveObject();
1023  $this->archives_obj->deleteAll();
1024 
1025  include_once './Modules/Course/classes/class.ilCourseObjective.php';
1027 
1028  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
1030 
1031  include_once './Modules/Course/classes/class.ilCourseFile.php';
1033 
1034  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
1036 
1037  $ilAppEventHandler->raise('Modules/Course',
1038  'delete',
1039  array('object' => $this,
1040  'obj_id' => $this->getId(),
1041  'appointments' => $this->prepareAppointments('delete')));
1042 
1043 
1044  return true;
1045  }
1046 
1047 
1048 
1052  function update()
1053  {
1054  global $ilAppEventHandler,$ilLog;
1055 
1056  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1057  $sorting = new ilContainerSortingSettings($this->getId());
1058  $sorting->setSortMode($this->getOrderType());
1059  $sorting->update();
1060 
1061  $this->updateMetaData();
1062  $this->updateSettings();
1063  parent::update();
1064 
1065  $ilAppEventHandler->raise('Modules/Course',
1066  'update',
1067  array('object' => $this,
1068  'obj_id' => $this->getId(),
1069  'appointments' => $this->prepareAppointments('update')));
1070 
1071  }
1072 
1073  function updateSettings()
1074  {
1075  global $ilDB;
1076 
1077  // Due to a bug 3.5.alpha maybe no settings exist. => create default settings
1078 
1079  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1080  $res = $ilDB->query($query);
1081 
1082  if(!$res->numRows())
1083  {
1084  $this->__createDefaultSettings();
1085  }
1086 
1087  $query = "UPDATE crs_settings SET ".
1088  "syllabus = ".$ilDB->quote($this->getSyllabus() ,'text').", ".
1089  "contact_name = ".$ilDB->quote($this->getContactName() ,'text').", ".
1090  "contact_responsibility = ".$ilDB->quote($this->getContactResponsibility() ,'text').", ".
1091  "contact_phone = ".$ilDB->quote($this->getContactPhone() ,'text').", ".
1092  "contact_email = ".$ilDB->quote($this->getContactEmail() ,'text').", ".
1093  "contact_consultation = ".$ilDB->quote($this->getContactConsultation() ,'text').", ".
1094  "activation_type = ".$ilDB->quote($this->getActivationType() ,'integer').", ".
1095  "activation_start = ".$ilDB->quote($this->getActivationStart() ,'integer').", ".
1096  "activation_end = ".$ilDB->quote($this->getActivationEnd() ,'integer').", ".
1097  "sub_limitation_type = ".$ilDB->quote($this->getSubscriptionLimitationType() ,'integer').", ".
1098  "sub_start = ".$ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1099  "sub_end = ".$ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1100  "sub_type = ".$ilDB->quote($this->getSubscriptionType() ,'integer').", ".
1101  "sub_password = ".$ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1102  "sub_mem_limit = ".$ilDB->quote((int) $this->isSubscriptionMembershipLimited() ,'integer').", ".
1103  "sub_max_members = ".$ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1104  "sub_notify = ".$ilDB->quote($this->getSubscriptionNotify() ,'integer').", ".
1105  "view_mode = ".$ilDB->quote($this->getViewMode() ,'integer').", ".
1106  "archive_start = ".$ilDB->quote($this->getArchiveStart() ,'integer').", ".
1107  "archive_end = ".$ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1108  "archive_type = ".$ilDB->quote($this->getArchiveType() ,'integer').", ".
1109  "abo = ".$ilDB->quote($this->getAboStatus() ,'integer').", ".
1110  "waiting_list = ".$ilDB->quote($this->enabledWaitingList() ,'integer').", ".
1111  "important = ".$ilDB->quote($this->getImportantInformation() ,'text').", ".
1112  "show_members = ".$ilDB->quote($this->getShowMembers() ,'integer').", ".
1113  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
1114  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
1115  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
1116  "enable_course_map = ".$ilDB->quote((int) $this->getEnableCourseMap() ,'integer').", ".
1117  'session_limit = '.$ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1118  'session_prev = '.$ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1119  'session_next = '.$ilDB->quote($this->getNumberOfNextSessions(),'integer').', '.
1120  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1121  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1122  'auto_noti_disabled = '.$ilDB->quote( (int)$this->getAutoNotiDisabled(), 'integer').' '.
1123  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1124 
1125  $res = $ilDB->manipulate($query);
1126  }
1127 
1135  public function cloneSettings($new_obj)
1136  {
1137  $new_obj->setSyllabus($this->getSyllabus());
1138  $new_obj->setContactName($this->getContactName());
1139  $new_obj->setContactResponsibility($this->getContactResponsibility());
1140  $new_obj->setContactPhone($this->getContactPhone());
1141  $new_obj->setContactEmail($this->getContactEmail());
1142  $new_obj->setContactConsultation($this->getContactConsultation());
1143  $new_obj->setActivationType($this->getActivationType()); // #9914
1144  $new_obj->setActivationStart($this->getActivationStart());
1145  $new_obj->setActivationEnd($this->getActivationEnd());
1146  $new_obj->setSubscriptionLimitationType($this->getSubscriptionLimitationType());
1147  $new_obj->setSubscriptionStart($this->getSubscriptionStart());
1148  $new_obj->setSubscriptionEnd($this->getSubscriptionEnd());
1149  $new_obj->setSubscriptionType($this->getSubscriptionType());
1150  $new_obj->setSubscriptionPassword($this->getSubscriptionPassword());
1151  $new_obj->enableSubscriptionMembershipLimitation($this->isSubscriptionMembershipLimited());
1152  $new_obj->setSubscriptionMaxMembers($this->getSubscriptionMaxMembers());
1153  $new_obj->setSubscriptionNotify($this->getSubscriptionNotify());
1154  $new_obj->setViewMode($this->getViewMode());
1155  $new_obj->setOrderType($this->getOrderType());
1156  $new_obj->setArchiveStart($this->getArchiveStart());
1157  $new_obj->setArchiveEnd($this->getArchiveEnd());
1158  $new_obj->setArchiveType($this->getArchiveType());
1159  $new_obj->setAboStatus($this->getAboStatus());
1160  $new_obj->enableWaitingList($this->enabledWaitingList());
1161  $new_obj->setImportantInformation($this->getImportantInformation());
1162  $new_obj->setShowMembers($this->getShowMembers());
1163  $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
1164  $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
1165  $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
1166  $new_obj->setAutoNotiDisabled( $this->getAutoNotiDisabled() );
1167  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
1168  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1169  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
1170 
1171  $new_obj->update();
1172  }
1173 
1175  {
1176  global $ilDB;
1177 
1178  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1180 
1181  $query = "INSERT INTO crs_settings (obj_id,syllabus,contact_name,contact_responsibility,".
1182  "contact_phone,contact_email,contact_consultation,activation_type,activation_start,".
1183  "activation_end,sub_limitation_type,sub_start,sub_end,sub_type,sub_password,sub_mem_limit,".
1184  "sub_max_members,sub_notify,view_mode,archive_start,archive_end,archive_type,abo," .
1185  "latitude,longitude,location_zoom,enable_course_map,waiting_list,show_members, ".
1186  "session_limit,session_prev,session_next, reg_ac_enabled, reg_ac, auto_noti_disabled) ".
1187  "VALUES( ".
1188  $ilDB->quote($this->getId() ,'integer').", ".
1189  $ilDB->quote($this->getSyllabus() ,'text').", ".
1190  $ilDB->quote($this->getContactName() ,'text').", ".
1191  $ilDB->quote($this->getContactResponsibility() ,'text').", ".
1192  $ilDB->quote($this->getContactPhone() ,'text').", ".
1193  $ilDB->quote($this->getContactEmail() ,'text').", ".
1194  $ilDB->quote($this->getContactConsultation() ,'text').", ".
1195  $ilDB->quote(IL_CRS_ACTIVATION_OFFLINE ,'integer').", ".
1196  $ilDB->quote($this->getActivationStart() ,'integer').", ".
1197  $ilDB->quote($this->getActivationEnd() ,'integer').", ".
1198  $ilDB->quote(IL_CRS_SUBSCRIPTION_DEACTIVATED ,'integer').", ".
1199  $ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1200  $ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1201  $ilDB->quote(IL_CRS_SUBSCRIPTION_DIRECT ,'integer').", ".
1202  $ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1203  "0, ".
1204  $ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1205  "1, ".
1206  "0, ".
1207  $ilDB->quote($this->getArchiveStart() ,'integer').", ".
1208  $ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1209  $ilDB->quote(IL_CRS_ARCHIVE_NONE ,'integer').", ".
1210  $ilDB->quote($this->ABO_ENABLED ,'integer').", ".
1211  $ilDB->quote($this->getLatitude() ,'text').", ".
1212  $ilDB->quote($this->getLongitude() ,'text').", ".
1213  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
1214  $ilDB->quote($this->getEnableCourseMap() ,'integer').", ".
1215  #"objective_view = '0', ".
1216  "1, ".
1217  "1,".
1218  $ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1219  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1220  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1221  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1222  $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1223  $ilDB->quote((int)$this->getAutoNotiDisabled(),'integer').' '.
1224  ")";
1225 
1226  $res = $ilDB->manipulate($query);
1227  $this->__readSettings();
1228 
1229  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1230  $sorting = new ilContainerSortingSettings($this->getId());
1231  $sorting->setSortMode(ilContainer::SORT_MANUAL);
1232  $sorting->update();
1233  }
1234 
1235 
1236  function __readSettings()
1237  {
1238  global $ilDB;
1239 
1240  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1241 
1242  $res = $ilDB->query($query);
1243  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1244  {
1245  $this->setSyllabus($row->syllabus);
1246  $this->setContactName($row->contact_name);
1247  $this->setContactResponsibility($row->contact_responsibility);
1248  $this->setContactPhone($row->contact_phone);
1249  $this->setContactEmail($row->contact_email);
1250  $this->setContactConsultation($row->contact_consultation);
1251  $this->setActivationType($row->activation_type);
1252  $this->setActivationStart($row->activation_start);
1253  $this->setActivationEnd($row->activation_end);
1254  $this->setSubscriptionLimitationType($row->sub_limitation_type);
1255  $this->setSubscriptionStart($row->sub_start);
1256  $this->setSubscriptionEnd($row->sub_end);
1257  $this->setSubscriptionType($row->sub_type);
1258  $this->setSubscriptionPassword($row->sub_password);
1259  $this->enableSubscriptionMembershipLimitation($row->sub_mem_limit);
1260  $this->setSubscriptionMaxMembers($row->sub_max_members);
1261  $this->setSubscriptionNotify($row->sub_notify);
1262  $this->setViewMode($row->view_mode);
1263  $this->setArchiveStart($row->archive_start);
1264  $this->setArchiveEnd($row->archive_end);
1265  $this->setArchiveType($row->archive_type);
1266  $this->setAboStatus($row->abo);
1267  $this->enableWaitingList($row->waiting_list);
1268  $this->setImportantInformation($row->important);
1269  $this->setShowMembers($row->show_members);
1270  $this->setLatitude($row->latitude);
1271  $this->setLongitude($row->longitude);
1272  $this->setLocationZoom($row->location_zoom);
1273  $this->setEnableCourseMap($row->enable_course_map);
1274  $this->enableSessionLimit($row->session_limit);
1275  $this->setNumberOfPreviousSessions($row->session_prev);
1276  $this->setNumberOfNextSessions($row->session_next);
1277  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
1278  $this->setRegistrationAccessCode($row->reg_ac);
1279  $this->setAutoNotiDisabled($row->auto_noti_disabled == 1 ? true : false);
1280  }
1281 
1282  return true;
1283  }
1284 
1285  function initWaitingList()
1286  {
1287  include_once "./Modules/Course/classes/class.ilCourseWaitingList.php";
1288 
1289  if(!is_object($this->waiting_list_obj))
1290  {
1291  $this->waiting_list_obj = new ilCourseWaitingList($this->getId());
1292  }
1293  return true;
1294  }
1295 
1296 
1302  protected function initCourseMemberObject()
1303  {
1304  global $ilUser;
1305 
1306  include_once "./Modules/Course/classes/class.ilCourseParticipant.php";
1307  $this->member_obj = ilCourseParticipant::_getInstanceByObjId($this->getId(),$ilUser->getId());
1308  return true;
1309  }
1310 
1316  protected function initCourseMembersObject()
1317  {
1318  global $ilUser;
1319 
1320  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1321  $this->members_obj = ilCourseParticipants::_getInstanceByObjId($this->getId());
1322  return true;
1323  }
1324 
1329  public function getMemberObject()
1330  {
1331  if(!$this->member_obj instanceof ilCourseParticipant)
1332  {
1333  $this->initCourseMemberObject();
1334  }
1335  return $this->member_obj;
1336  }
1337 
1342  public function getMembersObject()
1343  {
1344  if(!$this->members_obj instanceof ilCourseParticipants)
1345  {
1346  $this->initCourseMembersObject();
1347  }
1348  return $this->members_obj;
1349  }
1350 
1351  function initCourseItemObject($a_child_id = 0)
1352  {
1353  include_once "./Modules/Course/classes/class.ilCourseItems.php";
1354 
1355  if(!is_object($this->items_obj))
1356  {
1357  $this->items_obj = new ilCourseItems($this->getRefId(),$a_child_id);
1358  }
1359  return true;
1360  }
1361 
1369  public function getCourseItemObject()
1370  {
1371  if(is_object($this->items_obj))
1372  {
1373  return $this->items_obj;
1374  }
1375  $this->initCourseItemObject();
1376  return $this->items_obj;
1377  }
1378 
1379 
1381  {
1382  include_once "./Modules/Course/classes/class.ilCourseArchives.php";
1383 
1384  if(!is_object($this->archives_obj))
1385  {
1386  $this->archives_obj =& new ilCourseArchives($this);
1387  }
1388  return true;
1389  }
1390 
1391 
1392 
1393  // RBAC METHODS
1394  function initDefaultRoles()
1395  {
1396  global $rbacadmin,$rbacreview,$ilDB;
1397 
1398  $rolf_obj = $this->createRoleFolder();
1399 
1400  // CREATE ADMIN ROLE
1401  $role_obj = $rolf_obj->createRole("il_crs_admin_".$this->getRefId(),"Admin of course obj_no.".$this->getId());
1402  $admin_id = $role_obj->getId();
1403 
1404  // SET PERMISSION TEMPLATE OF NEW LOCAL ADMIN ROLE
1405  $query = "SELECT obj_id FROM object_data ".
1406  " WHERE type='rolt' AND title='il_crs_admin'";
1407 
1408  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1409  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1410 
1411  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1412  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1413  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1414 
1415  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1416  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1417  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1418 
1419  // CREATE TUTOR ROLE
1420  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1421  $role_obj = $rolf_obj->createRole("il_crs_tutor_".$this->getRefId(),"Tutors of course obj_no.".$this->getId());
1422  $member_id = $role_obj->getId();
1423 
1424  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1425  $query = "SELECT obj_id FROM object_data ".
1426  " WHERE type='rolt' AND title='il_crs_tutor'";
1427  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1428  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1429 
1430  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1431  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1432  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1433 
1434  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1435  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1436  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1437 
1438  // CREATE MEMBER ROLE
1439  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1440  $role_obj = $rolf_obj->createRole("il_crs_member_".$this->getRefId(),"Member of course obj_no.".$this->getId());
1441  $member_id = $role_obj->getId();
1442 
1443  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1444  $query = "SELECT obj_id FROM object_data ".
1445  " WHERE type='rolt' AND title='il_crs_member'";
1446  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1447  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1448 
1449  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1450  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1451  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1452 
1453  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1454  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1455  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1456 
1457  unset($role_obj);
1458  unset($rolf_obj);
1459 
1460  // Break inheritance, create local roles and initialize permission
1461  // settings depending on course status.
1462  $this->__setCourseStatus();
1463 
1464  return true;
1465  }
1466 
1484  {
1485  global $rbacadmin, $rbacreview, $rbacsystem;
1486 
1487  //get Rolefolder of course
1488  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1489 
1490  //define all relevant roles for which rights are needed to be changed
1491  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1492  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultCourseRoles());
1493 
1494  $template_id = $this->__getCrsNonMemberTemplateId();
1495 
1496  //get defined operations from template
1497  if (is_null($template_id))
1498  {
1499  $template_ops = array();
1500  } else {
1501  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'crs', ROLE_FOLDER_ID);
1502  }
1503 
1504  foreach ($arr_relevantParentRoleIds as $parentRole)
1505  {
1506  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1507  {
1508  continue;
1509  }
1510 
1511  $granted_permissions = array();
1512 
1513  // Delete the linked role for the parent role
1514  // (just in case if it already exists).
1515  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1516 
1517  // Grant permissions on the course object for
1518  // the parent role. In the foreach loop we
1519  // compute the intersection of the role
1520  // template il_crs_non_member and the
1521  // permission template of the parent role.
1522  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1523  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1524  foreach ($template_ops as $template_op)
1525  {
1526  if (in_array($template_op,$current_ops))
1527  {
1528  array_push($granted_permissions,$template_op);
1529  }
1530  }
1531  if (!empty($granted_permissions))
1532  {
1533  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1534  }
1535 
1536  // Create a linked role for the parent role and
1537  // initialize it with the intersection of
1538  // il_crs_non_member and the permission
1539  // template of the parent role
1540  if (! is_null($template_id))
1541  {
1542  $rbacadmin->copyRolePermissionIntersection(
1543  $template_id, ROLE_FOLDER_ID,
1544  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1545  $rolf_data["child"], $parentRole
1546  );
1547  }
1548  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1549  }//END foreach
1550  }
1551 
1559  {
1560  global $ilDB;
1561 
1562  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
1563  $res = $this->ilias->db->query($q);
1564  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1565 
1566  return $row["obj_id"];
1567  }
1568 
1575  public function getLocalCourseRoles($a_translate = false)
1576  {
1577  global $rbacadmin,$rbacreview;
1578 
1579  if (empty($this->local_roles))
1580  {
1581  $this->local_roles = array();
1582  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1583  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1584 
1585  foreach ($role_arr as $role_id)
1586  {
1587  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1588  {
1589  $role_Obj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
1590 
1591  if ($a_translate)
1592  {
1593  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1594  }
1595  else
1596  {
1597  $role_name = $role_Obj->getTitle();
1598  }
1599  $this->local_roles[$role_name] = $role_Obj->getId();
1600  }
1601  }
1602  }
1603 
1604  return $this->local_roles;
1605  }
1606 
1607 
1608 
1618  public function getDefaultCourseRoles($a_crs_id = "")
1619  {
1620  global $rbacadmin, $rbacreview;
1621 
1622  if (strlen($a_crs_id) > 0)
1623  {
1624  $crs_id = $a_crs_id;
1625  }
1626  else
1627  {
1628  $crs_id = $this->getRefId();
1629  }
1630 
1631  $rolf = $rbacreview->getRoleFolderOfObject($crs_id);
1632  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1633 
1634  foreach ($role_arr as $role_id)
1635  {
1636  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1637 
1638  $crs_Member ="il_crs_member_".$crs_id;
1639  $crs_Admin ="il_crs_admin_".$crs_id;
1640  $crs_Tutor ="il_crs_tutor_".$crs_id;
1641 
1642  if (strcmp($role_Obj->getTitle(), $crs_Member) == 0 )
1643  {
1644  $arr_crsDefaultRoles["crs_member_role"] = $role_Obj->getId();
1645  }
1646 
1647  if (strcmp($role_Obj->getTitle(), $crs_Admin) == 0)
1648  {
1649  $arr_crsDefaultRoles["crs_admin_role"] = $role_Obj->getId();
1650  }
1651 
1652  if (strcmp($role_Obj->getTitle(), $crs_Tutor) == 0)
1653  {
1654  $arr_crsDefaultRoles["crs_tutor_role"] = $role_Obj->getId();
1655  }
1656  }
1657 
1658  return $arr_crsDefaultRoles;
1659  }
1660 
1661  function __getLocalRoles()
1662  {
1663  global $rbacreview;
1664 
1665  // GET role_objects of predefined roles
1666 
1667  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1668 
1669  return $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1670  }
1671 
1672  function __deleteSettings()
1673  {
1674  global $ilDB;
1675 
1676  $query = "DELETE FROM crs_settings ".
1677  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1678  $res = $ilDB->manipulate($query);
1679 
1680  return true;
1681  }
1682 
1683 
1685  {
1686  $local_roles = $this->__getLocalRoles();
1687 
1688  foreach($local_roles as $role_id)
1689  {
1690  $title = ilObject::_lookupTitle($role_id);
1691  if(substr($title,0,8) == 'il_crs_m')
1692  {
1693  return $role_id;
1694  }
1695  }
1696  return 0;
1697  }
1699  {
1700  $local_roles = $this->__getLocalRoles();
1701 
1702  foreach($local_roles as $role_id)
1703  {
1704  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1705  {
1706  if(!strcmp($tmp_role->getTitle(),"il_crs_tutor_".$this->getRefId()))
1707  {
1708  return $role_id;
1709  }
1710  }
1711  }
1712  return false;
1713  }
1715  {
1716  $local_roles = $this->__getLocalRoles();
1717 
1718  foreach($local_roles as $role_id)
1719  {
1720  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1721  {
1722  if(!strcmp($tmp_role->getTitle(),"il_crs_admin_".$this->getRefId()))
1723  {
1724  return $role_id;
1725  }
1726  }
1727  }
1728  return false;
1729  }
1730 
1731  // static method for condition handler
1732  function _checkCondition($a_obj_id,$a_operator,$a_value,$a_usr_id = 0)
1733  {
1734  global $ilUser;
1735 
1736  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
1737 
1738  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1739 
1740  switch($a_operator)
1741  {
1742  case 'passed':
1743  return ilCourseParticipants::_hasPassed($a_obj_id,$a_usr_id);
1744 
1745  default:
1746  return true;
1747  }
1748  }
1749 
1750  function _deleteUser($a_usr_id)
1751  {
1752  // Delete all user related data
1753  // delete lm_history
1754  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
1755  ilCourseLMHistory::_deleteUser($a_usr_id);
1756 
1757  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
1759 
1760  // Course objectives
1761  include_once './Modules/Course/classes/class.ilCourseObjectiveResult.php';
1763  }
1764 
1774  public function handleECSSettings($a_server_id,$a_export,$a_owner,$a_mids)
1775  {
1776  try
1777  {
1778  include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
1779 
1780  $writer = new ilECSContentWriter($this,$a_server_id);
1781  $writer->setExportable($a_export);
1782  $writer->setOwnerId($a_owner);
1783  $writer->setParticipantIds((array) $a_mids);
1784  $writer->refresh();
1785  }
1786  catch(ilECSConnectorException $exc)
1787  {
1788  throw $exc;
1789  }
1790  catch(ilECSContentWriterException $exc)
1791  {
1792  throw $exc;
1793  }
1794  }
1795 
1802  public function MDUpdateListener($a_element)
1803  {
1804  global $ilLog;
1805 
1806  parent::MDUpdateListener($a_element);
1807 
1808  switch($a_element)
1809  {
1810  case 'General':
1811  $this->updateECSContent();
1812  break;
1813  default:
1814  return true;
1815  }
1816  }
1817 
1825  public function updateECSContent()
1826  {
1827  global $ilLog;
1828 
1829 
1830  include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
1831 
1832  $export_servers = ilECSExport::getExportServerIds($this->getId());
1833  foreach($export_servers as $server_id)
1834  {
1835  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
1836  if(ilECSSetting::getInstanceByServerId($server_id)->isEnabled())
1837  {
1838  try {
1839  // Update ECS EContent
1840  include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
1841  $writer = new ilECSContentWriter($this,$server_id);
1842  $writer->refreshSettings();
1843  }
1844  catch(ilException $exc)
1845  {
1846  $ilLog->write(__METHOD__.': Cannot save ECS settings. '.$exc->getMessage());
1847  return false;
1848  }
1849  }
1850  }
1851  }
1852 
1857  function addAdditionalSubItemInformation(&$a_item_data)
1858  {
1859  global $ilBench;
1860 
1861  $ilBench->start("Course", "initCourseItemObject");
1862  $this->initCourseItemObject();
1863  $ilBench->stop("Course", "initCourseItemObject");
1864 
1865  $ilBench->start("Course", "addAdditionalSubItemInformation");
1866  $this->items_obj->addAdditionalSubItemInformation($a_item_data);
1867  $ilBench->stop("Course", "addAdditionalSubItemInformation");
1868  }
1869 
1877  protected function prepareAppointments($a_mode = 'create')
1878  {
1879  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1880  include_once('./Services/Calendar/classes/class.ilDateTime.php');
1881 
1882  switch($a_mode)
1883  {
1884  case 'create':
1885  case 'update':
1886  if(!$this->getActivationUnlimitedStatus() and !$this->getOfflineStatus())
1887  {
1888  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_START);
1889  $app->setTitle($this->getTitle());
1890  $app->setSubtitle('crs_cal_activation_start');
1891  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1892  $app->setDescription($this->getLongDescription());
1893  $app->setStart(new ilDateTime($this->getActivationStart(),IL_CAL_UNIX));
1894  $apps[] = $app;
1895 
1896  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_END);
1897  $app->setTitle($this->getTitle());
1898  $app->setSubtitle('crs_cal_activation_end');
1899  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1900  $app->setDescription($this->getLongDescription());
1901  $app->setStart(new ilDateTime($this->getActivationEnd(),IL_CAL_UNIX));
1902  $apps[] = $app;
1903  }
1905  {
1906  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1907  $app->setTitle($this->getTitle());
1908  $app->setSubtitle('crs_cal_reg_start');
1909  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1910  $app->setDescription($this->getLongDescription());
1911  $app->setStart(new ilDateTime($this->getSubscriptionStart(),IL_CAL_UNIX));
1912  $apps[] = $app;
1913 
1914  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1915  $app->setTitle($this->getTitle());
1916  $app->setSubtitle('crs_cal_reg_end');
1917  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1918  $app->setDescription($this->getLongDescription());
1919  $app->setStart(new ilDateTime($this->getSubscriptionEnd(),IL_CAL_UNIX));
1920  $apps[] = $app;
1921  }
1922 
1923  return $apps ? $apps : array();
1924 
1925  case 'delete':
1926  // Nothing to do: The category and all assigned appointments will be deleted.
1927  return array();
1928  }
1929  }
1930 
1931  ###### Interface ilMembershipRegistrationCodes
1932 
1936  public static function lookupObjectsByCode($a_code)
1937  {
1938  global $ilDB;
1939 
1940  $query = "SELECT obj_id FROM crs_settings ".
1941  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1942  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1943  $res = $ilDB->query($query);
1944 
1945  $obj_ids = array();
1946  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1947  {
1948  $obj_ids[] = $row->obj_id;
1949  }
1950  return $obj_ids;
1951  }
1952 
1959  public function register($a_user_id,$a_role = ilCourseConstants::CRS_MEMBER, $a_force_registration = false)
1960  {
1961  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1962  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1964 
1965  if($part->isAssigned($a_user_id))
1966  {
1967  return true;
1968  }
1969 
1970  if(!$a_force_registration)
1971  {
1972  // Availability
1973  if(!self::_registrationEnabled($this->getId()))
1974  {
1975  $this->lng->loadLanguageModule('crs');
1976  throw new ilMembershipRegistrationException($this->lng->txt('crs_info_reg_deactivated'),$this->getRefId());
1977  }
1978  // Max members
1979  if($this->isSubscriptionMembershipLimited())
1980  {
1981  $free = max(0,$this->getSubscriptionMaxMembers() - $part->getCountMembers());
1982  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
1983  $waiting_list = new ilCourseWaitingList($this->getId());
1984  if($this->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
1985  {
1986  throw new ilMembershipRegistrationException('',$this->getRefId());
1987  }
1988  }
1989  }
1990 
1991  $part->add($a_user_id,$a_role);
1992  $part->sendNotification($part->NOTIFY_ACCEPT_USER, $a_user_id);
1993 
1994  include_once './Modules/Forum/classes/class.ilForumNotification.php';
1996 
1997  return true;
1998  }
1999 
2006  public function getAutoNotiDisabled()
2007  {
2009  }
2010 
2011 
2018  public function setAutoNotiDisabled($value)
2019  {
2020  $this->auto_noti_disabled = $value;
2021  }
2022 } //END class.ilObjCourse
2023 ?>