Remove unused code, fix PHP errors, adding psalm config file.

pull/3064/head
Julio 5 years ago
parent faab0f81bb
commit 53f6ecf63f
  1. 163
      psalm.xml
  2. 3
      src/CoreBundle/Entity/Resource/AbstractResource.php
  3. 1157
      src/CoreBundle/Framework/PageController.php
  4. 2
      src/CoreBundle/Hook/HookEvent.php
  5. 1
      src/CoreBundle/Hook/HookMyStudentsLpTracking.php
  6. 2
      src/CoreBundle/Hook/HookObserver.php
  7. 19
      src/CoreBundle/Repository/ResourceRepository.php
  8. 16
      src/CoreBundle/Security/Authorization/Voter/GroupVoter.php
  9. 18
      src/CoreBundle/Settings/CourseSettingsSchema.php
  10. 35
      src/CoreBundle/ToolChain.php
  11. 9
      src/CourseBundle/Admin/CourseAdmin.php
  12. 2
      src/UserBundle/Entity/User.php
  13. 116
      src/UserBundle/Form/EventListener/BuildAttributeFormChoicesListener.php
  14. 100
      src/UserBundle/Form/EventListener/BuildAttributeValueFormListener.php
  15. 65
      src/UserBundle/Form/EventSubscriber/BuildAttributeFormSubscriber.php
  16. 83
      src/UserBundle/Form/EventSubscriber/BuildAttributeValueFormSubscriber.php
  17. 65
      src/UserBundle/Form/Type/AttributeType.php
  18. 58
      src/UserBundle/Form/Type/AttributeTypeChoiceType.php
  19. 114
      src/UserBundle/Form/Type/AttributeValueType.php
  20. 134
      src/UserBundle/Form/Type/RegistrationFormType.php
  21. 103
      src/UserBundle/Form/UserType.php
  22. 25
      src/UserBundle/Repository/UserRepository.php
  23. 76
      src/UserBundle/Security/FOSUBUserProvider.php

