Skip to content

Commit

Permalink
Merge branch 'master' of github.com:chamilo/chamilo-lms
Browse files Browse the repository at this point in the history
ywarnier committed Nov 13, 2023

Verified

This commit was signed with the committer’s verified signature.
d2iq-dispatch D2iQ Dispatch
2 parents c30aa7b + be0b36b commit 2bb14b8
Showing 6 changed files with 229 additions and 8 deletions.
2 changes: 1 addition & 1 deletion assets/vue/router/index.js
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ import Index from "../pages/Index.vue"
import Home from "../pages/Home.vue"
import Login from "../pages/Login.vue"
import Faq from "../pages/Faq.vue"
import Contact from "../pages/Contact.vue"
//import Contact from "../pages/Contact.vue"
import Demo from "../pages/Demo.vue"

import { useCidReqStore } from "../store/cidReq"
Original file line number Diff line number Diff line change
@@ -7,20 +7,22 @@
<body>
<table border="0" bgcolor="#92c647" cellpadding="0" cellspacing="0" align="center" width="80%">
<tr>
<td bgcolor="#92c647"><img src="{{ url('index') ~ '/build/css/themes/chamilo/images/header_top.png' }}" style="display: block;"></td>
<td bgcolor="#92c647">
<img src="{{ url('index') ~ 'build/css/themes/' ~ chamilo_settings_get('stylesheets.stylesheets') ~ '/images/header_top.png' }}" style="display: block;">
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td bgcolor="#92c647" width=58 height=91>
<img src="{{ _p.web_css_theme }}images/lado-b.png" style="display:block;">
<img src="{{ url('index') ~ 'build/css/themes/' ~ chamilo_settings_get('stylesheets.stylesheets') ~ '/images/lado-b.png' }}" style="display:block;">
</td>
<td bgcolor="#92c647" width=700 height=91 style="font-family:CourierSans-Light; font-weight: bold; line-height: 47px; color:#FFF; padding-bottom: 10px; font-size: 45px;">
{{ 'CertificateHeader' | get_lang }}
</td>
<td bgcolor="#92c647" width=58 height=91>
<img src="{{ url('index') ~ '/build/css/themes/chamilo/images/lado-header.png' }}" style="display:block;">
<img src="{{ url('index') ~ 'build/css/themes/' ~ chamilo_settings_get('stylesheets.stylesheets') ~ '/images/lado-header.png' }}" style="display:block;">
</td>
</tr>
</table>
@@ -30,7 +32,9 @@
<td>
<table bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0" width="100%" height=900>
<tr>
<td bgcolor="#92c647" height=755><img src="{{ url('index') ~ '/build/css/themes/chamilo/images/lado-a.png' }}" style="display:block;"></td>
<td bgcolor="#92c647" height=755>
<img src="{{ url('index') ~ 'build/css/themes/' ~ chamilo_settings_get('stylesheets.stylesheets') ~ '/images/lado-a.png' }}" style="display:block;">
</td>
<td height=755 style="font-family:CourierSans-Light; line-height: 22px; color:#40ad49; padding: 40px; font-size: 18px;" valign="top">
<h3 style="color: #672290; font-size: 24px;">
{{ complete_name }}
@@ -63,7 +67,7 @@
<br />
</td>
<td height=755 bgcolor="#92c647">
<img src="{{ url('index') ~ '/build/css/themes/chamilo/images/lado-b.png' }}" style="display:block;">
<img src="{{ url('index') ~ 'build/css/themes/' ~ chamilo_settings_get('stylesheets.stylesheets') ~ '/images/lado-b.png' }}" style="display:block;">
</td>
</tr>
</table>
@@ -73,11 +77,15 @@
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%" height=91>
<tr>
<td bgcolor="#92c647" width=58 height=91><img src="{{ url('index') ~ '/build/css/themes/chamilo/images/lado-b.png' }}" style="display:block;"></td>
<td bgcolor="#92c647" width=58 height=91>
<img src="{{ url('index') ~ 'build/css/themes/' ~ chamilo_settings_get('stylesheets.stylesheets') ~ '/images/lado-b.png' }}" style="display:block;">
</td>
<td bgcolor="#92c647" width=500 height=91 style="font-family:CourierSans-Light; line-height: 18px; color:#FFF;">
{{ 'CertificateFooter' | get_lang }}
</td>
<td bgcolor="#92c647" width=245 height=91><img src="{{ url('index') ~ '/build/css/themes/chamilo/images/lado-footer.png' }}" style="display:block;"></td>
<td bgcolor="#92c647" width=245 height=91>
<img src="{{ url('index') ~ 'build/css/themes/' ~ chamilo_settings_get('stylesheets.stylesheets') ~ '/images/lado-footer.png' }}" style="display:block;">
</td>
</tr>
</table>
</td>
133 changes: 133 additions & 0 deletions src/CoreBundle/Migrations/Schema/V200/Version20231110194300.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

/* For licensing terms, see /license.txt */

declare(strict_types=1);

namespace Chamilo\CoreBundle\Migrations\Schema\V200;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Finder\Finder;

final class Version20231110194300 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return "Copy custom theme folder to assets and update webpack.config";
}

