ILIAS  release_4-3 Revision
 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 
71  private $auto_notification = true;
72 
79  function ilObjCourse($a_id = 0,$a_call_by_reference = true)
80  {
81 
82  #define("ILIAS_MODULE","course");
83  #define("KEEP_IMAGE_PATH",1);
84 
85  $this->SUBSCRIPTION_DEACTIVATED = 1;
86  $this->SUBSCRIPTION_CONFIRMATION = 2;
87  $this->SUBSCRIPTION_DIRECT = 3;
88  $this->SUBSCRIPTION_PASSWORD = 4;
89  $this->SUBSCRIPTION_AUTOSUBSCRIPTION = 5;
90  $this->ARCHIVE_DISABLED = 1;
91  $this->ARCHIVE_READ = 2;
92  $this->ARCHIVE_DOWNLOAD = 3;
93  $this->ABO_ENABLED = 1;
94  $this->ABO_DISABLED = 0;
95  $this->SHOW_MEMBERS_ENABLED = 1;
96  $this->SHOW_MEMBERS_DISABLED = 0;
97  $this->status_dt = self::STATUS_DETERMINATION_LP;
98 
99  $this->type = "crs";
100 
101  parent::__construct($a_id,$a_call_by_reference);
102 
103  }
104 
110  public static function lookupShowMembersEnabled($a_obj_id)
111  {
112  $query = 'SELECT show_members FROM crs_settings '.
113  'WHERE obj_id = '.$GLOBALS['ilDB']->quote($a_obj_id,'integer');
114  $res = $GLOBALS['ilDB']->query($query);
115  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
116  {
117  return (bool) $row->show_members;
118  }
119  return false;
120  }
121 
126  public function getRegistrationAccessCode()
127  {
128  return $this->reg_access_code;
129  }
130 
136  public function setRegistrationAccessCode($a_code)
137  {
138  $this->reg_access_code = $a_code;
139  }
140 
146  {
147  return (bool) $this->reg_access_code_enabled;
148  }
149 
155  public function enableRegistrationAccessCode($a_status)
156  {
157  $this->reg_access_code_enabled = $a_status;
158  }
159 
161  {
162  return $this->important;
163  }
164  function setImportantInformation($a_info)
165  {
166  $this->important = $a_info;
167  }
168  function getSyllabus()
169  {
170  return $this->syllabus;
171  }
172  function setSyllabus($a_syllabus)
173  {
174  $this->syllabus = $a_syllabus;
175  }
176  function getContactName()
177  {
178  return $this->contact_name;
179  }
180  function setContactName($a_cn)
181  {
182  $this->contact_name = $a_cn;
183  }
185  {
186  return $this->contact_consultation;
187  }
188  function setContactConsultation($a_value)
189  {
190  $this->contact_consultation = $a_value;
191  }
192  function getContactPhone()
193  {
194  return $this->contact_phone;
195  }
196  function setContactPhone($a_value)
197  {
198  $this->contact_phone = $a_value;
199  }
200  function getContactEmail()
201  {
202  return $this->contact_email;
203  }
204  function setContactEmail($a_value)
205  {
206  $this->contact_email = $a_value;
207  }
209  {
210  return $this->contact_responsibility;
211  }
212  function setContactResponsibility($a_value)
213  {
214  $this->contact_responsibility = $a_value;
215  }
216  function getActivationType()
217  {
218  return (int) $this->activation_type;
219  }
220  function setActivationType($a_type)
221  {
222  // offline is separate property now
223  if($a_type == IL_CRS_ACTIVATION_OFFLINE)
224  {
225  $this->setOfflineStatus(true);
226  $a_type = IL_CRS_ACTIVATION_UNLIMITED;
227  }
228 
229  $this->activation_type = $a_type;
230  }
232  {
233  return $this->activation_type == IL_CRS_ACTIVATION_UNLIMITED;
234  }
236  {
237  return $this->activation_start ? $this->activation_start : time();
238  }
239  function setActivationStart($a_value)
240  {
241  $this->activation_start = $a_value;
242  }
243  function getActivationEnd()
244  {
245  return $this->activation_end ? $this->activation_end : mktime(0,0,0,12,12,date("Y",time())+2);
246  }
247  function setActivationEnd($a_value)
248  {
249  $this->activation_end = $a_value;
250  }
251  function getOfflineStatus()
252  {
253  return (bool)$this->activation_offline;
254  }
255  function setOfflineStatus($a_value)
256  {
257  $this->activation_offline = (bool) $a_value;
258  }
259  function setActivationVisibility($a_value)
260  {
261  $this->activation_visibility = (bool) $a_value;
262  }
264  {
265  return $this->activation_visibility;
266  }
267 
269  {
270  return $this->subscription_limitation_type;
271  }
273  {
274  $this->subscription_limitation_type = $a_type;
275  }
277  {
278  return $this->subscription_limitation_type == IL_CRS_SUBSCRIPTION_UNLIMITED;
279  }
281  {
282  return $this->subscription_start ? $this->subscription_start : time();
283  }
284  function setSubscriptionStart($a_value)
285  {
286  $this->subscription_start = $a_value;
287  }
289  {
290  return $this->subscription_end ? $this->subscription_end : mktime(0,0,0,12,12,date("Y",time())+2);
291  }
292  function setSubscriptionEnd($a_value)
293  {
294  $this->subscription_end = $a_value;
295  }
297  {
298  return $this->subscription_type ? $this->subscription_type : IL_CRS_SUBSCRIPTION_DIRECT;
299  #return $this->subscription_type ? $this->subscription_type : $this->SUBSCRIPTION_DEACTIVATED;
300  }
301  function setSubscriptionType($a_value)
302  {
303  $this->subscription_type = $a_value;
304  }
306  {
307  return $this->subscription_password;
308  }
309  function setSubscriptionPassword($a_value)
310  {
311  $this->subscription_password = $a_value;
312  }
314  {
315  return $this->view_mode == IL_CRS_VIEW_OBJECTIVE;
316  }
317 
319  {
320  return (bool) $this->waiting_list;
321  }
322 
323  function enableWaitingList($a_status)
324  {
325  $this->waiting_list = (bool) $a_status;
326  }
327 
329  {
330  if($this->getSubscriptionUnlimitedStatus())
331  {
332  return true;
333  }
334  if(time() > $this->getSubscriptionStart() and time() < $this->getSubscriptionEnd())
335  {
336  return true;
337  }
338  return false;
339  }
340 
346  public function enableSessionLimit($a_status)
347  {
348  $this->session_limit = $a_status;
349  }
350 
351  public function isSessionLimitEnabled()
352  {
353  return (bool) $this->session_limit;
354  }
355 
363  public function enableSubscriptionMembershipLimitation($a_status)
364  {
365  $this->subscription_membership_limitation = $a_status;
366  }
367 
373  public function setNumberOfPreviousSessions($a_num)
374  {
375  $this->session_prev = $a_num;
376  }
377 
382  public function getNumberOfPreviousSessions()
383  {
384  return $this->session_prev;
385  }
386 
392  public function setNumberOfNextSessions($a_num)
393  {
394  $this->session_next = $a_num;
395  }
396 
401  public function getNumberOfNextSessions()
402  {
403  return $this->session_next;
404  }
413  {
414  return (bool) $this->subscription_membership_limitation;
415  }
416 
418  {
419  return $this->subscription_max_members;
420  }
421  function setSubscriptionMaxMembers($a_value)
422  {
423  $this->subscription_max_members = $a_value;
424  }
425 
434  public static function _isSubscriptionNotificationEnabled($a_course_id)
435  {
436  global $ilDB;
437 
438  $query = "SELECT * FROM crs_settings ".
439  "WHERE obj_id = ".$ilDB->quote($a_course_id ,'integer')." ".
440  "AND sub_notify = 1";
441  $res = $ilDB->query($query);
442  return $res->numRows() ? true : false;
443  }
444 
451  public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
452  {
453  global $ilUser;
454 
455  // Caching
456  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]))
457  {
458  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
459  }
460 
461  // Results are stored in $this->items
462  parent::getSubItems($a_admin_panel_enabled,$a_include_side_block);
463 
464  // No sessions
465  if(!is_array($this->items['sess']) or !$this->items['sess'])
466  {
467  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
468  }
469  // No session limit
470  if(!$this->isSessionLimitEnabled() or $a_admin_panel_enabled)
471  {
472  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
473  }
474 
475  if($a_include_side_block)
476  {
477  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
478  }
479 
480  // @todo move to gui class
481  if(isset($_GET['crs_prev_sess']))
482  {
483  $ilUser->writePref('crs_sess_show_prev_'.$this->getId(), (string) (int) $_GET['crs_prev_sess']);
484  }
485  if(isset($_GET['crs_next_sess']))
486  {
487  $ilUser->writePref('crs_sess_show_next_'.$this->getId(), (string) (int) $_GET['crs_next_sess']);
488  }
489 
490  $sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
491  $today = new ilDate(date('Ymd',time()),IL_CAL_DATE);
492  $previous = $current = $next = array();
493  foreach($sessions as $key => $item)
494  {
495  $start = new ilDateTime($item['start'],IL_CAL_UNIX);
496  $end = new ilDateTime($item['end'],IL_CAL_UNIX);
497 
498  if(ilDateTime::_within($today, $start, $end, IL_CAL_DAY))
499  {
500  $current[] = $item;
501  }
502  elseif(ilDateTime::_before($start, $today, IL_CAL_DAY))
503  {
504  $previous[] = $item;
505  }
506  elseif(ilDateTime::_after($start, $today, IL_CAL_DAY))
507  {
508  $next[] = $item;
509  }
510  }
511  $num_previous_remove = max(
512  count($previous) - $this->getNumberOfPreviousSessions(),
513  0
514  );
515  while($num_previous_remove--)
516  {
517  if(!$ilUser->getPref('crs_sess_show_prev_'.$this->getId()))
518  {
519  array_shift($previous);
520  }
521  $this->items['sess_link']['prev']['value'] = 1;
522  }
523 
524  $num_next_remove = max(
525  count($next) - $this->getNumberOfNextSessions(),
526  0
527  );
528  while($num_next_remove--)
529  {
530  if(!$ilUser->getPref('crs_sess_show_next_'.$this->getId()))
531  {
532  array_pop($next);
533  }
534  // @fixme
535  $this->items['sess_link']['next']['value'] = 1;
536  }
537 
538  $sessions = array_merge($previous,$current,$next);
539  $this->items['sess'] = $sessions;
540  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $this->items;
541  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
542  }
543 
545  {
546  return true;
547  return $this->subscription_notify ? true : false;
548  }
549  function setSubscriptionNotify($a_value)
550  {
551  $this->subscription_notify = $a_value ? true : false;
552  }
553 
554  function setViewMode($a_mode)
555  {
556  $this->view_mode = $a_mode;
557  }
558  function getViewMode()
559  {
560  return $this->view_mode;
561  }
562 
563  function _lookupViewMode($a_id)
564  {
565  global $ilDB;
566 
567  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
568  $res = $ilDB->query($query);
569  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
570  {
571  return $row->view_mode;
572  }
573  return false;
574  }
575 
576  function _lookupAboStatus($a_id)
577  {
578  global $ilDB;
579 
580  $query = "SELECT abo FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
581  $res = $ilDB->query($query);
582  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
583  {
584  return $row->abo;
585  }
586  return false;
587  }
588 
589  function getArchiveStart()
590  {
591  return $this->archive_start ? $this->archive_start : time();
592  }
593  function setArchiveStart($a_value)
594  {
595  $this->archive_start = $a_value;
596  }
597  function getArchiveEnd()
598  {
599  return $this->archive_end ? $this->archive_end : mktime(0,0,0,12,12,date("Y",time())+2);
600  }
601  function setArchiveEnd($a_value)
602  {
603  $this->archive_end = $a_value;
604  }
605  function getArchiveType()
606  {
607  return $this->archive_type ? IL_CRS_ARCHIVE_DOWNLOAD : IL_CRS_ARCHIVE_NONE;
608  }
609  function setArchiveType($a_value)
610  {
611  $this->archive_type = $a_value;
612  }
613  function setAboStatus($a_status)
614  {
615  $this->abo = $a_status;
616  }
617  function getAboStatus()
618  {
619  return $this->abo;
620  }
621  function setShowMembers($a_status)
622  {
623  $this->show_members = $a_status;
624  }
625  function getShowMembers()
626  {
627  return $this->show_members;
628  }
629 
630  function getMessage()
631  {
632  return $this->message;
633  }
634  function setMessage($a_message)
635  {
636  $this->message = $a_message;
637  }
638  function appendMessage($a_message)
639  {
640  if($this->getMessage())
641  {
642  $this->message .= "<br /> ";
643  }
644  $this->message .= $a_message;
645  }
646 
647  function isActivated($a_check_archive = false)
648  {
649  if($a_check_archive)
650  {
651  if($this->isArchived())
652  {
653  return true;
654  }
655  }
656  if($this->getOfflineStatus())
657  {
658  return false;
659  }
660  if($this->getActivationUnlimitedStatus())
661  {
662  return true;
663  }
664  if(time() < $this->getActivationStart() or
665  time() > $this->getActivationEnd())
666  {
667  return false;
668  }
669  return true;
670  }
671 
678  function _isActivated($a_obj_id)
679  {
680  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
681  return ilObjCourseAccess::_isActivated($a_obj_id);
682  }
683 
690  function _registrationEnabled($a_obj_id)
691  {
692  include_once("./Modules/Course/classes/class.ilObjCourseAccess.php");
693  return ilObjCourseAccess::_registrationEnabled($a_obj_id);
694  }
695 
696  function isArchived()
697  {
698  if($this->getViewMode() != IL_CRS_VIEW_ARCHIVE)
699  {
700  return false;
701  }
702  if(time() < $this->getArchiveStart() or time() > $this->getArchiveEnd())
703  {
704  return false;
705  }
706  return true;
707  }
708 
709  function allowAbo()
710  {
711  return $this->ABO == $this->ABO_ENABLED;
712  }
713 
714  function read($a_force_db = false)
715  {
716  parent::read($a_force_db);
717 
718  $this->__readSettings();
719  }
720  function create($a_upload = false)
721  {
722  global $ilAppEventHandler;
723 
724  parent::create($a_upload);
725 
726  if(!$a_upload)
727  {
728  $this->createMetaData();
729  }
730  $this->__createDefaultSettings();
731 
732  $ilAppEventHandler->raise('Modules/Course',
733  'create',
734  array('object' => $this,
735  'obj_id' => $this->getId(),
736  'appointments' => $this->prepareAppointments('create')));
737 
738  }
739 
745  function setLatitude($a_latitude)
746  {
747  $this->latitude = $a_latitude;
748  }
749 
755  function getLatitude()
756  {
757  return $this->latitude;
758  }
759 
765  function setLongitude($a_longitude)
766  {
767  $this->longitude = $a_longitude;
768  }
769 
775  function getLongitude()
776  {
777  return $this->longitude;
778  }
779 
785  function setLocationZoom($a_locationzoom)
786  {
787  $this->locationzoom = $a_locationzoom;
788  }
789 
795  function getLocationZoom()
796  {
797  return $this->locationzoom;
798  }
799 
805  function setEnableCourseMap($a_enablemap)
806  {
807  $this->enablemap = $a_enablemap;
808  }
809 
816  {
817  return $this->enablemap;
818  }
819 
828  public function cloneObject($a_target_id,$a_copy_id = 0)
829  {
830  global $ilDB,$ilUser;
831 
832  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
833 
834  $this->cloneAutoGeneratedRoles($new_obj);
835  $this->cloneMetaData($new_obj);
836 
837  // Assign admin
838  $new_obj->getMemberObject()->add($ilUser->getId(),IL_CRS_ADMIN);
839 
840  // #14596
841  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
842  if($cwo->isRootNode($this->getRefId()))
843  {
844  $this->setOfflineStatus(true);
845  }
846 
847  // Copy settings
848  $this->cloneSettings($new_obj);
849 
850  // Course Defined Fields
851  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
852  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
853 
854  // Clone course files
855  include_once('Modules/Course/classes/class.ilCourseFile.php');
856  ilCourseFile::_cloneFiles($this->getId(),$new_obj->getId());
857 
858  // Copy learning progress settings
859  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
860  $obj_settings = new ilLPObjSettings($this->getId());
861  $obj_settings->cloneSettings($new_obj->getId());
862  unset($obj_settings);
863 
864  // clone icons
865  global $ilLog;
866  $ilLog->write(__METHOD__.': '.$this->getBigIconPath().' '.$this->getSmallIconPath());
867  $new_obj->saveIcons($this->getBigIconPath(),
868  $this->getSmallIconPath(),
869  $this->getTinyIconPath());
870 
871  // clone certificate (#11085)
872  include_once "./Services/Certificate/classes/class.ilCertificate.php";
873  include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
874  $cert = new ilCertificate(new ilCourseCertificateAdapter($this));
875  $newcert = new ilCertificate(new ilCourseCertificateAdapter($new_obj));
876  $cert->cloneCertificate($newcert);
877 
878  return $new_obj;
879  }
880 
889  public function cloneDependencies($a_target_id,$a_copy_id)
890  {
891  parent::cloneDependencies($a_target_id,$a_copy_id);
892 
893  // Clone course start objects
894  include_once('Modules/Course/classes/class.ilCourseStart.php');
895  $start = new ilCourseStart($this->getRefId(),$this->getId());
896  $start->cloneDependencies($a_target_id,$a_copy_id);
897 
898  // Clone course item settings
899  include_once('Services/Object/classes/class.ilObjectActivation.php');
900  ilObjectActivation::cloneDependencies($this->getRefId(),$a_target_id,$a_copy_id);
901 
902  // Clone course learning objectives
903  include_once('Modules/Course/classes/class.ilCourseObjective.php');
904  $crs_objective = new ilCourseObjective($this);
905  $crs_objective->ilClone($a_target_id,$a_copy_id);
906 
907  include_once('Services/Tracking/classes/class.ilLPCollections.php');
908  $lp_collection = new ilLPCollections($this->getId());
909  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
910 
911  return true;
912  }
913 
921  public function cloneAutoGeneratedRoles($new_obj)
922  {
923  global $ilLog,$rbacadmin,$rbacreview;
924 
925  $admin = $this->getDefaultAdminRole();
926  $new_admin = $new_obj->getDefaultAdminRole();
927  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
928  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
929 
930  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
931  {
932  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_admin');
933  }
934  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
935  $ilLog->write(__METHOD__.' : Finished copying of role crs_admin.');
936 
937  $tutor = $this->getDefaultTutorRole();
938  $new_tutor = $new_obj->getDefaultTutorRole();
939  if(!$tutor || !$new_tutor)
940  {
941  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_tutor');
942  }
943  $rbacadmin->copyRolePermissions($tutor,$source_rolf,$target_rolf,$new_tutor,true);
944  $ilLog->write(__METHOD__.' : Finished copying of role crs_tutor.');
945 
946  $member = $this->getDefaultMemberRole();
947  $new_member = $new_obj->getDefaultMemberRole();
948  if(!$member || !$new_member)
949  {
950  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_crs_member');
951  }
952  $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
953  $ilLog->write(__METHOD__.' : Finished copying of role crs_member.');
954 
955  return true;
956  }
957 
958 
959  function validate()
960  {
961  $this->setMessage('');
962 
963  #if(($this->getSubscriptionLimitationType() != IL_CRS_SUBSCRIPTION_DEACTIVATED) and
964  # $this->getSubscriptionType() == )
965  #{
966  # $this->appendMessage($this->lng->txt('crs_select_registration_type'));
967  #}
968 
969  if(($this->getActivationType() == IL_CRS_ACTIVATION_LIMITED) and
970  $this->getActivationEnd() < $this->getActivationStart())
971  {
972  $this->appendMessage($this->lng->txt("activation_times_not_valid"));
973  }
975  $this->getSubscriptionStart() > $this->getSubscriptionEnd())
976  {
977  $this->appendMessage($this->lng->txt("subscription_times_not_valid"));
978  }
979  #if((!$this->getActivationUnlimitedStatus() and
980  # !$this->getSubscriptionUnlimitedStatus()) and
981  # ($this->getSubscriptionStart() > $this->getActivationEnd() or
982  # $this->getSubscriptionStart() < $this->getActivationStart() or
983  # $this->getSubscriptionEnd() > $this->getActivationEnd() or
984  # $this->getSubscriptionEnd() < $this->getActivationStart()))
985  #
986  #{
987  # $this->appendMessage($this->lng->txt("subscription_time_not_within_activation"));
988  #}
990  {
991  $this->appendMessage($this->lng->txt("crs_password_required"));
992  }
993  if($this->isSubscriptionMembershipLimited() and ($this->getSubscriptionMaxMembers() <= 0 or !is_numeric($this->getSubscriptionMaxMembers())))
994  {
995  $this->appendMessage($this->lng->txt("max_members_not_numeric"));
996  }
997  if(($this->getViewMode() == IL_CRS_VIEW_ARCHIVE) and
998  $this->getArchiveStart() > $this->getArchiveEnd())
999  {
1000  $this->appendMessage($this->lng->txt("archive_times_not_valid"));
1001  }
1002  if(!$this->getTitle() || !$this->getStatusDetermination())
1003  {
1004  $this->appendMessage($this->lng->txt('err_check_input'));
1005  }
1006 
1007 
1008  return $this->getMessage() ? false : true;
1009  }
1010 
1012  {
1013  global $ilErr;
1014  $error = false;
1015  if($this->getContactEmail()) {
1016  $emails = split(",",$this->getContactEmail());
1017 
1018  foreach ($emails as $email) {
1019  $email = trim($email);
1020  if (!(ilUtil::is_email($email) or ilObjUser::getUserIdByLogin($email)))
1021  {
1022  $ilErr->appendMessage($this->lng->txt('contact_email_not_valid')." '".$email."'");
1023  $error = true;
1024  }
1025  }
1026  }
1027  return !$error;
1028  }
1029 
1030  function hasContactData()
1031  {
1032  return strlen($this->getContactName()) or
1033  strlen($this->getContactResponsibility()) or
1034  strlen($this->getContactEmail()) or
1035  strlen($this->getContactPhone()) or
1036  strlen($this->getContactConsultation());
1037  }
1038 
1039 
1046  function delete()
1047  {
1048  global $ilAppEventHandler;
1049 
1050  // always call parent delete function first!!
1051  if (!parent::delete())
1052  {
1053  return false;
1054  }
1055 
1056  // delete meta data
1057  $this->deleteMetaData();
1058 
1059  // put here course specific stuff
1060 
1061  $this->__deleteSettings();
1062 
1063  include_once('Modules/Course/classes/class.ilCourseParticipants.php');
1065 
1066  $this->initCourseArchiveObject();
1067  $this->archives_obj->deleteAll();
1068 
1069  include_once './Modules/Course/classes/class.ilCourseObjective.php';
1071 
1072  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
1074 
1075  include_once './Modules/Course/classes/class.ilCourseFile.php';
1077 
1078  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
1080 
1081  $ilAppEventHandler->raise('Modules/Course',
1082  'delete',
1083  array('object' => $this,
1084  'obj_id' => $this->getId(),
1085  'appointments' => $this->prepareAppointments('delete')));
1086 
1087 
1088  return true;
1089  }
1090 
1091 
1092 
1096  function update()
1097  {
1098  global $ilAppEventHandler,$ilLog;
1099 
1100  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1101  $sorting = new ilContainerSortingSettings($this->getId());
1102  $sorting->setSortMode($this->getOrderType());
1103  $sorting->update();
1104 
1105  $this->updateMetaData();
1106  $this->updateSettings();
1107  parent::update();
1108 
1109  $ilAppEventHandler->raise('Modules/Course',
1110  'update',
1111  array('object' => $this,
1112  'obj_id' => $this->getId(),
1113  'appointments' => $this->prepareAppointments('update')));
1114 
1115  }
1116 
1117  function updateSettings()
1118  {
1119  global $ilDB;
1120 
1121  // Due to a bug 3.5.alpha maybe no settings exist. => create default settings
1122 
1123  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1124  $res = $ilDB->query($query);
1125 
1126  if(!$res->numRows())
1127  {
1128  $this->__createDefaultSettings();
1129  }
1130 
1131  $query = "UPDATE crs_settings SET ".
1132  "syllabus = ".$ilDB->quote($this->getSyllabus() ,'text').", ".
1133  "contact_name = ".$ilDB->quote($this->getContactName() ,'text').", ".
1134  "contact_responsibility = ".$ilDB->quote($this->getContactResponsibility() ,'text').", ".
1135  "contact_phone = ".$ilDB->quote($this->getContactPhone() ,'text').", ".
1136  "contact_email = ".$ilDB->quote($this->getContactEmail() ,'text').", ".
1137  "contact_consultation = ".$ilDB->quote($this->getContactConsultation() ,'text').", ".
1138  "activation_type = ".$ilDB->quote(!$this->getOfflineStatus() ,'integer').", ".
1139  "sub_limitation_type = ".$ilDB->quote($this->getSubscriptionLimitationType() ,'integer').", ".
1140  "sub_start = ".$ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1141  "sub_end = ".$ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1142  "sub_type = ".$ilDB->quote($this->getSubscriptionType() ,'integer').", ".
1143  "sub_password = ".$ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1144  "sub_mem_limit = ".$ilDB->quote((int) $this->isSubscriptionMembershipLimited() ,'integer').", ".
1145  "sub_max_members = ".$ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1146  "sub_notify = ".$ilDB->quote($this->getSubscriptionNotify() ,'integer').", ".
1147  "view_mode = ".$ilDB->quote($this->getViewMode() ,'integer').", ".
1148  "archive_start = ".$ilDB->quote($this->getArchiveStart() ,'integer').", ".
1149  "archive_end = ".$ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1150  "archive_type = ".$ilDB->quote($this->getArchiveType() ,'integer').", ".
1151  "abo = ".$ilDB->quote($this->getAboStatus() ,'integer').", ".
1152  "waiting_list = ".$ilDB->quote($this->enabledWaitingList() ,'integer').", ".
1153  "important = ".$ilDB->quote($this->getImportantInformation() ,'text').", ".
1154  "show_members = ".$ilDB->quote($this->getShowMembers() ,'integer').", ".
1155  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
1156  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
1157  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
1158  "enable_course_map = ".$ilDB->quote((int) $this->getEnableCourseMap() ,'integer').", ".
1159  'session_limit = '.$ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1160  'session_prev = '.$ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1161  'session_next = '.$ilDB->quote($this->getNumberOfNextSessions(),'integer').', '.
1162  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1163  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1164  'auto_notification = '.$ilDB->quote( (int)$this->getAutoNotification(), 'integer').', '.
1165  'status_dt = '.$ilDB->quote((int) $this->getStatusDetermination()).' '.
1166  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1167 
1168  $res = $ilDB->manipulate($query);
1169 
1170  // moved activation to ilObjectActivation
1171  if($this->ref_id)
1172  {
1173  include_once "./Services/Object/classes/class.ilObjectActivation.php";
1174  ilObjectActivation::getItem($this->ref_id);
1175 
1176  $item = new ilObjectActivation;
1177  if($this->getActivationUnlimitedStatus())
1178  {
1180  }
1181  else
1182  {
1183  $item->setTimingType(ilObjectActivation::TIMINGS_ACTIVATION);
1184  $item->setTimingStart($this->getActivationStart());
1185  $item->setTimingEnd($this->getActivationEnd());
1186  $item->toggleVisible($this->getActivationVisibility());
1187  }
1188 
1189  $item->update($this->ref_id);
1190  }
1191  }
1192 
1200  public function cloneSettings($new_obj)
1201  {
1202  $new_obj->setSyllabus($this->getSyllabus());
1203  $new_obj->setContactName($this->getContactName());
1204  $new_obj->setContactResponsibility($this->getContactResponsibility());
1205  $new_obj->setContactPhone($this->getContactPhone());
1206  $new_obj->setContactEmail($this->getContactEmail());
1207  $new_obj->setContactConsultation($this->getContactConsultation());
1208  $new_obj->setOfflineStatus($this->getOfflineStatus()); // #9914
1209  $new_obj->setActivationType($this->getActivationType());
1210  $new_obj->setActivationStart($this->getActivationStart());
1211  $new_obj->setActivationEnd($this->getActivationEnd());
1212  $new_obj->setActivationVisibility($this->getActivationVisibility());
1213  $new_obj->setSubscriptionLimitationType($this->getSubscriptionLimitationType());
1214  $new_obj->setSubscriptionStart($this->getSubscriptionStart());
1215  $new_obj->setSubscriptionEnd($this->getSubscriptionEnd());
1216  $new_obj->setSubscriptionType($this->getSubscriptionType());
1217  $new_obj->setSubscriptionPassword($this->getSubscriptionPassword());
1218  $new_obj->enableSubscriptionMembershipLimitation($this->isSubscriptionMembershipLimited());
1219  $new_obj->setSubscriptionMaxMembers($this->getSubscriptionMaxMembers());
1220  $new_obj->setSubscriptionNotify($this->getSubscriptionNotify());
1221  $new_obj->setViewMode($this->getViewMode());
1222  $new_obj->setOrderType($this->getOrderType());
1223  $new_obj->setArchiveStart($this->getArchiveStart());
1224  $new_obj->setArchiveEnd($this->getArchiveEnd());
1225  $new_obj->setArchiveType($this->getArchiveType());
1226  $new_obj->setAboStatus($this->getAboStatus());
1227  $new_obj->enableWaitingList($this->enabledWaitingList());
1228  $new_obj->setImportantInformation($this->getImportantInformation());
1229  $new_obj->setShowMembers($this->getShowMembers());
1230  $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
1231  $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
1232  $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
1233  $new_obj->setAutoNotification( $this->getAutoNotification() );
1234  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
1235  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1236  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
1237  $new_obj->setStatusDetermination($this->getStatusDetermination());
1238 
1239  $new_obj->update();
1240  }
1241 
1243  {
1244  global $ilDB;
1245 
1246  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1248 
1249  $query = "INSERT INTO crs_settings (obj_id,syllabus,contact_name,contact_responsibility,".
1250  "contact_phone,contact_email,contact_consultation,activation_type,activation_start,".
1251  "activation_end,sub_limitation_type,sub_start,sub_end,sub_type,sub_password,sub_mem_limit,".
1252  "sub_max_members,sub_notify,view_mode,archive_start,archive_end,archive_type,abo," .
1253  "latitude,longitude,location_zoom,enable_course_map,waiting_list,show_members, ".
1254  "session_limit,session_prev,session_next, reg_ac_enabled, reg_ac, auto_notification, status_dt) ".
1255  "VALUES( ".
1256  $ilDB->quote($this->getId() ,'integer').", ".
1257  $ilDB->quote($this->getSyllabus() ,'text').", ".
1258  $ilDB->quote($this->getContactName() ,'text').", ".
1259  $ilDB->quote($this->getContactResponsibility() ,'text').", ".
1260  $ilDB->quote($this->getContactPhone() ,'text').", ".
1261  $ilDB->quote($this->getContactEmail() ,'text').", ".
1262  $ilDB->quote($this->getContactConsultation() ,'text').", ".
1263  $ilDB->quote(0 ,'integer').", ".
1264  $ilDB->quote($this->getActivationStart() ,'integer').", ".
1265  $ilDB->quote($this->getActivationEnd() ,'integer').", ".
1266  $ilDB->quote(IL_CRS_SUBSCRIPTION_DEACTIVATED ,'integer').", ".
1267  $ilDB->quote($this->getSubscriptionStart() ,'integer').", ".
1268  $ilDB->quote($this->getSubscriptionEnd() ,'integer').", ".
1269  $ilDB->quote(IL_CRS_SUBSCRIPTION_DIRECT ,'integer').", ".
1270  $ilDB->quote($this->getSubscriptionPassword() ,'text').", ".
1271  "0, ".
1272  $ilDB->quote($this->getSubscriptionMaxMembers() ,'integer').", ".
1273  "1, ".
1274  "0, ".
1275  $ilDB->quote($this->getArchiveStart() ,'integer').", ".
1276  $ilDB->quote($this->getArchiveEnd() ,'integer').", ".
1277  $ilDB->quote(IL_CRS_ARCHIVE_NONE ,'integer').", ".
1278  $ilDB->quote($this->ABO_ENABLED ,'integer').", ".
1279  $ilDB->quote($this->getLatitude() ,'text').", ".
1280  $ilDB->quote($this->getLongitude() ,'text').", ".
1281  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
1282  $ilDB->quote($this->getEnableCourseMap() ,'integer').", ".
1283  #"objective_view = '0', ".
1284  "1, ".
1285  "1,".
1286  $ilDB->quote($this->isSessionLimitEnabled(),'integer').', '.
1287  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1288  $ilDB->quote($this->getNumberOfPreviousSessions(),'integer').', '.
1289  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
1290  $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
1291  $ilDB->quote((int)$this->getAutoNotification(),'integer').', '.
1292  $ilDB->quote((int)$this->getStatusDetermination(),'integer').' '.
1293  ")";
1294 
1295  $res = $ilDB->manipulate($query);
1296  $this->__readSettings();
1297 
1298  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1299  $sorting = new ilContainerSortingSettings($this->getId());
1300  $sorting->setSortMode(ilContainer::SORT_MANUAL);
1301  $sorting->update();
1302  }
1303 
1304 
1305  function __readSettings()
1306  {
1307  global $ilDB;
1308 
1309  $query = "SELECT * FROM crs_settings WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')."";
1310 
1311  $res = $ilDB->query($query);
1312  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1313  {
1314  $this->setSyllabus($row->syllabus);
1315  $this->setContactName($row->contact_name);
1316  $this->setContactResponsibility($row->contact_responsibility);
1317  $this->setContactPhone($row->contact_phone);
1318  $this->setContactEmail($row->contact_email);
1319  $this->setContactConsultation($row->contact_consultation);
1320  $this->setOfflineStatus(!(bool)$row->activation_type); // see below
1321  $this->setSubscriptionLimitationType($row->sub_limitation_type);
1322  $this->setSubscriptionStart($row->sub_start);
1323  $this->setSubscriptionEnd($row->sub_end);
1324  $this->setSubscriptionType($row->sub_type);
1325  $this->setSubscriptionPassword($row->sub_password);
1326  $this->enableSubscriptionMembershipLimitation($row->sub_mem_limit);
1327  $this->setSubscriptionMaxMembers($row->sub_max_members);
1328  $this->setSubscriptionNotify($row->sub_notify);
1329  $this->setViewMode($row->view_mode);
1330  $this->setArchiveStart($row->archive_start);
1331  $this->setArchiveEnd($row->archive_end);
1332  $this->setArchiveType($row->archive_type);
1333  $this->setAboStatus($row->abo);
1334  $this->enableWaitingList($row->waiting_list);
1335  $this->setImportantInformation($row->important);
1336  $this->setShowMembers($row->show_members);
1337  $this->setLatitude($row->latitude);
1338  $this->setLongitude($row->longitude);
1339  $this->setLocationZoom($row->location_zoom);
1340  $this->setEnableCourseMap($row->enable_course_map);
1341  $this->enableSessionLimit($row->session_limit);
1342  $this->setNumberOfPreviousSessions($row->session_prev);
1343  $this->setNumberOfNextSessions($row->session_next);
1344  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
1345  $this->setRegistrationAccessCode($row->reg_ac);
1346  $this->setAutoNotification($row->auto_notification == 1 ? true : false);
1347  $this->setStatusDetermination((int) $row->status_dt);
1348  }
1349 
1350  // moved activation to ilObjectActivation
1351  if($this->ref_id)
1352  {
1353  include_once "./Services/Object/classes/class.ilObjectActivation.php";
1354  $activation = ilObjectActivation::getItem($this->ref_id);
1355  switch($activation["timing_type"])
1356  {
1359  $this->setActivationStart($activation["timing_start"]);
1360  $this->setActivationEnd($activation["timing_end"]);
1361  $this->setActivationVisibility($activation["visible"]);
1362  break;
1363 
1364  default:
1366  break;
1367  }
1368  }
1369 
1370  return true;
1371  }
1372 
1373  function initWaitingList()
1374  {
1375  include_once "./Modules/Course/classes/class.ilCourseWaitingList.php";
1376 
1377  if(!is_object($this->waiting_list_obj))
1378  {
1379  $this->waiting_list_obj = new ilCourseWaitingList($this->getId());
1380  }
1381  return true;
1382  }
1383 
1384 
1390  protected function initCourseMemberObject()
1391  {
1392  global $ilUser;
1393 
1394  include_once "./Modules/Course/classes/class.ilCourseParticipant.php";
1395  $this->member_obj = ilCourseParticipant::_getInstanceByObjId($this->getId(),$ilUser->getId());
1396  return true;
1397  }
1398 
1404  protected function initCourseMembersObject()
1405  {
1406  global $ilUser;
1407 
1408  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1409  $this->members_obj = ilCourseParticipants::_getInstanceByObjId($this->getId());
1410  return true;
1411  }
1412 
1417  public function getMemberObject()
1418  {
1419  if(!$this->member_obj instanceof ilCourseParticipant)
1420  {
1421  $this->initCourseMemberObject();
1422  }
1423  return $this->member_obj;
1424  }
1425 
1430  public function getMembersObject()
1431  {
1432  if(!$this->members_obj instanceof ilCourseParticipants)
1433  {
1434  $this->initCourseMembersObject();
1435  }
1436  return $this->members_obj;
1437  }
1438 
1440  {
1441  include_once "./Modules/Course/classes/class.ilCourseArchives.php";
1442 
1443  if(!is_object($this->archives_obj))
1444  {
1445  $this->archives_obj =& new ilCourseArchives($this);
1446  }
1447  return true;
1448  }
1449 
1450 
1451 
1452  // RBAC METHODS
1453  function initDefaultRoles()
1454  {
1455  global $rbacadmin,$rbacreview,$ilDB;
1456 
1457  $rolf_obj = $this->createRoleFolder();
1458 
1459  // CREATE ADMIN ROLE
1460  $role_obj = $rolf_obj->createRole("il_crs_admin_".$this->getRefId(),"Admin of course obj_no.".$this->getId());
1461  $admin_id = $role_obj->getId();
1462 
1463  // SET PERMISSION TEMPLATE OF NEW LOCAL ADMIN ROLE
1464  $query = "SELECT obj_id FROM object_data ".
1465  " WHERE type='rolt' AND title='il_crs_admin'";
1466 
1467  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1468  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1469 
1470  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1471  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1472  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1473 
1474  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1475  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1476  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1477 
1478  // CREATE TUTOR ROLE
1479  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1480  $role_obj = $rolf_obj->createRole("il_crs_tutor_".$this->getRefId(),"Tutors of course obj_no.".$this->getId());
1481  $member_id = $role_obj->getId();
1482 
1483  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1484  $query = "SELECT obj_id FROM object_data ".
1485  " WHERE type='rolt' AND title='il_crs_tutor'";
1486  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1487  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1488 
1489  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1490  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1491  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1492 
1493  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1494  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1495  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1496 
1497  // CREATE MEMBER ROLE
1498  // CREATE ROLE AND ASSIGN ROLE TO ROLEFOLDER...
1499  $role_obj = $rolf_obj->createRole("il_crs_member_".$this->getRefId(),"Member of course obj_no.".$this->getId());
1500  $member_id = $role_obj->getId();
1501 
1502  // SET PERMISSION TEMPLATE OF NEW LOCAL ROLE
1503  $query = "SELECT obj_id FROM object_data ".
1504  " WHERE type='rolt' AND title='il_crs_member'";
1505  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
1506  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
1507 
1508  // SET OBJECT PERMISSIONS OF COURSE OBJECT
1509  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"crs",$rolf_obj->getRefId());
1510  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
1511 
1512  // SET OBJECT PERMISSIONS OF ROLE FOLDER OBJECT
1513  //$ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"rolf",$rolf_obj->getRefId());
1514  //$rbacadmin->grantPermission($role_obj->getId(),$ops,$rolf_obj->getRefId());
1515 
1516  unset($role_obj);
1517  unset($rolf_obj);
1518 
1519  // Break inheritance, create local roles and initialize permission
1520  // settings depending on course status.
1521  $this->__setCourseStatus();
1522 
1523  return true;
1524  }
1525 
1543  {
1544  global $rbacadmin, $rbacreview, $rbacsystem;
1545 
1546  //get Rolefolder of course
1547  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1548 
1549  //define all relevant roles for which rights are needed to be changed
1550  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1551  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultCourseRoles());
1552 
1553  $template_id = $this->__getCrsNonMemberTemplateId();
1554 
1555  //get defined operations from template
1556  if (is_null($template_id))
1557  {
1558  $template_ops = array();
1559  } else {
1560  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'crs', ROLE_FOLDER_ID);
1561  }
1562 
1563  foreach ($arr_relevantParentRoleIds as $parentRole)
1564  {
1565  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1566  {
1567  continue;
1568  }
1569 
1570  $granted_permissions = array();
1571 
1572  // Delete the linked role for the parent role
1573  // (just in case if it already exists).
1574  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1575 
1576  // Grant permissions on the course object for
1577  // the parent role. In the foreach loop we
1578  // compute the intersection of the role
1579  // template il_crs_non_member and the
1580  // permission template of the parent role.
1581  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1582  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1583  foreach ($template_ops as $template_op)
1584  {
1585  if (in_array($template_op,$current_ops))
1586  {
1587  array_push($granted_permissions,$template_op);
1588  }
1589  }
1590  if (!empty($granted_permissions))
1591  {
1592  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1593  }
1594 
1595  // Create a linked role for the parent role and
1596  // initialize it with the intersection of
1597  // il_crs_non_member and the permission
1598  // template of the parent role
1599  if (! is_null($template_id))
1600  {
1601  $rbacadmin->copyRolePermissionIntersection(
1602  $template_id, ROLE_FOLDER_ID,
1603  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1604  $rolf_data["child"], $parentRole
1605  );
1606  }
1607  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1608  }//END foreach
1609  }
1610 
1618  {
1619  global $ilDB;
1620 
1621  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
1622  $res = $this->ilias->db->query($q);
1623  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1624 
1625  return $row["obj_id"];
1626  }
1627 
1634  public function getLocalCourseRoles($a_translate = false)
1635  {
1636  global $rbacadmin,$rbacreview;
1637 
1638  if (empty($this->local_roles))
1639  {
1640  $this->local_roles = array();
1641  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1642  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1643 
1644  foreach ($role_arr as $role_id)
1645  {
1646  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1647  {
1648  $role_Obj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
1649 
1650  if ($a_translate)
1651  {
1652  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1653  }
1654  else
1655  {
1656  $role_name = $role_Obj->getTitle();
1657  }
1658  $this->local_roles[$role_name] = $role_Obj->getId();
1659  }
1660  }
1661  }
1662 
1663  return $this->local_roles;
1664  }
1665 
1666 
1667 
1677  public function getDefaultCourseRoles($a_crs_id = "")
1678  {
1679  global $rbacadmin, $rbacreview;
1680 
1681  if (strlen($a_crs_id) > 0)
1682  {
1683  $crs_id = $a_crs_id;
1684  }
1685  else
1686  {
1687  $crs_id = $this->getRefId();
1688  }
1689 
1690  $rolf = $rbacreview->getRoleFolderOfObject($crs_id);
1691  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1692 
1693  foreach ($role_arr as $role_id)
1694  {
1695  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1696 
1697  $crs_Member ="il_crs_member_".$crs_id;
1698  $crs_Admin ="il_crs_admin_".$crs_id;
1699  $crs_Tutor ="il_crs_tutor_".$crs_id;
1700 
1701  if (strcmp($role_Obj->getTitle(), $crs_Member) == 0 )
1702  {
1703  $arr_crsDefaultRoles["crs_member_role"] = $role_Obj->getId();
1704  }
1705 
1706  if (strcmp($role_Obj->getTitle(), $crs_Admin) == 0)
1707  {
1708  $arr_crsDefaultRoles["crs_admin_role"] = $role_Obj->getId();
1709  }
1710 
1711  if (strcmp($role_Obj->getTitle(), $crs_Tutor) == 0)
1712  {
1713  $arr_crsDefaultRoles["crs_tutor_role"] = $role_Obj->getId();
1714  }
1715  }
1716 
1717  return $arr_crsDefaultRoles;
1718  }
1719 
1720  function __getLocalRoles()
1721  {
1722  global $rbacreview;
1723 
1724  // GET role_objects of predefined roles
1725 
1726  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1727 
1728  return $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1729  }
1730 
1731  function __deleteSettings()
1732  {
1733  global $ilDB;
1734 
1735  $query = "DELETE FROM crs_settings ".
1736  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
1737  $res = $ilDB->manipulate($query);
1738 
1739  return true;
1740  }
1741 
1742 
1744  {
1745  $local_roles = $this->__getLocalRoles();
1746 
1747  foreach($local_roles as $role_id)
1748  {
1749  $title = ilObject::_lookupTitle($role_id);
1750  if(substr($title,0,8) == 'il_crs_m')
1751  {
1752  return $role_id;
1753  }
1754  }
1755  return 0;
1756  }
1758  {
1759  $local_roles = $this->__getLocalRoles();
1760 
1761  foreach($local_roles as $role_id)
1762  {
1763  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1764  {
1765  if(!strcmp($tmp_role->getTitle(),"il_crs_tutor_".$this->getRefId()))
1766  {
1767  return $role_id;
1768  }
1769  }
1770  }
1771  return false;
1772  }
1774  {
1775  $local_roles = $this->__getLocalRoles();
1776 
1777  foreach($local_roles as $role_id)
1778  {
1779  if($tmp_role =& ilObjectFactory::getInstanceByObjId($role_id,false))
1780  {
1781  if(!strcmp($tmp_role->getTitle(),"il_crs_admin_".$this->getRefId()))
1782  {
1783  return $role_id;
1784  }
1785  }
1786  }
1787  return false;
1788  }
1789 
1790  // static method for condition handler
1791  function _checkCondition($a_obj_id,$a_operator,$a_value,$a_usr_id = 0)
1792  {
1793  global $ilUser;
1794 
1795  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
1796 
1797  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1798 
1799  switch($a_operator)
1800  {
1801  case 'passed':
1802  return ilCourseParticipants::_hasPassed($a_obj_id,$a_usr_id);
1803 
1804  default:
1805  return true;
1806  }
1807  }
1808 
1809  function _deleteUser($a_usr_id)
1810  {
1811  // Delete all user related data
1812  // delete lm_history
1813  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
1814  ilCourseLMHistory::_deleteUser($a_usr_id);
1815 
1816  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
1818 
1819  // Course objectives
1820  include_once './Modules/Course/classes/class.ilCourseObjectiveResult.php';
1822  }
1823 
1830  public function MDUpdateListener($a_element)
1831  {
1832  global $ilLog;
1833 
1834  parent::MDUpdateListener($a_element);
1835 
1836  switch($a_element)
1837  {
1838  case 'General':
1839  // Update ecs content
1840  include_once 'Modules/Course/classes/class.ilECSCourseSettings.php';
1841  $ecs = new ilECSCourseSettings($this);
1842  $ecs->handleContentUpdate();
1843  break;
1844 
1845  default:
1846  return true;
1847  }
1848  }
1849 
1854  function addAdditionalSubItemInformation(&$a_item_data)
1855  {
1856  include_once './Services/Object/classes/class.ilObjectActivation.php';
1858  }
1859 
1867  protected function prepareAppointments($a_mode = 'create')
1868  {
1869  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1870  include_once('./Services/Calendar/classes/class.ilDateTime.php');
1871 
1872  switch($a_mode)
1873  {
1874  case 'create':
1875  case 'update':
1876  if(!$this->getActivationUnlimitedStatus() and !$this->getOfflineStatus())
1877  {
1878  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_START);
1879  $app->setTitle($this->getTitle());
1880  $app->setSubtitle('crs_cal_activation_start');
1881  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1882  $app->setDescription($this->getLongDescription());
1883  $app->setStart(new ilDateTime($this->getActivationStart(),IL_CAL_UNIX));
1884  $apps[] = $app;
1885 
1886  $app = new ilCalendarAppointmentTemplate(self::CAL_ACTIVATION_END);
1887  $app->setTitle($this->getTitle());
1888  $app->setSubtitle('crs_cal_activation_end');
1889  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1890  $app->setDescription($this->getLongDescription());
1891  $app->setStart(new ilDateTime($this->getActivationEnd(),IL_CAL_UNIX));
1892  $apps[] = $app;
1893  }
1895  {
1896  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1897  $app->setTitle($this->getTitle());
1898  $app->setSubtitle('crs_cal_reg_start');
1899  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1900  $app->setDescription($this->getLongDescription());
1901  $app->setStart(new ilDateTime($this->getSubscriptionStart(),IL_CAL_UNIX));
1902  $apps[] = $app;
1903 
1904  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1905  $app->setTitle($this->getTitle());
1906  $app->setSubtitle('crs_cal_reg_end');
1907  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1908  $app->setDescription($this->getLongDescription());
1909  $app->setStart(new ilDateTime($this->getSubscriptionEnd(),IL_CAL_UNIX));
1910  $apps[] = $app;
1911  }
1912 
1913  return $apps ? $apps : array();
1914 
1915  case 'delete':
1916  // Nothing to do: The category and all assigned appointments will be deleted.
1917  return array();
1918  }
1919  }
1920 
1921  ###### Interface ilMembershipRegistrationCodes
1922 
1926  public static function lookupObjectsByCode($a_code)
1927  {
1928  global $ilDB;
1929 
1930  $query = "SELECT obj_id FROM crs_settings ".
1931  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1932  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1933  $res = $ilDB->query($query);
1934 
1935  $obj_ids = array();
1936  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1937  {
1938  $obj_ids[] = $row->obj_id;
1939  }
1940  return $obj_ids;
1941  }
1942 
1949  public function register($a_user_id,$a_role = ilCourseConstants::CRS_MEMBER, $a_force_registration = false)
1950  {
1951  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1952  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
1954 
1955  if($part->isAssigned($a_user_id))
1956  {
1957  return true;
1958  }
1959 
1960  if(!$a_force_registration)
1961  {
1962  // Availability
1963  if(!self::_registrationEnabled($this->getId()))
1964  {
1965  $this->lng->loadLanguageModule('crs');
1966  throw new ilMembershipRegistrationException($this->lng->txt('crs_info_reg_deactivated'),$this->getRefId());
1967  }
1968  // Max members
1969  if($this->isSubscriptionMembershipLimited())
1970  {
1971  $free = max(0,$this->getSubscriptionMaxMembers() - $part->getCountMembers());
1972  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
1973  $waiting_list = new ilCourseWaitingList($this->getId());
1974  if($this->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
1975  {
1976  throw new ilMembershipRegistrationException('',$this->getRefId());
1977  }
1978  }
1979  }
1980 
1981  $part->add($a_user_id,$a_role);
1982  $part->sendNotification($part->NOTIFY_ACCEPT_USER, $a_user_id);
1983  $part->sendNotification($part->NOTIFY_ADMINS,$a_user_id);
1984 
1985 
1986  include_once './Modules/Forum/classes/class.ilForumNotification.php';
1988 
1989  return true;
1990  }
1991 
1998  public function getAutoNotification()
1999  {
2000  return $this->auto_notification;
2001  }
2002 
2003 
2010  public function setAutoNotification($value)
2011  {
2012  $this->auto_notification = $value;
2013  }
2014 
2020  public function setStatusDetermination($a_value)
2021  {
2022  $this->status_dt = (int)$a_value;
2023  }
2024 
2030  public function getStatusDetermination()
2031  {
2032  return $this->status_dt;
2033  }
2034 
2038  public function syncMembersStatusWithLP()
2039  {
2040  include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
2041  foreach($this->getMembersObject()->getParticipants() as $user_id)
2042  {
2043  ilLPStatusWrapper::_updateStatus($this->getId(), $user_id);
2044  }
2045  }
2046 
2054  public function checkLPStatusSync($a_member_id)
2055  {
2056  // #11113
2057  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
2060  {
2061  include_once("Services/Tracking/classes/class.ilLPStatus.php");
2062  $has_completed = (ilLPStatus::_lookupStatus($this->getId(), $a_member_id) == LP_STATUS_COMPLETED_NUM);
2063  $this->getMembersObject()->updatePassed($a_member_id, $has_completed, false, true);
2064  }
2065  }
2066 
2067 } //END class.ilObjCourse
2068 ?>