@ -0,0 +1,163 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<directory name="src/AdminBundle" />
<directory name="src/ClassificationBundle" />
<directory name="src/ContactBundle" />
<!-- <directory name="src/CoreBundle" />-->
<directory name="src/CoreBundle/Migrations" />
<directory name="src/CourseBundle" />
<directory name="src/FaqBundle" />
<directory name="src/GraphQlBundle" />
<directory name="src/LtiBundle" />
<directory name="src/MediaBundle" />
<directory name="src/NotificationBundle" />
<directory name="src/PageBundle" />
<directory name="src/SettingsBundle" />
<directory name="src/SkillBundle" />
<directory name="src/ThemeBundle" />
<directory name="src/TicketBundle" />
<directory name="src/TimelineBundle" />
<directory name="src/UserBundle" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
<LessSpecificReturnType errorLevel="info" />
<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->
<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />
<InternalMethod errorLevel="info" />
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />
<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />
<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />
<MissingParamType errorLevel="info" />
<RedundantCondition errorLevel="info" />
<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />
<UnresolvableInclude errorLevel="info" />
<RawObjectIteration errorLevel="info" />
<InvalidStringClass errorLevel="info" />
<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->
<MoreSpecificReturnType errorLevel="info" />
<LessSpecificReturnStatement errorLevel="info" />
<TypeCoercion errorLevel="info" />
<PossiblyFalseArgument errorLevel="info" />
<PossiblyFalseIterator errorLevel="info" />
<PossiblyFalseOperand errorLevel="info" />
<PossiblyFalsePropertyAssignmentValue errorLevel="info" />
<PossiblyFalseReference errorLevel="info" />
<PossiblyInvalidArgument errorLevel="info" />
<PossiblyInvalidArrayAccess errorLevel="info" />
<PossiblyInvalidArrayAssignment errorLevel="info" />
<PossiblyInvalidArrayOffset errorLevel="info" />
<PossiblyInvalidCast errorLevel="info" />
<PossiblyInvalidFunctionCall errorLevel="info" />
<PossiblyInvalidIterator errorLevel="info" />
<PossiblyInvalidMethodCall errorLevel="info" />
<PossiblyInvalidOperand errorLevel="info" />
<PossiblyInvalidPropertyAssignment errorLevel="info" />
<PossiblyInvalidPropertyAssignmentValue errorLevel="info" />
<PossiblyInvalidPropertyFetch errorLevel="info" />
<PossiblyNullArgument errorLevel="info" />
<PossiblyNullArrayAccess errorLevel="info" />
<PossiblyNullArrayAssignment errorLevel="info" />
<PossiblyNullArrayOffset errorLevel="info" />
<PossiblyNullFunctionCall errorLevel="info" />
<PossiblyNullIterator errorLevel="info" />
<PossiblyNullOperand errorLevel="info" />
<PossiblyNullPropertyAssignment errorLevel="info" />
<PossiblyNullPropertyAssignmentValue errorLevel="info" />
<PossiblyNullPropertyFetch errorLevel="info" />
<PossiblyNullReference errorLevel="info" />
<PossiblyUndefinedGlobalVariable errorLevel="info" />
<PossiblyUndefinedVariable errorLevel="info" />
<PossiblyUndefinedArrayOffset errorLevel="info" />
<PossiblyUndefinedMethod errorLevel="info" />
<PossibleRawObjectIteration errorLevel="info" />
<!-- level 5 issues - should be avoided at most costs... -->
<ForbiddenCode errorLevel="info" />
<ImplicitToStringCast errorLevel="info" />
<InvalidScalarArgument errorLevel="info" />
<InvalidToString errorLevel="info" />
<InvalidOperand errorLevel="info" />
<NoInterfaceProperties errorLevel="info" />
<TooManyArguments errorLevel="info" />
<TypeDoesNotContainType errorLevel="info" />
<TypeDoesNotContainNull errorLevel="info" />
<MissingDocblockType errorLevel="info" />
<ImplementedReturnTypeMismatch errorLevel="info" />
<ImplementedParamTypeMismatch errorLevel="info" />
<!-- level 6 issues - really bad things -->
<InvalidNullableReturnType errorLevel="info" />
<NullableReturnStatement errorLevel="info" />
<InvalidFalsableReturnType errorLevel="info" />
<FalsableReturnStatement errorLevel="info" />
<MoreSpecificImplementedParamType errorLevel="info" />
<LessSpecificImplementedReturnType errorLevel="info" />
<InvalidReturnStatement errorLevel="info" />
<InvalidReturnType errorLevel="info" />
<UndefinedThisPropertyAssignment errorLevel="info" />
<UndefinedInterfaceMethod errorLevel="info" />
<!-- level 7 issues - even worse -->
<UndefinedThisPropertyAssignment errorLevel="info" />
<UndefinedPropertyAssignment errorLevel="info" />
<UndefinedThisPropertyFetch errorLevel="info" />
<UndefinedPropertyFetch errorLevel="info" />
<InvalidReturnStatement errorLevel="info" />
<InvalidReturnType errorLevel="info" />
<InvalidArgument errorLevel="info" />
<InvalidPropertyAssignmentValue errorLevel="info" />
<InvalidArrayOffset errorLevel="info" />
<InvalidArrayAssignment errorLevel="info" />
<InvalidArrayAccess errorLevel="info" />
<InvalidClone errorLevel="info" />
</issueHandlers>
</psalm>

