1<?php 2/* 3 +-----------------------------------------------------------------------------+ 4 | ILIAS open source | 5 +-----------------------------------------------------------------------------+ 6 | Copyright (c) 1998-2006 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 24include_once('Services/Calendar/classes/class.ilTimeZone.php'); 25 26/** 27* Stores all calendar relevant settings. 28* 29* @author Stefan Meyer <meyer@leifos.com> 30* @version $Id$ 31* 32* 33* @ingroup ServicesCalendar 34*/ 35class ilCalendarSettings 36{ 37 const WEEK_START_MONDAY = 1; 38 const WEEK_START_SUNDAY = 0; 39 40 const DEFAULT_DAY_START = 8; 41 const DEFAULT_DAY_END = 19; 42 43 const DATE_FORMAT_DMY = 1; 44 const DATE_FORMAT_YMD = 2; 45 const DATE_FORMAT_MDY = 3; 46 47 const TIME_FORMAT_24 = 1; 48 const TIME_FORMAT_12 = 2; 49 50 const DEFAULT_CACHE_MINUTES = 0; 51 const DEFAULT_SYNC_CACHE_MINUTES = 10; 52 53 const DEFAULT_SHOW_WEEKS = true; 54 55 private static $instance = null; 56 57 private $db = null; 58 private $storage = null; 59 private $timezone = null; 60 private $time_format = null; 61 private $week_start = 0; 62 private $day_start = null; 63 private $day_end = null; 64 private $enabled = false; 65 private $cal_settings_id = 0; 66 67 private $consultation_hours = false; 68 69 private $cache_enabled = true; 70 private $cache_minutes = 1; 71 72 private $sync_cache_enabled = true; 73 private $sync_cache_minutes = 10; 74 75 private $notification = false; 76 private $notification_user = false; 77 78 private $cg_registration = false; 79 80 private $course_cal_enabled = true; 81 private $group_cal_enabled = true; 82 83 private $webcal_sync = false; 84 private $webcal_sync_hours = 2; 85 private $show_weeks = false; 86 87 private $batch_file_downloads = false; 88 89 /** 90 * singleton contructor 91 * 92 * @access private 93 * 94 */ 95 private function __construct() 96 { 97 global $DIC; 98 99 $ilDB = $DIC['ilDB']; 100 101 $this->db = $ilDB; 102 103 $this->initStorage(); 104 $this->read(); 105 $this->readCalendarSettingsId(); 106 } 107 108 /** 109 * get singleton instance 110 * 111 * @access public 112 * @static 113 * @return ilCalendarSettings 114 * @return ilCalendarSettings 115 */ 116 public static function _getInstance() 117 { 118 if (self::$instance) { 119 return self::$instance; 120 } 121 return self::$instance = new ilCalendarSettings(); 122 } 123 124 /** 125 * 126 * @param type $a_obj_id 127 */ 128 public static function lookupCalendarActivated($a_obj_id) 129 { 130 if (!ilCalendarSettings::_getInstance()->isEnabled()) { 131 return false; 132 } 133 $type = ilObject::_lookupType($a_obj_id); 134 // lookup global setting 135 $gl_activated = false; 136 switch ($type) { 137 case 'crs': 138 $gl_activated = ilCalendarSettings::_getInstance()->isCourseCalendarEnabled(); 139 break; 140 141 case 'grp': 142 $gl_activated = ilCalendarSettings::_getInstance()->isGroupCalendarEnabled(); 143 break; 144 145 default: 146 return false; 147 } 148 // look individual object setting 149 include_once './Services/Container/classes/class.ilContainer.php'; 150 return ilContainer::_lookupContainerSetting( 151 $a_obj_id, 152 'cont_show_calendar', 153 $gl_activated 154 ); 155 } 156 157 /** 158 * Enable cache 159 * @param object $a_status 160 * @return 161 */ 162 public function useCache($a_status) 163 { 164 $this->cache_enabled = $a_status; 165 } 166 167 /** 168 * Check if cache is used 169 * @return 170 */ 171 public function isCacheUsed() 172 { 173 return $this->cache_enabled; 174 } 175 176 /** 177 * Set time of cache storage 178 * @param int $a_min 179 * @return 180 */ 181 public function setCacheMinutes($a_min) 182 { 183 $this->cache_minutes = $a_min; 184 } 185 186 /** 187 * Get cache minutes 188 * @return 189 */ 190 public function getCacheMinutes() 191 { 192 return (int) $this->cache_minutes; 193 } 194 195 /** 196 * set enabled 197 * 198 * @access public 199 * 200 */ 201 public function setEnabled($a_enabled) 202 { 203 $this->enabled = $a_enabled; 204 } 205 206 /** 207 * is calendar enabled 208 * 209 * @access public 210 * 211 */ 212 public function isEnabled() 213 { 214 return (bool) $this->enabled; 215 } 216 217 /** 218 * set week start 219 * 220 * @access public 221 * 222 */ 223 public function setDefaultWeekStart($a_start) 224 { 225 $this->week_start = $a_start; 226 } 227 228 /** 229 * get default week start 230 * 231 * @access public 232 * 233 */ 234 public function getDefaultWeekStart() 235 { 236 return $this->week_start; 237 } 238 239 /** 240 * set default timezone 241 * 242 * @access public 243 */ 244 public function setDefaultTimeZone($a_zone) 245 { 246 $this->timezone = $a_zone; 247 } 248 249 /** 250 * get derfault time zone 251 * 252 * @access public 253 */ 254 public function getDefaultTimeZone() 255 { 256 return $this->timezone; 257 } 258 259 /** 260 * set default date format 261 * 262 * @access public 263 * @param int date format 264 * @return 265 */ 266 public function setDefaultDateFormat($a_format) 267 { 268 $this->date_format = $a_format; 269 } 270 271 /** 272 * get default date format 273 * 274 * @access public 275 * @return int date format 276 */ 277 public function getDefaultDateFormat() 278 { 279 return $this->date_format; 280 } 281 282 /** 283 * set default time format 284 * 285 * @access public 286 * @param int time format 287 * @return 288 */ 289 public function setDefaultTimeFormat($a_format) 290 { 291 $this->time_format = $a_format; 292 } 293 294 /** 295 * get default time format 296 * 297 * @access public 298 * @return int time format 299 */ 300 public function getDefaultTimeFormat() 301 { 302 return $this->time_format; 303 } 304 305 /** 306 * Get default end of day 307 * @return 308 */ 309 public function getDefaultDayStart() 310 { 311 return $this->day_start; 312 } 313 314 /** 315 * Set default start of day 316 * @return 317 * @param object $a_start 318 */ 319 public function setDefaultDayStart($a_start) 320 { 321 $this->day_start = $a_start; 322 } 323 324 /** 325 * Get default end of day 326 * @return 327 */ 328 public function getDefaultDayEnd() 329 { 330 return $this->day_end; 331 } 332 333 /** 334 * set default end of day 335 * @return 336 * @param object $a_end 337 */ 338 public function setDefaultDayEnd($a_end) 339 { 340 $this->day_end = $a_end; 341 } 342 343 /** 344 * Check if consultation hours are enabled 345 * @return 346 */ 347 public function areConsultationHoursEnabled() 348 { 349 return $this->consultation_hours; 350 } 351 352 /** 353 * En/Disable consultation hours 354 * @return 355 */ 356 public function enableConsultationHours($a_status) 357 { 358 $this->consultation_hours = $a_status; 359 } 360 361 362 /** 363 * Get calendar settings id 364 * (Used for permission checks) 365 * 366 * @access public 367 * @return 368 */ 369 public function getCalendarSettingsId() 370 { 371 return $this->cal_settings_id; 372 } 373 374 /** 375 * Set Enable milestone planning feature for groups. 376 * 377 * @param boolean $a_enablegroupmilestones Enable milestone planning feature for groups 378 */ 379 public function setEnableGroupMilestones($a_enablegroupmilestones) 380 { 381 $this->enablegroupmilestones = $a_enablegroupmilestones; 382 } 383 384 /** 385 * Get Enable milestone planning feature for groups. 386 * 387 * @return boolean Enable milestone planning feature for groups 388 */ 389 public function getEnableGroupMilestones() 390 { 391 return $this->enablegroupmilestones; 392 } 393 394 /** 395 * Check if cache is active for calendar synchronisation 396 * @return 397 */ 398 public function isSynchronisationCacheEnabled() 399 { 400 return (bool) $this->sync_cache_enabled; 401 } 402 403 /** 404 * En/Disable synchronisation cache 405 * @return 406 */ 407 public function enableSynchronisationCache($a_status) 408 { 409 $this->sync_cache_enabled = $a_status; 410 } 411 412 /** 413 * Set synchronisation cache minutes 414 * @param object $a_min 415 * @return 416 */ 417 public function setSynchronisationCacheMinutes($a_min) 418 { 419 $this->sync_cache_minutes = $a_min; 420 } 421 422 /** 423 * get synchronisation cache minutes 424 * @return 425 */ 426 public function getSynchronisationCacheMinutes() 427 { 428 return $this->sync_cache_minutes; 429 } 430 431 /** 432 * Course group notification enabled 433 * @return 434 */ 435 public function isNotificationEnabled() 436 { 437 return (bool) $this->notification; 438 } 439 440 /** 441 * Enable course group notification 442 * @param bool $a_status 443 * @return 444 */ 445 public function enableNotification($a_status) 446 { 447 $this->notification = $a_status; 448 } 449 450 public function isUserNotificationEnabled() 451 { 452 return $this->notification_user; 453 } 454 455 public function enableUserNotification($a_not) 456 { 457 $this->notification_user = $a_not; 458 } 459 460 /** 461 * Enable optional registration for courses and groups 462 * @param bool $a_status 463 * @return 464 */ 465 public function enableCGRegistration($a_status) 466 { 467 $this->cg_registration = $a_status; 468 } 469 470 public function isCGRegistrationEnabled() 471 { 472 return $this->cg_registration; 473 } 474 475 public function enableCourseCalendar($a_stat) 476 { 477 $this->course_cal_enabled = $a_stat; 478 } 479 480 public function isCourseCalendarEnabled() 481 { 482 return $this->course_cal_enabled; 483 } 484 485 public function enableGroupCalendar($a_stat) 486 { 487 $this->group_cal_enabled = $a_stat; 488 } 489 490 public function isGroupCalendarEnabled() 491 { 492 return $this->group_cal_enabled; 493 } 494 495 public function enableWebCalSync($a_stat) 496 { 497 $this->webcal_sync = $a_stat; 498 } 499 500 public function isWebCalSyncEnabled() 501 { 502 return $this->webcal_sync; 503 } 504 505 public function setWebCalSyncHours($a_hours) 506 { 507 $this->webcal_sync_hours = $a_hours; 508 } 509 510 public function getWebCalSyncHours() 511 { 512 return $this->webcal_sync_hours; 513 } 514 515 /** 516 * Set show weeks 517 * 518 * @param bool $a_val show weeks 519 */ 520 public function setShowWeeks($a_val) 521 { 522 $this->show_weeks = $a_val; 523 } 524 525 /** 526 * Get show weeks 527 * 528 * @return bool show weeks 529 */ 530 public function getShowWeeks() 531 { 532 return $this->show_weeks; 533 } 534 535 public function enableBatchFileDownloads($a_stat) 536 { 537 $this->batch_file_downloads = $a_stat; 538 } 539 540 public function isBatchFileDownloadsEnabled() 541 { 542 return $this->batch_file_downloads; 543 } 544 545 /** 546 * save 547 * 548 * @access public 549 */ 550 public function save() 551 { 552 $this->storage->set('enabled', (int) $this->isEnabled()); 553 $this->storage->set('default_timezone', $this->getDefaultTimeZone()); 554 $this->storage->set('default_week_start', $this->getDefaultWeekStart()); 555 $this->storage->set('default_date_format', $this->getDefaultDateFormat()); 556 $this->storage->set('default_time_format', $this->getDefaultTimeFormat()); 557 $this->storage->set('enable_grp_milestones', (int) $this->getEnableGroupMilestones()); 558 $this->storage->set('default_day_start', (int) $this->getDefaultDayStart()); 559 $this->storage->set('default_day_end', (int) $this->getDefaultDayEnd()); 560 $this->storage->set('cache_minutes', (int) $this->getCacheMinutes()); 561 $this->storage->set('sync_cache_enabled', (int) $this->isSynchronisationCacheEnabled()); 562 $this->storage->set('sync_cache_minutes', (int) $this->getSynchronisationCacheMinutes()); 563 $this->storage->set('cache_enabled', (int) $this->isCacheUsed()); 564 $this->storage->set('notification', (int) $this->isNotificationEnabled()); 565 $this->storage->set('consultation_hours', (int) $this->areConsultationHoursEnabled()); 566 $this->storage->set('cg_registration', (int) $this->isCGRegistrationEnabled()); 567 $this->storage->set('course_cal', (int) $this->isCourseCalendarEnabled()); 568 $this->storage->set('group_cal', (int) $this->isGroupCalendarEnabled()); 569 $this->storage->set('notification_user', (int) $this->isUserNotificationEnabled()); 570 $this->storage->set('webcal_sync', (int) $this->isWebCalSyncEnabled()); 571 $this->storage->set('webcal_sync_hours', (int) $this->getWebCalSyncHours()); 572 $this->storage->set('show_weeks', (int) $this->getShowWeeks()); 573 $this->storage->set('batch_files', (int) $this->isBatchFileDownloadsEnabled()); 574 } 575 576 /** 577 * Read settings 578 * 579 * @access private 580 * @param 581 * 582 */ 583 private function read() 584 { 585 $this->setEnabled($this->storage->get('enabled')); 586 $this->setDefaultTimeZone($this->storage->get('default_timezone', ilTimeZone::_getDefaultTimeZone())); 587 $this->setDefaultWeekStart($this->storage->get('default_week_start', self::WEEK_START_MONDAY)); 588 $this->setDefaultDateFormat($this->storage->get('default_date_format', self::DATE_FORMAT_DMY)); 589 $this->setDefaultTimeFormat($this->storage->get('default_time_format', self::TIME_FORMAT_24)); 590 $this->setEnableGroupMilestones($this->storage->get('enable_grp_milestones')); 591 $this->setDefaultDayStart($this->storage->get('default_day_start', self::DEFAULT_DAY_START)); 592 $this->setDefaultDayEnd($this->storage->get('default_day_end', self::DEFAULT_DAY_END)); 593 $this->useCache($this->storage->get('cache_enabled'), $this->cache_enabled); 594 $this->setCacheMinutes($this->storage->get('cache_minutes', self::DEFAULT_CACHE_MINUTES)); 595 $this->enableSynchronisationCache($this->storage->get('sync_cache_enabled'), $this->isSynchronisationCacheEnabled()); 596 $this->setSynchronisationCacheMinutes($this->storage->get('sync_cache_minutes', self::DEFAULT_SYNC_CACHE_MINUTES)); 597 $this->enableNotification($this->storage->get('notification', $this->isNotificationEnabled())); 598 $this->enableConsultationHours($this->storage->get('consultation_hours', $this->areConsultationHoursEnabled())); 599 $this->enableCGRegistration($this->storage->get('cg_registration', $this->isCGRegistrationEnabled())); 600 $this->enableCourseCalendar($this->storage->get('course_cal', $this->isCourseCalendarEnabled())); 601 $this->enableGroupCalendar($this->storage->get('group_cal', $this->isGroupCalendarEnabled())); 602 $this->enableUserNotification($this->storage->get('notification_user', $this->isUserNotificationEnabled())); 603 $this->enableWebCalSync($this->storage->get('webcal_sync', $this->isWebCalSyncEnabled())); 604 $this->setWebCalSyncHours($this->storage->get('webcal_sync_hours', $this->getWebCalSyncHours())); 605 $this->setShowWeeks($this->storage->get('show_weeks', $this->getShowWeeks())); 606 $this->enableBatchFileDownloads($this->storage->get('batch_files', $this->isBatchFileDownloadsEnabled())); 607 } 608 609 /** 610 * Read ref_id of calendar settings 611 * 612 * @access private 613 * @param 614 * @return 615 */ 616 private function readCalendarSettingsId() 617 { 618 $query = "SELECT ref_id FROM object_reference obr " . 619 "JOIN object_data obd ON obd.obj_id = obr.obj_id " . 620 "WHERE type = 'cals'"; 621 622 $set = $this->db->query($query); 623 $row = $this->db->fetchAssoc($set); 624 625 $this->cal_settings_id = $row["ref_id"]; 626 return true; 627 } 628 629 /** 630 * Init storage class (ilSetting) 631 * @access private 632 * 633 */ 634 private function initStorage() 635 { 636 include_once('./Services/Administration/classes/class.ilSetting.php'); 637 $this->storage = new ilSetting('calendar'); 638 } 639} 640