Example #1
0
 /**
  * Adds events to the calendar.
  *
  * @param CalendarGeneratorEvent $event
  *
  * @todo   This method is only a model and should be removed when actual data is being populated
  */
 public function onCalendarGenerate(CalendarGeneratorEvent $event)
 {
     $dates = $event->getDates();
     $commonSelect = 'p.title, p.id as page_id, c.color';
     $eventTypes = ['publish.up' => ['dateName' => 'publish_up', 'setter' => 'PublishUp'], 'publish.down' => ['dateName' => 'publish_down', 'setter' => 'PublishDown']];
     $query = $this->em->getConnection()->createQueryBuilder();
     $query->from(MAUTIC_TABLE_PREFIX . 'pages', 'p')->leftJoin('p', MAUTIC_TABLE_PREFIX . 'categories', 'c', 'c.id = p.category_id AND c.bundle=:bundle')->setParameter('bundle', 'page')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(50);
     foreach ($eventTypes as $eventKey => $eventType) {
         $query->select($commonSelect . ', ' . $eventType['dateName'] . ' AS start')->where($query->expr()->andX($query->expr()->gte('p.' . $eventType['dateName'], ':start'), $query->expr()->lte('p.' . $eventType['dateName'], ':end')));
         $results = $query->execute()->fetchAll();
         // We need to convert the date to a ISO8601 compliant string
         foreach ($results as &$object) {
             $date = new DateTimeHelper($object['start']);
             $eventTitle = $this->translator->trans('mautic.page.event.' . $eventKey, ['%page%' => $object['title']]);
             $object['start'] = $date->toLocalString(\DateTime::ISO8601);
             $object['setter'] = $eventType['setter'];
             $object['entityId'] = $object['page_id'];
             $object['entityType'] = 'page';
             $object['editable'] = true;
             $object['url'] = $this->router->generate('mautic_calendar_action', ['objectAction' => 'edit', 'source' => 'page', 'objectId' => $object['page_id'], 'startDate' => $date->toLocalString()], true);
             $object['viewUrl'] = $this->router->generate('mautic_page_action', ['objectAction' => 'view', 'objectId' => $object['page_id']], true);
             $object['attr'] = ['data-toggle' => 'ajaxmodal', 'data-target' => '#CalendarEditModal', 'data-header' => $eventTitle];
             $object['description'] = $this->translator->trans('mautic.page.event.' . $eventKey . '.description', ['%page%' => $object['title']]);
             $object['title'] = $eventTitle;
         }
         $event->addEvents($results);
     }
 }
 /**
  * Adds events to the calendar
  *
  * @param CalendarGeneratorEvent $event
  *
  * @return void
  */
 public function onCalendarGenerate(CalendarGeneratorEvent $event)
 {
     $dates = $event->getDates();
     $router = $this->factory->getRouter();
     $now = new DateTimeHelper();
     $commonSelect = 'cl.campaign_id, c.name AS campaign_name, l.firstname, l.lastname, ce.type AS event_type, ce.name as event_name, cat.color';
     $eventTypes = array();
     $eventTypes['triggered'] = array('dateName' => 'cl.date_triggered');
     $eventTypes['upcoming'] = array('dateName' => 'cl.trigger_date');
     $query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
     $query->from(MAUTIC_TABLE_PREFIX . 'campaign_lead_event_log', 'cl')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'campaigns', 'c', 'cl.campaign_id = c.id')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'leads', 'l', 'cl.lead_id = l.id')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'campaign_events', 'ce', 'cl.event_id = ce.id')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'categories', 'cat', 'cat.id = c.category_id AND cat.bundle="campaign"')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(50);
     foreach ($eventTypes as $eventKey => $eventType) {
         $query->select($commonSelect . ', ' . $eventType['dateName'] . ' AS start')->where($query->expr()->andX($query->expr()->gte($eventType['dateName'], ':start'), $query->expr()->lte($eventType['dateName'], ':end')));
         if ($eventKey == 'upcoming') {
             $query->andWhere($query->expr()->gte($eventType['dateName'], ':now'))->setParameter('now', $now->toUtcString());
         }
         $results = $query->execute()->fetchAll();
         // echo "<pre>";var_dump($results);die("</pre>");
         // We need to convert the date to a ISO8601 compliant string
         foreach ($results as &$object) {
             if ($object['firstname'] || $object['lastname']) {
                 $leadName = $object['firstname'] . ' ' . $object['lastname'];
             } else {
                 $leadName = $this->translator->trans('mautic.lead.lead.anonymous');
             }
             $date = new DateTimeHelper($object['start']);
             $object['start'] = $date->toLocalString(\DateTime::ISO8601);
             $object['url'] = $router->generate('mautic_campaign_action', array('objectAction' => 'view', 'objectId' => $object['campaign_id']), true);
             $object['attr'] = 'data-toggle="ajax"';
             $object['description'] = $this->translator->trans('mautic.campaign.event.' . $eventKey . '.description', array('%campaign%' => $object['campaign_name'], '%lead%' => $leadName));
             $object['title'] = $this->translator->trans('mautic.campaign.event.' . $eventKey, array('%event%' => $object['event_name']));
         }
         $event->addEvents($results);
     }
 }
