ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCourse.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once "./Services/Container/classes/class.ilContainer.php";
25 include_once './Modules/Course/classes/class.ilCourseConstants.php';
26 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  // No sessions
467  if(!is_array($this->items['sess']) or !$this->items['sess'])
468  {
469  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
470  }
471  // No session limit
472  if(!$this->isSessionLimitEnabled() or $a_admin_panel_enabled)
473  {
474  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
475  }
476 
477  if($a_include_side_block)
478  {
479  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
480  }
481 
482  // @todo move to gui class
483  if(isset($_GET['crs_prev_sess']))
484  {
485  $ilUser->writePref('crs_sess_show_prev_'.$this->getId(), (string) (int) $_GET['crs_prev_sess']);
486  }
487  if(isset($_GET['crs_next_sess']))
488  {
489  $ilUser->writePref('crs_sess_show_next_'.$this->getId(), (string) (int) $_GET['crs_next_sess']);
490  }
491 
492  $sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
493  $today = new ilDate(date('Ymd',time()),IL_CAL_DATE);
494  $previous = $current = $next = array();
495  foreach($sessions as $key => $item)
496  {
497  $start = new ilDateTime($item['start'],IL_CAL_UNIX);
498  $end = new ilDateTime($item['end'],IL_CAL_UNIX);
499 
500  if(ilDateTime::_within($today, $start, $end, IL_CAL_DAY))
501  {
502  $current[] = $item;
503  }
504  elseif(ilDateTime::_before($start, $today, IL_CAL_DAY))
505  {
506  $previous[] = $item;
507  }
508  elseif(ilDateTime::_after($start, $today, IL_CAL_DAY))
509  {
510  $next[] = $item;
511  }
512  }
513  $num_previous_remove = max(
514  count($previous) - $this->getNumberOfPreviousSessions(),
515  0
516  );
517  while($num_previous_remove--)
518  {
519  if(!$ilUser->getPref('crs_sess_show_prev_'.$this->getId()))
520  {
521  array_shift($previous);
522  }
523  $this->items['sess_link']['prev']['value'] = 1;
524  }
525 
526  $num_next_remove = max(
527  count($next) - $this->getNumberOfNextSessions(),
528  0
529  );
530  while($num_next_remove--)
531  {
532  if(!$ilUser->getPref('crs_sess_show_next_'.$this->getId()))
533  {
534  array_pop($next);
535  }
536  // @fixme
537  $this->items['sess_link']['next']['value'] = 1;
538  }
539 
540  $sessions = array_merge($previous,$current,$next);
541  $this->items['sess'] = $sessions;
542 
543  // #15389 - see ilContainer::getSubItems()
544  include_once('Services/Container/classes/class.ilContainerSorting.php');
545  $sort = ilContainerSorting::_getInstance($this->getId());
546  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $sort->sortItems($this->items);
547 
548  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
549  }
550 
552  {
553  return true;
554  return $this->subscription_notify ? true : false;
555  }
556  function setSubscriptionNotify($a_value)
557  {
558  $this->subscription_notify = $a_value ? true : false;
559  }
560 
561  function setViewMode($a_mode)
562  {
563  $this->view_mode = $a_mode;
564  }
565  function getViewMode()
566  {
567  return $this->view_mode;
568  }
569 
570  function _lookupViewMode($a_id)
571  {
572  global $ilDB;
573 
574  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
575  $res = $ilDB->query($query);
576  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
577  {
578  return $row->view_mode;
579  }
580  return false;
581  }
582 
583  function _lookupAboStatus($a_id)
584  {
585  global $ilDB;
586 
587  $query = "SELECT abo FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
588  $res = $ilDB->query($query);
589  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
590  {
591  return $row->abo;
592  }
593  return false;
594  }
595 
596  function getArchiveStart()
597  {
598  return $this->archive_start ? $this->archive_start : time();
599  }
600  function setArchiveStart($a_value)
601  {
602  $this->archive_start = $a_value;
603  }
604  function getArchiveEnd()
605  {
606  return $this->archive_end ? $this->archive_end : mktime(0,0,0,12,12,date("Y",time())+2);
607  }
608  function setArchiveEnd($a_value)
609  {
610  $this->archive_end = $a_value;
611  }
612  function getArchiveType()
613  {
614  return $this->archive_type ? IL_CRS_ARCHIVE_DOWNLOAD : IL_CRS_ARCHIVE_NONE;
615  }
616  function setArchiveType($a_value)
617  {
618  $this->archive_type = $a_value;
619  }
620  function setAboStatus($a_status)
621  {
622  $this->abo = $a_status;
623  }
624  function getAboStatus()
625  {
626  return $this->abo;
627  }
628  function setShowMembers($a_status)
629  {
630  $this->show_members = $a_status;
631  }
632  function getShowMembers()
633  {
634  return $this->show_members;
635  }
636 
642  public function setMailToMembersType($a_type)
643  {
644  $this->mail_members = $a_type;
645  }
646 
651  public function getMailToMembersType()
652  {
653  return $this->mail_members;
654  }
655 
656  function getMessage()
657  {
658  return $this->message;
659  }
660  function setMessage($a_message)
661  {
662  $this->message = $a_message;
663  }
664  function appendMessage($a_message)
665  {
666  if($this->getMessage())
667  {
668  $this->message .= "<br /> ";
669  }
670  $this->message .= $a_message;
671  }
672 
673  function isActivated($a_check_archive = false)
674  {
675  if($a_check_archive)
676  {
677  if($this->isArchived())
678  {
679  return true;
680  }
681  }
682  if($this->getOfflineStatus())
683  {
684  return false;
685  }
686  if($this->getActivationUnlimitedStatus())
687  {
688  return true;
689  }
690  if(time() < $this->getActivationStart() or
691  time() > $this->getActivationEnd())
692  {
693  return false;
694  }
695  return true;
696  }
697 
704  function _isActivated($a_obj_id)
705  {
706  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
707  return ilObjCourseAccess::_isActivated($a_obj_id);
708  }
709 
716  function _registrationEnabled($a_obj_id)
717  {
718  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
719  return ilObjCourseAccess::_registrationEnabled($a_obj_id);
720  }
721 
722  function isArchived()
723  {
724  if($this->getViewMode() != IL_CRS_VIEW_ARCHIVE)
725  {
726  return false;
727  }
728  if(time() < $this->getArchiveStart() or time() > $this->getArchiveEnd())
729  {
730  return false;
731  }
732  return true;
733  }
734 
735  function allowAbo()
736  {
737  return $this->ABO == $this->ABO_ENABLED;
738  }
739 
740  function read($a_force_db = false)
741  {
742  parent::read($a_force_db);
743 
744  $this->__readSettings();
745  }
746  function create($a_upload = false)
747  {
748  global $ilAppEventHandler;
749 
750  parent::create($a_upload);
751 
752  if(!$a_upload)
753  {
754  $this->createMetaData();
755  }
756  $this->__createDefaultSettings();
757 
758  $ilAppEventHandler->raise('Modules/Course',
759  'create',
760  array('object' => $this,
761  'obj_id' => $this->getId(),
762  'appointments' => $this->prepareAppointments('create')));
763 
764  }
765 
771  function setLatitude($a_latitude)
772  {
773  $this->latitude = $a_latitude;
774  }
775 
781  function getLatitude()
782  {
783  return $this->latitude;
784  }
785 
791  function setLongitude($a_longitude)
792  {
793  $this->longitude = $a_longitude;
794  }
795 
801  function getLongitude()
802  {
803  return $this->longitude;
804  }
805 
811  function setLocationZoom($a_locationzoom)
812  {
813  $this->locationzoom = $a_locationzoom;
814  }
815 
821  function getLocationZoom()
822  {
823  return $this->locationzoom;
824  }
825 
831  function setEnableCourseMap($a_enablemap)
832  {
833  $this->enablemap = $a_enablemap;
834  }
835 
842  {
843  return $this->enablemap;
844  }
845 
854  public function cloneObject($a_target_id,$a_copy_id = 0)
855  {
856  global $ilDB,$ilUser;
857 
858  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
859 
860  $this->cloneAutoGeneratedRoles($new_obj);
861  $this->cloneMetaData($new_obj);
862 
863  // Assign admin
864  $new_obj->getMemberObject()->add($ilUser->getId(),IL_CRS_ADMIN);
865 
866  // #14596
867  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
868  if($cwo->isRootNode($this->getRefId()))
869  {
870  $this->setOfflineStatus(true);
871  }
872 
873  // Copy settings
874  $this->cloneSettings($new_obj);
875 
876  // Course Defined Fields
877  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
878  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
879 
880  // Clone course files
881  include_once('Modules/Course/classes/class.ilCourseFile.php');
882  ilCourseFile::_cloneFiles($this->getId(),$new_obj->getId());
883 
884  // Copy learning progress settings
885  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
886  $obj_settings = new ilLPObjSettings($this->getId());
887  $obj_settings->cloneSettings($new_obj->getId());
888  unset($obj_settings);
889 
890  // clone icons
891  global $ilLog;
892  $ilLog->write(__METHOD__.': '.$this->getBigIconPath().' '.$this->getSmallIconPath());
893  $new_obj->saveIcons($this->getBigIconPath(),
894  $this->getSmallIconPath(),
895  $this->getTinyIconPath());
896 
897  // clone certificate (#11085)
898  include_once "./Services/Certificate/classes/class.ilCertificate.php";
899  include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
900  $cert = new ilCertificate(new ilCourseCertificateAdapter($this));
901  $newcert = new ilCertificate(new ilCourseCertificateAdapter($new_obj));
902  $cert->cloneCertificate($newcert);
903 
904  return $new_obj;
905  }
906 
915  public function cloneDependencies($a_target_id,$a_copy_id)
916  {
917  parent::cloneDependencies($a_target_id,$a_copy_id);
918 
919  // Clone course start objects
920  include_once('Modules/Course/classes/class.ilCourseStart.php');
921  $start = new ilCourseStart($this->getRefId(),$this->getId());
922  $start->cloneDependencies($a_target_id,$a_copy_id);
923 
924  // Clone course item settings
925  include_once('Services/Object/classes/class.ilObjectActivation.php');
926  ilObjectActivation::cloneDependencies($this->getRefId(),$a_target_id,$a_copy_id);
927 
928  // Clone course learning objectives
929  include_once('Modules/Course/classes/class.ilCourseObjective.php');
930  $crs_objective = new ilCourseObjective($this);
931  $crs_objective->ilClone($a_target_id,$a_copy_id);
932 
933  return true;
934  }
935 
943  public function cloneAutoGeneratedRoles($new_obj)
944  {
945  global $ilLog,$rbacadmin,$rbacreview;
946 
947  $admin = $this->getDefaultAdminRole();
948  $new_admin = $new_obj->getDefaultAdminRole();
949  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
950  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
951 
952  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
953  {
954  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_admin');
955  }
956  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
957  $ilLog->write(__METHOD__.' : Finished copying of role crs_admin.');
958 
959  $tutor = $this->getDefaultTutorRole();
960  $new_tutor = $new_obj->getDefaultTutorRole();
961  if(!$tutor || !$new_tutor)
962  {
963  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_tutor');
964  }
965  $rbacadmin->copyRolePermissions($tutor,$source_rolf,$target_rolf,$new_tutor,true);
966  $ilLog->write(__METHOD__.' : Finished copying of role crs_tutor.');
967 
968  $member = $this->getDefaultMemberRole();
969  $new_member = $new_obj->getDefaultMemberRole();
970  if(!$member || !$new_member)
971  {
972  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_member');
973  }
974  $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
975  $ilLog->write(__METHOD__.' : Finished copying of role crs_member.');
976 
977  return true;
978  }
979 
980 
981  function validate()
982  {
983  $this->setMessage('');
984 
985  #if(($this->getSubscriptionLimitationType() != IL_CRS_SUBSCRIPTION_DEACTIVATED) and
986  # $this->getSubscriptionType() == )
987  #{
988  # $this->appendMessage($this->lng->txt('crs_select_registration_type'));
989  #}
990 
991  if(($this->getActivationType() == IL_CRS_ACTIVATION_LIMITED) and
992  $this->getActivationEnd() < $this->getActivationStart())
993  {
994  $this->appendMessage($this->lng->txt("activation_times_not_valid"));
995  }
997  $this->getSubscriptionStart() > $this->getSubscriptionEnd())
998  {
999  $this->appendMessage($this->lng->txt("subscription_times_not_valid"));
1000  }
1001  #if((!$this->getActivationUnlimitedStatus() and
1002  # !$this->getSubscriptionUnlimitedStatus()) and
1003  # ($this->getSubscriptionStart() > $this->getActivationEnd() or
1004  # $this->getSubscriptionStart() < $this->getActivationStart() or
1005  # $this->getSubscriptionEnd() > $this->getActivationEnd() or
1006  # $this->getSubscriptionEnd() < $this->getActivationStart()))
1007  #
1008  #{
1009  # $this->appendMessage($this->lng->txt("subscription_time_not_within_activation"));
1010  #}
1012  {
1013  $this->appendMessage($this->lng->txt("crs_password_required"));
1014  }
1015  if($this->isSubscriptionMembershipLimited() and ($this->getSubscriptionMaxMembers() <= 0 or !is_numeric($this->getSubscriptionMaxMembers())))
1016  {
1017  $this->appendMessage($this->lng->txt("max_members_not_numeric"));
1018  }
1019  if(($this->getViewMode() == IL_CRS_VIEW_ARCHIVE) and
1020  $this->getArchiveStart() > $this->getArchiveEnd())
1021  {
1022  $this->appendMessage($this->lng->txt("archive_times_not_valid"));
1023  }
1024  if(!$this->getTitle() || !$this->getStatusDetermination())
1025  {
1026  $this->appendMessage($this->lng->txt('err_check_input'));
1027  }
1028 
1029 
1030  return $this->getMessage() ? false : true;
1031  }
1032 
1034  {
1035  global $ilErr;
1036  $error = false;
1037  if($this->getContactEmail()) {
1038  $emails = split(",",$this->getContactEmail());
1039 
1040  foreach ($emails as $email) {
1041  $email = trim($email);
1042  if (!(ilUtil::is_email($email) or ilObjUser::getUserIdByLogin($email)))
1043  {
1044  $ilErr->appendMessage($this->lng->txt('contact_email_not_valid')." '".$email."'");
1045  $error = true;
1046  }
1047  }
1048  }
1049  return !$error;
1050  }
1051 
1052  function hasContactData()
1053  {
1054  return strlen($this->getContactName()) or
1055  strlen($this->getContactResponsibility()) or
1056  strlen($this->getContactEmail()) or
1057  strlen($this->getContactPhone()) or
1058  strlen($this->getContactConsultation());
1059  }
1060 
1061 
1068  function delete()
1069  {
1070  global $ilAppEventHandler;
1071 
1072  // always call parent delete function first!!
1073  if (!parent::delete())
1074  {
1075  return false;
1076  }
1077 
1078  // delete meta data
1079  $this->deleteMetaData();
1080 
1081  // put here course specific stuff
1082 
1083  $this->__deleteSettings();
1084 
1085  include_once('Modules/Course/classes/class.ilCourseParticipants.php');
1087 
1088  $this->initCourseArchiveObject();
1089  $this->archives_obj->deleteAll();
1090 
1091  include_once './Modules/Course/classes/class.ilCourseObjective.php';
1093 
1094  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
1096 
1097  include_once './Modules/Course/classes/class.ilCourseFile.php';
1099 
1100  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
1102 
1103  $ilAppEventHandler->raise('Modules/Course',
1104  'delete',
1105  array('object' => $this,
1106  'obj_id' => $this->getId(),
1107  'appointments' => $this->prepareAppointments('delete')));
1108 
1109 
1110  return true;
1111  }
1112 
1113 
1114 
1118  function update()
1119  {
1120  global $ilAppEventHandler,$ilLog;
1121 
1122  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1123  $sorting = new ilContainerSortingSettings($this->getId());
1124  $sorting->setSortMode($this->getOrderType());
1125  $sorting->update();
1126 
1127  $this->updateMetaData();
1128  $this->updateSettings();
1129  parent::update();
1130 
1131  $ilAppEventHandler->raise('Modules/Course',
1132  'update',
1133  array('object' => $this,
1134  'obj_id' => $this->getId(),
1135  'appointments' => $this->prepareAppointments('update')));
1136 
1137  }
1138 
1139  function updateSettings()
1140  {
1141  global $ilDB;
1142 
1143  // Due to a bug 3.5.alpha maybe no settings exist. => create default settings
1144 
1145  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1146  $res = $ilDB->query($query);
1147 
1148  if(!$res->numRows())
1149  {
1150  $this->__createDefaultSettings();
1151  }
1152 
1153  $query = "UPDATE crs_settings SET ".
1154  "syllabus = ".$ilDB->quote($this->getSyllabus() ,'text').", ".
1155  "contact_name = ".$ilDB->quote($this->getContactName() ,'text').", ".
1156  "contact_responsibility = ".$ilDB->quote($this->getContactResponsibility() ,'text').", ".
1157  "contact_phone = ".$ilDB->quote($this->getContactPhone() ,'text').", ".
1158  "contact_email = ".$ilDB->quote($this->getContactEmail() ,'text').", ".
1159  "contact_consultation = ".$ilDB->quote($this->getContactConsultation() ,'text').", ".
1160  "activation_type = ".$ilDB->quote(!$this->getOfflineStatus() ,'integer').", ".
1161  "sub_limitation_type = ".$ilDB->quote($this->getSubscriptionLimitationType() ,'integer').", ".
1162  "sub_start = ".$ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1163  "sub_end = ".$ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1164  "sub_type = ".$ilDB->quote($this->getSubscriptionType() ,'integer').", ".
1165  "sub_password = ".$ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1166  "sub_mem_limit = ".$ilDB->quote((int) $this->isSubscriptionMembershipLimited() ,'integer').", ".
1167  "sub_max_members = ".$ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1168  "sub_notify = ".$ilDB->quote($this->getSubscriptionNotify() ,'integer').", ".
1169  "view_mode = ".$ilDB->quote($this->getViewMode() ,'integer').", ".
1170  "archive_start = ".$ilDB->quote($this->getArchiveStart() ,'integer').", ".
1171  "archive_end = ".$ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1172  "archive_type = ".$ilDB->quote($this->getArchiveType() ,'integer').", ".
1173  "abo = ".$ilDB->quote($this->getAboStatus() ,'integer').", ".
1174  "waiting_list = ".$ilDB->quote($this->enabledWaitingList() ,'integer').", ".
1175  "important = ".$ilDB->quote($this->getImportantInformation() ,'text').", ".
1176  "show_members = ".$ilDB->quote($this->getShowMembers() ,'integer').", ".
1177  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
1178  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
1179  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
1180  "enable_course_map = ".$ilDB->quote((int) $this->getEnableCourseMap() ,'integer').", ".
1181  'session_limit = '.$ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1182  'session_prev = '.$ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1183  'session_next = '.$ilDB->quote($this->getNumberOfNextSessions(),'integer').', '.
1184  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1185  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1186  'auto_notification = '.$ilDB->quote( (int)$this->getAutoNotification(), 'integer').', '.
1187  'status_dt = '.$ilDB->quote((int) $this->getStatusDetermination()).', '.
1188  'mail_members_type = '.$ilDB->quote((int) $this->getMailToMembersType(),'integer').' '.
1189  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1190 
1191 
1192  $res = $ilDB->manipulate($query);
1193 
1194  // moved activation to ilObjectActivation
1195  if($this->ref_id)
1196  {
1197  include_once "./Services/Object/classes/class.ilObjectActivation.php";
1198  ilObjectActivation::getItem($this->ref_id);
1199 
1200  $item = new ilObjectActivation;
1201  if($this->getActivationUnlimitedStatus())
1202  {
1204  }
1205  else
1206  {
1207  $item->setTimingType(ilObjectActivation::TIMINGS_ACTIVATION);
1208  $item->setTimingStart($this->getActivationStart());
1209  $item->setTimingEnd($this->getActivationEnd());
1210  $item->toggleVisible($this->getActivationVisibility());
1211  }
1212 
1213  $item->update($this->ref_id);
1214  }
1215  }
1216 
1224  public function cloneSettings($new_obj)
1225  {
1226  $new_obj->setSyllabus($this->getSyllabus());
1227  $new_obj->setContactName($this->getContactName());
1228  $new_obj->setContactResponsibility($this->getContactResponsibility());
1229  $new_obj->setContactPhone($this->getContactPhone());
1230  $new_obj->setContactEmail($this->getContactEmail());
1231  $new_obj->setContactConsultation($this->getContactConsultation());
1232  $new_obj->setOfflineStatus($this->getOfflineStatus()); // #9914
1233  $new_obj->setActivationType($this->getActivationType());
1234  $new_obj->setActivationStart($this->getActivationStart());
1235  $new_obj->setActivationEnd($this->getActivationEnd());
1236  $new_obj->setActivationVisibility($this->getActivationVisibility());
1237  $new_obj->setSubscriptionLimitationType($this->getSubscriptionLimitationType());
1238  $new_obj->setSubscriptionStart($this->getSubscriptionStart());
1239  $new_obj->setSubscriptionEnd($this->getSubscriptionEnd());
1240  $new_obj->setSubscriptionType($this->getSubscriptionType());
1241  $new_obj->setSubscriptionPassword($this->getSubscriptionPassword());
1242  $new_obj->enableSubscriptionMembershipLimitation($this->isSubscriptionMembershipLimited());
1243  $new_obj->setSubscriptionMaxMembers($this->getSubscriptionMaxMembers());
1244  $new_obj->setSubscriptionNotify($this->getSubscriptionNotify());
1245  $new_obj->setViewMode($this->getViewMode());
1246  $new_obj->setOrderType($this->getOrderType());
1247  $new_obj->setArchiveStart($this->getArchiveStart());
1248  $new_obj->setArchiveEnd($this->getArchiveEnd());
1249  $new_obj->setArchiveType($this->getArchiveType());
1250  $new_obj->setAboStatus($this->getAboStatus());
1251  $new_obj->enableWaitingList($this->enabledWaitingList());
1252  $new_obj->setImportantInformation($this->getImportantInformation());
1253  $new_obj->setShowMembers($this->getShowMembers());
1254  $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
1255  $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
1256  $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
1257  $new_obj->setAutoNotification( $this->getAutoNotification() );
1258  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
1259  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1260  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
1261  $new_obj->setStatusDetermination($this->getStatusDetermination());
1262  $new_obj->setMailToMembersType($this->getMailToMembersType());
1263 
1264  $new_obj->update();
1265  }
1266 
1268  {
1269  global $ilDB;
1270 
1271  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1273 
1274  $query = "INSERT INTO crs_settings (obj_id,syllabus,contact_name,contact_responsibility,".
1275  "contact_phone,contact_email,contact_consultation,activation_type,activation_start,".
1276  "activation_end,sub_limitation_type,sub_start,sub_end,sub_type,sub_password,sub_mem_limit,".
1277  "sub_max_members,sub_notify,view_mode,archive_start,archive_end,archive_type,abo," .
1278  "latitude,longitude,location_zoom,enable_course_map,waiting_list,show_members, ".
1279  "session_limit,session_prev,session_next, reg_ac_enabled, reg_ac, auto_notification, status_dt,mail_members_type) ".
1280  "VALUES( ".
1281  $ilDB->quote($this->getId() ,'integer').", ".
1282  $ilDB->quote($this->getSyllabus() ,'text').", ".
1283  $ilDB->quote($this->getContactName() ,'text').", ".
1284  $ilDB->quote($this->getContactResponsibility() ,'text').", ".
1285  $ilDB->quote($this->getContactPhone() ,'text').", ".
1286  $ilDB->quote($this->getContactEmail() ,'text').", ".
1287  $ilDB->quote($this->getContactConsultation() ,'text').", ".
1288  $ilDB->quote(0 ,'integer').", ".
1289  $ilDB->quote($this->getActivationStart() ,'integer').", ".
1290  $ilDB->quote($this->getActivationEnd() ,'integer').", ".
1291  $ilDB->quote(IL_CRS_SUBSCRIPTION_DEACTIVATED ,'integer').", ".
1292  $ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1293  $ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1294  $ilDB->quote(IL_CRS_SUBSCRIPTION_DIRECT ,'integer').", ".
1295  $ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1296  "0, ".
1297  $ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1298  "1, ".
1299  "0, ".
1300  $ilDB->quote($this->getArchiveStart() ,'integer').", ".
1301  $ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1302  $ilDB->quote(IL_CRS_ARCHIVE_NONE ,'integer').", ".
1303  $ilDB->quote($this->ABO_ENABLED ,'integer').", ".
1304  $ilDB->quote($this->getLatitude() ,'text').", ".
1305  $ilDB->quote($this->getLongitude() ,'text').", ".
1306  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
1307  $ilDB->quote($this->getEnableCourseMap() ,'integer').", ".
1308  #"objective_view = '0', ".
1309  "1, ".
1310  "1,".
1311  $ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1312  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1313  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1314  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1315  $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1316  $ilDB->quote((int)$this->getAutoNotification(),'integer').', '.
1317  $ilDB->quote((int)$this->getStatusDetermination(),'integer').', '.
1318  $ilDB->quote((int) $this->getMailToMembersType(),'integer').' '.
1319  ")";
1320 
1321  $res = $ilDB->manipulate($query);
1322  $this->__readSettings();
1323 
1324  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1325  $sorting = new ilContainerSortingSettings($this->getId());
1326  $sorting->setSortMode(ilContainer::SORT_MANUAL);
1327  $sorting->update();
1328  }
1329 
1330 
1331  function __readSettings()
1332  {
1333  global $ilDB;
1334 
1335  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1336 
1337  $res = $ilDB->query($query);
1338  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1339  {
1340  $this->setSyllabus($row->syllabus);
1341  $this->setContactName($row->contact_name);
1342  $this->setContactResponsibility($row->contact_responsibility);
1343  $this->setContactPhone($row->contact_phone);
1344  $this->setContactEmail($row->contact_email);
1345  $this->setContactConsultation($row->contact_consultation);
1346  $this->setOfflineStatus(!(bool)$row->activation_type); // see below
1347  $this->setSubscriptionLimitationType($row->sub_limitation_type);
1348  $this->setSubscriptionStart($row->sub_start);
1349  $this->setSubscriptionEnd($row->sub_end);
1350  $this->setSubscriptionType($row->sub_type);
1351  $this->setSubscriptionPassword($row->sub_password);
1352  $this->enableSubscriptionMembershipLimitation($row->sub_mem_limit);
1353  $this->setSubscriptionMaxMembers($row->sub_max_members);
1354  $this->setSubscriptionNotify($row->sub_notify);
1355  $this->setViewMode($row->view_mode);
1356  $this->setArchiveStart($row->archive_start);
1357  $this->setArchiveEnd($row->archive_end);
1358  $this->setArchiveType($row->archive_type);
1359  $this->setAboStatus($row->abo);
1360  $this->enableWaitingList($row->waiting_list);
1361  $this->setImportantInformation($row->important);
1362  $this->setShowMembers($row->show_members);
1363  $this->setLatitude($row->latitude);
1364  $this->setLongitude($row->longitude);
1365  $this->setLocationZoom($row->location_zoom);
1366  $this->setEnableCourseMap($row->enable_course_map);
1367  $this->enableSessionLimit($row->session_limit);
1368  $this->setNumberOfPreviousSessions($row->session_prev);
1369  $this->setNumberOfNextSessions($row->session_next);
1370  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
1371  $this->setRegistrationAccessCode($row->reg_ac);
1372  $this->setAutoNotification($row->auto_notification == 1 ? true : false);
1373  $this->setStatusDetermination((int) $row->status_dt);
1374  $this->setMailToMembersType($row->mail_members_type);
1375  }
1376 
1377  // moved activation to ilObjectActivation
1378  if($this->ref_id)
1379  {
1380  include_once "./Services/Object/classes/class.ilObjectActivation.php";
1381  $activation = ilObjectActivation::getItem($this->ref_id);
1382  switch($activation["timing_type"])
1383  {
1386  $this->setActivationStart($activation["timing_start"]);
1387  $this->setActivationEnd($activation["timing_end"]);
1388  $this->setActivationVisibility($activation["visible"]);
1389  break;
1390 
1391  default:
1393  break;
1394  }
1395  }
1396  else
1397  {
1398  // #13176 - there should always be default
1400  }
1401 
1402  return true;
1403  }
1404 
1405  function initWaitingList()
1406  {
1407  include_once "./Modules/Course/classes/class.ilCourseWaitingList.php";
1408 
1409  if(!is_object($this->waiting_list_obj))
1410  {
1411  $this->waiting_list_obj = new ilCourseWaitingList($this->getId());
1412  }
1413  return true;
1414  }
1415 
1416 
1422  protected function initCourseMemberObject()
1423  {
1424  global $ilUser;
1425 
1426  include_once "./Modules/Course/classes/class.ilCourseParticipant.php";
1427  $this->member_obj = ilCourseParticipant::_getInstanceByObjId($this->getId(),$ilUser->getId());
1428  return true;
1429  }
1430 
1436  protected function initCourseMembersObject()
1437  {
1438  global $ilUser;
1439 
1440  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1441  $this->members_obj = ilCourseParticipants::_getInstanceByObjId($this->getId());
1442  return true;
1443  }
1444 
1449  public function getMemberObject()
1450  {
1451  if(!$this->member_obj instanceof ilCourseParticipant)
1452  {
1453  $this->initCourseMemberObject();
1454  }
1455  return $this->member_obj;
1456  }
1457 
1462  public function getMembersObject()
1463  {
1464  if(!$this->members_obj instanceof ilCourseParticipants)
1465  {
1466  $this->initCourseMembersObject();
1467  }
1468  return $this->members_obj;
1469  }
1470 
1472  {
1473  include_once "./Modules/Course/classes/class.ilCourseArchives.php";
1474 
1475  if(!is_object($this->archives_obj))
1476  {
1477  $this->archives_obj =& new ilCourseArchives($this);
1478  }
1479  return true;
1480  }
1481 
1482 
1483 
1484  // RBAC METHODS
1485  function initDefaultRoles()
1486  {
1487  global $rbacadmin,$rbacreview,$ilDB;
1488 
1489  $rolf_obj = $this->createRoleFolder();
1490 
1491  // CREATE ADMIN ROLE
1492  $role_obj = $rolf_obj->createRole("il_crs_admin_".$this->getRefId(),"Admin of course obj_no.".$this->getId());
1493  $admin_id = $role_obj->getId();
1494 
1495  // SET PERMISSION TEMPLATE OF NEW LOCAL ADMIN ROLE
1496  $query = "SELECT obj_id FROM object_data ".
1497  " WHERE type='rolt' AND title='il_crs_admin'";
1498 
1499  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1500  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1501 
1502  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1503  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1504  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1505 
1506  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1507  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1508  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1509 
1510  // CREATE TUTOR ROLE
1511  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1512  $role_obj = $rolf_obj->createRole("il_crs_tutor_".$this->getRefId(),"Tutors of course obj_no.".$this->getId());
1513  $member_id = $role_obj->getId();
1514 
1515  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1516  $query = "SELECT obj_id FROM object_data ".
1517  " WHERE type='rolt' AND title='il_crs_tutor'";
1518  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1519  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1520 
1521  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1522  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1523  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1524 
1525  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1526  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1527  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1528 
1529  // CREATE MEMBER ROLE
1530  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1531  $role_obj = $rolf_obj->createRole("il_crs_member_".$this->getRefId(),"Member of course obj_no.".$this->getId());
1532  $member_id = $role_obj->getId();
1533 
1534  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1535  $query = "SELECT obj_id FROM object_data ".
1536  " WHERE type='rolt' AND title='il_crs_member'";
1537  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1538  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1539 
1540  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1541  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1542  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1543 
1544  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1545  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1546  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1547 
1548  unset($role_obj);
1549  unset($rolf_obj);
1550 
1551  // Break inheritance, create local roles and initialize permission
1552  // settings depending on course status.
1553  $this->__setCourseStatus();
1554 
1555  return true;
1556  }
1557 
1575  {
1576  global $rbacadmin, $rbacreview, $rbacsystem;
1577 
1578  //get Rolefolder of course
1579  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1580 
1581  //define all relevant roles for which rights are needed to be changed
1582  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1583  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultCourseRoles());
1584 
1585  $template_id = $this->__getCrsNonMemberTemplateId();
1586 
1587  //get defined operations from template
1588  if (is_null($template_id))
1589  {
1590  $template_ops = array();
1591  } else {
1592  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'crs', ROLE_FOLDER_ID);
1593  }
1594 
1595  foreach ($arr_relevantParentRoleIds as $parentRole)
1596  {
1597  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1598  {
1599  continue;
1600  }
1601 
1602  $granted_permissions = array();
1603 
1604  // Delete the linked role for the parent role
1605  // (just in case if it already exists).
1606  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1607 
1608  // Grant permissions on the course object for
1609  // the parent role. In the foreach loop we
1610  // compute the intersection of the role
1611  // template il_crs_non_member and the
1612  // permission template of the parent role.
1613  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1614  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1615  foreach ($template_ops as $template_op)
1616  {
1617  if (in_array($template_op,$current_ops))
1618  {
1619  array_push($granted_permissions,$template_op);
1620  }
1621  }
1622  if (!empty($granted_permissions))
1623  {
1624  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1625  }
1626 
1627  // Create a linked role for the parent role and
1628  // initialize it with the intersection of
1629  // il_crs_non_member and the permission
1630  // template of the parent role
1631  if (! is_null($template_id))
1632  {
1633  $rbacadmin->copyRolePermissionIntersection(
1634  $template_id, ROLE_FOLDER_ID,
1635  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1636  $rolf_data["child"], $parentRole
1637  );
1638  }
1639  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1640  }//END foreach
1641  }
1642 
1650  {
1651  global $ilDB;
1652 
1653  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
1654  $res = $this->ilias->db->query($q);
1655  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1656 
1657  return $row["obj_id"];
1658  }
1659 
1666  public function getLocalCourseRoles($a_translate = false)
1667  {
1668  global $rbacadmin,$rbacreview;
1669 
1670  if (empty($this->local_roles))
1671  {
1672  $this->local_roles = array();
1673  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1674  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1675 
1676  foreach ($role_arr as $role_id)
1677  {
1678  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1679  {
1680  $role_Obj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
1681 
1682  if ($a_translate)
1683  {
1684  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1685  }
1686  else
1687  {
1688  $role_name = $role_Obj->getTitle();
1689  }
1690  $this->local_roles[$role_name] = $role_Obj->getId();
1691  }
1692  }
1693  }
1694 
1695  return $this->local_roles;
1696  }
1697 
1698 
1699 
1709  public function getDefaultCourseRoles($a_crs_id = "")
1710  {
1711  global $rbacadmin, $rbacreview;
1712 
1713  if (strlen($a_crs_id) > 0)
1714  {
1715  $crs_id = $a_crs_id;
1716  }
1717  else
1718  {
1719  $crs_id = $this->getRefId();
1720  }
1721 
1722  $rolf = $rbacreview->getRoleFolderOfObject($crs_id);
1723  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1724 
1725  foreach ($role_arr as $role_id)
1726  {
1727  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1728 
1729  $crs_Member ="il_crs_member_".$crs_id;
1730  $crs_Admin ="il_crs_admin_".$crs_id;
1731  $crs_Tutor ="il_crs_tutor_".$crs_id;
1732 
1733  if (strcmp($role_Obj->getTitle(), $crs_Member) == 0 )
1734  {
1735  $arr_crsDefaultRoles["crs_member_role"] = $role_Obj->getId();
1736  }
1737 
1738  if (strcmp($role_Obj->getTitle(), $crs_Admin) == 0)
1739  {
1740  $arr_crsDefaultRoles["crs_admin_role"] = $role_Obj->getId();
1741  }
1742 
1743  if (strcmp($role_Obj->getTitle(), $crs_Tutor) == 0)
1744  {
1745  $arr_crsDefaultRoles["crs_tutor_role"] = $role_Obj->getId();
1746  }
1747  }
1748 
1749  return $arr_crsDefaultRoles;
1750  }
1751 
1752  function __getLocalRoles()
1753  {
1754  global $rbacreview;
1755 
1756  // GET role_objects of predefined roles
1757 
1758  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1759 
1760  return $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1761  }
1762 
1763  function __deleteSettings()
1764  {
1765  global $ilDB;
1766 
1767  $query = "DELETE FROM crs_settings ".
1768  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1769  $res = $ilDB->manipulate($query);
1770 
1771  return true;
1772  }
1773 
1774 
1776  {
1777  $local_roles = $this->__getLocalRoles();
1778 
1779  foreach($local_roles as $role_id)
1780  {
1781  $title = ilObject::_lookupTitle($role_id);
1782  if(substr($title,0,8) == 'il_crs_m')
1783  {
1784  return $role_id;
1785  }
1786  }
1787  return 0;
1788  }
1790  {
1791  $local_roles = $this->__getLocalRoles();
1792 
1793  foreach($local_roles as $role_id)
1794  {
1795  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1796  {
1797  if(!strcmp($tmp_role->getTitle(),"il_crs_tutor_".$this->getRefId()))
1798  {
1799  return $role_id;
1800  }
1801  }
1802  }
1803  return false;
1804  }
1806  {
1807  $local_roles = $this->__getLocalRoles();
1808 
1809  foreach($local_roles as $role_id)
1810  {
1811  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1812  {
1813  if(!strcmp($tmp_role->getTitle(),"il_crs_admin_".$this->getRefId()))
1814  {
1815  return $role_id;
1816  }
1817  }
1818  }
1819  return false;
1820  }
1821 
1822  // static method for condition handler
1823  function _checkCondition($a_obj_id,$a_operator,$a_value,$a_usr_id = 0)
1824  {
1825  global $ilUser;
1826 
1827  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
1828 
1829  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1830 
1831  switch($a_operator)
1832  {
1833  case 'passed':
1834  return ilCourseParticipants::_hasPassed($a_obj_id,$a_usr_id);
1835 
1836  default:
1837  return true;
1838  }
1839  }
1840 
1841  function _deleteUser($a_usr_id)
1842  {
1843  // Delete all user related data
1844  // delete lm_history
1845  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
1846  ilCourseLMHistory::_deleteUser($a_usr_id);
1847 
1848  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
1850 
1851  // Course objectives
1852  include_once './Modules/Course/classes/class.ilCourseObjectiveResult.php';
1854  }
1855 
1862  public function MDUpdateListener($a_element)
1863  {
1864  global $ilLog;
1865 
1866  parent::MDUpdateListener($a_element);
1867 
1868  switch($a_element)
1869  {
1870  case 'General':
1871  // Update ecs content
1872  include_once 'Modules/Course/classes/class.ilECSCourseSettings.php';
1873  $ecs = new ilECSCourseSettings($this);
1874  $ecs->handleContentUpdate();
1875  break;
1876 
1877  default:
1878  return true;
1879  }
1880  }
1881 
1886  function addAdditionalSubItemInformation(&$a_item_data)
1887  {
1888  include_once './Services/Object/classes/class.ilObjectActivation.php';
1890  }
1891 
1899  protected function prepareAppointments($a_mode = 'create')
1900  {
1901  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1902  include_once('./Services/Calendar/classes/class.ilDateTime.php');
1903 
1904  switch($a_mode)
1905  {
1906  case 'create':
1907  case 'update':
1908  if(!$this->getActivationUnlimitedStatus() and !$this->getOfflineStatus())
1909  {
1910  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_START);
1911  $app->setTitle($this->getTitle());
1912  $app->setSubtitle('crs_cal_activation_start');
1913  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1914  $app->setDescription($this->getLongDescription());
1915  $app->setStart(new ilDateTime($this->getActivationStart(),IL_CAL_UNIX));
1916  $apps[] = $app;
1917 
1918  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_END);
1919  $app->setTitle($this->getTitle());
1920  $app->setSubtitle('crs_cal_activation_end');
1921  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1922  $app->setDescription($this->getLongDescription());
1923  $app->setStart(new ilDateTime($this->getActivationEnd(),IL_CAL_UNIX));
1924  $apps[] = $app;
1925  }
1927  {
1928  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1929  $app->setTitle($this->getTitle());
1930  $app->setSubtitle('crs_cal_reg_start');
1931  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1932  $app->setDescription($this->getLongDescription());
1933  $app->setStart(new ilDateTime($this->getSubscriptionStart(),IL_CAL_UNIX));
1934  $apps[] = $app;
1935 
1936  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1937  $app->setTitle($this->getTitle());
1938  $app->setSubtitle('crs_cal_reg_end');
1939  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1940  $app->setDescription($this->getLongDescription());
1941  $app->setStart(new ilDateTime($this->getSubscriptionEnd(),IL_CAL_UNIX));
1942  $apps[] = $app;
1943  }
1944 
1945  return $apps ? $apps : array();
1946 
1947  case 'delete':
1948  // Nothing to do: The category and all assigned appointments will be deleted.
1949  return array();
1950  }
1951  }
1952 
1953  ###### Interface ilMembershipRegistrationCodes
1954 
1958  public static function lookupObjectsByCode($a_code)
1959  {
1960  global $ilDB;
1961 
1962  $query = "SELECT obj_id FROM crs_settings ".
1963  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1964  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1965  $res = $ilDB->query($query);
1966 
1967  $obj_ids = array();
1968  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1969  {
1970  $obj_ids[] = $row->obj_id;
1971  }
1972  return $obj_ids;
1973  }
1974 
1981  public function register($a_user_id,$a_role = ilCourseConstants::CRS_MEMBER, $a_force_registration = false)
1982  {
1983  global $ilCtrl, $tree;
1984  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1985  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1987 
1988  if($part->isAssigned($a_user_id))
1989  {
1990  return true;
1991  }
1992 
1993  if(!$a_force_registration)
1994  {
1995  // Availability
1997  {
1998  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1999 
2001  {
2002  throw new ilMembershipRegistrationException('Cant registrate to course '.$this->getId().
2003  ', course subscription is deactivated.', '456');
2004  }
2005  }
2006 
2007  // Time Limitation
2009  {
2010  if( !$this->inSubscriptionTime() )
2011  {
2012  throw new ilMembershipRegistrationException('Cant registrate to course '.$this->getId().
2013  ', course is out of registration time.', '789');
2014  }
2015  }
2016 
2017  // Max members
2018  if($this->isSubscriptionMembershipLimited())
2019  {
2020  $free = max(0,$this->getSubscriptionMaxMembers() - $part->getCountMembers());
2021  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
2022  $waiting_list = new ilCourseWaitingList($this->getId());
2023  if($this->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
2024  {
2025  $waiting_list->addToList($a_user_id);
2026  $this->lng->loadLanguageModule("crs");
2027  $info = sprintf($this->lng->txt('crs_added_to_list'),
2028  $waiting_list->getPosition($a_user_id));
2029  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
2030  $participants = ilCourseParticipants::_getInstanceByObjId($this->getId());
2031  $participants->sendNotification($participants->NOTIFY_WAITING_LIST,$a_user_id);
2032 
2033  throw new ilMembershipRegistrationException($info, '124');
2034  }
2035 
2036  if(!$this->enabledWaitingList() && !$free)
2037  {
2038  throw new ilMembershipRegistrationException('Cant registrate to course '.$this->getId().
2039  ', membership is limited.', '123');
2040  }
2041  }
2042  }
2043 
2044  $part->add($a_user_id,$a_role);
2045  $part->sendNotification($part->NOTIFY_ACCEPT_USER, $a_user_id);
2046  $part->sendNotification($part->NOTIFY_ADMINS,$a_user_id);
2047 
2048 
2049  include_once './Modules/Forum/classes/class.ilForumNotification.php';
2051 
2052  return true;
2053  }
2054 
2061  public function getAutoNotification()
2062  {
2063  return $this->auto_notification;
2064  }
2065 
2066 
2073  public function setAutoNotification($value)
2074  {
2075  $this->auto_notification = $value;
2076  }
2077 
2083  public function setStatusDetermination($a_value)
2084  {
2085  $a_value = (int)$a_value;
2086 
2087  // #13905
2088  if($a_value == self::STATUS_DETERMINATION_LP)
2089  {
2090  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
2092  {
2094  }
2095  }
2096 
2097  $this->status_dt = $a_value;
2098  }
2099 
2105  public function getStatusDetermination()
2106  {
2107  return $this->status_dt;
2108  }
2109 
2113  public function syncMembersStatusWithLP()
2114  {
2115  include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
2116  foreach($this->getMembersObject()->getParticipants() as $user_id)
2117  {
2118  // #15529 - force raise on sync
2119  ilLPStatusWrapper::_updateStatus($this->getId(), $user_id, null, false, false, true);
2120  }
2121  }
2122 
2130  public function checkLPStatusSync($a_member_id)
2131  {
2132  // #11113
2133  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
2136  {
2137  include_once("Services/Tracking/classes/class.ilLPStatus.php");
2138  $has_completed = ilLPStatus::_hasUserCompleted($this->getId(), $a_member_id);
2139  $this->getMembersObject()->updatePassed($a_member_id, $has_completed, false, true);
2140  }
2141  }
2142 
2143 } //END class.ilObjCourse
2144 ?>