Learnpath: Rename table c_lp_category user - refs #3808

pull/4758/head
christian 1 year ago
parent 2b647a35f4
commit 69f2c46d98
  1. 8
      public/main/lp/lp_subscribe_users_to_category.php
  2. 31
      src/CoreBundle/Migrations/Schema/V200/Version20230622150000.php
  3. 12
      src/CourseBundle/Entity/CLpCategory.php
  4. 6
      src/CourseBundle/Entity/CLpCategoryRelUser.php
  5. 4
      tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php

@ -5,7 +5,7 @@
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CLpCategoryUser;
use Chamilo\CourseBundle\Entity\CLpCategoryRelUser;
use Doctrine\Common\Collections\Criteria;
require_once __DIR__.'/../inc/global.inc.php';
@ -183,7 +183,7 @@ if ($allowUserGroups) {
foreach ($userList as $userId) {
$user = api_get_user_entity($userId);
if ($user) {
$categoryUser = new CLpCategoryUser();
$categoryUser = new CLpCategoryRelUser();
$categoryUser->setUser($user);
$category->addUser($categoryUser);
}
@ -278,7 +278,7 @@ if ($form->validate()) {
if (!empty($userForm)) {
$deleteUsers = [];
if ($subscribedUsersInCategory) {
/** @var CLpCategoryUser $user */
/** @var CLpCategoryRelUser $user */
foreach ($subscribedUsersInCategory as $user) {
$userId = $user->getUser()->getId();
@ -289,7 +289,7 @@ if ($form->validate()) {
}
foreach ($users as $userId) {
$categoryUser = new CLpCategoryUser();
$categoryUser = new CLpCategoryRelUser();
$user = UserManager::getRepository()->find($userId);
if ($user) {
$categoryUser->setUser($user);

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
final class Version20230622150000 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Rename table c_lp_category_user';
}
public function up(Schema $schema): void
{
if ($schema->hasTable('c_lp_category_user')) {
$this->addSql("ALTER TABLE c_lp_category_user RENAME TO c_lp_category_rel_user");
}
}
public function down(Schema $schema): void
{
if ($schema->hasTable('c_lp_category_rel_user')) {
$this->addSql("ALTER TABLE c_lp_category_rel_user RENAME TO c_lp_category_user");
}
}
}

@ -38,9 +38,9 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa
protected int $position;
/**
* @var Collection|CLpCategoryUser[]
* @var Collection|CLpCategoryRelUser[]
*/
#[ORM\OneToMany(targetEntity: \Chamilo\CourseBundle\Entity\CLpCategoryUser::class, mappedBy: 'category', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OneToMany(targetEntity: \Chamilo\CourseBundle\Entity\CLpCategoryRelUser::class, mappedBy: 'category', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected Collection $users;
/**
@ -119,7 +119,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa
}
}
public function addUser(CLpCategoryUser $categoryUser): void
public function addUser(CLpCategoryRelUser $categoryUser): void
{
$categoryUser->setCategory($this);
@ -128,7 +128,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa
}
}
public function hasUser(CLpCategoryUser $categoryUser): bool
public function hasUser(CLpCategoryRelUser $categoryUser): bool
{
if (0 !== $this->getUsers()->count()) {
$criteria = Criteria::create()->where(
@ -148,7 +148,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa
public function hasUserAdded(User $user): bool
{
if (0 !== $this->getUsers()->count()) {
$categoryUser = new CLpCategoryUser();
$categoryUser = new CLpCategoryRelUser();
$categoryUser->setCategory($this);
$categoryUser->setUser($user);
@ -158,7 +158,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa
return false;
}
public function removeUsers(CLpCategoryUser $user): self
public function removeUsers(CLpCategoryRelUser $user): self
{
$this->users->removeElement($user);

@ -12,11 +12,11 @@ use Doctrine\ORM\Mapping as ORM;
use Stringable;
/**
* CLpCategoryUser.
* CLpCategoryRelUser.
*/
#[ORM\Table(name: 'c_lp_category_user')]
#[ORM\Table(name: 'c_lp_category_rel_user')]
#[ORM\Entity]
class CLpCategoryUser implements Stringable
class CLpCategoryRelUser implements Stringable
{
use UserTrait;

@ -7,7 +7,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CLpCategoryUser;
use Chamilo\CourseBundle\Entity\CLpCategoryRelUser;
use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
@ -62,7 +62,7 @@ class CLpCategoryRepositoryTest extends AbstractApiTest
$em->persist($category);
$em->flush();
$categoryRelUser = (new CLpCategoryUser())
$categoryRelUser = (new CLpCategoryRelUser())
->setCategory($category)
->setUser($teacher)
;

Loading…
Cancel
Save