Skill: Rename Profile class to SkillLevelProfile

pull/5949/head
Angel Fernando Quiroz Campos 9 months ago
parent abac015729
commit 86ba829996
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 6
      public/main/inc/lib/SkillModel.php
  2. 6
      public/main/skills/assign.php
  3. 12
      public/main/skills/skill.php
  4. 8
      public/main/skills/skill_level.php
  5. 8
      public/main/skills/skill_profile.php
  6. 11
      src/CoreBundle/Entity/Level.php
  7. 12
      src/CoreBundle/Entity/Skill.php
  8. 4
      src/CoreBundle/Entity/SkillLevelProfile.php
  9. 10
      tests/CoreBundle/Repository/SkillRepositoryTest.php

@ -288,7 +288,7 @@ class SkillModel extends Model
'criteria' => $skill->getCriteria(), 'criteria' => $skill->getCriteria(),
'status' => $skill->getStatus(), 'status' => $skill->getStatus(),
'asset_id' => (string) $skill->getAsset()?->getId(), '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'])), 'icons_small' => sprintf('badges/%s-small.png', sha1($skill['title'])),
]; ];
} }
@ -1023,7 +1023,7 @@ class SkillModel extends Model
if (!empty($skills)) { if (!empty($skills)) {
foreach ($skills as &$skill) { foreach ($skills as &$skill) {
if (0 == $skill['parent_id']) { if (0 == $skill['parent_id']) {
$skill['parent_id'] = 1; $skill['parent_id'] = '-1';
} }
// because except main keys (id, title, children) others keys // because except main keys (id, title, children) others keys
@ -1070,7 +1070,7 @@ class SkillModel extends Model
// Check if the skill has related gradebooks // Check if the skill has related gradebooks
$skill['data']['skill_has_gradebook'] = false; $skill['data']['skill_has_gradebook'] = false;
if (isset($skill['gradebooks']) && !empty($skill['gradebooks'])) { if (!empty($skill['gradebooks'])) {
$skill['data']['skill_has_gradebook'] = true; $skill['data']['skill_has_gradebook'] = true;
} }
$refs[$skill['id']] = &$skill; $refs[$skill['id']] = &$skill;

@ -123,13 +123,13 @@ $skillId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : key($skillsOptions);
$skill = $skillRepo->find($skillId); $skill = $skillRepo->find($skillId);
$profile = false; $profile = false;
if ($skill) { if ($skill) {
$profile = $skill->getProfile(); $profile = $skill->getLevelProfile();
} }
if (!empty($subSkillList)) { if (!empty($subSkillList)) {
$skillFromLastSkill = $skillRepo->find(end($subSkillList)); $skillFromLastSkill = $skillRepo->find(end($subSkillList));
if ($skillFromLastSkill) { if ($skillFromLastSkill) {
$profile = $skillFromLastSkill->getProfile(); $profile = $skillFromLastSkill->getLevelProfile();
} }
} }
@ -139,7 +139,7 @@ if (!$profile) {
krsort($parents); krsort($parents);
foreach ($parents as $parent) { foreach ($parents as $parent) {
$skillParentId = $parent['skill_id']; $skillParentId = $parent['skill_id'];
$profile = $skillRepo->find($skillParentId)->getProfile(); $profile = $skillRepo->find($skillParentId)->getLevelProfile();
if ($profile) { if ($profile) {
break; break;

@ -1,7 +1,7 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Profile; use Chamilo\CoreBundle\Entity\SkillLevelProfile;
use Chamilo\CoreBundle\Entity\Skill; use Chamilo\CoreBundle\Entity\Skill;
/** /**
@ -11,7 +11,7 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(); api_protect_admin_script();
$em = Database::getManager(); $em = Database::getManager();
$profiles = $em->getRepository(Profile::class)->findAll(); $profiles = $em->getRepository(SkillLevelProfile::class)->findAll();
$list = $em->getRepository(Skill::class)->findAll(); $list = $em->getRepository(Skill::class)->findAll();
$listAction = api_get_self(); $listAction = api_get_self();
@ -40,11 +40,11 @@ $form->addHidden('id', $id);
$form->addButtonSave(get_lang('Update')); $form->addButtonSave(get_lang('Update'));
if (!empty($item)) { if (!empty($item)) {
$profile = $item->getProfile(); $profile = $item->getLevelProfile();
if ($profile) { if ($profile) {
$form->setDefaults( $form->setDefaults(
[ [
'profile_id' => $item->getProfile()->getId(), 'profile_id' => $item->getLevelProfile()->getId(),
] ]
); );
} }
@ -63,9 +63,9 @@ switch ($action) {
if ($form->validate()) { if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
$profile = $em->getRepository(Profile::class)->find($values['profile_id']); $profile = $em->getRepository(SkillLevelProfile::class)->find($values['profile_id']);
if ($profile) { if ($profile) {
$item->setProfile($profile); $item->setLevelProfile($profile);
$em->persist($item); $em->persist($item);
$em->flush(); $em->flush();
Display::addFlash(Display::return_message(get_lang('Update successful'))); Display::addFlash(Display::return_message(get_lang('Update successful')));

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Level; 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\ActionIcon;
use Chamilo\CoreBundle\Component\Utils\ObjectIcon; use Chamilo\CoreBundle\Component\Utils\ObjectIcon;
/** /**
@ -15,7 +15,7 @@ require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(); api_protect_admin_script();
$em = Database::getManager(); $em = Database::getManager();
$profiles = $em->getRepository(Profile::class)->findAll(); $profiles = $em->getRepository(SkillLevelProfile::class)->findAll();
$list = $em->getRepository(Level::class)->findAll(); $list = $em->getRepository(Level::class)->findAll();
$listAction = api_get_self(); $listAction = api_get_self();
@ -64,7 +64,7 @@ switch ($action) {
if ($form->validate()) { if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
if (isset($values['profile_id']) && !empty($values['profile_id'])) { 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) { if ($profile) {
$item = new Level(); $item = new Level();
$item->setTitle($values['title']); $item->setTitle($values['title']);
@ -101,7 +101,7 @@ switch ($action) {
$item->setTitle($values['title']); $item->setTitle($values['title']);
$item->setShortTitle($values['short_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) { if ($profile) {
$item->setProfile($profile); $item->setProfile($profile);
} }

@ -3,7 +3,7 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Level; use Chamilo\CoreBundle\Entity\Level;
use Chamilo\CoreBundle\Entity\Profile; use Chamilo\CoreBundle\Entity\SkillLevelProfile;
use Chamilo\CoreBundle\Entity\Skill; use Chamilo\CoreBundle\Entity\Skill;
use Chamilo\CoreBundle\Component\Utils\ActionIcon; use Chamilo\CoreBundle\Component\Utils\ActionIcon;
use Chamilo\CoreBundle\Component\Utils\ObjectIcon; use Chamilo\CoreBundle\Component\Utils\ObjectIcon;
@ -17,7 +17,7 @@ require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(); api_protect_admin_script();
$em = Database::getManager(); $em = Database::getManager();
$list = $em->getRepository(Profile::class)->findAll(); $list = $em->getRepository(SkillLevelProfile::class)->findAll();
$listAction = api_get_self(); $listAction = api_get_self();
@ -30,7 +30,7 @@ $id = isset($_GET['id']) ? $_GET['id'] : '';
$item = null; $item = null;
if (!empty($id)) { if (!empty($id)) {
$item = $em->getRepository(Profile::class)->find($id); $item = $em->getRepository(SkillLevelProfile::class)->find($id);
if (!$item) { if (!$item) {
api_not_allowed(); api_not_allowed();
} }
@ -89,7 +89,7 @@ switch ($action) {
$tpl->assign('form', $formToDisplay); $tpl->assign('form', $formToDisplay);
if ($form->validate()) { if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
$item = new Profile(); $item = new SkillLevelProfile();
$item->setTitle($values['name']); $item->setTitle($values['name']);
$em->persist($item); $em->persist($item);
$em->flush(); $em->flush();

@ -33,9 +33,9 @@ class Level implements Stringable
protected string $shortTitle; protected string $shortTitle;
#[Gedmo\SortableGroup] #[Gedmo\SortableGroup]
#[ORM\ManyToOne(targetEntity: Profile::class, inversedBy: 'levels')] #[ORM\ManyToOne(targetEntity: SkillLevelProfile::class, inversedBy: 'levels')]
#[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id')] #[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id')]
protected ?Profile $profile = null; protected ?SkillLevelProfile $profile = null;
public function __toString(): string public function __toString(): string
{ {
@ -89,15 +89,12 @@ class Level implements Stringable
return $this; return $this;
} }
/** public function getProfile(): ?SkillLevelProfile
* @return Profile
*/
public function getProfile()
{ {
return $this->profile; return $this->profile;
} }
public function setProfile(Profile $profile): self public function setProfile(SkillLevelProfile $profile): self
{ {
$this->profile = $profile; $this->profile = $profile;

@ -65,9 +65,9 @@ class Skill implements Stringable, Translatable
#[ORM\GeneratedValue] #[ORM\GeneratedValue]
protected ?int $id = null; 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')] #[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id')]
protected ?Profile $profile = null; protected ?SkillLevelProfile $levelProfile = null;
/** /**
* @var Collection<int, SkillRelUser> * @var Collection<int, SkillRelUser>
@ -259,14 +259,14 @@ class Skill implements Stringable, Translatable
return $this->id; 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; return $this;
} }

@ -13,7 +13,7 @@ use Stringable;
#[ORM\Table(name: 'skill_level_profile')] #[ORM\Table(name: 'skill_level_profile')]
#[ORM\Entity] #[ORM\Entity]
class Profile implements Stringable class SkillLevelProfile implements Stringable
{ {
#[ORM\Column(name: 'id', type: 'integer')] #[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id] #[ORM\Id]
@ -26,7 +26,7 @@ class Profile implements Stringable
/** /**
* @var Collection<int, Skill> * @var Collection<int, Skill>
*/ */
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: Skill::class, cascade: ['persist'])] #[ORM\OneToMany(mappedBy: 'levelProfile', targetEntity: Skill::class, cascade: ['persist'])]
protected Collection $skills; protected Collection $skills;
/** /**

@ -9,7 +9,7 @@ namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\Asset; use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Entity\GradebookCategory; use Chamilo\CoreBundle\Entity\GradebookCategory;
use Chamilo\CoreBundle\Entity\Level; use Chamilo\CoreBundle\Entity\Level;
use Chamilo\CoreBundle\Entity\Profile; use Chamilo\CoreBundle\Entity\SkillLevelProfile;
use Chamilo\CoreBundle\Entity\Skill; use Chamilo\CoreBundle\Entity\Skill;
use Chamilo\CoreBundle\Entity\SkillProfile; use Chamilo\CoreBundle\Entity\SkillProfile;
use Chamilo\CoreBundle\Entity\SkillRelCourse; use Chamilo\CoreBundle\Entity\SkillRelCourse;
@ -64,7 +64,7 @@ class SkillRepositoryTest extends AbstractApiTest
{ {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$skillRepo = self::getContainer()->get(SkillRepository::class); $skillRepo = self::getContainer()->get(SkillRepository::class);
$profileRepo = $em->getRepository(Profile::class); $profileRepo = $em->getRepository(SkillLevelProfile::class);
$course = $this->createCourse('new'); $course = $this->createCourse('new');
$session = $this->createSession('session'); $session = $this->createSession('session');
@ -79,7 +79,7 @@ class SkillRepositoryTest extends AbstractApiTest
; ;
$em->persist($skillProfile); $em->persist($skillProfile);
$profile = (new Profile()) $profile = (new SkillLevelProfile())
->setTitle('profile') ->setTitle('profile')
; ;
$em->persist($profile); $em->persist($profile);
@ -97,7 +97,7 @@ class SkillRepositoryTest extends AbstractApiTest
->setShortCode('Dev') ->setShortCode('Dev')
->setStatus(Skill::STATUS_ENABLED) ->setStatus(Skill::STATUS_ENABLED)
->setAccessUrlId($accessUrl->getId()) ->setAccessUrlId($accessUrl->getId())
->setProfile($profile) ->setLevelProfile($profile)
; ;
$skillRepo->update($skill); $skillRepo->update($skill);
@ -166,7 +166,7 @@ class SkillRepositoryTest extends AbstractApiTest
$em->flush(); $em->flush();
$em->clear(); $em->clear();
/** @var Profile $profile */ /** @var SkillLevelProfile $profile */
$profile = $profileRepo->find($profile->getId()); $profile = $profileRepo->find($profile->getId());
/** @var Skill $skill */ /** @var Skill $skill */

Loading…
Cancel
Save