Skip to content

Commit b36c0c0

Browse files
Internal: Add ColorTheme fixture and AccessUrlRelColorTheme relation
1 parent 0256363 commit b36c0c0

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

src/CoreBundle/DataFixtures/ColorThemeFixtures.php

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,77 @@
66

77
namespace Chamilo\CoreBundle\DataFixtures;
88

9+
use Chamilo\CoreBundle\Entity\AccessUrlRelColorTheme;
910
use Chamilo\CoreBundle\Entity\ColorTheme;
11+
use Chamilo\CoreBundle\Helpers\AccessUrlHelper;
1012
use Doctrine\Bundle\FixturesBundle\Fixture;
13+
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
1114
use Doctrine\Persistence\ObjectManager;
1215

13-
class ColorThemeFixtures extends Fixture
16+
class ColorThemeFixtures extends Fixture implements FixtureGroupInterface
1417
{
18+
public function __construct(
19+
private readonly AccessUrlHelper $accessUrlHelper
20+
) {}
21+
22+
public static function getGroups(): array
23+
{
24+
return ['color_theme'];
25+
}
26+
1527
public function load(ObjectManager $manager): void
1628
{
17-
$date = api_get_utc_datetime(null, false, true);
18-
$json = '{"--color-primary-base":"46 117 163","--color-primary-gradient":"-1 86 130","--color-primary-button-text":"46 117 163","--color-primary-button-alternative-text":"255 255 255","--color-secondary-base":"243 126 47","--color-secondary-gradient":"193 81 -31","--color-secondary-button-text":"255 255 255","--color-tertiary-base":"51 51 51","--color-tertiary-gradient":"103 103 103","--color-tertiary-button-text":"51 51 51","--color-success-base":"119 170 12","--color-success-gradient":"80 128 -43","--color-success-button-text":"255 255 255","--color-info-base":"13 123 253","--color-info-gradient":"-33 83 211","--color-info-button-text":"255 255 255","--color-warning-base":"245 206 1","--color-warning-gradient":"189 151 -65","--color-warning-button-text":"0 0 0","--color-danger-base":"223 59 59","--color-danger-gradient":"180 -13 20","--color-danger-button-text":"255 255 255","--color-form-base":"46 117 163"}';
29+
$existing = $manager->getRepository(ColorTheme::class)
30+
->findOneBy(['slug' => 'chamilo']);
31+
32+
if ($existing) {
33+
echo "Chamilo color theme already exists. Skipping fixture.\n";
34+
return;
35+
}
1936

20-
// @todo check if we still need skill_rel_skill
2137
$theme = (new ColorTheme())
2238
->setTitle('Chamilo')
2339
->setSlug('chamilo')
24-
->setVariables([$json])
25-
->setCreatedAt($date)
26-
->setUpdatedAt($date)
40+
->setVariables([
41+
'--color-primary-base' => '46 117 163',
42+
'--color-primary-gradient' => '-1 86 130',
43+
'--color-primary-button-text' => '46 117 163',
44+
'--color-primary-button-alternative-text' => '255 255 255',
45+
'--color-secondary-base' => '243 126 47',
46+
'--color-secondary-gradient' => '193 81 -31',
47+
'--color-secondary-button-text' => '255 255 255',
48+
'--color-tertiary-base' => '51 51 51',
49+
'--color-tertiary-gradient' => '103 103 103',
50+
'--color-tertiary-button-text' => '51 51 51',
51+
'--color-success-base' => '119 170 12',
52+
'--color-success-gradient' => '80 128 -43',
53+
'--color-success-button-text' => '255 255 255',
54+
'--color-info-base' => '13 123 253',
55+
'--color-info-gradient' => '-33 83 211',
56+
'--color-info-button-text' => '255 255 255',
57+
'--color-warning-base' => '245 206 1',
58+
'--color-warning-gradient' => '189 151 -65',
59+
'--color-warning-button-text' => '0 0 0',
60+
'--color-danger-base' => '223 59 59',
61+
'--color-danger-gradient' => '180 -13 20',
62+
'--color-danger-button-text' => '255 255 255',
63+
'--color-form-base' => '46 117 163',
64+
])
2765
;
28-
$manager->persist($theme);
2966

67+
$accessUrl = $this->accessUrlHelper->getCurrent();
68+
69+
$accessUrlRel = (new AccessUrlRelColorTheme())
70+
->setUrl($accessUrl)
71+
->setColorTheme($theme)
72+
->setActive(true);
73+
74+
$theme->addUrl($accessUrlRel);
75+
76+
$manager->persist($theme);
77+
$manager->persist($accessUrlRel);
3078
$manager->flush();
79+
80+
echo "Chamilo color theme fixture loaded successfully.\n";
3181
}
3282
}

0 commit comments

Comments
 (0)