@ -26,7 +26,8 @@ abstract class AbstractResource
* @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE")
*/
public $resourceNode;
//abstract public function getResourceName(): string;
abstract public function getResourceName(): string;
/**
* @return $this

File diff suppressed because it is too large Load Diff

@ -95,7 +95,7 @@ abstract class HookEvent implements HookEventInterface
$class = get_called_class();
return new $class($entityManager);
} catch (Exception $e) {
} catch (\Exception $e) {
return null;
}
}

@ -5,6 +5,7 @@
namespace Chamilo\CoreBundle\Hook;
use Chamilo\CoreBundle\Hook\Interfaces\HookMyStudentsLpTrackingEventInterface;
use Chamilo\CoreBundle\Hook\Interfaces\HookMyStudentsLpTrackingObserverInterface;
use Doctrine\ORM\EntityManager;
/**

@ -63,7 +63,7 @@ abstract class HookObserver implements HookObserverInterface
$class = get_called_class();
return new $class();
} catch (Exception $e) {
} catch (\Exception $e) {
return null;
}
}

@ -356,7 +356,7 @@ class ResourceRepository extends BaseEntityRepository
$resourceLink = new ResourceLink();
$resourceLink
->setResourceNode($resourceNode)
->setPrivate(true);
;
$this->getEntityManager()->persist($resourceLink);
$this->getEntityManager()->flush();
@ -726,14 +726,15 @@ class ResourceRepository extends BaseEntityRepository
$resourceNode = $resource->getResourceNode();
if ($resourceNode->hasResourceFile()) {
$resourceFile = $resourceNode->getResourceFile();
$fileName = $resourceFile->getFile()->getPathname();
$this->fs->update($fileName, $content);
$size = $this->fs->getSize($fileName);
$resource->setSize($size);
$this->entityManager->persist($resource);
return true;
if ($resourceFile) {
$fileName = $resourceFile->getFile()->getPathname();
$this->fs->update($fileName, $content);
$size = $this->fs->getSize($fileName);
$resource->setSize($size);
$this->entityManager->persist($resource);
return true;
}
}
return false;

@ -55,22 +55,6 @@ class GroupVoter extends Voter
return $this->entityManager;
}
/**
* @return CourseManager
*/
public function getCourseManager()
{
return $this->courseManager;
}
/**
* @return GroupManager
*/
public function getGroupManager()
{
return $this->groupManager;
}
/**
* {@inheritdoc}
*/

@ -28,26 +28,8 @@ class CourseSettingsSchema extends AbstractSettingsSchema
*/
protected $toolChain;
/**
* @var CourseManager
*/
protected $courseManager;
protected $repository;
public function setToolChain(ToolChain $tools): void
{
$this->toolChain = $tools;
}
/**
* @param CourseManager $manager
*/
public function setCourseManager($manager): void
{
$this->courseManager = $manager;
}
public function getProcessedToolChain(): array
{
$tools = [];

@ -115,41 +115,6 @@ class ToolChain
}
}
public function updateTools(): void
{
$manager = $this->entityManager;
$tools = $this->getTools();
/** @var AbstractTool $tool */
foreach ($tools as $tool) {
$toolEntity = new Tool();
$toolEntity
->setName($tool->getName())
;
if (1 === $tool->getAdmin()) {
// Only check ROLE_ADMIN
} else {
$this->setToolPermissions($toolEntity);
}
$manager->persist($toolEntity);
$types = $tool->getResourceTypes();
if (!empty($types)) {
foreach ($types as $name => $data) {
$resourceType = new ResourceType();
$resourceType->setName($name);
//$resourceType->setService($data['entity']);
$resourceType->setTool($toolEntity);
$manager->persist($resourceType);
}
}
$manager->flush();
}
}
public function setToolPermissions(Tool $tool): void
{
$toolResourceRight = new ToolResourceRight();

@ -86,22 +86,19 @@ class CourseAdmin extends AbstractAdmin
}
}
foreach ($tools as $tool) {
/*foreach ($tools as $tool) {
$toolName = $tool->getName();
if (!in_array($toolName, $addedTools)) {
$toolEntity = new CTool();
$toolEntity
->setCId($course->getId())
->setImage($tool->getImage())
->setCourse($course)
->setName($tool->getName())
->setLink($tool->getLink())
->setTarget($tool->getTarget())
->setCategory($tool->getCategory())
;
$course->addTools($toolEntity);
}
}
}*/
}
public function setToolChain(ToolChain $chainTool)

@ -1431,7 +1431,7 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement
}
/**
* @param $slug
* @param string $slug
*
* @return User
*/

