Fix type hints, fix PHP errors

pull/3844/head
Julio Montoya 4 years ago
parent 9958699561
commit b3073b5076
  1. 4
      src/CoreBundle/Entity/TrackEAccess.php
  2. 4
      src/CoreBundle/Entity/TrackEAttempt.php
  3. 10
      src/CoreBundle/Entity/TrackECourseAccess.php
  4. 2
      src/CoreBundle/Entity/TrackEDefault.php
  5. 10
      src/CoreBundle/Entity/TrackELogin.php
  6. 12
      src/CoreBundle/Framework/Container.php
  7. 20
      src/CoreBundle/Repository/Node/UserRepository.php
  8. 105
      src/CoreBundle/Settings/SettingsManager.php
  9. 20
      src/CoreBundle/Traits/ResourceControllerTrait.php

@ -36,11 +36,9 @@ class TrackEAccess
protected $accessUserId;
/**
* @var \DateTime
*
* @ORM\Column(name="access_date", type="datetime", nullable=false)
*/
protected $accessDate;
protected \DateTime $accessDate;
/**
* @var int

@ -92,9 +92,9 @@ class TrackEAttempt
/**
* @var \DateTime
*
* @ORM\Column(name="tms", type="datetime", nullable=true)
* @ORM\Column(name="tms", type="datetime", nullable=false)
*/
protected $tms;
protected \DateTime $tms;
/**
* @var int

@ -51,18 +51,14 @@ class TrackECourseAccess
protected $user;
/**
* @var \DateTime
*
* @ORM\Column(name="login_course_date", type="datetime", nullable=false)
*/
protected $loginCourseDate;
protected \DateTime $loginCourseDate;
/**
* @var \DateTime
*
* @ORM\Column(name="logout_course_date", type="datetime", nullable=true)
*/
protected $logoutCourseDate;
protected ?\DateTime $logoutCourseDate;
/**
* @var int
@ -150,7 +146,7 @@ class TrackECourseAccess
/**
* Get logoutCourseDate.
*
* @return \DateTime
* @return \DateTime|null
*/
public function getLogoutCourseDate()
{

@ -47,7 +47,7 @@ class TrackEDefault
/**
* @var \DateTime
*
* @ORM\Column(name="default_date", type="datetime", nullable=true)
* @ORM\Column(name="default_date", type="datetime", nullable=false)
*/
protected $defaultDate;

@ -25,11 +25,9 @@ class TrackELogin
protected $loginUserId;
/**
* @var \DateTime
*
* @ORM\Column(name="login_date", type="datetime", nullable=false)
*/
protected $loginDate;
protected \DateTime $loginDate;
/**
* @var string
@ -39,11 +37,9 @@ class TrackELogin
protected $userIp;
/**
* @var \DateTime
*
* @ORM\Column(name="logout_date", type="datetime", nullable=true)
*/
protected $logoutDate;
protected ?\DateTime $logoutDate;
/**
* @var int
@ -143,7 +139,7 @@ class TrackELogin
/**
* Get logoutDate.
*
* @return \DateTime
* @return \DateTime|null
*/
public function getLogoutDate()
{

@ -82,7 +82,7 @@ class Container
public static $environment;
public static $urlGenerator;
public static $checker;
/** @var TranslatorInterface */
/** @var TranslatorInterface|null */
public static $translator;
public static $mailer;
public static $template;
@ -210,7 +210,7 @@ class Container
*/
public static function getSession()
{
if (self::$container && self::$container->has('session')) {
if (self::$container) {
return self::$container->get('session');
}
@ -242,11 +242,9 @@ class Container
return self::$translator;
}
if (null !== self::$container) {
return self::$container->get('translator');
}
return false;
//if (self::$container->has('translator')) {
return self::$container->get('translator');
//}
}
public static function getMailer(): Mailer

@ -791,7 +791,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackEAttempt = [];
/** @var TrackEAttempt $item */
foreach ($result as $item) {
$date = $item->getTms() ? $item->getTms()->format($dateFormat) : '';
$date = $item->getTms()->format($dateFormat);
$list = [
'Attempt #'.$item->getExeId(),
'Course # '.$item->getCourse()->getCode(),
@ -812,7 +812,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackECourseAccessList = [];
/** @var TrackECourseAccess $item */
foreach ($result as $item) {
$startDate = $item->getLoginCourseDate() ? $item->getLoginCourseDate()->format($dateFormat) : '';
$startDate = $item->getLoginCourseDate()->format($dateFormat);
$endDate = $item->getLogoutCourseDate() ? $item->getLogoutCourseDate()->format($dateFormat) : '';
$list = [
'IP: '.$item->getUserIp(),
@ -867,7 +867,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackELoginList = [];
/** @var TrackELogin $item */
foreach ($trackResults['ChamiloCoreBundle:TrackELogin'] as $item) {
$startDate = $item->getLoginDate() ? $item->getLoginDate()->format($dateFormat) : '';
$startDate = $item->getLoginDate()->format($dateFormat);
$endDate = $item->getLogoutDate() ? $item->getLogoutDate()->format($dateFormat) : '';
$list = [
'IP: '.$item->getUserIp(),
@ -881,7 +881,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackEAccessList = [];
/** @var TrackEAccess $item */
foreach ($trackResults['ChamiloCoreBundle:TrackEAccess'] as $item) {
$date = $item->getAccessDate() ? $item->getAccessDate()->format($dateFormat) : '';
$date = $item->getAccessDate()->format($dateFormat);
$list = [
'IP: '.$item->getUserIp(),
'Tool: '.$item->getAccessTool(),
@ -894,7 +894,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackEOnlineList = [];
/** @var TrackEOnline $item */
foreach ($trackResults['ChamiloCoreBundle:TrackEOnline'] as $item) {
$date = $item->getLoginDate() ? $item->getLoginDate()->format($dateFormat) : '';
$date = $item->getLoginDate()->format($dateFormat);
$list = [
'IP: '.$item->getUserIp(),
'Login date: '.$date,
@ -908,7 +908,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackEDefault = [];
/** @var TrackEDefault $item */
foreach ($trackResults['ChamiloCoreBundle:TrackEDefault'] as $item) {
$date = $item->getDefaultDate() ? $item->getDefaultDate()->format($dateFormat) : '';
$date = $item->getDefaultDate()->format($dateFormat);
$list = [
'Type: '.$item->getDefaultEventType(),
'Value: '.$item->getDefaultValue(),
@ -924,7 +924,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackELastaccess = [];
/** @var TrackELastaccess $item */
foreach ($trackResults['ChamiloCoreBundle:TrackELastaccess'] as $item) {
$date = $item->getAccessDate() ? $item->getAccessDate()->format($dateFormat) : '';
$date = $item->getAccessDate()->format($dateFormat);
$list = [
'Course #'.$item->getCId(),
'Session # '.$item->getAccessSessionId(),
@ -938,7 +938,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackEUploads = [];
/** @var TrackEUploads $item */
foreach ($trackResults['ChamiloCoreBundle:TrackEUploads'] as $item) {
$date = $item->getUploadDate() ? $item->getUploadDate()->format($dateFormat) : '';
$date = $item->getUploadDate()->format($dateFormat);
$list = [
'Course #'.$item->getCId(),
'Uploaded at: '.$date,
@ -950,7 +950,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$gradebookResult = [];
/** @var GradebookResult $item */
foreach ($trackResults['ChamiloCoreBundle:GradebookResult'] as $item) {
$date = $item->getCreatedAt() ? $item->getCreatedAt()->format($dateFormat) : '';
$date = $item->getCreatedAt()->format($dateFormat);
$list = [
'Evaluation id# '.$item->getEvaluation()->getId(),
//'Score: '.$item->getScore(),
@ -962,7 +962,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$trackEDownloads = [];
/** @var TrackEDownloads $item */
foreach ($trackResults['ChamiloCoreBundle:TrackEDownloads'] as $item) {
$date = $item->getDownDate() ? $item->getDownDate()->format($dateFormat) : '';
$date = $item->getDownDate()->format($dateFormat);
$list = [
'File: '.$item->getDownDocPath(),
'Download at: '.$date,

@ -419,59 +419,60 @@ class SettingsManager implements SettingsManagerInterface
$this->manager->flush();
return;
$schemaAlias = $settings->getSchemaAlias();
$schemaAliasChamilo = str_replace('chamilo_core.settings.', '', $schemaAlias);
$schema = $this->schemaRegistry->get($schemaAlias);
$settingsBuilder = new SettingsBuilder();
$schema->buildSettings($settingsBuilder);
$parameters = $settingsBuilder->resolve($settings->getParameters());
foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) {
if (array_key_exists($parameter, $parameters)) {
$parameters[$parameter] = $transformer->transform($parameters[$parameter]);
}
}
/** @var \Sylius\Bundle\SettingsBundle\Event\SettingsEvent $event */
$event = $this->eventDispatcher->dispatch(
SettingsEvent::PRE_SAVE,
new SettingsEvent($settings)
);
/** @var SettingsCurrent $url */
$url = $event->getSettings()->getAccessUrl();
foreach ($parameters as $name => $value) {
if (isset($persistedParametersMap[$name])) {
if ($value instanceof Course) {
$value = $value->getId();
}
$persistedParametersMap[$name]->setValue($value);
} else {
$setting = new Settings();
$setting->setSchemaAlias($schemaAlias);
$setting
->setNamespace($schemaAliasChamilo)
->setName($name)
->setValue($value)
->setUrl($url)
->setAccessUrlLocked(0)
->setAccessUrlChangeable(1)
;
/** @var ConstraintViolationListInterface $errors */
/*$errors = $this->->validate($parameter);
if (0 < $errors->count()) {
throw new ValidatorException($errors->get(0)->getMessage());
}*/
$this->manager->persist($setting);
$this->manager->flush();
}
}
// $schemaAlias = $settings->getSchemaAlias();
// $schemaAliasChamilo = str_replace('chamilo_core.settings.', '', $schemaAlias);
//
// $schema = $this->schemaRegistry->get($schemaAlias);
//
// $settingsBuilder = new SettingsBuilder();
// $schema->buildSettings($settingsBuilder);
//
// $parameters = $settingsBuilder->resolve($settings->getParameters());
//
// foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) {
// if (array_key_exists($parameter, $parameters)) {
// $parameters[$parameter] = $transformer->transform($parameters[$parameter]);
// }
// }
//
// /** @var \Sylius\Bundle\SettingsBundle\Event\SettingsEvent $event */
// $event = $this->eventDispatcher->dispatch(
// SettingsEvent::PRE_SAVE,
// new SettingsEvent($settings)
// );
//
// /** @var SettingsCurrent $url */
// $url = $event->getSettings()->getAccessUrl();
//
// foreach ($parameters as $name => $value) {
// if (isset($persistedParametersMap[$name])) {
// if ($value instanceof Course) {
// $value = $value->getId();
// }
// $persistedParametersMap[$name]->setValue($value);
// } else {
// $setting = new Settings();
// $setting->setSchemaAlias($schemaAlias);
//
// $setting
// ->setNamespace($schemaAliasChamilo)
// ->setName($name)
// ->setValue($value)
// ->setUrl($url)
// ->setAccessUrlLocked(0)
// ->setAccessUrlChangeable(1)
// ;
//
// /** @var ConstraintViolationListInterface $errors */
// /*$errors = $this->->validate($parameter);
// if (0 < $errors->count()) {
// throw new ValidatorException($errors->get(0)->getMessage());
// }*/
// $this->manager->persist($setting);
// $this->manager->flush();
// }
// }
/*$parameters = $settingsBuilder->resolve($settings->getParameters());
$settings->setParameters($parameters);

@ -115,20 +115,20 @@ trait ResourceControllerTrait
protected function getUser(): ?UserInterface
{
if (!$this->container->has('security.token_storage')) {
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require symfony/security-bundle".');
}
if ($this->container->has('security.token_storage')) {
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
return null;
}
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
return null;
}
if (!\is_object($user = $token->getUser())) {
// e.g. anonymous authentication
return null;
}
if (!\is_object($user = $token->getUser())) {
// e.g. anonymous authentication
return null;
return $user;
}
return $user;
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require symfony/security-bundle".');
}
private function setBreadCrumb(Request $request, ResourceNode $resourceNode)

Loading…
Cancel
Save