Example #3
0
 /**
  * Adds events to the calendar.
  *
  * @param CalendarGeneratorEvent $event
  */
 public function onCalendarGenerate(CalendarGeneratorEvent $event)
 {
     $dates = $event->getDates();
     $query = $this->em->getConnection()->createQueryBuilder();
     $query->select('es.email_id, e.subject AS title, COUNT(es.id) AS quantity, es.date_sent AS start, e.plain_text AS description, cat.color, es.lead_id, l.firstname, l.lastname, l.email')->from(MAUTIC_TABLE_PREFIX . 'email_stats', 'es')->leftJoin('es', MAUTIC_TABLE_PREFIX . 'emails', 'e', 'es.email_id = e.id')->leftJoin('e', MAUTIC_TABLE_PREFIX . 'categories', 'cat', 'cat.id = e.category_id AND cat.bundle=:bundle')->leftJoin('es', MAUTIC_TABLE_PREFIX . 'leads', 'l', 'l.id = es.lead_id')->where($query->expr()->andX($query->expr()->gte('es.date_sent', ':start'), $query->expr()->lte('es.date_sent', ':end')))->groupBy('e.id, es.email_id, e.subject, es.date_sent, e.plain_text, cat.color, es.lead_id, l.firstname, l.lastname, l.email')->setParameter('bundle', 'email')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(15);
     $results = $query->execute()->fetchAll();
     // We need to convert the date to a ISO8601 compliant string
     foreach ($results as &$object) {
         $date = new DateTimeHelper($object['start']);
         $object['start'] = $date->toLocalString(\DateTime::ISO8601);
         if ($object['email_id']) {
             $object['url'] = $this->router->generate('mautic_email_action', ['objectAction' => 'view', 'objectId' => $object['email_id']], true);
             $object['attr'] = 'data-toggle="ajax"';
             $object['description'] = html_entity_decode($object['description']);
             $object['title'] = $this->translator->trans('mautic.email.event.sent', ['%email%' => $object['title'], '%x%' => $object['quantity']]);
         } else {
             if ($object['firstname'] || $object['lastname']) {
                 $contactName = trim($object['firstname'] . ' ' . $object['lastname']);
             } elseif ($object['email']) {
                 $contactName = $object['email'];
             } else {
                 $contactName = $this->translator->trans('mautic.lead.lead.anonymous');
             }
             $details = $this->translator->trans('mautic.email.event.sent.direct', ['%contact%' => $contactName]);
             $object['url'] = $this->router->generate('mautic_contact_action', ['objectAction' => 'view', 'objectId' => $object['lead_id']], true);
             $object['attr'] = 'data-toggle="ajax"';
             $object['title'] = $details;
             $object['description'] = $details;
         }
     }
     $event->addEvents($results);
 }
 public function transform($rawFilters)
 {
     if (!is_array($rawFilters)) {
         return array();
     }
     foreach ($rawFilters as $k => $f) {
         if ($f['type'] == 'datetime') {
             $dt = new DateTimeHelper($f['filter'], 'Y-m-d H:i');
             $rawFilters[$k]['filter'] = $dt->toLocalString();
         }
     }
     return $rawFilters;
 }
 /**
  * Adds events to the calendar
  *
  * @param CalendarGeneratorEvent $event
  *
  * @return void
  */
 public function onCalendarGenerate(CalendarGeneratorEvent $event)
 {
     $dates = $event->getDates();
     $query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
     $query->select('fs.referer AS url, f.name AS title, fs.date_submitted AS start')->from(MAUTIC_TABLE_PREFIX . 'form_submissions', 'fs')->leftJoin('fs', MAUTIC_TABLE_PREFIX . 'forms', 'f', 'fs.form_id = f.id')->where($query->expr()->andX($query->expr()->gte('fs.date_submitted', ':start'), $query->expr()->lte('fs.date_submitted', ':end')))->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(5);
     $results = $query->execute()->fetchAll();
     // We need to convert the date to a ISO8601 compliant string
     foreach ($results as &$object) {
         $date = new DateTimeHelper($object['start']);
         $object['start'] = $date->toLocalString(\DateTime::ISO8601);
         $object['title'] = $this->translator->trans('mautic.form.event.submission', array('%form%' => $object['title']));
     }
     $event->addEvents($results);
 }
