parent
faab0f81bb
commit
53f6ecf63f
@ -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> |
File diff suppressed because it is too large
Load Diff
@ -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'; |
||||
} |
||||
} |
@ -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…
Reference in new issue