@@ -531,6 +531,7 @@ public static function get_group_properties($group_id, $useIid = false)
531531 self ::get_subscribed_tutors ($ result )
532532 );
533533 $ result ['count_all ' ] = $ result ['count_users ' ] + $ result ['count_tutor ' ];
534+ $ result ['document_access ' ] = isset ($ db_object ->document_access ) ? $ db_object ->document_access : 0 ;
534535 }
535536
536537 return $ result ;
@@ -620,6 +621,7 @@ public static function getGroupListFilterByName($name, $categoryId, $courseId)
620621 * @param bool Whether self registration is allowed or not
621622 * @param bool Whether self unregistration is allowed or not
622623 * @param int $categoryId
624+ * @param int $documentAccess
623625 *
624626 * @return bool TRUE if properties are successfully changed, false otherwise
625627 */
@@ -637,14 +639,22 @@ public static function set_group_properties(
637639 $ chat_state ,
638640 $ self_registration_allowed ,
639641 $ self_unregistration_allowed ,
640- $ categoryId = null
642+ $ categoryId = null ,
643+ $ documentAccess = 0
641644 ) {
642645 $ table_group = Database::get_course_table (TABLE_GROUP );
643646 $ table_forum = Database::get_course_table (TABLE_FORUM );
644647 $ categoryId = intval ($ categoryId );
645648 $ group_id = intval ($ group_id );
646649 $ course_id = api_get_course_int_id ();
647650
651+ $ allowDocumentAccess = api_get_configuration_value ('group_document_access ' );
652+ $ documentCondition = '' ;
653+ if ($ allowDocumentAccess ) {
654+ $ documentAccess = (int ) $ documentAccess ;
655+ $ documentCondition = " document_access = $ documentAccess, " ;
656+ }
657+
648658 $ sql = "UPDATE " .$ table_group ." SET
649659 name=' " .Database::escape_string (trim ($ name ))."',
650660 doc_state = ' " .Database::escape_string ($ doc_state )."',
@@ -658,10 +668,12 @@ public static function set_group_properties(
658668 max_student = ' " .Database::escape_string ($ maximum_number_of_students )."',
659669 self_registration_allowed = ' " .Database::escape_string ($ self_registration_allowed )."',
660670 self_unregistration_allowed = ' " .Database::escape_string ($ self_unregistration_allowed )."',
671+ $ documentCondition
661672 category_id = " .intval ($ categoryId )."
662673 WHERE c_id = $ course_id AND id= " .$ group_id ;
663674 $ result = Database::query ($ sql );
664675
676+
665677 /* Here we are updating a field in the table forum_forum that perhaps
666678 duplicates the table group_info.forum_state cvargas*/
667679 $ forum_state = (int ) $ forum_state ;
@@ -2955,4 +2967,32 @@ public static function setInvisible($groupId)
29552967 {
29562968 self ::setStatus ($ groupId , 0 );
29572969 }
2970+
2971+ /**
2972+ * @param int $userId
2973+ * @param int $courseId
2974+ * @param array $groupInfo
2975+ * @param bool $blockPage
2976+ */
2977+ public static function allowUploadEditDocument ($ userId , $ courseId , $ groupInfo , $ blockPage = false )
2978+ {
2979+ $ allow = api_get_configuration_value ('group_document_access ' );
2980+ if (!$ allow ) {
2981+ return true ;
2982+ }
2983+
2984+ if (isset ($ groupInfo ['document_access ' ]) &&
2985+ $ groupInfo ['document_access ' ] == 1 &&
2986+ (!api_is_allowed_to_edit () ||
2987+ (!api_is_allowed_to_edit () && !GroupManager::is_tutor_of_group ($ userId , $ groupInfo , $ courseId ))
2988+ )
2989+ ) {
2990+ if ($ blockPage ) {
2991+ api_not_allowed (true );
2992+ }
2993+ return false ;
2994+ }
2995+
2996+ return true ;
2997+ }
29582998}
0 commit comments