@ -1,116 +0,0 @@
<?php
namespace Chamilo\UserBundle\Form\EventListener;
use Sylius\Bundle\AttributeBundle\Form\EventListener\BuildAttributeFormChoicesListener as BaseBuildAttributeFormChoicesListener;
use Sylius\Component\Attribute\Model\AttributeTypes;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;
/**
* Form event listener that builds choices for attribute form.
*
* @author Leszek Prabucki <leszek.prabucki@gmail.com>
* @author Liverbool <liverbool@gmail.com>
*/
class BuildAttributeFormChoicesListener extends BaseBuildAttributeFormChoicesListener
{
/**
* Form factory.
*
* @var FormFactoryInterface
*/
private $factory;
/**
* Constructor.
*/
public function __construct(FormFactoryInterface $factory)
{
$this->factory = $factory;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
FormEvents::PRE_SET_DATA => 'buildChoices',
FormEvents::PRE_SUBMIT => 'buildConfiguration',
];
}
/**
* Build configuration field for attribute form.
*/
public function buildConfiguration(FormEvent $event)
{
$data = $event->getData();
$choices = [];
if (AttributeTypes::CHOICE === $data['type'] && !empty($data['choices'])) {
$choices = $data['choices'];
}
$data['configuration'] = $choices;
if (!$event->getForm()->has('configuration')) {
$event->getForm()->add(
$this->factory->createNamed(
'configuration',
'collection',
null,
[
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'auto_initialize' => false,
]
)
);
}
$event->setData($data);
}
/**
* Builds choices for attribute form.
*/
public function buildChoices(FormEvent $event)
{
$attribute = $event->getData();
if (null === $attribute) {
return;
}
$type = $attribute->getType();
if (null === $type || AttributeTypes::CHOICE === $type) {
$data = null;
$config = $attribute->getConfiguration();
if (!empty($config['choices'])) {
$data = $config['choices'];
}
$event->getForm()->add(
$this->factory->createNamed(
'choices',
'collection',
null,
[
'type' => 'text',
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'auto_initialize' => false,
'mapped' => false,
'data' => $data,
]
)
);
}
}
}

@ -1,100 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Form\EventListener;
use Sylius\Component\Attribute\Model\AttributeValueInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
/**
* Class BuildAttributeValueFormListener.
*/
class BuildAttributeValueFormListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
FormEvents::PRE_SET_DATA => 'onPreSetData',
FormEvents::PRE_SUBMIT => 'onPreSubmit',
];
}
/**
* Builds proper product form after setting the product.
*/
public function buildForm(FormEvent $event)
{
/** @var \Chamilo\CoreBundle\Entity\ExtraFieldValues $attributeValue */
$attributeValue = $event->getData();
$form = $event->getForm();
if (null === $attributeValue) {
$form->add(
$this->factory->createNamed(
'value',
'text',
null,
['auto_initialize' => false]
)
);
return;
}
$type = $attributeValue->getType();
$attributeValue->setAttribute($attributeValue->getField());
$options = [
'label' => $attributeValue->getName(),
'auto_initialize' => false,
];
if (is_array($attributeValue->getConfiguration())) {
$options = array_merge(
$options,
$attributeValue->getConfiguration()
);
}
$this->verifyValue($attributeValue);
// If we're editing the attribute value, let's just render the value field, not full selection.
$form
->remove('extraField')
->add($this->factory->createNamed('value', $type, null, $options));
}
/**
* Verify value before set to form.
*/
protected function verifyValue(AttributeValueInterface $attributeValue)
{
switch ($attributeValue->getType()) {
case AttributeTypes::CHECKBOX:
if (!is_bool($attributeValue->getValue())) {
$attributeValue->setValue(false);
}
break;
case AttributeTypes::CHOICE:
if (!is_array($attributeValue->getValue())) {
$attributeValue->setValue(null);
}
break;
case AttributeTypes::MONEY:
case AttributeTypes::NUMBER:
case AttributeTypes::PERCENTAGE:
if (!is_numeric($attributeValue->getValue())) {
$attributeValue->setValue(null);
}
break;
}
}
}

@ -1,65 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Chamilo\UserBundle\Form\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class BuildAttributeFormSubscriber implements EventSubscriberInterface
{
/**
* @var FormFactoryInterface
*/
protected $factory;
public function __construct(FormFactoryInterface $formFactory)
{
$this->factory = $formFactory;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
FormEvents::PRE_SET_DATA => 'addConfigurationFields',
];
}
public function addConfigurationFields(FormEvent $event)
{
$attribute = $event->getData();
$form = $event->getForm();
try {
$requiredFields = $this->factory->createNamed(
'configuration',
'sylius_attribute_type_configuration_'.$attribute->getType(),
null,
[
'auto_initialize' => false,
'label' => 'sylius.attribute_type.configuration',
]
);
$form->add($requiredFields);
} catch (InvalidArgumentException $exception) {
}
}
}