Example #6
0
 /**
  * From DB format to form format
  *
  * @param mixed $rawFilters
  *
  * @return array|mixed
  */
 public function transform($rawFilters)
 {
     if (!is_array($rawFilters)) {
         return array();
     }
     foreach ($rawFilters as $k => $f) {
         if ($f['type'] == 'datetime') {
             if (in_array($f['filter'], $this->relativeDateStrings) or stristr($f['filter'][0], '-') or stristr($f['filter'][0], '+')) {
                 continue;
             }
             $dt = new DateTimeHelper($f['filter'], 'Y-m-d H:i');
             $rawFilters[$k]['filter'] = $dt->toLocalString();
         }
     }
     return $rawFilters;
 }
 /**
  * {@inheritdoc}
  *
  * @return array
  */
 public function transform($filters)
 {
     if (!is_array($filters)) {
         return [];
     }
     foreach ($filters as &$f) {
         if (!isset($this->columns[$f['column']])) {
             // Likely being called by form.pre_set_data after post
             return $filters;
         }
         $type = $this->columns[$f['column']]['type'];
         if (in_array($type, ['datetime', 'date', 'time'])) {
             $dt = new DateTimeHelper($f['value'], '', 'utc');
             $f['value'] = $dt->toLocalString();
         }
     }
     return $filters;
 }
 /**
  * Adds events to the calendar
  *
  * @param CalendarGeneratorEvent $event
  *
  * @return void
  */
 public function onCalendarGenerate(CalendarGeneratorEvent $event)
 {
     $dates = $event->getDates();
     $router = $this->factory->getRouter();
     $query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
     $query->select('es.email_id, e.subject AS title, COUNT(es.id) AS quantity, es.date_sent AS start, e.plain_text AS description, cat.color')->from(MAUTIC_TABLE_PREFIX . 'email_stats', 'es')->leftJoin('es', MAUTIC_TABLE_PREFIX . 'emails', 'e', 'es.email_id = e.id')->leftJoin('e', MAUTIC_TABLE_PREFIX . 'categories', 'cat', 'cat.id = e.category_id AND cat.bundle="email"')->where($query->expr()->andX($query->expr()->gte('es.date_sent', ':start'), $query->expr()->lte('es.date_sent', ':end')))->groupBy('e.id, es.email_id, e.subject, es.date_sent, e.plain_text, cat.color')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(15);
     $results = $query->execute()->fetchAll();
     // We need to convert the date to a ISO8601 compliant string
     foreach ($results as &$object) {
         $date = new DateTimeHelper($object['start']);
         $object['start'] = $date->toLocalString(\DateTime::ISO8601);
         $object['url'] = $router->generate('mautic_email_action', array('objectAction' => 'view', 'objectId' => $object['email_id']), true);
         $object['attr'] = 'data-toggle="ajax"';
         $object['description'] = html_entity_decode($object['description']);
         $object['title'] = $this->translator->trans('mautic.email.event.sent', array('%email%' => $object['title'], '%x%' => $object['quantity']));
     }
     $event->addEvents($results);
 }
