Internal: Fix course creation, fix group category creation

Add behat test
pull/3464/head
Julio Montoya 4 years ago
parent bc2785ec7b
commit 9c6c3f545d
  1. 2
      .travis.yml
  2. 27
      public/main/inc/lib/add_course.lib.inc.php
  3. 15
      public/main/inc/lib/api.lib.php
  4. 15
      public/main/inc/lib/groupmanager.lib.php
  5. 14
      src/CourseBundle/Entity/CGroupCategory.php
  6. 2
      tests/behat/features/toolGroup.feature

@ -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

@ -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],

@ -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 */

@ -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;
}

@ -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

@ -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"

Loading…
Cancel
Save