@ -1,83 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Chamilo\UserBundle\Form\EventSubscriber;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class BuildAttributeValueFormSubscriber implements EventSubscriberInterface
{
/**
* @var RepositoryInterface
*/
protected $attributeRepository;
public function __construct(RepositoryInterface $attributeRepository)
{
$this->attributeRepository = $attributeRepository;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
FormEvents::PRE_SET_DATA => 'preSetData',
FormEvents::PRE_SUBMIT => 'preSubmit',
];
}
public function preSetData(FormEvent $event)
{
$attributeValue = $event->getData();
if (null === $attributeValue || null === $attributeValue->getAttribute()) {
return;
}
$this->addValueField($event->getForm(), $attributeValue->getAttribute());
}
public function preSubmit(FormEvent $event)
{
$attributeValue = $event->getData();
if (!isset($attributeValue['value']) || !isset($attributeValue['attribute'])) {
throw new \InvalidArgumentException('Cannot create an attribute value form on pre submit event without "attribute" and "value" keys in data.');
}
$form = $event->getForm();
$attribute = $this->attributeRepository->find($attributeValue['attribute']);
$attribute = $attribute->getAttribute();
$this->addValueField($form, $attribute);
}
private function addValueField(FormInterface $form, AttributeInterface $attribute)
{
$options = [
'auto_initialize' => false,
'label' => $attribute->getName(),
];
$form->add('attribute');
$form->add('value', 'sylius_attribute_type_'.$attribute->getType(), $options);
}
}

@ -1,65 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Form\Type;
use Sylius\Bundle\AttributeBundle\Form\EventSubscriber\BuildAttributeFormSubscriber;
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Attribute type.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
* @author Leszek Prabucki <leszek.prabucki@gmail.com>
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class AttributeType extends AbstractResourceType
{
/**
* @var string
*/
protected $subjectName;
/**
* @param string $dataClass
* @param string $subjectName
*/
public function __construct($dataClass, array $validationGroups, $subjectName)
{
parent::__construct($dataClass, $validationGroups);
$this->subjectName = $subjectName;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->addEventSubscriber(new BuildAttributeFormSubscriber($builder->getFormFactory()))
->addEventSubscriber(new AddCodeFormSubscriber())
/*->add('translations', 'a2lix_translationsForms', array(
'form_type' => sprintf('sylius_%s_attribute_translation', $this->subjectName),
'label' => 'sylius.form.attribute.translations',
))*/
->add('type', 'sylius_attribute_type_choice', [
'label' => 'sylius.form.attribute.type',
'disabled' => true,
])
;
}
/**
* {@inheritdoc}
*/
public function getName()
{ //chamilo_user_extra_field_choice
return 'chamilo_user_attribute_type';
return sprintf('%s_extra_field', $this->subjectName);
}
}

@ -1,58 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Attribute choice form type.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class AttributeTypeChoiceType extends AbstractType
{
/**
* @var array
*/
private $attributeTypes;
/**
* @param array $attributeTypes
*/
public function __construct($attributeTypes)
{
$this->attributeTypes = $attributeTypes;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults(
['choices' => $this->attributeTypes]
)
;
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'choice';
}
/**
* {@inheritdoc}
*/
public function getName()
{
//return sprintf('chamilo_%s_extra_field_choice', $this->subjectName);
return 'chamilo_user_attribute_choice';
}
}

