Minor: Format code

pull/5492/head
Angel Fernando Quiroz Campos 7 months ago
parent eff17ef8bd
commit dc4ca7cb25
  1. 4
      src/CoreBundle/Entity/Skill.php
  2. 18
      src/CoreBundle/Filter/SearchOr.php
  3. 2
      src/CoreBundle/Form/ContactType.php
  4. 9
      src/CoreBundle/Form/ProfileType.php
  5. 3
      src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php
  6. 3
      src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php
  7. 82
      src/CoreBundle/Migrations/Schema/V200/Version20230913162700.php
  8. 4
      src/CoreBundle/Migrations/Schema/V200/Version20231110194300.php
  9. 2
      src/CoreBundle/Migrations/Schema/V200/Version20240323181500.php
  10. 7
      src/CoreBundle/Migrations/Schema/V200/Version20240425192900.php
  11. 6
      src/CoreBundle/Migrations/Schema/V200/Version20240506165900.php
  12. 4
      src/CoreBundle/Settings/AbstractSettingsSchema.php
  13. 1
      src/CourseBundle/Entity/CCalendarEvent.php
  14. 4
      src/CourseBundle/Entity/CLpItem.php
  15. 1
      src/CourseBundle/Repository/CCalendarEventRepository.php
  16. 7
      src/CourseBundle/Settings/SettingsCourseManager.php

