diff --git a/Admin/EmailSendAdmin.php b/Admin/EmailSendAdmin.php index b8ecbf1..dfd33fe 100644 --- a/Admin/EmailSendAdmin.php +++ b/Admin/EmailSendAdmin.php @@ -58,8 +58,11 @@ protected function configureFormFields(FormMapper $formMapper) 'expanded' => false, 'required' => false, )) - ->add('isHtmlContent', 'checkbox', array( - 'required' => false + ->add('sendImmediately', 'checkbox', array( + 'mapped' => false, + 'label' => 'Send immediately?', + 'required' => false, + 'attr' => array('class' => 'send_immediately'), )) ->add('sendDate', 'datetime', array( 'required' => false, @@ -92,7 +95,6 @@ protected function configureShowField(ShowMapper $showMapper) ->add('title') ->add('sender') ->add('userLists') - ->add('isHtmlContent') ->add('sendDate') ->add('created') ->add('attempted') @@ -135,7 +137,6 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper) $datagridMapper ->add('title') - ->add('isHtmlContent') ->add('created', $dateType, array(), null, array( 'label' => 'Created after' )) @@ -150,7 +151,6 @@ protected function configureListFields(ListMapper $listMapper) ->add('title') ->add('sender') ->add('userLists') - ->add('isHtmlContent') ->add('sendDate') ->add('created') ->add('attempted') diff --git a/Form/Type/EmailSendChoiceType.php b/Form/Type/EmailSendChoiceType.php new file mode 100644 index 0000000..dbd74f3 --- /dev/null +++ b/Form/Type/EmailSendChoiceType.php @@ -0,0 +1,39 @@ +add('sender') + ->add('userLists') + ->add('sendImmediately', 'checkbox', array( + 'mapped' => false, + 'label' => 'Send immediately?', + 'required' => false, + )) + ->add('sendDate', 'datetime', array( + 'required' => false, + 'date_widget' => 'single_text', + 'time_widget' => 'choice', + )) + ->add('testEmails', 'san_emails') + ; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'emailSendChoice'; + } +} \ No newline at end of file diff --git a/Form/Type/EmailSendType.php b/Form/Type/EmailSendType.php index 7b2646b..f933d0f 100644 --- a/Form/Type/EmailSendType.php +++ b/Form/Type/EmailSendType.php @@ -16,9 +16,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('sender') ->add('userLists') - ->add('isHtmlContent', 'checkbox', array( - 'required' => false - )) ->add('sendDate', 'datetime', array( 'required' => false, 'date_widget' => 'single_text', diff --git a/Resources/views/Admin/CRUD/email_send.html.twig b/Resources/views/Admin/CRUD/email_send.html.twig index e50c5cb..fa06584 100644 --- a/Resources/views/Admin/CRUD/email_send.html.twig +++ b/Resources/views/Admin/CRUD/email_send.html.twig @@ -1,18 +1,18 @@ {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %} {% block form %} -
- {% if form.vars.errors|length > 0 %} -
- {{ form_errors(form) }} -
- {% endif %} - - {% block sonata_pre_fieldsets %} + + {% if form.vars.errors|length > 0 %} +
+ {{ form_errors(form) }} +
+ {% endif %} + + {% block sonata_pre_fieldsets %}
- {% endblock %} - -
- {% for name, form_group in admin.formgroups %} -
-
-
- {% if form_group.description != false %} -

{{ form_group.description|raw }}

- {% endif %} + {% endblock %} - {% for field_name in form_group.fields %} - {% if admin.formfielddescriptions[field_name] is defined %} - {{ form_row(form[field_name])}} +
+ {% for name, form_group in admin.formgroups %} +
+
+
+ {% if form_group.description != false %} +

{{ form_group.description|raw }}

{% endif %} - {% endfor %} -
-
-
- {% endfor %} -
- {% block sonata_post_fieldsets %} + {% for field_name in form_group.fields %} + {% if admin.formfielddescriptions[field_name] is defined %} + {{ form_row(form[field_name])}} + {% endif %} + {% endfor %} +
+
+
+ {% endfor %} +
+ + {% block sonata_post_fieldsets %}
- {% endblock %} + {% endblock %} - {{ form_rest(form) }} + {{ form_rest(form) }} - {% block formactions %} -
- - -
- {% endblock formactions %} -
+ {% block formactions %} +
+ + +
+ {% endblock formactions %} + {% endblock %} {% block footer %} + {{ parent() }} {% include 'SanEmailBundle:Admin/CRUD:preview_modal.html.twig' %} + {% endblock %} diff --git a/Validator/Constraints/EmailSendConstraint.php b/Validator/Constraints/EmailSendConstraint.php index c489a3d..87d0789 100644 --- a/Validator/Constraints/EmailSendConstraint.php +++ b/Validator/Constraints/EmailSendConstraint.php @@ -12,6 +12,8 @@ class EmailSendConstraint extends Constraint public $invalidUserLists = 'Please pick up at least one user list'; + public $invalidSendDate = 'Please set a send date in future'; + public function getTargets() { return self::CLASS_CONSTRAINT; diff --git a/Validator/Constraints/EmailSendConstraintValidator.php b/Validator/Constraints/EmailSendConstraintValidator.php index 157f70d..fc9030c 100644 --- a/Validator/Constraints/EmailSendConstraintValidator.php +++ b/Validator/Constraints/EmailSendConstraintValidator.php @@ -25,6 +25,16 @@ public function validate($object, Constraint $constraint) return; } + if (!$object->getIsTest()) { + if ($object->getSendDate() == null) { + return; + } + if ($object->getSendDate() < new \DateTime()) { + return $this->context->addViolationAt('emailSend', $constraint->invalidSendDate); + } else { + return; + } + } if ($object->getUserLists()->count() == 0) { return $this->context->addViolationAt('userLists', $constraint->invalidUserLists);