@ -1,114 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Form\Type;
use Chamilo\UserBundle\Form\EventSubscriber\BuildAttributeValueFormSubscriber;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
//use Sylius\Component\Product\Model\AttributeInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
/**
* Attribute value form type.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class AttributeValueType extends AbstractResourceType
{
/**
* Attributes subject name.
*
* @var string
*/
protected $subjectName;
/**
* @var EntityRepository
*/
protected $attributeRepository;
/**
* @param string $dataClass
* @param string $subjectName
*/
public function __construct($dataClass, array $validationGroups, $subjectName, EntityRepository $attributeRepository)
{
parent::__construct($dataClass, $validationGroups);
$this->subjectName = $subjectName;
$this->attributeRepository = $attributeRepository;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
/*->add(
'attribute',
sprintf('chamilo_%s_attribute_choice', $this->subjectName),
['label' => sprintf('chamilo.form.attribute.%s_attribute_value.attribute', $this->subjectName)]
)*/
->addEventSubscriber(
new BuildAttributeValueFormSubscriber($this->attributeRepository)
)
;
// $prototypes = array();
// $attributes = $this->getAttributes($builder);
//
// if ($attributes) {
// /** @var \Chamilo\CoreBundle\Entity\ExtraField $attribute */
// foreach ($attributes as $attribute) {
// if (!empty($attribute)) {
// $configuration = $attribute->getConfiguration();
// $type = $attribute->getTypeToString();
//
// if (!is_array($configuration)) {
// $configuration = array();
// }
//
// if (empty($type)) {
// continue;
// }
// }
//
// $prototypes[] = $builder->create(
// 'value',
// $type,
// $configuration
// )->getForm();
// }
// }
//
// $builder->setAttribute('prototypes', $prototypes);
}
/**
* {@inheritdoc}
*/
/*public function buildView(
FormView $view,
FormInterface $form,
array $options
) {
$view->vars['prototypes'] = array();
foreach ($form->getConfig()->getAttribute('prototypes', array()) as $name => $prototype) {
$view->vars['prototypes'][$name] = $prototype->createView($view);
}
}*/
/**
* {@inheritdoc}
*/
public function getName()
{
return sprintf('chamilo_%s_extra_field_value', $this->subjectName);
}
}

@ -1,134 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Form\Type;
use Chamilo\UserBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Class RegistrationFormType
* Form located in web/app_dev.php/register/.
*/
class RegistrationFormType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'username',
null,
[
'label' => 'form.username',
'translation_domain' => 'FOSUserBundle',
]
)
->add('firstname', 'text')
->add('lastname', 'text')
->add(
'email',
'email',
[
'label' => 'form.email',
'translation_domain' => 'FOSUserBundle',
]
)
->add('captcha', 'Gregwar\CaptchaBundle\Type\CaptchaType');
//$builder
/*->add('official_code', 'text')
->add('email', 'email')
->add('username', 'text')
->add('phone', 'text')
->add('password', 'password')
->add('groups')
->add('timezone', 'timezone')
->add(
'locale',
'locale',
array('preferred_choices' => array('en', 'fr', 'es'))
)
->add(
'picture_uri',
'sonata_media_type',
array(
'provider' => 'sonata.media.provider.image',
'context' => 'user_image',
'required' => false,
)
)
->add(
'extraFields',
'collection',
array(
'required' => false,
'type' => 'chamilo_user.form.type.attribute_value_type',
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
)
)
->add('save', 'submit', array('label' => 'Update'))*/
// ;
// Update Author id
/*$builder->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($currentUser) {
// @var User $user
$user = $event->getData();
$extraFields = $user->getExtrafields();
foreach ($extraFields as $extraField) {
$extraField->setAuthor($currentUser);
}
}
);*/
}
/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to Symfony 2.7+
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'class' => 'Chamilo\UserBundle\Entity\User',
]
);
}
/**
* @return string
*/
public function getParent()
{
return 'fos_user_registration';
}
/**
* @return string
*/
public function getName()
{
return 'chamilo_sonata_user_registration';
}
}

@ -1,103 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Form;
use Chamilo\UserBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Security\Core\SecurityContext;
/**
* Class UserType.
*
* @deprecated
*/
class UserType extends AbstractType
{
private $securityContext;
public function __construct(SecurityContext $securityContext)
{
$this->securityContext = $securityContext;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$currentUser = $this->securityContext->getToken()->getUser();
$builder
->add('firstname', 'text')
->add('lastname', 'text')
->add('official_code', 'text')
->add('email', 'email')
->add('username', 'text')
->add('phone', 'text')
->add('password', 'password')
->add('groups')
->add('timezone', 'timezone')
->add(
'locale',
'locale',
['preferred_choices' => ['en', 'fr', 'es']]
)
->add(
'picture_uri',
'sonata_media_type',
[
'provider' => 'sonata.media.provider.image',
'context' => 'user_image',
'required' => false,
]
)
/*->add(
'extraFields',
'collection',
array(
'required' => false,
//'type' => 'chamilo_user.form.type.attribute_value_type',
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
)
)*/
->add('save', 'submit', ['label' => 'Update']);
// Update Author id
$builder->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($currentUser) {
/** @var User $user */
$user = $event->getData();
$extraFields = $user->getExtrafields();
foreach ($extraFields as $extraField) {
$extraField->setAuthor($currentUser);
}
}
);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
[
'data_class' => 'Chamilo\UserBundle\Entity\User',
]
);
}
/**
* @return string
*/
public function getName()
{
return 'user';
}
}

