diff --git a/public/main/inc/lib/SkillModel.php b/public/main/inc/lib/SkillModel.php index 37ecb3777e..bfcaed0953 100644 --- a/public/main/inc/lib/SkillModel.php +++ b/public/main/inc/lib/SkillModel.php @@ -288,7 +288,7 @@ class SkillModel extends Model 'criteria' => $skill->getCriteria(), 'status' => $skill->getStatus(), 'asset_id' => (string) $skill->getAsset()?->getId(), - 'profile_id' => $skill->getProfile()?->getId(), + 'profile_id' => $skill->getLevelProfile()?->getId(), 'icons_small' => sprintf('badges/%s-small.png', sha1($skill['title'])), ]; } @@ -1023,7 +1023,7 @@ class SkillModel extends Model if (!empty($skills)) { foreach ($skills as &$skill) { if (0 == $skill['parent_id']) { - $skill['parent_id'] = 1; + $skill['parent_id'] = '-1'; } // because except main keys (id, title, children) others keys @@ -1070,7 +1070,7 @@ class SkillModel extends Model // Check if the skill has related gradebooks $skill['data']['skill_has_gradebook'] = false; - if (isset($skill['gradebooks']) && !empty($skill['gradebooks'])) { + if (!empty($skill['gradebooks'])) { $skill['data']['skill_has_gradebook'] = true; } $refs[$skill['id']] = &$skill; diff --git a/public/main/skills/assign.php b/public/main/skills/assign.php index 6bb719aead..cc8691a48f 100644 --- a/public/main/skills/assign.php +++ b/public/main/skills/assign.php @@ -123,13 +123,13 @@ $skillId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : key($skillsOptions); $skill = $skillRepo->find($skillId); $profile = false; if ($skill) { - $profile = $skill->getProfile(); + $profile = $skill->getLevelProfile(); } if (!empty($subSkillList)) { $skillFromLastSkill = $skillRepo->find(end($subSkillList)); if ($skillFromLastSkill) { - $profile = $skillFromLastSkill->getProfile(); + $profile = $skillFromLastSkill->getLevelProfile(); } } @@ -139,7 +139,7 @@ if (!$profile) { krsort($parents); foreach ($parents as $parent) { $skillParentId = $parent['skill_id']; - $profile = $skillRepo->find($skillParentId)->getProfile(); + $profile = $skillRepo->find($skillParentId)->getLevelProfile(); if ($profile) { break; diff --git a/public/main/skills/skill.php b/public/main/skills/skill.php index b1ea9e3b92..155e348134 100644 --- a/public/main/skills/skill.php +++ b/public/main/skills/skill.php @@ -1,7 +1,7 @@ getRepository(Profile::class)->findAll(); +$profiles = $em->getRepository(SkillLevelProfile::class)->findAll(); $list = $em->getRepository(Skill::class)->findAll(); $listAction = api_get_self(); @@ -40,11 +40,11 @@ $form->addHidden('id', $id); $form->addButtonSave(get_lang('Update')); if (!empty($item)) { - $profile = $item->getProfile(); + $profile = $item->getLevelProfile(); if ($profile) { $form->setDefaults( [ - 'profile_id' => $item->getProfile()->getId(), + 'profile_id' => $item->getLevelProfile()->getId(), ] ); } @@ -63,9 +63,9 @@ switch ($action) { if ($form->validate()) { $values = $form->exportValues(); - $profile = $em->getRepository(Profile::class)->find($values['profile_id']); + $profile = $em->getRepository(SkillLevelProfile::class)->find($values['profile_id']); if ($profile) { - $item->setProfile($profile); + $item->setLevelProfile($profile); $em->persist($item); $em->flush(); Display::addFlash(Display::return_message(get_lang('Update successful'))); diff --git a/public/main/skills/skill_level.php b/public/main/skills/skill_level.php index d9ecc4ece4..2e34a2776e 100644 --- a/public/main/skills/skill_level.php +++ b/public/main/skills/skill_level.php @@ -2,7 +2,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Entity\Level; -use Chamilo\CoreBundle\Entity\Profile; +use Chamilo\CoreBundle\Entity\SkillLevelProfile; use Chamilo\CoreBundle\Component\Utils\ActionIcon; use Chamilo\CoreBundle\Component\Utils\ObjectIcon; /** @@ -15,7 +15,7 @@ require_once __DIR__.'/../inc/global.inc.php'; api_protect_admin_script(); $em = Database::getManager(); -$profiles = $em->getRepository(Profile::class)->findAll(); +$profiles = $em->getRepository(SkillLevelProfile::class)->findAll(); $list = $em->getRepository(Level::class)->findAll(); $listAction = api_get_self(); @@ -64,7 +64,7 @@ switch ($action) { if ($form->validate()) { $values = $form->exportValues(); if (isset($values['profile_id']) && !empty($values['profile_id'])) { - $profile = $em->getRepository(Profile::class)->find($values['profile_id']); + $profile = $em->getRepository(SkillLevelProfile::class)->find($values['profile_id']); if ($profile) { $item = new Level(); $item->setTitle($values['title']); @@ -101,7 +101,7 @@ switch ($action) { $item->setTitle($values['title']); $item->setShortTitle($values['short_title']); - $profile = $em->getRepository(Profile::class)->find($values['profile_id']); + $profile = $em->getRepository(SkillLevelProfile::class)->find($values['profile_id']); if ($profile) { $item->setProfile($profile); } diff --git a/public/main/skills/skill_profile.php b/public/main/skills/skill_profile.php index 0ceefc516f..c4c6aabafb 100644 --- a/public/main/skills/skill_profile.php +++ b/public/main/skills/skill_profile.php @@ -3,7 +3,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Entity\Level; -use Chamilo\CoreBundle\Entity\Profile; +use Chamilo\CoreBundle\Entity\SkillLevelProfile; use Chamilo\CoreBundle\Entity\Skill; use Chamilo\CoreBundle\Component\Utils\ActionIcon; use Chamilo\CoreBundle\Component\Utils\ObjectIcon; @@ -17,7 +17,7 @@ require_once __DIR__.'/../inc/global.inc.php'; api_protect_admin_script(); $em = Database::getManager(); -$list = $em->getRepository(Profile::class)->findAll(); +$list = $em->getRepository(SkillLevelProfile::class)->findAll(); $listAction = api_get_self(); @@ -30,7 +30,7 @@ $id = isset($_GET['id']) ? $_GET['id'] : ''; $item = null; if (!empty($id)) { - $item = $em->getRepository(Profile::class)->find($id); + $item = $em->getRepository(SkillLevelProfile::class)->find($id); if (!$item) { api_not_allowed(); } @@ -89,7 +89,7 @@ switch ($action) { $tpl->assign('form', $formToDisplay); if ($form->validate()) { $values = $form->exportValues(); - $item = new Profile(); + $item = new SkillLevelProfile(); $item->setTitle($values['name']); $em->persist($item); $em->flush(); diff --git a/src/CoreBundle/Entity/Level.php b/src/CoreBundle/Entity/Level.php index 695740e4d1..c46296d299 100644 --- a/src/CoreBundle/Entity/Level.php +++ b/src/CoreBundle/Entity/Level.php @@ -33,9 +33,9 @@ class Level implements Stringable protected string $shortTitle; #[Gedmo\SortableGroup] - #[ORM\ManyToOne(targetEntity: Profile::class, inversedBy: 'levels')] + #[ORM\ManyToOne(targetEntity: SkillLevelProfile::class, inversedBy: 'levels')] #[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id')] - protected ?Profile $profile = null; + protected ?SkillLevelProfile $profile = null; public function __toString(): string { @@ -89,15 +89,12 @@ class Level implements Stringable return $this; } - /** - * @return Profile - */ - public function getProfile() + public function getProfile(): ?SkillLevelProfile { return $this->profile; } - public function setProfile(Profile $profile): self + public function setProfile(SkillLevelProfile $profile): self { $this->profile = $profile; diff --git a/src/CoreBundle/Entity/Skill.php b/src/CoreBundle/Entity/Skill.php index 80ad4907e7..1430bc6906 100644 --- a/src/CoreBundle/Entity/Skill.php +++ b/src/CoreBundle/Entity/Skill.php @@ -65,9 +65,9 @@ class Skill implements Stringable, Translatable #[ORM\GeneratedValue] protected ?int $id = null; - #[ORM\ManyToOne(targetEntity: Profile::class, inversedBy: 'skills')] + #[ORM\ManyToOne(targetEntity: SkillLevelProfile::class, inversedBy: 'skills')] #[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id')] - protected ?Profile $profile = null; + protected ?SkillLevelProfile $levelProfile = null; /** * @var Collection @@ -259,14 +259,14 @@ class Skill implements Stringable, Translatable return $this->id; } - public function getProfile(): ?Profile + public function getLevelProfile(): ?SkillLevelProfile { - return $this->profile; + return $this->levelProfile; } - public function setProfile(Profile $profile): self + public function setLevelProfile(SkillLevelProfile $levelProfile): self { - $this->profile = $profile; + $this->levelProfile = $levelProfile; return $this; } diff --git a/src/CoreBundle/Entity/Profile.php b/src/CoreBundle/Entity/SkillLevelProfile.php similarity index 93% rename from src/CoreBundle/Entity/Profile.php rename to src/CoreBundle/Entity/SkillLevelProfile.php index f3cc5be07c..2fcb10cee9 100644 --- a/src/CoreBundle/Entity/Profile.php +++ b/src/CoreBundle/Entity/SkillLevelProfile.php @@ -13,7 +13,7 @@ use Stringable; #[ORM\Table(name: 'skill_level_profile')] #[ORM\Entity] -class Profile implements Stringable +class SkillLevelProfile implements Stringable { #[ORM\Column(name: 'id', type: 'integer')] #[ORM\Id] @@ -26,7 +26,7 @@ class Profile implements Stringable /** * @var Collection */ - #[ORM\OneToMany(mappedBy: 'profile', targetEntity: Skill::class, cascade: ['persist'])] + #[ORM\OneToMany(mappedBy: 'levelProfile', targetEntity: Skill::class, cascade: ['persist'])] protected Collection $skills; /** diff --git a/tests/CoreBundle/Repository/SkillRepositoryTest.php b/tests/CoreBundle/Repository/SkillRepositoryTest.php index 39955bc009..d5ada8e9a2 100644 --- a/tests/CoreBundle/Repository/SkillRepositoryTest.php +++ b/tests/CoreBundle/Repository/SkillRepositoryTest.php @@ -9,7 +9,7 @@ namespace Chamilo\Tests\CoreBundle\Repository; use Chamilo\CoreBundle\Entity\Asset; use Chamilo\CoreBundle\Entity\GradebookCategory; use Chamilo\CoreBundle\Entity\Level; -use Chamilo\CoreBundle\Entity\Profile; +use Chamilo\CoreBundle\Entity\SkillLevelProfile; use Chamilo\CoreBundle\Entity\Skill; use Chamilo\CoreBundle\Entity\SkillProfile; use Chamilo\CoreBundle\Entity\SkillRelCourse; @@ -64,7 +64,7 @@ class SkillRepositoryTest extends AbstractApiTest { $em = $this->getEntityManager(); $skillRepo = self::getContainer()->get(SkillRepository::class); - $profileRepo = $em->getRepository(Profile::class); + $profileRepo = $em->getRepository(SkillLevelProfile::class); $course = $this->createCourse('new'); $session = $this->createSession('session'); @@ -79,7 +79,7 @@ class SkillRepositoryTest extends AbstractApiTest ; $em->persist($skillProfile); - $profile = (new Profile()) + $profile = (new SkillLevelProfile()) ->setTitle('profile') ; $em->persist($profile); @@ -97,7 +97,7 @@ class SkillRepositoryTest extends AbstractApiTest ->setShortCode('Dev') ->setStatus(Skill::STATUS_ENABLED) ->setAccessUrlId($accessUrl->getId()) - ->setProfile($profile) + ->setLevelProfile($profile) ; $skillRepo->update($skill); @@ -166,7 +166,7 @@ class SkillRepositoryTest extends AbstractApiTest $em->flush(); $em->clear(); - /** @var Profile $profile */ + /** @var SkillLevelProfile $profile */ $profile = $profileRepo->find($profile->getId()); /** @var Skill $skill */