PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/app/bundles/LeadBundle/Form/Type/LeadImportFieldType.php

https://gitlab.com/mautic-master/mautic
PHP | 290 lines | 230 code | 29 blank | 31 comment | 1 complexity | b1af3f6fbb65536f0369008a178240c8 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Mautic
  4. * @copyright 2014 Mautic Contributors. All rights reserved.
  5. * @author Mautic
  6. * @link http://mautic.org
  7. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
  8. */
  9. namespace Mautic\LeadBundle\Form\Type;
  10. use Mautic\CoreBundle\Factory\MauticFactory;
  11. use Symfony\Component\Form\AbstractType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  14. /**
  15. * Class LeadImportFieldType
  16. *
  17. * @package Mautic\LeadBundle\Form\Type
  18. */
  19. class LeadImportFieldType extends AbstractType
  20. {
  21. private $factory;
  22. /**
  23. * @param MauticFactory $factory
  24. */
  25. public function __construct(MauticFactory $factory)
  26. {
  27. $this->factory = $factory;
  28. }
  29. /**
  30. * @param FormBuilderInterface $builder
  31. * @param array $options
  32. */
  33. public function buildForm(FormBuilderInterface $builder, array $options)
  34. {
  35. foreach ($options['lead_fields'] as $field => $label) {
  36. $builder->add(
  37. $field,
  38. 'choice',
  39. array(
  40. 'choices' => $options['import_fields'],
  41. 'label' => $label,
  42. 'required' => false,
  43. 'label_attr' => array('class' => 'control-label'),
  44. 'attr' => array('class' => 'form-control'),
  45. 'data' => $this->getDefaultValue($field, $options['import_fields'])
  46. )
  47. );
  48. }
  49. $properties = $builder->create('properties', 'form', array('virtual' => true));
  50. $properties->add(
  51. 'dateAdded',
  52. 'choice',
  53. array(
  54. 'choices' => $options['import_fields'],
  55. 'label' => 'mautic.lead.import.label.dateAdded',
  56. 'required' => false,
  57. 'label_attr' => array('class' => 'control-label'),
  58. 'attr' => array('class' => 'form-control'),
  59. 'data' => $this->getDefaultValue('dateAdded', $options['import_fields'])
  60. )
  61. );
  62. $properties->add(
  63. 'createdByUser',
  64. 'choice',
  65. array(
  66. 'choices' => $options['import_fields'],
  67. 'label' => 'mautic.lead.import.label.createdByUser',
  68. 'required' => false,
  69. 'label_attr' => array('class' => 'control-label'),
  70. 'attr' => array('class' => 'form-control'),
  71. 'data' => $this->getDefaultValue('createdByUser', $options['import_fields'])
  72. )
  73. );
  74. $properties->add(
  75. 'dateModified',
  76. 'choice',
  77. array(
  78. 'choices' => $options['import_fields'],
  79. 'label' => 'mautic.lead.import.label.dateModified',
  80. 'required' => false,
  81. 'label_attr' => array('class' => 'control-label'),
  82. 'attr' => array('class' => 'form-control'),
  83. 'data' => $this->getDefaultValue('dateModified', $options['import_fields'])
  84. )
  85. );
  86. $properties->add(
  87. 'modifiedByUser',
  88. 'choice',
  89. array(
  90. 'choices' => $options['import_fields'],
  91. 'label' => 'mautic.lead.import.label.modifiedByUser',
  92. 'required' => false,
  93. 'label_attr' => array('class' => 'control-label'),
  94. 'attr' => array('class' => 'form-control'),
  95. 'data' => $this->getDefaultValue('modifiedByUser', $options['import_fields'])
  96. )
  97. );
  98. $properties->add(
  99. 'lastActive',
  100. 'choice',
  101. array(
  102. 'choices' => $options['import_fields'],
  103. 'label' => 'mautic.lead.import.label.lastActive',
  104. 'required' => false,
  105. 'label_attr' => array('class' => 'control-label'),
  106. 'attr' => array('class' => 'form-control'),
  107. 'data' => $this->getDefaultValue('lastActive', $options['import_fields'])
  108. )
  109. );
  110. $properties->add(
  111. 'dateIdentified',
  112. 'choice',
  113. array(
  114. 'choices' => $options['import_fields'],
  115. 'label' => 'mautic.lead.import.label.dateIdentified',
  116. 'required' => false,
  117. 'label_attr' => array('class' => 'control-label'),
  118. 'attr' => array('class' => 'form-control'),
  119. 'data' => $this->getDefaultValue('dateIdentified', $options['import_fields'])
  120. )
  121. );
  122. $properties->add(
  123. 'ip',
  124. 'choice',
  125. array(
  126. 'choices' => $options['import_fields'],
  127. 'label' => 'mautic.lead.import.label.ip',
  128. 'required' => false,
  129. 'label_attr' => array('class' => 'control-label'),
  130. 'attr' => array('class' => 'form-control'),
  131. 'data' => $this->getDefaultValue('ip', $options['import_fields'])
  132. )
  133. );
  134. $properties->add(
  135. 'points',
  136. 'choice',
  137. array(
  138. 'choices' => $options['import_fields'],
  139. 'label' => 'mautic.lead.import.label.points',
  140. 'required' => false,
  141. 'label_attr' => array('class' => 'control-label'),
  142. 'attr' => array('class' => 'form-control'),
  143. 'data' => $this->getDefaultValue('points', $options['import_fields'])
  144. )
  145. );
  146. $properties->add(
  147. 'stage',
  148. 'choice',
  149. array(
  150. 'choices' => $options['import_fields'],
  151. 'label' => 'mautic.lead.import.label.stage',
  152. 'required' => false,
  153. 'label_attr' => array('class' => 'control-label'),
  154. 'attr' => array('class' => 'form-control'),
  155. 'data' => $this->getDefaultValue('stage', $options['import_fields'])
  156. )
  157. );
  158. $properties->add(
  159. 'doNotEmail',
  160. 'choice',
  161. array(
  162. 'choices' => $options['import_fields'],
  163. 'label' => 'mautic.lead.import.label.doNotEmail',
  164. 'required' => false,
  165. 'label_attr' => array('class' => 'control-label'),
  166. 'attr' => array('class' => 'form-control'),
  167. 'data' => $this->getDefaultValue('doNotEmail', $options['import_fields'])
  168. )
  169. );
  170. $builder->add($properties);
  171. $transformer = new \Mautic\CoreBundle\Form\DataTransformer\IdToEntityModelTransformer(
  172. $this->factory->getEntityManager(),
  173. 'MauticUserBundle:User'
  174. );
  175. $builder->add(
  176. $builder->create(
  177. 'owner',
  178. 'user_list',
  179. array(
  180. 'label' => 'mautic.lead.lead.field.owner',
  181. 'label_attr' => array('class' => 'control-label'),
  182. 'attr' => array(
  183. 'class' => 'form-control'
  184. ),
  185. 'required' => false,
  186. 'multiple' => false
  187. )
  188. )
  189. ->addModelTransformer($transformer)
  190. );
  191. $builder->add(
  192. $builder->create(
  193. 'list',
  194. 'leadlist_choices',
  195. array(
  196. 'label' => 'mautic.lead.lead.field.list',
  197. 'label_attr' => array('class' => 'control-label'),
  198. 'attr' => array(
  199. 'class' => 'form-control'
  200. ),
  201. 'required' => false,
  202. 'multiple' => false
  203. )
  204. )
  205. );
  206. $builder->add(
  207. 'tags',
  208. 'lead_tag',
  209. array(
  210. 'label' => 'mautic.lead.tags',
  211. 'required' => false,
  212. 'label_attr' => array('class' => 'control-label'),
  213. 'attr' => array(
  214. 'class' => 'form-control',
  215. 'data-placeholder' => $this->factory->getTranslator()->trans('mautic.lead.tags.select_or_create'),
  216. 'data-no-results-text' => $this->factory->getTranslator()->trans('mautic.lead.tags.enter_to_create'),
  217. 'data-allow-add' => 'true',
  218. 'onchange' => 'Mautic.createLeadTag(this)'
  219. )
  220. )
  221. );
  222. $builder->add(
  223. 'buttons',
  224. 'form_buttons',
  225. array(
  226. 'apply_text' => false,
  227. 'save_text' => 'mautic.lead.import.start',
  228. 'save_class' => 'btn btn-primary',
  229. 'save_icon' => 'fa fa-user-plus',
  230. 'cancel_icon' => 'fa fa-times'
  231. )
  232. );
  233. }
  234. /**
  235. * @param OptionsResolverInterface $resolver
  236. */
  237. public function setDefaultOptions(OptionsResolverInterface $resolver)
  238. {
  239. $resolver->setRequired(array('lead_fields', 'import_fields'));
  240. }
  241. /**
  242. * @return string
  243. */
  244. public function getName()
  245. {
  246. return "lead_field_import";
  247. }
  248. /**
  249. * @param string $fieldName
  250. * @param array $importFields
  251. *
  252. * @return string
  253. */
  254. public function getDefaultValue($fieldName, array $importFields)
  255. {
  256. if (isset($importFields[$fieldName])) {
  257. return $importFields[$fieldName];
  258. }
  259. return null;
  260. }
  261. }