@ -26,7 +26,6 @@ use Chamilo\CoreBundle\Entity\TrackELastaccess;
use Chamilo\CoreBundle\Entity\TrackELogin;
use Chamilo\CoreBundle\Entity\TrackEOnline;
use Chamilo\CoreBundle\Entity\TrackEUploads;
use Chamilo\CoreBundle\Entity\UserApiKey;
use Chamilo\CoreBundle\Entity\UserCourseCategory;
use Chamilo\CoreBundle\Entity\UsergroupRelUser;
use Chamilo\CoreBundle\Entity\UserRelCourseVote;
@ -1262,29 +1261,6 @@ class UserRepository extends ResourceRepository
$userRelCourseVote[] = implode(', ', $list);
}
// UserApiKey
$criteria = [
'userId' => $userId,
];
$result = $em->getRepository('ChamiloCoreBundle:UserApiKey')->findBy($criteria);
$userApiKey = [];
/** @var UserApiKey $item */
foreach ($result as $item) {
$validityStart = $item->getValidityStartDate() ? $item->getValidityStartDate()->format($dateFormat) : '';
$validityEnd = $item->getValidityEndDate() ? $item->getValidityEndDate()->format($dateFormat) : '';
$created = $item->getCreatedDate() ? $item->getCreatedDate()->format($dateFormat) : '';
$list = [
'ApiKey #'.$item->getApiKey(),
'Service: '.$item->getApiService(),
'EndPoint: '.$item->getApiEndPoint(),
'Validity start date: '.$validityStart,
'Validity enddate: '.$validityEnd,
'Created at: '.$created,
];
$userApiKey[] = implode(', ', $list);
}
$user->setDropBoxSentFiles(
[
'Friends' => $friendList,
@ -1303,7 +1279,6 @@ class UserRepository extends ResourceRepository
'UserCourseCategory' => $userCourseCategory,
'SkillRelUserComment' => $skillRelUserComment,
'UserRelCourseVote' => $userRelCourseVote,
'UserApiKey' => $userApiKey,
// courses
'AttendanceResult' => $cAttendanceResult,

@ -1,76 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\UserBundle\Security;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider as BaseFOSUBProvider;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Class FOSUBUserProvider.
*/
class FOSUBUserProvider extends BaseFOSUBProvider
{
/**
* {@inheritdoc}
*/
public function connect(UserInterface $user, UserResponseInterface $response)
{
$property = $this->getProperty($response);
$username = $response->getUsername();
//on connect - get the access token and the user ID
$service = $response->getResourceOwner()->getName();
$setter = 'set'.ucfirst($service);
$setterId = $setter.'Id';
$setter_token = $setter.'AccessToken';
//we "disconnect" previously connected users
if (null !== $previousUser = $this->userManager->findUserBy([$property => $username])) {
$previousUser->$setterId(null);
$previousUser->$setter_token(null);
$this->userManager->updateUser($previousUser);
}
// We connect current user
$user->$setterId($username);
$user->$setter_token($response->getAccessToken());
$this->userManager->updateUser($user);
}
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$username = $response->getUsername();
$user = $this->userManager->findUserBy([$this->getProperty($response) => $username]);
// User creation
if (null === $user) {
$service = $response->getResourceOwner()->getName();
$setter = 'set'.ucfirst($service);
$setterId = $setter.'Id';
$setterToken = $setter.'AccessToken';
// create new user here
$user = $this->userManager->createUser();
$user->$setterId($username);
$user->$setterToken($response->getAccessToken());
//I have set all requested data with the user's username
//modify here with relevant data
$user->setUsername($username);
$user->setEmail($username);
$user->setPassword($username);
$user->setEnabled(true);
$this->userManager->updateUser($user);
return $user;
}
//if user exists - go with the HWIOAuth way
$user = parent::loadUserByOAuthUserResponse($response);
$serviceName = $response->getResourceOwner()->getName();
$setter = 'set'.ucfirst($serviceName).'AccessToken';
//update access token
$user->$setter($response->getAccessToken());
return $user;
}
}
Loading…
Cancel
Save