| Conditions | 36 |
| Paths | 1154 |
| Total Lines | 676 |
| Code Lines | 463 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 400 | public static function fill_db_course( |
||
| 401 | $course_id, |
||
| 402 | $course_repository, |
||
| 403 | $language, |
||
| 404 | $fill_with_exemplary_content = null, |
||
| 405 | $authorId = 0 |
||
| 406 | ) { |
||
| 407 | if (is_null($fill_with_exemplary_content)) { |
||
| 408 | $fill_with_exemplary_content = api_get_setting('example_material_course_creation') != 'false'; |
||
| 409 | } |
||
| 410 | $course_id = intval($course_id); |
||
| 411 | |||
| 412 | if (empty($course_id)) { |
||
| 413 | return false; |
||
| 414 | } |
||
| 415 | |||
| 416 | $courseInfo = api_get_course_info_by_id($course_id); |
||
| 417 | $authorId = empty($authorId) ? api_get_user_id() : (int) $authorId; |
||
| 418 | |||
| 419 | $tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST); |
||
| 420 | $TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY); |
||
| 421 | $TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||
| 422 | $TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT); |
||
| 423 | $TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING); |
||
| 424 | $TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); |
||
| 425 | $TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
||
| 426 | $visible_for_course_admin = 0; |
||
| 427 | /* Course tools */ |
||
| 428 | Database::query( |
||
| 429 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 430 | VALUES ($course_id, 1, '".TOOL_COURSE_DESCRIPTION."','course_description/','info.gif','".self::string2binary( |
||
| 431 | api_get_setting( |
||
| 432 | 'course_create_active_tools', |
||
| 433 | 'course_description' |
||
| 434 | ) |
||
| 435 | )."','0','squaregrey.gif', 0,'_self','authoring','0')" |
||
| 436 | ); |
||
| 437 | Database::query( |
||
| 438 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 439 | VALUES ($course_id, 2, '".TOOL_CALENDAR_EVENT."','calendar/agenda.php','agenda.gif','".self::string2binary( |
||
| 440 | api_get_setting('course_create_active_tools', 'agenda') |
||
| 441 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 442 | ); |
||
| 443 | Database::query( |
||
| 444 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 445 | VALUES ($course_id, 3, '".TOOL_DOCUMENT."','document/document.php','folder_document.gif','".self::string2binary( |
||
| 446 | api_get_setting('course_create_active_tools', 'documents') |
||
| 447 | )."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 448 | ); |
||
| 449 | Database::query( |
||
| 450 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 451 | VALUES ($course_id, 4, '".TOOL_LEARNPATH."','lp/lp_controller.php','scorms.gif','".self::string2binary( |
||
| 452 | api_get_setting('course_create_active_tools', 'learning_path') |
||
| 453 | )."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 454 | ); |
||
| 455 | Database::query( |
||
| 456 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 457 | VALUES ($course_id, 5, '".TOOL_LINK."','link/link.php','links.gif','".self::string2binary( |
||
| 458 | api_get_setting('course_create_active_tools', 'links') |
||
| 459 | )."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 460 | ); |
||
| 461 | Database::query( |
||
| 462 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 463 | VALUES ($course_id, 6, '".TOOL_QUIZ."','exercise/exercise.php','quiz.gif','".self::string2binary( |
||
| 464 | api_get_setting('course_create_active_tools', 'quiz') |
||
| 465 | )."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 466 | ); |
||
| 467 | Database::query( |
||
| 468 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 469 | VALUES ($course_id, 7, '".TOOL_ANNOUNCEMENT."','announcements/announcements.php','valves.gif','".self::string2binary( |
||
| 470 | api_get_setting('course_create_active_tools', 'announcements') |
||
| 471 | )."','0','squaregrey.gif', 0,'_self','authoring','0')" |
||
| 472 | ); |
||
| 473 | Database::query( |
||
| 474 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 475 | VALUES ($course_id, 8, '".TOOL_FORUM."','forum/index.php','forum.gif','".self::string2binary( |
||
| 476 | api_get_setting('course_create_active_tools', 'forums') |
||
| 477 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 478 | ); |
||
| 479 | Database::query( |
||
| 480 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 481 | VALUES ($course_id, 9, '".TOOL_DROPBOX."','dropbox/index.php','dropbox.gif','".self::string2binary( |
||
| 482 | api_get_setting('course_create_active_tools', 'dropbox') |
||
| 483 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 484 | ); |
||
| 485 | Database::query( |
||
| 486 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 487 | VALUES ($course_id, 10, '".TOOL_USER."','user/user.php','members.gif','".self::string2binary( |
||
| 488 | api_get_setting('course_create_active_tools', 'users') |
||
| 489 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 490 | ); |
||
| 491 | Database::query( |
||
| 492 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 493 | VALUES ($course_id, 11, '".TOOL_GROUP."','group/group.php','group.gif','".self::string2binary( |
||
| 494 | api_get_setting('course_create_active_tools', 'groups') |
||
| 495 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 496 | ); |
||
| 497 | Database::query( |
||
| 498 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 499 | VALUES ($course_id, 12, '".TOOL_CHAT."','chat/chat.php','chat.gif','".self::string2binary( |
||
| 500 | api_get_setting('course_create_active_tools', 'chat') |
||
| 501 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 502 | ); |
||
| 503 | Database::query( |
||
| 504 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 505 | VALUES ($course_id, 13, '".TOOL_STUDENTPUBLICATION."','work/work.php','works.gif','".self::string2binary( |
||
| 506 | api_get_setting( |
||
| 507 | 'course_create_active_tools', |
||
| 508 | 'student_publications' |
||
| 509 | ) |
||
| 510 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 511 | ); |
||
| 512 | Database::query( |
||
| 513 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 514 | VALUES ($course_id, 14, '".TOOL_SURVEY."','survey/survey_list.php','survey.gif','".self::string2binary( |
||
| 515 | api_get_setting('course_create_active_tools', 'survey') |
||
| 516 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 517 | ); |
||
| 518 | Database::query( |
||
| 519 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 520 | VALUES ($course_id, 15, '".TOOL_WIKI."','wiki/index.php','wiki.gif','".self::string2binary( |
||
| 521 | api_get_setting('course_create_active_tools', 'wiki') |
||
| 522 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 523 | ); |
||
| 524 | Database::query( |
||
| 525 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 526 | VALUES ($course_id, 16, '".TOOL_GRADEBOOK."','gradebook/index.php','gradebook.gif','".self::string2binary( |
||
| 527 | api_get_setting('course_create_active_tools', 'gradebook') |
||
| 528 | )."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 529 | ); |
||
| 530 | Database::query( |
||
| 531 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 532 | VALUES ($course_id, 17, '".TOOL_GLOSSARY."','glossary/index.php','glossary.gif','".self::string2binary( |
||
| 533 | api_get_setting('course_create_active_tools', 'glossary') |
||
| 534 | )."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 535 | ); |
||
| 536 | Database::query( |
||
| 537 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 538 | VALUES ($course_id, 18, '".TOOL_NOTEBOOK."','notebook/index.php','notebook.gif','".self::string2binary( |
||
| 539 | api_get_setting('course_create_active_tools', 'notebook') |
||
| 540 | )."','0','squaregrey.gif',0,'_self','interaction','0')" |
||
| 541 | ); |
||
| 542 | |||
| 543 | $setting = intval(self::string2binary( |
||
| 544 | api_get_setting('course_create_active_tools', 'attendances') |
||
| 545 | )); |
||
| 546 | |||
| 547 | Database::query( |
||
| 548 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 549 | VALUES ($course_id, 19, '".TOOL_ATTENDANCE."','attendance/index.php','attendance.gif','".$setting."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 550 | ); |
||
| 551 | Database::query( |
||
| 552 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 553 | VALUES ($course_id, 20, '".TOOL_COURSE_PROGRESS."','course_progress/index.php','course_progress.gif','".self::string2binary( |
||
| 554 | intval(api_get_setting('course_create_active_tools', 'course_progress')) |
||
| 555 | )."','0','squaregrey.gif',0,'_self','authoring','0')" |
||
| 556 | ); |
||
| 557 | |||
| 558 | if (api_get_setting('search_enabled') === 'true') { |
||
| 559 | Database::query( |
||
| 560 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 561 | VALUES ($course_id, 23, '".TOOL_SEARCH."','search/','info.gif','".self::string2binary( |
||
| 562 | api_get_setting( |
||
| 563 | 'course_create_active_tools', |
||
| 564 | 'enable_search' |
||
| 565 | ) |
||
| 566 | )."','0','search.gif',0,'_self','authoring','0')" |
||
| 567 | ); |
||
| 568 | } |
||
| 569 | |||
| 570 | $sql = "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 571 | VALUES ($course_id, 24,'".TOOL_BLOGS."','blog/blog_admin.php','blog_admin.gif','".intval( |
||
| 572 | self::string2binary( |
||
| 573 | api_get_setting('course_create_active_tools', 'blogs') |
||
| 574 | ) |
||
| 575 | )."','1','squaregrey.gif',0,'_self','admin','0')"; |
||
| 576 | Database::query($sql); |
||
| 577 | |||
| 578 | /* Course homepage tools for course admin only */ |
||
| 579 | Database::query( |
||
| 580 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 581 | VALUES ($course_id, 25, '".TOOL_TRACKING."','tracking/courseLog.php','statistics.gif','$visible_for_course_admin','1','', 0,'_self','admin','0')" |
||
| 582 | ); |
||
| 583 | Database::query( |
||
| 584 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 585 | VALUES ($course_id, 26, '".TOOL_COURSE_SETTING."','course_info/infocours.php','reference.gif','$visible_for_course_admin','1','', 0,'_self','admin','0')" |
||
| 586 | ); |
||
| 587 | Database::query( |
||
| 588 | "INSERT INTO $tbl_course_homepage (c_id, id, name, link, image, visibility, admin, address, added_tool, target, category, session_id) |
||
| 589 | VALUES ($course_id, 27, '".TOOL_COURSE_MAINTENANCE."','course_info/maintenance.php','backup.gif','$visible_for_course_admin','1','',0,'_self', 'admin','0')" |
||
| 590 | ); |
||
| 591 | |||
| 592 | $alert = api_get_setting('email_alert_manager_on_new_quiz'); |
||
| 593 | if ($alert === 'true') { |
||
| 594 | $defaultEmailExerciseAlert = 1; |
||
| 595 | } else { |
||
| 596 | $defaultEmailExerciseAlert = 0; |
||
| 597 | } |
||
| 598 | |||
| 599 | /* course_setting table (courseinfo tool) */ |
||
| 600 | $settings = [ |
||
| 601 | 'email_alert_manager_on_new_doc' => ['title' => '', 'default' => 0, 'category' => 'work'], |
||
| 602 | 'email_alert_on_new_doc_dropbox' => ['default' => 0, 'category' => 'dropbox'], |
||
| 603 | 'allow_user_edit_agenda' => ['default' => 0, 'category' => 'agenda'], |
||
| 604 | 'allow_user_edit_announcement' => ['default' => 0, 'category' => 'announcement'], |
||
| 605 | 'email_alert_manager_on_new_quiz' => ['default' => $defaultEmailExerciseAlert, 'category' => 'quiz'], |
||
| 606 | 'allow_user_image_forum' => ['default' => 1, 'category' => 'forum'], |
||
| 607 | 'course_theme' => ['default' => '', 'category' => 'theme'], |
||
| 608 | 'allow_learning_path_theme' => ['default' => 1, 'category' => 'theme'], |
||
| 609 | 'allow_open_chat_window' => ['default' => 1, 'category' => 'chat'], |
||
| 610 | 'email_alert_to_teacher_on_new_user_in_course' => ['default' => 0, 'category' =>'registration'], |
||
| 611 | 'allow_user_view_user_list' => ['default' =>1, 'category' =>'user'], |
||
| 612 | 'display_info_advance_inside_homecourse' => ['default' => 1, 'category' =>'thematic_advance'], |
||
| 613 | 'email_alert_students_on_new_homework' => ['default' => 0, 'category' =>'work'], |
||
| 614 | 'enable_lp_auto_launch' => ['default' => 0, 'category' =>'learning_path'], |
||
| 615 | 'pdf_export_watermark_text' => ['default' =>'', 'category' =>'learning_path'], |
||
| 616 | 'allow_public_certificates' => [ |
||
| 617 | 'default' => api_get_setting('allow_public_certificates') === 'true' ? 1 : '', |
||
| 618 | 'category' =>'certificates' |
||
| 619 | ], |
||
| 620 | 'documents_default_visibility' => ['default' =>'visible', 'category' =>'document'], |
||
| 621 | 'show_course_in_user_language' => ['default' => 2, 'category' => null], |
||
| 622 | ]; |
||
| 623 | |||
| 624 | $counter = 1; |
||
| 625 | foreach ($settings as $variable => $setting) { |
||
| 626 | $title = isset($setting['title']) ? $setting['title'] : ''; |
||
| 627 | Database::query( |
||
| 628 | "INSERT INTO $TABLESETTING (id, c_id, title, variable, value, category) |
||
| 629 | VALUES ($counter, $course_id, '".$title."', '".$variable."', '".$setting['default']."', '".$setting['category']."')" |
||
| 630 | ); |
||
| 631 | $counter++; |
||
| 632 | } |
||
| 633 | |||
| 634 | /* Course homepage tools for platform admin only */ |
||
| 635 | |||
| 636 | /* Group tool */ |
||
| 637 | Database::insert( |
||
| 638 | $TABLEGROUPCATEGORIES, |
||
| 639 | [ |
||
| 640 | 'c_id' => $course_id, |
||
| 641 | 'id' => 2, |
||
| 642 | 'title' => get_lang('DefaultGroupCategory'), |
||
| 643 | 'description' => '', |
||
| 644 | 'max_student' => 8, |
||
| 645 | 'self_reg_allowed' => 0, |
||
| 646 | 'self_unreg_allowed' => 0, |
||
| 647 | 'groups_per_user' => 0, |
||
| 648 | 'display_order' => 0, |
||
| 649 | 'doc_state' => 1, |
||
| 650 | 'calendar_state' => 1, |
||
| 651 | 'work_state' => 1, |
||
| 652 | 'announcements_state' => 1, |
||
| 653 | 'forum_state' => 1, |
||
| 654 | 'wiki_state' => 1, |
||
| 655 | 'chat_state' => 1 |
||
| 656 | ] |
||
| 657 | ); |
||
| 658 | |||
| 659 | $now = api_get_utc_datetime(); |
||
| 660 | |||
| 661 | $files = [ |
||
| 662 | ['path' => '/shared_folder', 'title' => get_lang('UserFolders'), 'filetype' => 'folder', 'size' => 0], |
||
| 663 | ['path' => '/chat_files', 'title' => get_lang('ChatFiles'), 'filetype' => 'folder', 'size' => 0], |
||
| 664 | ]; |
||
| 665 | |||
| 666 | $counter = 1; |
||
| 667 | foreach ($files as $file) { |
||
| 668 | self::insertDocument($course_id, $counter, $file, $authorId); |
||
| 669 | $counter++; |
||
| 670 | } |
||
| 671 | |||
| 672 | $sys_course_path = api_get_path(SYS_COURSE_PATH); |
||
| 673 | $perm = api_get_permissions_for_new_directories(); |
||
| 674 | $perm_file = api_get_permissions_for_new_files(); |
||
| 675 | |||
| 676 | $chat_path = $sys_course_path.$course_repository.'/document/chat_files'; |
||
| 677 | |||
| 678 | if (!is_dir($chat_path)) { |
||
| 679 | @mkdir($chat_path, api_get_permissions_for_new_directories()); |
||
| 680 | } |
||
| 681 | |||
| 682 | /* Documents */ |
||
| 683 | if ($fill_with_exemplary_content) { |
||
| 684 | $files = [ |
||
| 685 | ['path' => '/images', 'title' => get_lang('Images'), 'filetype' => 'folder', 'size' => 0], |
||
| 686 | ['path' => '/images/gallery', 'title' => get_lang('DefaultCourseImages'), 'filetype' => 'folder', 'size' => 0], |
||
| 687 | ['path' => '/audio', 'title' => get_lang('Audio'), 'filetype' => 'folder', 'size' => 0], |
||
| 688 | ['path' => '/flash', 'title' => get_lang('Flash'), 'filetype' => 'folder', 'size' => 0], |
||
| 689 | ['path' => '/video', 'title' => get_lang('Video'), 'filetype' => 'folder', 'size' => 0], |
||
| 690 | ['path' => '/certificates', 'title' => get_lang('Certificates'), 'filetype' => 'folder', 'size' => 0] |
||
| 691 | ]; |
||
| 692 | |||
| 693 | foreach ($files as $file) { |
||
| 694 | self::insertDocument($course_id, $counter, $file, $authorId); |
||
| 695 | $counter++; |
||
| 696 | } |
||
| 697 | |||
| 698 | // FILL THE COURSE DOCUMENT WITH DEFAULT COURSE PICTURES |
||
| 699 | $folders_to_copy_from_default_course = [ |
||
| 700 | 'images', |
||
| 701 | 'audio', |
||
| 702 | 'flash', |
||
| 703 | 'video', |
||
| 704 | 'certificates', |
||
| 705 | ]; |
||
| 706 | |||
| 707 | $default_course_path = api_get_path(SYS_CODE_PATH).'default_course_document/'; |
||
| 708 | |||
| 709 | $default_document_array = []; |
||
| 710 | foreach ($folders_to_copy_from_default_course as $folder) { |
||
| 711 | $default_course_folder_path = $default_course_path.$folder.'/'; |
||
| 712 | $files = self::browse_folders( |
||
| 713 | $default_course_folder_path, |
||
| 714 | [], |
||
| 715 | $folder |
||
| 716 | ); |
||
| 717 | |||
| 718 | $sorted_array = self::sort_pictures($files, 'dir'); |
||
| 719 | $sorted_array = array_merge( |
||
| 720 | $sorted_array, |
||
| 721 | self::sort_pictures($files, 'file') |
||
| 722 | ); |
||
| 723 | $default_document_array[$folder] = $sorted_array; |
||
| 724 | } |
||
| 725 | |||
| 726 | // Light protection (adding index.html in every document folder) |
||
| 727 | $htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>"; |
||
| 728 | |||
| 729 | $example_cert_id = 0; |
||
| 730 | if (is_array($default_document_array) && count( |
||
| 731 | $default_document_array |
||
| 732 | ) > 0 |
||
| 733 | ) { |
||
| 734 | foreach ($default_document_array as $media_type => $array_media) { |
||
| 735 | $path_documents = "/$media_type/"; |
||
| 736 | |||
| 737 | //hack until feature #5242 is implemented |
||
| 738 | if ($media_type == 'images') { |
||
| 739 | $media_type = 'images/gallery'; |
||
| 740 | $images_folder = $sys_course_path.$course_repository."/document/images/"; |
||
| 741 | |||
| 742 | if (!is_dir($images_folder)) { |
||
| 743 | //Creating index.html |
||
| 744 | mkdir($images_folder, $perm); |
||
| 745 | $fd = fopen($images_folder.'index.html', 'w'); |
||
| 746 | fwrite($fd, $htmlpage); |
||
| 747 | @chmod($images_folder.'index.html', $perm_file); |
||
| 748 | } |
||
| 749 | } |
||
| 750 | |||
| 751 | $course_documents_folder = $sys_course_path.$course_repository."/document/$media_type/"; |
||
| 752 | $default_course_path = api_get_path(SYS_CODE_PATH).'default_course_document'.$path_documents; |
||
| 753 | |||
| 754 | if (!is_dir($course_documents_folder)) { |
||
| 755 | // Creating index.html |
||
| 756 | mkdir($course_documents_folder, $perm); |
||
| 757 | $fd = fopen( |
||
| 758 | $course_documents_folder.'index.html', |
||
| 759 | 'w' |
||
| 760 | ); |
||
| 761 | fwrite($fd, $htmlpage); |
||
| 762 | @chmod( |
||
| 763 | $course_documents_folder.'index.html', |
||
| 764 | $perm_file |
||
| 765 | ); |
||
| 766 | } |
||
| 767 | |||
| 768 | if (is_array($array_media) && count($array_media) > 0) { |
||
| 769 | foreach ($array_media as $key => $value) { |
||
| 770 | if (isset($value['dir']) && !empty($value['dir'])) { |
||
| 771 | if (!is_dir($course_documents_folder.$value['dir'])) { |
||
| 772 | //Creating folder |
||
| 773 | mkdir( |
||
| 774 | $course_documents_folder.$value['dir'], |
||
| 775 | $perm |
||
| 776 | ); |
||
| 777 | |||
| 778 | //Creating index.html (for light protection) |
||
| 779 | $index_html = $course_documents_folder.$value['dir'].'/index.html'; |
||
| 780 | $fd = fopen($index_html, 'w'); |
||
| 781 | fwrite($fd, $htmlpage); |
||
| 782 | @chmod($index_html, $perm_file); |
||
| 783 | |||
| 784 | //Inserting folder in the DB |
||
| 785 | $folder_path = substr( |
||
| 786 | $value['dir'], |
||
| 787 | 0, |
||
| 788 | strlen($value['dir']) - 1 |
||
| 789 | ); |
||
| 790 | $temp = explode('/', $folder_path); |
||
| 791 | $title = $temp[count($temp) - 1]; |
||
| 792 | |||
| 793 | //hack until feature #5242 is implemented |
||
| 794 | if ($title == 'gallery') { |
||
| 795 | $title = get_lang( |
||
| 796 | 'DefaultCourseImages' |
||
| 797 | ); |
||
| 798 | } |
||
| 799 | |||
| 800 | if ($media_type == 'images/gallery') { |
||
| 801 | $folder_path = 'gallery/'.$folder_path; |
||
| 802 | } |
||
| 803 | |||
| 804 | Database::query( |
||
| 805 | "INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) |
||
| 806 | VALUES ($course_id,'$path_documents".$folder_path."','".$title."','folder','0')" |
||
| 807 | ); |
||
| 808 | $image_id = Database:: insert_id(); |
||
| 809 | |||
| 810 | Database::insert( |
||
| 811 | $TABLEITEMPROPERTY, |
||
| 812 | [ |
||
| 813 | 'c_id' => $course_id, |
||
| 814 | 'tool' => 'document', |
||
| 815 | 'insert_user_id' => api_get_user_id(), |
||
| 816 | 'insert_date' => $now, |
||
| 817 | 'lastedit_date' => $now, |
||
| 818 | 'ref' => $image_id, |
||
| 819 | 'lastedit_type' => 'DocumentAdded', |
||
| 820 | 'lastedit_user_id' => api_get_user_id(), |
||
| 821 | 'to_group_id' => null, |
||
| 822 | 'to_user_id' => null, |
||
| 823 | 'visibility' => 0 |
||
| 824 | ] |
||
| 825 | ); |
||
| 826 | } |
||
| 827 | } |
||
| 828 | |||
| 829 | if (isset($value['file']) && !empty($value['file'])) { |
||
| 830 | if (!file_exists( |
||
| 831 | $course_documents_folder.$value['file'] |
||
| 832 | ) |
||
| 833 | ) { |
||
| 834 | //Copying file |
||
| 835 | copy( |
||
| 836 | $default_course_path.$value['file'], |
||
| 837 | $course_documents_folder.$value['file'] |
||
| 838 | ); |
||
| 839 | chmod( |
||
| 840 | $course_documents_folder.$value['file'], |
||
| 841 | $perm_file |
||
| 842 | ); |
||
| 843 | //echo $default_course_path.$value['file']; echo ' - '; echo $course_documents_folder.$value['file']; echo '<br />'; |
||
| 844 | $temp = explode('/', $value['file']); |
||
| 845 | $file_size = filesize( |
||
| 846 | $course_documents_folder.$value['file'] |
||
| 847 | ); |
||
| 848 | |||
| 849 | //hack until feature #5242 is implemented |
||
| 850 | if ($media_type == 'images/gallery') { |
||
| 851 | $value["file"] = 'gallery/'.$value["file"]; |
||
| 852 | } |
||
| 853 | |||
| 854 | //Inserting file in the DB |
||
| 855 | Database::query( |
||
| 856 | "INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) |
||
| 857 | VALUES ($course_id,'$path_documents".$value["file"]."','".$temp[count($temp) - 1]."','file','$file_size')" |
||
| 858 | ); |
||
| 859 | $image_id = Database:: insert_id(); |
||
| 860 | if ($image_id) { |
||
| 861 | $sql = "UPDATE $TABLETOOLDOCUMENT SET id = iid WHERE iid = $image_id"; |
||
| 862 | Database::query($sql); |
||
| 863 | |||
| 864 | if ($path_documents.$value['file'] == '/certificates/default.html') { |
||
| 865 | $example_cert_id = $image_id; |
||
| 866 | } |
||
| 867 | $docId = Database::insert( |
||
| 868 | $TABLEITEMPROPERTY, |
||
| 869 | [ |
||
| 870 | 'c_id' => $course_id, |
||
| 871 | 'tool' => 'document', |
||
| 872 | 'insert_user_id' => api_get_user_id(), |
||
| 873 | 'insert_date' => $now, |
||
| 874 | 'lastedit_date' => $now, |
||
| 875 | 'ref' => $image_id, |
||
| 876 | 'lastedit_type' => 'DocumentAdded', |
||
| 877 | 'lastedit_user_id' => api_get_user_id(), |
||
| 878 | 'to_group_id' => null, |
||
| 879 | 'to_user_id' => null, |
||
| 880 | 'visibility' => 1 |
||
| 881 | ] |
||
| 882 | ); |
||
| 883 | if ($docId) { |
||
| 884 | $sql = "UPDATE $TABLEITEMPROPERTY SET id = iid WHERE iid = $docId"; |
||
| 885 | Database::query($sql); |
||
| 886 | } |
||
| 887 | } |
||
| 888 | } |
||
| 889 | } |
||
| 890 | } |
||
| 891 | } |
||
| 892 | } |
||
| 893 | } |
||
| 894 | |||
| 895 | $agenda = new Agenda('course'); |
||
| 896 | $agenda->set_course($courseInfo); |
||
| 897 | $agenda->addEvent( |
||
| 898 | $now, |
||
| 899 | $now, |
||
| 900 | 0, |
||
| 901 | get_lang('AgendaCreationTitle'), |
||
| 902 | get_lang('AgendaCreationContenu') |
||
| 903 | ); |
||
| 904 | |||
| 905 | /* Links tool */ |
||
| 906 | |||
| 907 | $link = new Link(); |
||
| 908 | $link->setCourse($courseInfo); |
||
| 909 | $links = [ |
||
| 910 | [ |
||
| 911 | 'c_id' => $course_id, |
||
| 912 | 'url' => 'http://www.google.com', |
||
| 913 | 'title' => 'Google', |
||
| 914 | 'description' => get_lang('Google'), |
||
| 915 | 'category_id' => 0, |
||
| 916 | 'on_homepage' => 0, |
||
| 917 | 'target' => '_self', |
||
| 918 | 'session_id' => 0 |
||
| 919 | ], |
||
| 920 | [ |
||
| 921 | 'c_id' => $course_id, |
||
| 922 | 'url' => 'http://www.wikipedia.org', |
||
| 923 | 'title' => 'Wikipedia', |
||
| 924 | 'description' => get_lang('Wikipedia'), |
||
| 925 | 'category_id' => 0, |
||
| 926 | 'on_homepage' => 0, |
||
| 927 | 'target' => '_self', |
||
| 928 | 'session_id' => 0 |
||
| 929 | ] |
||
| 930 | ]; |
||
| 931 | |||
| 932 | foreach ($links as $params) { |
||
| 933 | $link->save($params); |
||
| 934 | } |
||
| 935 | |||
| 936 | /* Announcement tool */ |
||
| 937 | AnnouncementManager::add_announcement( |
||
| 938 | $courseInfo, |
||
| 939 | 0, |
||
| 940 | get_lang('AnnouncementExampleTitle'), |
||
| 941 | get_lang('AnnouncementEx'), |
||
| 942 | ['everyone' => 'everyone'], |
||
| 943 | null, |
||
| 944 | null, |
||
| 945 | $now |
||
| 946 | ); |
||
| 947 | |||
| 948 | $manager = Database::getManager(); |
||
| 949 | |||
| 950 | /* Introduction text */ |
||
| 951 | $intro_text = '<p style="text-align: center;"> |
||
| 952 | <img src="' . api_get_path(REL_CODE_PATH).'img/mascot.png" alt="Mr. Chamilo" title="Mr. Chamilo" /> |
||
| 953 | <h2>' . get_lang('IntroductionText').'</h2> |
||
| 954 | </p>'; |
||
| 955 | |||
| 956 | $toolIntro = new CToolIntro(); |
||
| 957 | $toolIntro |
||
| 958 | ->setCId($course_id) |
||
| 959 | ->setId(TOOL_COURSE_HOMEPAGE) |
||
| 960 | ->setSessionId(0) |
||
| 961 | ->setIntroText($intro_text); |
||
| 962 | $manager->persist($toolIntro); |
||
| 963 | |||
| 964 | $toolIntro = new CToolIntro(); |
||
| 965 | $toolIntro |
||
| 966 | ->setCId($course_id) |
||
| 967 | ->setId(TOOL_STUDENTPUBLICATION) |
||
| 968 | ->setSessionId(0) |
||
| 969 | ->setIntroText(get_lang('IntroductionTwo')); |
||
| 970 | $manager->persist($toolIntro); |
||
| 971 | |||
| 972 | $toolIntro = new CToolIntro(); |
||
| 973 | $toolIntro |
||
| 974 | ->setCId($course_id) |
||
| 975 | ->setId(TOOL_WIKI) |
||
| 976 | ->setSessionId(0) |
||
| 977 | ->setIntroText(get_lang('IntroductionWiki')); |
||
| 978 | $manager->persist($toolIntro); |
||
| 979 | |||
| 980 | $manager->flush(); |
||
| 981 | |||
| 982 | /* Exercise tool */ |
||
| 983 | $exercise = new Exercise($course_id); |
||
| 984 | $exercise->exercise = get_lang('ExerciceEx'); |
||
| 985 | $html = '<table width="100%" border="0" cellpadding="0" cellspacing="0"> |
||
| 986 | <tr> |
||
| 987 | <td width="220" valign="top" align="left"> |
||
| 988 | <img src="' . api_get_path(WEB_CODE_PATH).'default_course_document/images/mr_chamilo/doubts.png"> |
||
| 989 | </td> |
||
| 990 | <td valign="top" align="left">' . get_lang('Antique').'</td></tr> |
||
| 991 | </table>'; |
||
| 992 | $exercise->type = 1; |
||
| 993 | $exercise->setRandom(0); |
||
| 994 | $exercise->active = 1; |
||
| 995 | $exercise->results_disabled = 0; |
||
| 996 | $exercise->description = $html; |
||
| 997 | $exercise->save(); |
||
| 998 | |||
| 999 | $exercise_id = $exercise->id; |
||
| 1000 | |||
| 1001 | $question = new MultipleAnswer(); |
||
| 1002 | $question->question = get_lang('SocraticIrony'); |
||
| 1003 | $question->description = get_lang('ManyAnswers'); |
||
| 1004 | $question->weighting = 10; |
||
| 1005 | $question->position = 1; |
||
| 1006 | $question->course = $courseInfo; |
||
| 1007 | $question->save($exercise); |
||
| 1008 | $questionId = $question->id; |
||
| 1009 | |||
| 1010 | $answer = new Answer($questionId, $courseInfo['real_id']); |
||
| 1011 | |||
| 1012 | $answer->createAnswer(get_lang('Ridiculise'), 0, get_lang('NoPsychology'), -5, 1); |
||
| 1013 | $answer->createAnswer(get_lang('AdmitError'), 0, get_lang('NoSeduction'), -5, 2); |
||
| 1014 | $answer->createAnswer(get_lang('Force'), 1, get_lang('Indeed'), 5, 3); |
||
| 1015 | $answer->createAnswer(get_lang('Contradiction'), 1, get_lang('NotFalse'), 5, 4); |
||
| 1016 | $answer->save(); |
||
| 1017 | |||
| 1018 | /* Forum tool */ |
||
| 1019 | |||
| 1020 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
||
| 1021 | |||
| 1022 | $params = [ |
||
| 1023 | 'forum_category_title' => get_lang('ExampleForumCategory'), |
||
| 1024 | 'forum_category_comment' => '' |
||
| 1025 | ]; |
||
| 1026 | |||
| 1027 | $forumCategoryId = store_forumcategory($params, $courseInfo, false); |
||
| 1028 | |||
| 1029 | $params = [ |
||
| 1030 | 'forum_category' => $forumCategoryId, |
||
| 1031 | 'forum_title' => get_lang('ExampleForum'), |
||
| 1032 | 'forum_comment' => '', |
||
| 1033 | 'default_view_type_group' => ['default_view_type' => 'flat'], |
||
| 1034 | ]; |
||
| 1035 | |||
| 1036 | $forumId = store_forum($params, $courseInfo, true); |
||
| 1037 | |||
| 1038 | $forumInfo = get_forum_information($forumId, $courseInfo['real_id']); |
||
| 1039 | |||
| 1040 | $params = [ |
||
| 1041 | 'post_title' => get_lang('ExampleThread'), |
||
| 1042 | 'forum_id' => $forumId, |
||
| 1043 | 'post_text' => get_lang('ExampleThreadContent'), |
||
| 1044 | 'calification_notebook_title' => '', |
||
| 1045 | 'numeric_calification' => '', |
||
| 1046 | 'weight_calification' => '', |
||
| 1047 | 'forum_category' => $forumCategoryId, |
||
| 1048 | 'thread_peer_qualify' => 0, |
||
| 1049 | ]; |
||
| 1050 | |||
| 1051 | store_thread($forumInfo, $params, $courseInfo, false); |
||
| 1052 | |||
| 1053 | /* Gradebook tool */ |
||
| 1054 | $course_code = $courseInfo['code']; |
||
| 1055 | // father gradebook |
||
| 1056 | Database::query( |
||
| 1057 | "INSERT INTO $TABLEGRADEBOOK (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id) |
||
| 1058 | VALUES ('$course_code','',1,'$course_code',0,100,0,75,NULL,$example_cert_id)" |
||
| 1059 | ); |
||
| 1060 | $gbid = Database:: insert_id(); |
||
| 1061 | Database::query( |
||
| 1062 | "INSERT INTO $TABLEGRADEBOOK (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id) |
||
| 1063 | VALUES ('$course_code','',1,'$course_code',$gbid,100,1,75,NULL,$example_cert_id)" |
||
| 1064 | ); |
||
| 1065 | $gbid = Database:: insert_id(); |
||
| 1066 | Database::query( |
||
| 1067 | "INSERT INTO $TABLEGRADEBOOKLINK (type, ref_id, user_id, course_code, category_id, created_at, weight, visible, locked) |
||
| 1068 | VALUES (1,$exercise_id,1,'$course_code',$gbid,'$now',100,1,0)" |
||
| 1069 | ); |
||
| 1070 | } |
||
| 1071 | |||
| 1072 | //Installing plugins in course |
||
| 1073 | $app_plugin = new AppPlugin(); |
||
| 1074 | $app_plugin->install_course_plugins($course_id); |
||
| 1075 | return true; |
||
| 1076 | } |
||
| 1427 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.