@ -9,8 +9,8 @@ namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use Chamilo\CoreBundle\Repository\SkillRepository;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\CoreBundle\Repository\SkillRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -126,6 +126,7 @@ class Skill implements Stringable
return $translation;
}
}
return $this->title;
}
public function getShortCode($translated = true): string
@ -137,6 +138,7 @@ class Skill implements Stringable
return $translation;
}
}
return $this->shortCode;
}
public function setShortCode(string $shortCode): self

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Filter;
@ -8,19 +10,17 @@ use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
use Doctrine\ORM\QueryBuilder;
use InvalidArgumentException;
class SearchOr extends AbstractFilter
{
/**
* @inheritDoc
*/
protected function filterProperty(
string $property,
$value,
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
Operation $operation = null,
?Operation $operation = null,
array $context = []
): void {
if ('search' !== $property) {
@ -28,7 +28,7 @@ class SearchOr extends AbstractFilter
}
if (empty($value)) {
throw new \InvalidArgumentException('The property must not be empty.');
throw new InvalidArgumentException('The property must not be empty.');
}
$alias = $queryBuilder->getRootAliases()[0];
@ -48,12 +48,10 @@ class SearchOr extends AbstractFilter
$queryBuilder
->andWhere(
$queryBuilder->expr()->orX(...$ors)
);
)
;
}
/**
* @inheritDoc
*/
public function getDescription(string $resourceClass): array
{
return [
@ -65,4 +63,4 @@ class SearchOr extends AbstractFilter
],
];
}
}
}

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Form;
use Chamilo\CoreBundle\Entity\ContactCategory;
use Gregwar\CaptchaBundle\Type\CaptchaType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -18,7 +19,6 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
use Gregwar\CaptchaBundle\Type\CaptchaType;
/**
* @template-extends AbstractType<array>

@ -28,8 +28,10 @@ class ProfileType extends AbstractType
{
private LanguageRepository $languageRepository;
public function __construct(LanguageRepository $languageRepository, private readonly SettingsManager $settingsManager)
{
public function __construct(
LanguageRepository $languageRepository,
private readonly SettingsManager $settingsManager
) {
$this->languageRepository = $languageRepository;
}
@ -72,7 +74,8 @@ class ProfileType extends AbstractType
if ('true' === $this->settingsManager->getSetting('use_users_timezone')) {
$builder
->add('timezone', TimezoneType::class, ['label' => 'Timezone', 'required' => true]);
->add('timezone', TimezoneType::class, ['label' => 'Timezone', 'required' => true])
;
}
$builder

@ -6,7 +6,6 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\AgendaReminder;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
@ -151,7 +150,7 @@ final class Version20201215072918 extends AbstractMigrationChamilo
$newEvent = $oldNewEventMap[$oldEventId];
$this->addSql(
sprintf(
"UPDATE agenda_reminder SET event_id = %d WHERE id = %d",
'UPDATE agenda_reminder SET event_id = %d WHERE id = %d',
$newEvent->getIid(),
$reminder['id']
)

@ -6,7 +6,6 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\AgendaReminder;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
@ -238,7 +237,7 @@ class Version20230904173400 extends AbstractMigrationChamilo
$newEvent = $oldNewEventIdMap[$oldEventId];
$this->addSql(
sprintf(
"UPDATE agenda_reminder SET event_id = %d WHERE id = %d",
'UPDATE agenda_reminder SET event_id = %d WHERE id = %d',
$newEvent->getIid(),
$reminder['id']
)

@ -12,6 +12,11 @@ use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Doctrine\DBAL\Schema\Schema;
use Exception;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use const PHP_URL_PATH;
final class Version20230913162700 extends AbstractMigrationChamilo
{
@ -65,7 +70,7 @@ final class Version20230913162700 extends AbstractMigrationChamilo
} elseif (isset($config['fields'])) {
$fields = $config['fields'];
} else {
throw new \Exception('No field or fields specified for updating.');
throw new Exception('No field or fields specified for updating.');
}
foreach ($fields as $field) {
@ -94,11 +99,10 @@ final class Version20230913162700 extends AbstractMigrationChamilo
preg_match_all($specificCoursePattern, $contentText, $matches);
foreach ($matches[2] as $index => $fullUrl) {
$videoPath = parse_url($fullUrl, PHP_URL_PATH) ?: $fullUrl;
$actualCourseDirectory = $matches[5][$index];
if ($actualCourseDirectory !== $courseDirectory) {
$videoPath = preg_replace("/^\/courses\/$actualCourseDirectory\//i", "/courses/$courseDirectory/", $videoPath);
$videoPath = preg_replace("/^\\/courses\\/$actualCourseDirectory\\//i", "/courses/$courseDirectory/", $videoPath);
}
$documentPath = str_replace('/courses/'.$courseDirectory.'/document/', '/', $videoPath);
@ -114,7 +118,7 @@ final class Version20230913162700 extends AbstractMigrationChamilo
if ($document) {
$newUrl = $documentRepo->getResourceFileUrl($document);
if ($newUrl) {
$replacement = $matches[1][$index] . '="' . $newUrl . '"';
$replacement = $matches[1][$index].'="'.$newUrl.'"';
$contentText = str_replace($matches[0][$index], $replacement, $contentText);
}
}
@ -132,8 +136,8 @@ final class Version20230913162700 extends AbstractMigrationChamilo
if ($documentFile) {
$newUrl = $documentRepo->getResourceFileUrl($documentFile);
if (!empty($newUrl)) {
$patternForReplacement = '/' . preg_quote($matches[0][$index], '/') . '/';
$replacement = $matches[1][$index] . '="' . $newUrl . '"';
$patternForReplacement = '/'.preg_quote($matches[0][$index], '/').'/';
$replacement = $matches[1][$index].'="'.$newUrl.'"';
$contentText = preg_replace($patternForReplacement, $replacement, $contentText, 1);
}
}
@ -146,17 +150,17 @@ final class Version20230913162700 extends AbstractMigrationChamilo
$documentRepo = $this->container->get(CDocumentRepository::class);
$kernel = $this->container->get('kernel');
$rootPath = $kernel->getProjectDir();
$appCourseOldPath = $rootPath . '/app' . $videoPath;
$appCourseOldPath = $rootPath.'/app'.$videoPath;
$title = basename($appCourseOldPath);
$courseRepo = $this->container->get(CourseRepository::class);
$course = $courseRepo->find($courseId);
if (!$course) {
throw new \Exception("Course with ID $courseId not found.");
throw new Exception("Course with ID $courseId not found.");
}
$document = $documentRepo->findCourseResourceByTitle($title, $course->getResourceNode(), $course);
if ($document !== null) {
if (null !== $document) {
return $document;
}
@ -168,49 +172,55 @@ final class Version20230913162700 extends AbstractMigrationChamilo
->setReadonly(false)
->setCreator($this->getAdmin())
->setParent($course)
->addCourseLink($course);
->addCourseLink($course)
;
$this->entityManager->persist($document);
$this->entityManager->flush();
$documentRepo->addFileFromPath($document, $title, $appCourseOldPath);
return $document;
} else {
$generalCoursesPath = $rootPath . '/app/courses/';
$foundPath = $this->recursiveFileSearch($generalCoursesPath, $title);
if ($foundPath) {
$document = new CDocument();
$document->setFiletype('file')
->setTitle($title)
->setComment(null)
->setReadonly(false)
->setCreator($this->getAdmin())
->setParent($course)
->addCourseLink($course);
$this->entityManager->persist($document);
$this->entityManager->flush();
$documentRepo->addFileFromPath($document, $title, $foundPath);
error_log("File found in new location: " . $foundPath);
return $document;
} else {
throw new \Exception("File not found in any location.");
}
}
} catch (\Exception $e) {
error_log('Migration error: ' . $e->getMessage());
$generalCoursesPath = $rootPath.'/app/courses/';
$foundPath = $this->recursiveFileSearch($generalCoursesPath, $title);
if ($foundPath) {
$document = new CDocument();
$document->setFiletype('file')
->setTitle($title)
->setComment(null)
->setReadonly(false)
->setCreator($this->getAdmin())
->setParent($course)
->addCourseLink($course)
;
$this->entityManager->persist($document);
$this->entityManager->flush();
$documentRepo->addFileFromPath($document, $title, $foundPath);
error_log('File found in new location: '.$foundPath);
return $document;
}
throw new Exception('File not found in any location.');
} catch (Exception $e) {
error_log('Migration error: '.$e->getMessage());
return null;
}
}
private function recursiveFileSearch($directory, $title) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
private function recursiveFileSearch($directory, $title)
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getFilename() === $title) {
return $file->getRealPath();
}
}
return null;
}
}

@ -111,13 +111,13 @@ final class Version20231110194300 extends AbstractMigrationChamilo
}
$content = file_get_contents($webpackConfigPath);
$pattern = "/(const themes = \[\s*\")([^\"\]]+)(\"\s*\])/";
$pattern = '/(const themes = \\[\\s*")([^"\\]]+)("\\s*\\])/';
$replacement = function ($matches) use ($newThemes) {
$existingThemes = explode('", "', trim($matches[2], '"'));
$allThemes = array_unique(array_merge($existingThemes, $newThemes));
$newThemesString = implode('", "', $allThemes);
return $matches[1] . $newThemesString . $matches[3];
return $matches[1].$newThemesString.$matches[3];
};
$newContent = preg_replace_callback($pattern, $replacement, $content);

@ -118,7 +118,7 @@ class Version20240323181500 extends AbstractMigrationChamilo
$newEvent = $oldNewEventIdMap[$oldEventId];
$this->addSql(
sprintf(
"UPDATE agenda_reminder SET event_id = %d WHERE id = %d",
'UPDATE agenda_reminder SET event_id = %d WHERE id = %d',
$newEvent->getIid(),
$reminder['id']
)

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
@ -14,9 +16,6 @@ class Version20240425192900 extends AbstractMigration
return 'Changes on the agenda_reminder structure';
}
/**
* @inheritDoc
*/
public function up(Schema $schema): void
{
if (!$schema->hasTable('agenda_reminder')) {
@ -31,4 +30,4 @@ class Version20240425192900 extends AbstractMigration
$this->addSql('ALTER TABLE agenda_reminder ADD CONSTRAINT FK_416FFA2471F7E88B FOREIGN KEY (event_id) REFERENCES c_calendar_event (iid)');
$this->addSql('CREATE INDEX IDX_416FFA2471F7E88B ON agenda_reminder (event_id)');
}
}
}

