1<?php 2 3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */ 4 5include_once('./Modules/Session/classes/class.ilSessionAppointment.php'); 6include_once './Services/Membership/classes/class.ilMembershipRegistrationSettings.php'; 7 8/** 9* @defgroup ModulesSession Modules/Session 10* 11* @author Stefan Meyer <smeyer.ilias@gmx.de> 12* @version $Id$ 13* 14* @ingroup ModulesSession 15*/ 16class ilObjSession extends ilObject 17{ 18 const MAIL_ALLOWED_ALL = 1; 19 const MAIL_ALLOWED_ADMIN = 2; 20 21 const LOCAL_ROLE_PARTICIPANT_PREFIX = 'il_sess_participant'; 22 23 const CAL_REG_START = 1; 24 25 protected $db; 26 27 protected $location; 28 protected $name; 29 protected $phone; 30 protected $email; 31 protected $details; 32 protected $registration; 33 protected $event_id; 34 35 protected $reg_type = ilMembershipRegistrationSettings::TYPE_NONE; 36 protected $reg_limited = 0; 37 protected $reg_min_users = 0; 38 protected $reg_limited_users = 0; 39 protected $reg_waiting_list = 0; 40 protected $reg_waiting_list_autofill; // [bool] 41 42 /** 43 * @var bool 44 */ 45 protected $show_members = false; 46 47 /** 48 * @var int 49 */ 50 protected $mail_members = self::MAIL_ALLOWED_ADMIN; 51 52 protected $appointments; 53 protected $files = array(); 54 55 /** 56 * @var ilLogger 57 */ 58 protected $session_logger = null; 59 60 /** 61 * @var \ilSessionParticipants 62 */ 63 protected $members_obj; 64 65 private $registrationNotificationEnabled = false; 66 private $notificationOption = ilSessionConstants::NOTIFICATION_INHERIT_OPTION; 67 68 /** 69 * Constructor 70 * @access public 71 * @param integer reference_id or object_id 72 * @param boolean treat the id as reference_id (true) or object_id (false) 73 */ 74 public function __construct($a_id = 0, $a_call_by_reference = true) 75 { 76 global $DIC; 77 78 $ilDB = $DIC['ilDB']; 79 80 $this->session_logger = $GLOBALS['DIC']->logger()->sess(); 81 82 $this->db = $ilDB; 83 $this->type = "sess"; 84 parent::__construct($a_id, $a_call_by_reference); 85 } 86 87 /** 88 * lookup registration enabled 89 * 90 * @access public 91 * @param 92 * @return 93 * @static 94 */ 95 public static function _lookupRegistrationEnabled($a_obj_id) 96 { 97 global $DIC; 98 99 $ilDB = $DIC['ilDB']; 100 101 $query = "SELECT reg_type FROM event " . 102 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " "; 103 $res = $ilDB->query($query); 104 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { 105 return (bool) $row->reg_type != ilMembershipRegistrationSettings::TYPE_NONE; 106 } 107 return false; 108 } 109 110 /** 111 * Get session data 112 * @param object $a_obj_id 113 * @return 114 */ 115 public static function lookupSession($a_obj_id) 116 { 117 global $DIC; 118 119 $ilDB = $DIC['ilDB']; 120 121 $query = "SELECT * FROM event " . 122 "WHERE obj_id = " . $ilDB->quote($a_obj_id); 123 $res = $ilDB->query($query); 124 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { 125 $data['location'] = $row->location ? $row->location : ''; 126 $data['details'] = $row->details ? $row->details : ''; 127 $data['name'] = $row->tutor_name ? $row->tutor_name : ''; 128 $data['email'] = $row->tutor_email ? $row->tutor_email : ''; 129 $data['phone'] = $row->tutor_phone ? $row->tutor_phone : ''; 130 } 131 return (array) $data; 132 } 133 134 /** 135 * get title 136 * (overwritten from base class) 137 * 138 * @access public 139 * @return 140 */ 141 public function getPresentationTitle() 142 { 143 $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(), IL_CAL_UNIX); 144 if ($this->getTitle()) { 145 return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()) . ': ' . $this->getTitle(); 146 } else { 147 return ilDatePresentation::formatDate($date); 148 } 149 } 150 151 /** 152 * @return string 153 */ 154 public function getPresentationTitleAppointmentPeriod() 155 { 156 $title = ''; 157 if ($this->getTitle()) { 158 $title = ': ' . $this->getTitle(); 159 } 160 return ilDatePresentation::formatPeriod( 161 $this->getFirstAppointment()->getStart(), 162 $this->getFirstAppointment()->getEnd() 163 ) . $title; 164 } 165 166 /** 167 * Create local session participant role 168 */ 169 public function initDefaultRoles() 170 { 171 include_once './Services/AccessControl/classes/class.ilObjRole.php'; 172 $role = ilObjRole::createDefaultRole( 173 self::LOCAL_ROLE_PARTICIPANT_PREFIX . '_' . $this->getRefId(), 174 'Participant of session obj_no.' . $this->getId(), 175 self::LOCAL_ROLE_PARTICIPANT_PREFIX, 176 $this->getRefId() 177 ); 178 179 if (!$role instanceof ilObjRole) { 180 $this->session_logger->warning('Could not create default session role.'); 181 $this->session_logger->logStack(ilLogLevel::WARNING); 182 } 183 return array(); 184 } 185 186 /** 187 * sget event id 188 * 189 * @access public 190 * @return 191 */ 192 public function getEventId() 193 { 194 return $this->event_id; 195 } 196 197 /** 198 * set location 199 * 200 * @access public 201 * @param string location 202 */ 203 public function setLocation($a_location) 204 { 205 $this->location = $a_location; 206 } 207 208 /** 209 * get location 210 * 211 * @access public 212 * @return string location 213 */ 214 public function getLocation() 215 { 216 return $this->location; 217 } 218 219 /** 220 * set name 221 * 222 * @access public 223 * @param string name 224 */ 225 public function setName($a_name) 226 { 227 $this->name = $a_name; 228 } 229 230 /** 231 * get name 232 * 233 * @access public 234 * @return string name 235 */ 236 public function getName() 237 { 238 return $this->name; 239 } 240 241 /** 242 * set phone 243 * 244 * @access public 245 * @param string phone 246 */ 247 public function setPhone($a_phone) 248 { 249 $this->phone = $a_phone; 250 } 251 252 /** 253 * get phone 254 * 255 * @access public 256 * @return string phone 257 */ 258 public function getPhone() 259 { 260 return $this->phone; 261 } 262 263 /** 264 * set email 265 * 266 * @access public 267 * @param string email 268 * @return 269 */ 270 public function setEmail($a_email) 271 { 272 $this->email = $a_email; 273 } 274 275 /** 276 * get email 277 * 278 * @access public 279 * @return string email 280 */ 281 public function getEmail() 282 { 283 return $this->email; 284 } 285 286 /** 287 * check if there any tutor settings 288 * 289 * @access public 290 */ 291 public function hasTutorSettings() 292 { 293 return strlen($this->getName()) or 294 strlen($this->getEmail()) or 295 strlen($this->getPhone()); 296 } 297 298 299 /** 300 * set details 301 * 302 * @access public 303 * @param string details 304 */ 305 public function setDetails($a_details) 306 { 307 $this->details = $a_details; 308 } 309 310 /** 311 * get details 312 * 313 * @access public 314 * @return string details 315 */ 316 public function getDetails() 317 { 318 return $this->details; 319 } 320 321 public function setRegistrationType($a_type) 322 { 323 $this->reg_type = $a_type; 324 } 325 326 public function getRegistrationType() 327 { 328 return $this->reg_type; 329 } 330 331 public function isRegistrationUserLimitEnabled() 332 { 333 return $this->reg_limited; 334 } 335 336 public function enableRegistrationUserLimit($a_limit) 337 { 338 $this->reg_limited = $a_limit; 339 } 340 341 public function getRegistrationMinUsers() 342 { 343 return $this->reg_min_users; 344 } 345 346 public function setRegistrationMinUsers($a_users) 347 { 348 $this->reg_min_users = $a_users; 349 } 350 351 public function getRegistrationMaxUsers() 352 { 353 return $this->reg_limited_users; 354 } 355 356 public function setRegistrationMaxUsers($a_users) 357 { 358 $this->reg_limited_users = $a_users; 359 } 360 361 public function isRegistrationWaitingListEnabled() 362 { 363 return $this->reg_waiting_list; 364 } 365 366 public function enableRegistrationWaitingList($a_stat) 367 { 368 $this->reg_waiting_list = $a_stat; 369 } 370 371 public function setWaitingListAutoFill($a_value) 372 { 373 $this->reg_waiting_list_autofill = (bool) $a_value; 374 } 375 376 public function hasWaitingListAutoFill() 377 { 378 return (bool) $this->reg_waiting_list_autofill; 379 } 380 381 /** 382 * Show members gallery 383 * @param $a_status 384 */ 385 public function setShowMembers($a_status) 386 { 387 $this->show_members = (bool) $a_status; 388 } 389 390 /** 391 * Member gallery enabled 392 * @return bool 393 */ 394 public function getShowMembers() 395 { 396 return (bool) $this->show_members; 397 } 398 399 /** 400 * @return bool 401 */ 402 public function isRegistrationNotificationEnabled() 403 { 404 return (bool) $this->registrationNotificationEnabled; 405 } 406 407 /** 408 * @param $value 409 * @return mixed 410 */ 411 public function setRegistrationNotificationEnabled($value) 412 { 413 return $this->registrationNotificationEnabled = $value; 414 } 415 416 /** 417 * @return string 418 */ 419 public function getRegistrationNotificationOption() 420 { 421 return $this->notificationOption; 422 } 423 424 /** 425 * @param $value 426 */ 427 public function setRegistrationNotificationOption($value) 428 { 429 $this->notificationOption = $value; 430 } 431 432 /** 433 * is registration enabled 434 * 435 * @access public 436 * @return 437 */ 438 public function enabledRegistration() 439 { 440 return $this->reg_type != ilMembershipRegistrationSettings::TYPE_NONE; 441 } 442 443 /** 444 * get appointments 445 * 446 * @access public 447 * @return array 448 */ 449 public function getAppointments() 450 { 451 return $this->appointments ? $this->appointments : array(); 452 } 453 454 /** 455 * add appointment 456 * 457 * @access public 458 * @param object ilSessionAppointment 459 * @return 460 */ 461 public function addAppointment($appointment) 462 { 463 $this->appointments[] = $appointment; 464 } 465 466 /** 467 * set appointments 468 * 469 * @access public 470 * @param array ilSessionAppointments 471 * @return 472 */ 473 public function setAppointments($appointments) 474 { 475 $this->appointments = $appointments; 476 } 477 478 /** 479 * get first appointment 480 * 481 * @access public 482 * @return ilSessionAppointment 483 */ 484 public function getFirstAppointment() 485 { 486 return is_object($this->appointments[0]) ? $this->appointments[0] : ($this->appointments[0] = new ilSessionAppointment()); 487 } 488 489 /** 490 * get files 491 * 492 * @access public 493 * @param 494 * @return 495 */ 496 public function getFiles() 497 { 498 return $this->files ? $this->files : array(); 499 } 500 501 502 /** 503 * Set mail to members type 504 * @param int $a_type 505 */ 506 public function setMailToMembersType($a_type) 507 { 508 $this->mail_members = $a_type; 509 } 510 511 /** 512 * Get mail to members type 513 * @return int 514 */ 515 public function getMailToMembersType() 516 { 517 return $this->mail_members; 518 } 519 520 521 /** 522 * validate 523 * 524 * @access public 525 * @param 526 * @return bool 527 */ 528 public function validate() 529 { 530 global $DIC; 531 532 $ilErr = $DIC['ilErr']; 533 534 // #17114 535 if ($this->isRegistrationUserLimitEnabled() && 536 !$this->getRegistrationMaxUsers()) { 537 $ilErr->appendMessage($this->lng->txt("sess_max_members_needed")); 538 return false; 539 } 540 541 return true; 542 } 543 544 /** 545 * Clone course (no member data) 546 * 547 * @access public 548 * @param int target ref_id 549 * @param int copy id 550 * 551 */ 552 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false) 553 { 554 /** 555 * @var ilObjSession 556 */ 557 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree); 558 559 $dtpl = ilDidacticTemplateObjSettings::lookupTemplateId($this->getRefId()); 560 $new_obj->applyDidacticTemplate($dtpl); 561 562 $this->read(); 563 564 $this->cloneSettings($new_obj); 565 $this->cloneMetaData($new_obj); 566 567 568 // Clone appointment 569 $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId()); 570 $new_obj->setAppointments(array($new_app)); 571 $new_obj->update(true); 572 573 // Clone session files 574 foreach ($this->files as $file) { 575 $file->cloneFiles($new_obj->getEventId()); 576 } 577 578 // Raise update forn new appointments 579 580 581 582 // Copy learning progress settings 583 include_once('Services/Tracking/classes/class.ilLPObjSettings.php'); 584 $obj_settings = new ilLPObjSettings($this->getId()); 585 $obj_settings->cloneSettings($new_obj->getId()); 586 unset($obj_settings); 587 588 return $new_obj; 589 } 590 591 /** 592 * clone settings 593 * 594 * @access public 595 * @param ilObjSession 596 * @return 597 */ 598 public function cloneSettings(ilObjSession $new_obj) 599 { 600 ilContainer::_writeContainerSetting( 601 $new_obj->getId(), 602 ilObjectServiceSettingsGUI::CUSTOM_METADATA, 603 ilContainer::_lookupContainerSetting( 604 $this->getId(), 605 ilObjectServiceSettingsGUI::CUSTOM_METADATA 606 ) 607 ); 608 609 // @var 610 $new_obj->setLocation($this->getLocation()); 611 $new_obj->setName($this->getName()); 612 $new_obj->setPhone($this->getPhone()); 613 $new_obj->setEmail($this->getEmail()); 614 $new_obj->setDetails($this->getDetails()); 615 616 $new_obj->setRegistrationType($this->getRegistrationType()); 617 $new_obj->enableRegistrationUserLimit($this->isRegistrationUserLimitEnabled()); 618 $new_obj->enableRegistrationWaitingList($this->isRegistrationWaitingListEnabled()); 619 $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill()); 620 $new_obj->setRegistrationMinUsers($this->getRegistrationMinUsers()); 621 $new_obj->setRegistrationMaxUsers($this->getRegistrationMaxUsers()); 622 $new_obj->setShowMembers($this->getShowMembers()); 623 $new_obj->setMailToMembersType($this->getMailToMembersType()); 624 625 $new_obj->setRegistrationNotificationEnabled($this->isRegistrationNotificationEnabled()); 626 $new_obj->setRegistrationNotificationOption($this->getRegistrationNotificationOption()); 627 628 $new_obj->update(true); 629 630 return true; 631 } 632 633 /** 634 * Clone dependencies 635 * 636 * @param int target id ref_id of new session 637 * @param int copy_id 638 * @return 639 */ 640 public function cloneDependencies($a_target_id, $a_copy_id) 641 { 642 global $DIC; 643 644 $ilObjDataCache = $DIC['ilObjDataCache']; 645 646 parent::cloneDependencies($a_target_id, $a_copy_id); 647 648 $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id); 649 650 include_once('./Modules/Session/classes/class.ilEventItems.php'); 651 $session_materials = new ilEventItems($target_obj_id); 652 $session_materials->cloneItems($this->getId(), $a_copy_id); 653 654 return true; 655 } 656 657 658 659 /** 660 * create new session 661 * 662 * @access public 663 */ 664 public function create($a_skip_meta_data = false) 665 { 666 global $DIC; 667 668 $ilDB = $DIC['ilDB']; 669 global $DIC; 670 671 $ilAppEventHandler = $DIC['ilAppEventHandler']; 672 673 parent::create(); 674 675 if (!$a_skip_meta_data) { 676 $this->createMetaData(); 677 } 678 679 $next_id = $ilDB->nextId('event'); 680 $query = "INSERT INTO event (event_id,obj_id,location,tutor_name,tutor_phone,tutor_email,details,registration, " . 681 'reg_type, reg_limit_users, reg_limited, reg_waiting_list, reg_min_users, reg_auto_wait,show_members,mail_members, 682 reg_notification, notification_opt) ' . 683 "VALUES( " . 684 $ilDB->quote($next_id, 'integer') . ", " . 685 $this->db->quote($this->getId(), 'integer') . ", " . 686 $this->db->quote($this->getLocation(), 'text') . "," . 687 $this->db->quote($this->getName(), 'text') . ", " . 688 $this->db->quote($this->getPhone(), 'text') . ", " . 689 $this->db->quote($this->getEmail(), 'text') . ", " . 690 $this->db->quote($this->getDetails(), 'text') . "," . 691 $this->db->quote($this->enabledRegistration(), 'integer') . ", " . 692 $this->db->quote($this->getRegistrationType(), 'integer') . ', ' . 693 $this->db->quote($this->getRegistrationMaxUsers(), 'integer') . ', ' . 694 $this->db->quote($this->isRegistrationUserLimitEnabled(), 'integer') . ', ' . 695 $this->db->quote($this->isRegistrationWaitingListEnabled(), 'integer') . ', ' . 696 $this->db->quote($this->getRegistrationMinUsers(), 'integer') . ', ' . 697 $this->db->quote($this->hasWaitingListAutoFill(), 'integer') . ', ' . 698 $this->db->quote($this->getShowMembers(), 'integer') . ', ' . 699 $this->db->quote($this->getMailToMembersType(), 'integer') . ',' . 700 $this->db->quote($this->isRegistrationNotificationEnabled(), 'integer') . ', ' . 701 $this->db->quote($this->getRegistrationNotificationOption(), 'text') . 702 ")"; 703 $res = $ilDB->manipulate($query); 704 $this->event_id = $next_id; 705 706 $ilAppEventHandler->raise( 707 'Modules/Session', 708 'create', 709 array('object' => $this, 710 'obj_id' => $this->getId(), 711 'appointments' => $this->prepareCalendarAppointments('create')) 712 ); 713 714 return $this->getId(); 715 } 716 717 /** 718 * update object 719 * 720 * @access public 721 * @param 722 * @return bool success 723 */ 724 public function update($a_skip_meta_update = false) 725 { 726 global $DIC; 727 728 $ilDB = $DIC['ilDB']; 729 global $DIC; 730 731 $ilAppEventHandler = $DIC['ilAppEventHandler']; 732 733 if (!parent::update()) { 734 return false; 735 } 736 if (!$a_skip_meta_update) { 737 $this->updateMetaData(); 738 } 739 740 $query = "UPDATE event SET " . 741 "location = " . $this->db->quote($this->getLocation(), 'text') . "," . 742 "tutor_name = " . $this->db->quote($this->getName(), 'text') . ", " . 743 "tutor_phone = " . $this->db->quote($this->getPhone(), 'text') . ", " . 744 "tutor_email = " . $this->db->quote($this->getEmail(), 'text') . ", " . 745 "details = " . $this->db->quote($this->getDetails(), 'text') . ", " . 746 "registration = " . $this->db->quote($this->enabledRegistration(), 'integer') . ", " . 747 "reg_type = " . $this->db->quote($this->getRegistrationType(), 'integer') . ", " . 748 "reg_limited = " . $this->db->quote($this->isRegistrationUserLimitEnabled(), 'integer') . ", " . 749 "reg_limit_users = " . $this->db->quote($this->getRegistrationMaxUsers(), 'integer') . ", " . 750 "reg_min_users = " . $this->db->quote($this->getRegistrationMinUsers(), 'integer') . ", " . 751 "reg_waiting_list = " . $this->db->quote($this->isRegistrationWaitingListEnabled(), 'integer') . ", " . 752 "reg_auto_wait = " . $this->db->quote($this->hasWaitingListAutoFill(), 'integer') . ", " . 753 'show_members = ' . $this->db->quote($this->getShowMembers(), 'integer') . ', ' . 754 'mail_members = ' . $this->db->quote($this->getMailToMembersType(), 'integer') . ', ' . 755 "reg_auto_wait = " . $this->db->quote($this->hasWaitingListAutoFill(), 'integer') . ", " . 756 "reg_notification = " . $this->db->quote($this->isRegistrationNotificationEnabled(), 'integer') . ", " . 757 "notification_opt = " . $this->db->quote($this->getRegistrationNotificationOption(), 'text') . " " . 758 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer') . " "; 759 $res = $ilDB->manipulate($query); 760 761 $ilAppEventHandler->raise( 762 'Modules/Session', 763 'update', 764 array('object' => $this, 765 'obj_id' => $this->getId(), 766 'appointments' => $this->prepareCalendarAppointments('update')) 767 ); 768 return true; 769 } 770 771 /** 772 * delete session and all related data 773 * 774 * @access public 775 * @return bool 776 */ 777 public function delete() 778 { 779 global $DIC; 780 781 $ilDB = $DIC['ilDB']; 782 global $DIC; 783 784 $ilAppEventHandler = $DIC['ilAppEventHandler']; 785 786 if (!parent::delete()) { 787 return false; 788 } 789 790 // delete meta data 791 $this->deleteMetaData(); 792 793 $query = "DELETE FROM event " . 794 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer') . " "; 795 $res = $ilDB->manipulate($query); 796 797 include_once('./Modules/Session/classes/class.ilSessionAppointment.php'); 798 ilSessionAppointment::_deleteBySession($this->getId()); 799 800 include_once('./Modules/Session/classes/class.ilEventItems.php'); 801 ilEventItems::_delete($this->getId()); 802 803 include_once('./Modules/Session/classes/class.ilEventParticipants.php'); 804 ilEventParticipants::_deleteByEvent($this->getId()); 805 806 foreach ($this->getFiles() as $file) { 807 $file->delete(); 808 } 809 810 $ilAppEventHandler->raise( 811 'Modules/Session', 812 'delete', 813 array('object' => $this, 814 'obj_id' => $this->getId(), 815 'appointments' => $this->prepareCalendarAppointments('delete')) 816 ); 817 818 819 return true; 820 } 821 822 /** 823 * read session data 824 * 825 * @access public 826 * @param 827 * @return 828 */ 829 public function read() 830 { 831 parent::read(); 832 833 $query = "SELECT * FROM event WHERE " . 834 "obj_id = " . $this->db->quote($this->getId(), 'integer') . " "; 835 $res = $this->db->query($query); 836 837 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { 838 $this->setLocation($row->location); 839 $this->setName($row->tutor_name); 840 $this->setPhone($row->tutor_phone); 841 $this->setEmail($row->tutor_email); 842 $this->setDetails($row->details); 843 $this->setRegistrationType($row->reg_type); 844 $this->enableRegistrationUserLimit($row->reg_limited); 845 $this->enableRegistrationWaitingList($row->reg_waiting_list); 846 $this->setWaitingListAutoFill($row->reg_auto_wait); 847 $this->setRegistrationMaxUsers($row->reg_limit_users); 848 $this->setRegistrationMinUsers($row->reg_min_users); 849 $this->setShowMembers((bool) $row->show_members); 850 $this->setMailToMembersType((int) $row->mail_members); 851 $this->setRegistrationNotificationEnabled($row->reg_notification); 852 $this->setRegistrationNotificationOption($row->notification_opt); 853 $this->event_id = $row->event_id; 854 } 855 856 $this->initAppointments(); 857 $this->initFiles(); 858 } 859 860 /** 861 * init appointments 862 * 863 * @access protected 864 * @param 865 * @return 866 */ 867 protected function initAppointments() 868 { 869 // get assigned appointments 870 include_once('./Modules/Session/classes/class.ilSessionAppointment.php'); 871 $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId()); 872 } 873 874 /** 875 * init files 876 * 877 * @access protected 878 * @param 879 * @return 880 */ 881 public function initFiles() 882 { 883 include_once('./Modules/Session/classes/class.ilSessionFile.php'); 884 $this->files = ilSessionFile::_readFilesByEvent($this->getEventId()); 885 } 886 887 888 /** 889 * Prepare calendar appointments 890 * 891 * @access public 892 * @param string mode UPDATE|CREATE|DELETE 893 * @return 894 */ 895 public function prepareCalendarAppointments($a_mode = 'create') 896 { 897 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php'); 898 899 switch ($a_mode) { 900 case 'create': 901 case 'update': 902 903 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START); 904 $app->setTranslationType(IL_CAL_TRANSLATION_NONE); 905 $app->setTitle($this->getTitle() ? $this->getTitle() : $this->lng->txt('obj_sess')); 906 $app->setDescription($this->getLongDescription()); 907 $app->setLocation($this->getLocation()); 908 909 $sess_app = $this->getFirstAppointment(); 910 $app->setFullday($sess_app->isFullday()); 911 $app->setStart($sess_app->getStart()); 912 $app->setEnd($sess_app->getEnd()); 913 $apps[] = $app; 914 915 return $apps; 916 917 case 'delete': 918 // Nothing to do: The category and all assigned appointments will be deleted. 919 return array(); 920 } 921 } 922 923 /** 924 * Handle auto fill for session members 925 */ 926 public function handleAutoFill() 927 { 928 if ( 929 !$this->isRegistrationWaitingListEnabled() || 930 !$this->hasWaitingListAutoFill() 931 ) { 932 $this->session_logger->debug('Waiting list or auto fill is disabled.'); 933 return true; 934 } 935 936 $parts = ilSessionParticipants::_getInstanceByObjId($this->getId()); 937 $current = $parts->getCountParticipants(); 938 $max = $this->getRegistrationMaxUsers(); 939 940 if ($max <= $current) { 941 $this->session_logger->debug('Maximum number of participants not reached.'); 942 $this->session_logger->debug('Maximum number of members: ' . $max); 943 $this->session_logger->debug('Current number of members: ' . $current); 944 return true; 945 } 946 947 $session_waiting_list = new ilSessionWaitingList($this->getId()); 948 foreach ($session_waiting_list->getUserIds() as $user_id) { 949 $user = ilObjectFactory::getInstanceByObjId($user_id); 950 if (!$user instanceof ilObjUser) { 951 $this->session_logger->warning('Found invalid user id on waiting list: ' . $user_id); 952 continue; 953 } 954 if (in_array($user_id, $parts->getParticipants())) { 955 $this->session_logger->notice('User on waiting list already session member: ' . $user_id); 956 continue; 957 } 958 959 if ($this->enabledRegistration()) { 960 $this->session_logger->debug('Registration enabled: register user'); 961 $parts->register($user_id); 962 $parts->sendNotification( 963 ilSessionMembershipMailNotification::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER, 964 $user_id 965 ); 966 } else { 967 $this->session_logger->debug('Registration disabled: set user status to participated.'); 968 $parts->getEventParticipants()->updateParticipation($user_id, true); 969 $parts->sendNotification( 970 ilSessionMembershipMailNotification::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER, 971 $user_id 972 ); 973 } 974 975 $session_waiting_list->removeFromList($user_id); 976 977 $current++; 978 if ($current >= $max) { 979 break; 980 } 981 } 982 } 983 984 985 /** 986 * init participants object 987 * 988 * 989 * @access protected 990 * @return 991 */ 992 protected function initParticipants() 993 { 994 $this->members_obj = ilSessionParticipants::_getInstanceByObjId($this->getId()); 995 } 996 997 /** 998 * Get members objects 999 * 1000 * @return \ilSessionParticipants 1001 */ 1002 public function getMembersObject() 1003 { 1004 if (!$this->members_obj instanceof ilSessionParticipants) { 1005 $this->initParticipants(); 1006 } 1007 return $this->members_obj; 1008 } 1009 1010 /** 1011 * ALways disabled 1012 * @return bool 1013 */ 1014 public function getEnableMap() 1015 { 1016 return false; 1017 } 1018} 1019