public function up(Schema $schema): void
{
$container = $this->getContainer();
$doctrine = $container->get('doctrine');
$em = $doctrine->getManager();

$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();

$customThemesFolders = [
'academica',
'chamilo',
'chamilo_red',
'cosmic_campus',
'holi',
'readable',
'sober_brown',
'baby_orange',
'chamilo_electric_blue',
'chamilo_sport_red',
'delicious_bordeaux',
'journal',
'royal_purple',
'spacelab',
'beach',
'chamilo_green',
'cool_blue',
'empire_green',
'kiddy',
'silver_line',
'steel_grey',
'blue_lagoon',
'chamilo_orange',
'corporate',
'fruity_orange',
'medical',
'simplex',
'tasty_olive'
];


$sourceDir = $rootPath.'/app/Resources/public/css/themes';
$destinationDir = $rootPath.'/assets/css/themes/';
$chamiloDefaultCssPath = $destinationDir . 'chamilo/default.css';

if (!file_exists($sourceDir)) {
return;
}

$finder = new Finder();
$finder->directories()->in($sourceDir)->depth('== 0');
$newThemes = [];
foreach ($finder as $folder) {
$folderName = $folder->getRelativePathname();

if (!in_array($folderName, $customThemesFolders, true)) {
$sourcePath = $folder->getRealPath();
$destinationPath = $destinationDir . $folderName;

if (!file_exists($destinationPath)) {
$this->copyDirectory($sourcePath, $destinationPath);
$newThemes[] = $folderName;

if (file_exists($chamiloDefaultCssPath)) {
$newThemeDefaultCssPath = $destinationPath . '/default.css';
copy($chamiloDefaultCssPath, $newThemeDefaultCssPath);
}
}
}
}

$this->updateWebpackConfig($rootPath, $newThemes);
}

private function copyDirectory($src, $dst): void
{
$dir = opendir($src);
@mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
$this->copyDirectory($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}

private function updateWebpackConfig(string $rootPath, array $newThemes): void
{
$webpackConfigPath = $rootPath . '/webpack.config.js';

if (!file_exists($webpackConfigPath)) {
return;
}

$content = file_get_contents($webpackConfigPath);

$pattern = "/(const themes = \[\n\s*)([^\]]*?)(\s*\];)/s";
$replacement = function($matches) use ($newThemes) {
$existingThemesString = rtrim($matches[2], ", \n");
$newThemesString = implode("',\n '", $newThemes);
$formattedNewThemesString = $existingThemesString .
(empty($existingThemesString) ? '' : ",\n '") . $newThemesString . "'";
return $matches[1] . $formattedNewThemesString . $matches[3];
};

$newContent = preg_replace_callback($pattern, $replacement, $content);

file_put_contents($webpackConfigPath, $newContent);
}
}
5 changes: 5 additions & 0 deletions src/CoreBundle/Resources/config/settings.yml
Original file line number Diff line number Diff line change
@@ -185,3 +185,8 @@ services:
class: Chamilo\CoreBundle\Settings\WebServiceSettingsSchema
tags:
- {name: sylius.settings_schema, alias: chamilo_core.settings.webservice, namespace: webservice}

chamilo_core.settings.stylesheets:
class: Chamilo\CoreBundle\Settings\StylesheetsSettingsSchema
tags:
- { name: sylius.settings_schema, alias: chamilo_core.settings.stylesheets, namespace: stylesheets }
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
'ticket': 'ticket-confirmation',
'tracking': 'chart-box',
'webservice': 'cloud-sync',
'stylesheets': 'language-css3',
}
%}
{% for namespace in schemas|keys %}
74 changes: 74 additions & 0 deletions src/CoreBundle/Settings/StylesheetsSettingsSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

/* For licensing terms, see /license.txt */

namespace Chamilo\CoreBundle\Settings;

use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Contracts\Service\Attribute\Required;

class StylesheetsSettingsSchema extends AbstractSettingsSchema
{
private ParameterBagInterface $parameterBag;

#[Required]
public function setParameterBag(ParameterBagInterface $parameterBag): void
{
$this->parameterBag = $parameterBag;
}

public function buildSettings(AbstractSettingsBuilder $builder): void
{
$builder
->setDefaults(
[
'stylesheets' => 'chamilo',
]
);
$allowedTypes = [
'stylesheets' => ['string'],
];
$this->setMultipleAllowedTypes($allowedTypes, $builder);
}

public function buildForm(FormBuilderInterface $builder): void
{
$builder
->add('stylesheets', ChoiceType::class, [
'choices' => $this->getThemeChoices(),
'label' => 'Select Stylesheet Theme',
])
;
}

private function getThemeChoices(): array
{
$projectDir = $this->parameterBag->get('kernel.project_dir');
$themesDirectory = $projectDir . '/assets/css/themes/';

$finder = new Finder();
$choices = [];

$finder->directories()->in($themesDirectory)->depth('== 0');
if ($finder->hasResults()) {
foreach ($finder as $folder) {
$folderName = $folder->getRelativePathname();
$choices[$this->formatFolderName($folderName)] = $folderName;
}
}

return $choices;
}


private function formatFolderName(string $name): string
{
return ucwords(str_replace('_', ' ', $name));
}
}

0 comments on commit 2bb14b8

Please sign in to comment.