@ -11,6 +11,8 @@ use Chamilo\CoreBundle\Repository\Node\PersonalFileRepository;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Doctrine\DBAL\Schema\Schema;
use const PREG_SET_ORDER;
final class Version20240506165900 extends AbstractMigrationChamilo
{
public function getDescription(): string
@ -75,13 +77,13 @@ final class Version20240506165900 extends AbstractMigrationChamilo
foreach ($matches as $match) {
$attribute = $match[1];
$baseUrlWithApp = $match[2] ? $match[2] . $match[3] : $match[3];
$baseUrlWithApp = $match[2] ? $match[2].$match[3] : $match[3];
$folderId = (int) $match[4];
$userId = (int) $match[5];
$filename = $match[6];
$user = $userRepo->find($userId);
if ($user !== null) {
if (null !== $user) {
$personalFile = $personalRepo->getResourceByCreatorFromTitle($filename, $user, $user->getResourceNode());
if ($personalFile) {
$newUrl = $personalRepo->getResourceFileUrl($personalFile);

@ -65,7 +65,7 @@ abstract class AbstractSettingsSchema implements SchemaInterface
foreach ($builder->all() as $fieldName => $field) {
$options = $field->getOptions();
$labelAttributes = $options['label_attr'] ?? [];
$labelAttributes['class'] = (isset($labelAttributes['class']) ? $labelAttributes['class'] . ' ' : '') . 'settings-label';
$labelAttributes['class'] = (isset($labelAttributes['class']) ? $labelAttributes['class'].' ' : '').'settings-label';
$options['label_attr'] = $labelAttributes;
if (isset($settingsInfo[$fieldName])) {
@ -75,7 +75,7 @@ abstract class AbstractSettingsSchema implements SchemaInterface
$helpFromDb = $this->translator->trans($fieldConfig['help']);
$existingHelp = $options['help'] ?? '';
$combinedHelp = !empty($existingHelp) ? $helpFromDb . '<br>' . $existingHelp : $helpFromDb;
$combinedHelp = !empty($existingHelp) ? $helpFromDb.'<br>'.$existingHelp : $helpFromDb;
$options['label'] = $labelFromDb;
$options['help'] = $combinedHelp;

@ -22,7 +22,6 @@ use Chamilo\CoreBundle\Entity\AgendaReminder;
use Chamilo\CoreBundle\Entity\Career;
use Chamilo\CoreBundle\Entity\Promotion;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\Room;
use Chamilo\CoreBundle\Filter\CidFilter;
use Chamilo\CoreBundle\Filter\GlobalEventFilter;

@ -520,12 +520,12 @@ class CLpItem implements Stringable
return $this;
}
public function getRoot(): ?CLpItem
public function getRoot(): ?self
{
return $this->root;
}
public function setRoot(?CLpItem $root): CLpItem
public function setRoot(?self $root): self
{
$this->root = $root;

@ -8,7 +8,6 @@ namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\ResourceRepository;

@ -155,15 +155,16 @@ class SettingsCourseManager extends SettingsManager
/**
* Fetches the value of a specific setting for the given course and variable.
*
* @param string $variableName The name of the variable to fetch.
* @return string|null The value of the setting if found, or null if not.
* @param string $variableName the name of the variable to fetch
*
* @return string|null the value of the setting if found, or null if not
*/
public function getCourseSettingValue(string $variableName): ?string
{
$repo = $this->manager->getRepository(CCourseSetting::class);
$courseSetting = $repo->findOneBy([
'cId' => $this->course->getId(),
'variable' => $variableName
'variable' => $variableName,
]);
return $courseSetting ? $courseSetting->getValue() : null;

Loading…
Cancel
Save