Example #9
0
 /**
  * Adds events to the calendar
  *
  * @param CalendarGeneratorEvent $event
  *
  * @return void
  */
 public function onCalendarGenerate(CalendarGeneratorEvent $event)
 {
     $dates = $event->getDates();
     $router = $this->factory->getRouter();
     // Lead Notes
     $query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
     $query->select('ln.lead_id, l.firstname, l.lastname, ln.date_time AS start, ln.text AS description, ln.type')->from(MAUTIC_TABLE_PREFIX . 'lead_notes', 'ln')->leftJoin('ln', MAUTIC_TABLE_PREFIX . 'leads', 'l', 'ln.lead_id = l.id')->where($query->expr()->andX($query->expr()->gte('ln.date_time', ':start'), $query->expr()->lte('ln.date_time', ':end')))->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(100);
     $results = $query->execute()->fetchAll();
     // We need to convert the date to a ISO8601 compliant string
     foreach ($results as &$object) {
         if ($object['firstname'] || $object['lastname']) {
             $leadName = $object['firstname'] . ' ' . $object['lastname'];
         } else {
             $leadName = $this->translator->trans('mautic.lead.lead.anonymous');
         }
         $date = new DateTimeHelper($object['start']);
         $object['start'] = $date->toLocalString(\DateTime::ISO8601);
         $object['url'] = $router->generate('mautic_contact_action', array('objectAction' => 'view', 'objectId' => $object['lead_id']), true);
         $object['attr'] = 'data-toggle="ajax"';
         $object['description'] = strip_tags(html_entity_decode($object['description']));
         switch ($object['type']) {
             default:
             case 'general':
                 $icon = 'fa-file-text';
                 break;
             case 'email':
                 $icon = 'fa-send';
                 break;
             case 'call':
                 $icon = 'fa-phone';
                 break;
             case 'meeting':
                 $icon = 'fa-group';
                 break;
         }
         $object['iconClass'] = 'fa fa-fw ' . $icon;
         $object['title'] = $leadName;
         //$object['title'] .= ' (' . $this->translator->trans('mautic.lead.note.type.' . $object['type']) . ')';
     }
     $event->addEvents($results);
 }
 private function getFormFields(FormBuilderInterface $builder, array $options, $object = 'lead')
 {
     $fieldValues = [];
     $isObject = false;
     if (!empty($options['data'])) {
         $isObject = is_object($options['data']);
         $fieldValues = $isObject ? $options['data']->getFields() : $options['data'];
     }
     $mapped = !$isObject;
     foreach ($options['fields'] as $field) {
         if ($field['isPublished'] === false || $field['object'] !== $object) {
             continue;
         }
         $attr = ['class' => 'form-control'];
         $properties = $field['properties'];
         $type = $field['type'];
         $required = $isObject ? $field['isRequired'] : false;
         $alias = $field['alias'];
         $group = $field['group'];
         if ($field['isUniqueIdentifer']) {
             $attr['data-unique-identifier'] = $field['alias'];
         }
         if ($isObject) {
             $value = isset($fieldValues[$group][$alias]['value']) ? $fieldValues[$group][$alias]['value'] : $field['defaultValue'];
         } else {
             $value = isset($fieldValues[$alias]) ? $fieldValues[$alias] : '';
         }
         $constraints = [];
         if ($required && empty($options['ignore_required_constraints'])) {
             $constraints[] = new NotBlank(['message' => 'mautic.lead.customfield.notblank']);
         }
         switch ($type) {
             case 'number':
                 if (empty($properties['precision'])) {
                     $properties['precision'] = null;
                 } else {
                     $properties['precision'] = (int) $properties['precision'];
                 }
                 if ('' === $value) {
                     // Prevent transform errors
                     $value = null;
                 }
                 $builder->add($alias, $type, ['required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'attr' => $attr, 'data' => null !== $value ? (double) $value : $value, 'mapped' => $mapped, 'constraints' => $constraints, 'precision' => $properties['precision'], 'rounding_mode' => isset($properties['roundmode']) ? (int) $properties['roundmode'] : 0]);
                 break;
             case 'date':
             case 'datetime':
             case 'time':
                 $attr['data-toggle'] = $type;
                 $opts = ['required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'widget' => 'single_text', 'attr' => $attr, 'mapped' => $mapped, 'input' => 'string', 'html5' => false, 'constraints' => $constraints];
                 if ($value) {
                     try {
                         $dtHelper = new DateTimeHelper($value, null, 'local');
                     } catch (\Exception $e) {
                         // Rather return empty value than break the page
                         $value = null;
                     }
                 }
                 if ($type == 'datetime') {
                     $opts['model_timezone'] = 'UTC';
                     $opts['view_timezone'] = date_default_timezone_get();
                     $opts['format'] = 'yyyy-MM-dd HH:mm';
                     $opts['with_seconds'] = false;
                     $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d H:i:s') : null;
                 } elseif ($type == 'date') {
                     $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d') : null;
                 } else {
                     $opts['data'] = !empty($value) ? $dtHelper->toLocalString('H:i:s') : null;
                 }
                 $builder->add($alias, $type, $opts);
                 break;
             case 'select':
             case 'multiselect':
             case 'boolean':
                 $typeProperties = ['required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'attr' => $attr, 'mapped' => $mapped, 'multiple' => false, 'constraints' => $constraints];
                 $choiceType = 'choice';
                 $emptyValue = '';
                 if (in_array($type, ['select', 'multiselect']) && !empty($properties['list'])) {
                     $typeProperties['choices'] = FormFieldHelper::parseList($properties['list']);
                     $typeProperties['expanded'] = false;
                     $typeProperties['multiple'] = 'multiselect' === $type;
                 }
                 if ($type == 'boolean' && !empty($properties['yes']) && !empty($properties['no'])) {
                     $choiceType = 'yesno_button_group';
                     $typeProperties['expanded'] = true;
                     $typeProperties['yes_label'] = $properties['yes'];
                     $typeProperties['no_label'] = $properties['no'];
                     $typeProperties['attr'] = [];
                     $emptyValue = ' x ';
                     if ($value !== '' && $value !== null) {
                         $value = (int) $value;
                     }
                 }
                 $typeProperties['data'] = $type === 'multiselect' ? FormFieldHelper::parseList($value) : $value;
                 $typeProperties['empty_value'] = $emptyValue;
                 $builder->add($alias, $choiceType, $typeProperties);
                 break;
             case 'country':
             case 'region':
             case 'timezone':
             case 'locale':
                 switch ($type) {
                     case 'country':
                         $choices = FormFieldHelper::getCountryChoices();
                         break;
                     case 'region':
                         $choices = FormFieldHelper::getRegionChoices();
                         break;
                     case 'timezone':
                         $choices = FormFieldHelper::getTimezonesChoices();
                         break;
                     case 'locale':
                         $choices = FormFieldHelper::getLocaleChoices();
                         break;
                 }
                 $builder->add($alias, 'choice', ['choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'data' => $value, 'attr' => ['class' => 'form-control', 'data-placeholder' => $field['label']], 'mapped' => $mapped, 'multiple' => false, 'expanded' => false, 'constraints' => $constraints]);
                 break;
             default:
                 if ($type == 'lookup') {
                     $type = 'text';
                     $attr['data-toggle'] = 'field-lookup';
                     $attr['data-action'] = 'lead:fieldList';
                     $attr['data-target'] = $alias;
                     if (!empty($properties['list'])) {
                         $attr['data-options'] = $properties['list'];
                     }
                 }
                 $builder->add($alias, $type, ['required' => $field['isRequired'], 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'attr' => $attr, 'data' => $value, 'mapped' => $mapped, 'constraints' => $constraints]);
                 break;
         }
     }
 }
Example #11
0
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new CleanFormSubscriber());
     $builder->addEventSubscriber(new FormExitSubscriber('lead.lead', $options));
     if (!$options['isShortForm']) {
         $transformer = new IdToEntityModelTransformer($this->factory->getEntityManager(), 'MauticUserBundle:User');
         $builder->add($builder->create('owner', 'user_list', array('label' => 'mautic.lead.lead.field.owner', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false, 'multiple' => false))->addModelTransformer($transformer));
         $imageChoices = array('gravatar' => 'Gravatar', 'custom' => 'mautic.lead.lead.field.custom_avatar');
         $cache = $options['data']->getSocialCache();
         if (count($cache)) {
             foreach ($cache as $key => $data) {
                 $imageChoices[$key] = $key;
             }
         }
         $builder->add('preferred_profile_image', 'choice', array('choices' => $imageChoices, 'label' => 'mautic.lead.lead.field.preferred_profile', 'label_attr' => array('class' => 'control-label'), 'required' => true, 'multiple' => false, 'attr' => array('class' => 'form-control')));
         $builder->add('custom_avatar', 'file', array('label' => false, 'label_attr' => array('class' => 'control-label'), 'required' => false, 'attr' => array('class' => 'form-control'), 'mapped' => false, 'constraints' => array(new File(array('mimeTypes' => array('image/gif', 'image/jpeg', 'image/png'), 'mimeTypesMessage' => 'mautic.lead.avatar.types_invalid')))));
     }
     $fieldValues = !empty($options['data']) ? $options['data']->getFields() : array('filter' => array('isVisible' => true));
     foreach ($options['fields'] as $field) {
         $attr = array('class' => 'form-control');
         $properties = $field['properties'];
         $type = $field['type'];
         $required = $field['isRequired'];
         $alias = $field['alias'];
         $group = $field['group'];
         $value = isset($fieldValues[$group][$alias]['value']) ? $fieldValues[$group][$alias]['value'] : $field['defaultValue'];
         $constraints = array();
         if ($required) {
             $constraints[] = new NotBlank(array('message' => 'mautic.lead.customfield.notblank'));
         }
         if ($type == 'number') {
             if (empty($properties['precision'])) {
                 $properties['precision'] = null;
             } else {
                 $properties['precision'] = (int) $properties['precision'];
             }
             $builder->add($alias, $type, array('required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'attr' => $attr, 'data' => isset($fieldValues[$group][$alias]['value']) ? (double) $fieldValues[$group][$alias]['value'] : (double) $field['defaultValue'], 'mapped' => false, 'constraints' => $constraints, 'precision' => $properties['precision'], 'rounding_mode' => (int) $properties['roundmode']));
         } elseif (in_array($type, array('date', 'datetime', 'time'))) {
             $attr['data-toggle'] = $type;
             $opts = array('required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'widget' => 'single_text', 'attr' => $attr, 'mapped' => false, 'input' => 'string', 'html5' => false, 'constraints' => $constraints);
             $dtHelper = new DateTimeHelper($value, null, 'local');
             if ($type == 'datetime') {
                 $opts['model_timezone'] = 'UTC';
                 $opts['view_timezone'] = date_default_timezone_get();
                 $opts['format'] = 'yyyy-MM-dd HH:mm';
                 $opts['with_seconds'] = false;
                 $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d H:i:s') : null;
             } elseif ($type == 'date') {
                 $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d') : null;
             } else {
                 $opts['data'] = !empty($value) ? $dtHelper->toLocalString('H:i:s') : null;
             }
             $builder->add($alias, $type, $opts);
         } elseif ($type == 'select' || $type == 'boolean') {
             $choices = array();
             if ($type == 'select' && !empty($properties['list'])) {
                 $list = explode('|', $properties['list']);
                 foreach ($list as $l) {
                     $l = trim($l);
                     $choices[$l] = $l;
                 }
                 $expanded = false;
             }
             if ($type == 'boolean' && !empty($properties['yes']) && !empty($properties['no'])) {
                 $expanded = true;
                 $choices = array(1 => $properties['yes'], 0 => $properties['no']);
                 $attr = array();
             }
             if (!empty($choices)) {
                 $builder->add($alias, 'choice', array('choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'data' => $type == 'boolean' ? (int) $value : $value, 'attr' => $attr, 'mapped' => false, 'multiple' => false, 'empty_value' => false, 'expanded' => $expanded, 'constraints' => $constraints));
             }
         } elseif ($type == 'country' || $type == 'region' || $type == 'timezone') {
             if ($type == 'country') {
                 $choices = FormFieldHelper::getCountryChoices();
             } elseif ($type == 'region') {
                 $choices = FormFieldHelper::getRegionChoices();
             } else {
                 $choices = FormFieldHelper::getTimezonesChoices();
             }
             $builder->add($alias, 'choice', array('choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'data' => $value, 'attr' => array('class' => 'form-control', 'data-placeholder' => $field['label']), 'mapped' => false, 'multiple' => false, 'expanded' => false, 'constraints' => $constraints));
         } else {
             if ($type == 'lookup') {
                 $type = "text";
                 $attr['data-toggle'] = 'field-lookup';
                 $attr['data-target'] = $alias;
                 if (!empty($properties['list'])) {
                     $attr['data-options'] = $properties['list'];
                 }
             }
             $builder->add($alias, $type, array('required' => $field['isRequired'], 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'attr' => $attr, 'data' => $value, 'mapped' => false, 'constraints' => $constraints));
         }
     }
     $builder->add('tags', 'lead_tag', array('by_reference' => false, 'attr' => array('data-placeholder' => $this->factory->getTranslator()->trans('mautic.lead.tags.select_or_create'), 'data-no-results-text' => $this->factory->getTranslator()->trans('mautic.lead.tags.enter_to_create'), 'data-allow-add' => 'true', 'onchange' => 'Mautic.createLeadTag(this)')));
     if (!$options['isShortForm']) {
         $builder->add('buttons', 'form_buttons');
     } else {
         $builder->add('buttons', 'form_buttons', array('apply_text' => false, 'save_text' => 'mautic.core.form.save'));
     }
     if (!empty($options["action"])) {
         $builder->setAction($options["action"]);
     }
 }
Example #12
0
 /**
  * Returns date and time concat eg 2014-08-02 5:00am
  *
  * @param \DateTime|string $datetime
  * @param string           $timezone
  * @param string           $fromFormat
  *
  * @return string
  */
 public function toFullConcat($datetime, $timezone = 'local', $fromFormat = 'Y-m-d H:i:s')
 {
     $this->helper->setDateTime($datetime, $fromFormat, $timezone);
     return $this->helper->toLocalString($this->formats['date'] . ' ' . $this->formats['time']);
 }