diff --git a/.travis.yml b/.travis.yml index 5e12bc3dd8..e0ad6e4511 100755 --- a/.travis.yml +++ b/.travis.yml @@ -124,7 +124,7 @@ script: # - ../../vendor/behat/behat/bin/behat features/toolDocument.feature -v # - ../../vendor/behat/behat/bin/behat features/toolExercise.feature -v # - ../../vendor/behat/behat/bin/behat features/toolForum.feature -v -# - ../../vendor/behat/behat/bin/behat features/toolGroup.feature -v + - ../../vendor/behat/behat/bin/behat features/toolGroup.feature -vvv # - ../../vendor/behat/behat/bin/behat features/toolLink.feature -v # - ../../vendor/behat/behat/bin/behat features/toolLp.feature -v # - ../../vendor/behat/behat/bin/behat features/toolWork.feature -v diff --git a/public/main/inc/lib/add_course.lib.inc.php b/public/main/inc/lib/add_course.lib.inc.php index aea46703de..2fca2d15b1 100644 --- a/public/main/inc/lib/add_course.lib.inc.php +++ b/public/main/inc/lib/add_course.lib.inc.php @@ -2,6 +2,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Framework\Container; +use Chamilo\CourseBundle\Entity\CGroupCategory; use Chamilo\CourseBundle\Entity\CToolIntro; /** @@ -303,27 +304,15 @@ class AddCourse /* Course homepage tools for platform admin only */ /* Group tool */ - Database::insert( - $TABLEGROUPCATEGORIES, - [ - 'title' => get_lang('Default groups'), - 'description' => '', - 'max_student' => 0, - 'self_reg_allowed' => 0, - 'self_unreg_allowed' => 0, - 'groups_per_user' => 0, - 'doc_state' => 1, - 'calendar_state' => 1, - 'work_state' => 1, - 'announcements_state' => 1, - 'forum_state' => 1, - 'wiki_state' => 1, - 'chat_state' => 1, - ] - ); + $groupCategory = new CGroupCategory(); + $groupCategory + ->setTitle(get_lang('Default groups')) + ->setParent($course) + ->addCourseLink($course) + ; + Database::getManager()->persist($groupCategory); $now = api_get_utc_datetime(); - $files = [ ['path' => '/shared_folder', 'title' => get_lang('Folders of users'), 'filetype' => 'folder', 'size' => 0], ['path' => '/chat_files', 'title' => get_lang('Chat conversations history'), 'filetype' => 'folder', 'size' => 0], diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index fd065a1d8e..c3c613b629 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Entity\SettingsCurrent; use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Framework\Container; use Chamilo\CourseBundle\Entity\CGroup; +use Chamilo\CourseBundle\Entity\CLp; use ChamiloSession as Session; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\Finder\Finder; @@ -1841,14 +1842,14 @@ function api_get_user_info_from_entity( return $result; } -/** - * @param int $userId - * - * @return User - */ -function api_get_user_entity($userId) +function api_get_lp_entity(int $id): ? CLp +{ + return Database::getManager()->getRepository(CLp::class)->find($id); +} + +function api_get_user_entity(int $userId = 0): ?User { - $userId = (int) $userId; + $userId = $userId ?: api_get_user_id(); $repo = UserManager::getRepository(); /** @var User $user */ diff --git a/public/main/inc/lib/groupmanager.lib.php b/public/main/inc/lib/groupmanager.lib.php index 65d05da01f..8aa5a02567 100644 --- a/public/main/inc/lib/groupmanager.lib.php +++ b/public/main/inc/lib/groupmanager.lib.php @@ -967,7 +967,7 @@ class GroupManager $table_group_cat = Database::get_course_table(TABLE_GROUP_CATEGORY); $cat_id = (int) $cat_id; $sql = "SELECT iid FROM $table_group - WHERE c_id = $course_id AND category_id='".$cat_id."'"; + WHERE category_id='".$cat_id."'"; $res = Database::query($sql); if (Database::num_rows($res) > 0) { while ($group = Database::fetch_object($res)) { @@ -980,9 +980,16 @@ class GroupManager Database::query($sql); } } - $sql = "DELETE FROM $table_group_cat - WHERE c_id = $course_id AND iid='".$cat_id."'"; - Database::query($sql); + + $category = Database::getManager()->getRepository(CGroupCategory::class)->find($cat_id); + if ($category) { + Database::getManager()->remove($category); + Database::getManager()->flush(); + } + + /*$sql = "DELETE FROM $table_group_cat + WHERE iid='".$cat_id."'"; + Database::query($sql);*/ return true; } diff --git a/src/CourseBundle/Entity/CGroupCategory.php b/src/CourseBundle/Entity/CGroupCategory.php index f4e76e2fbb..711a0b7a22 100644 --- a/src/CourseBundle/Entity/CGroupCategory.php +++ b/src/CourseBundle/Entity/CGroupCategory.php @@ -132,6 +132,20 @@ class CGroupCategory extends AbstractResource implements ResourceInterface public function __construct() { + $this->maxStudent = 0; + $this->description = ''; + $this->selfRegAllowed = 0; + $this->selfUnregAllowed = 0; + $this->groupsPerUser = 0; + + $this->announcementsState = 1; + $this->calendarState = 1; + $this->documentAccess = 1; + $this->chatState = 1; + $this->docState = 1; + $this->forumState = 1; + $this->wikiState = 1; + $this->workState = 1; } public function __toString(): string diff --git a/tests/behat/features/toolGroup.feature b/tests/behat/features/toolGroup.feature index d04a8378a8..8c1853e6d0 100644 --- a/tests/behat/features/toolGroup.feature +++ b/tests/behat/features/toolGroup.feature @@ -15,6 +15,7 @@ Feature: Group tool Scenario: Create a group directory Given I am on "/main/group/group_category.php?cid=1&sid=0&action=add_category" + And wait for the page to be loaded When I fill in the following: | title | Group category 1 | And I press "group_category_submit" @@ -40,7 +41,6 @@ Feature: Group tool And I press "submit" Then I should see "group(s) has (have) been added" - Scenario: Create document folder in group Given I am on "/main/group/group.php?cid=1&sid=0" And I follow "Group 0001"