Exemplo n.º 1
0
 /**
  * Get a list of field choices for filters.
  *
  * @return array
  */
 public function getChoiceFields()
 {
     $operators = ['text' => ['include' => ['=', '!=', 'empty', '!empty', 'like', '!like']], 'select' => ['include' => ['=', '!=', 'empty', '!empty', 'in', '!in']], 'bool' => ['include' => ['=', '!=']], 'default' => ['exclude' => ['in', '!in']], 'multiselect' => ['include' => ['in', '!in']]];
     //field choices
     $choices['lead'] = ['date_added' => ['label' => $this->translator->trans('mautic.core.date.added'), 'properties' => ['type' => 'date'], 'operators' => 'default', 'object' => 'lead'], 'date_identified' => ['label' => $this->translator->trans('mautic.lead.list.filter.date_identified'), 'properties' => ['type' => 'date'], 'operators' => 'default', 'object' => 'lead'], 'last_active' => ['label' => $this->translator->trans('mautic.lead.list.filter.last_active'), 'properties' => ['type' => 'date'], 'operators' => 'default', 'object' => 'lead'], 'owner_id' => ['label' => $this->translator->trans('mautic.lead.list.filter.owner'), 'properties' => ['type' => 'lookup_id', 'callback' => 'activateLeadFieldTypeahead'], 'operators' => 'text', 'object' => 'lead'], 'points' => ['label' => $this->translator->trans('mautic.lead.lead.event.points'), 'properties' => ['type' => 'number'], 'operators' => 'default', 'object' => 'lead'], 'leadlist' => ['label' => $this->translator->trans('mautic.lead.list.filter.lists'), 'properties' => ['type' => 'leadlist'], 'operators' => 'multiselect', 'object' => 'lead'], 'lead_email_received' => ['label' => $this->translator->trans('mautic.lead.list.filter.lead_email_received'), 'properties' => ['type' => 'lead_email_received'], 'operators' => ['include' => ['in', '!in']], 'object' => 'lead'], 'tags' => ['label' => $this->translator->trans('mautic.lead.list.filter.tags'), 'properties' => ['type' => 'tags'], 'operators' => 'multiselect', 'object' => 'lead'], 'dnc_bounced' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_bounced'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'dnc_unsubscribed' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_unsubscribed'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'dnc_bounced_sms' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_bounced_sms'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'dnc_unsubscribed_sms' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_unsubscribed_sms'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'hit_url' => ['label' => $this->translator->trans('mautic.lead.list.filter.visited_url'), 'properties' => ['type' => 'text'], 'operators' => ['include' => ['=', 'like']], 'object' => 'lead'], 'stage' => ['label' => $this->translator->trans('mautic.lead.lead.field.stage'), 'properties' => ['type' => 'stage'], 'operators' => ['include' => ['=', '!=']], 'object' => 'lead']];
     //get list of custom fields
     $fields = $this->em->getRepository('MauticLeadBundle:LeadField')->getEntities(['filter' => ['isListable' => true, 'isPublished' => true], 'orderBy' => 'f.object']);
     foreach ($fields as $field) {
         $type = $field->getType();
         $properties = $field->getProperties();
         $properties['type'] = $type;
         if (in_array($type, ['lookup', 'multiselect', 'boolean'])) {
             if ($type == 'boolean') {
                 //create a lookup list with ID
                 $properties['list'] = [0 => $properties['no'], 1 => $properties['yes']];
             } else {
                 $properties['callback'] = 'activateLeadFieldTypeahead';
             }
             $properties['list'] = isset($properties['list']) ? FormFieldHelper::formatList(FormFieldHelper::FORMAT_BAR, FormFieldHelper::parseList($properties['list'])) : '';
         }
         $choices[$field->getObject()][$field->getAlias()] = ['label' => $field->getLabel(), 'properties' => $properties, 'object' => $field->getObject()];
         // Set operators allowed
         if ($type == 'boolean') {
             $choices[$field->getObject()][$field->getAlias()]['operators'] = 'bool';
         } elseif (in_array($type, ['select', 'multiselect', 'country', 'timezone', 'region', 'locale'])) {
             $choices[$field->getObject()][$field->getAlias()]['operators'] = 'select';
         } elseif (in_array($type, ['lookup', 'lookup_id', 'text', 'email', 'url', 'email', 'tel'])) {
             $choices[$field->getObject()][$field->getAlias()]['operators'] = 'text';
         } else {
             $choices[$field->getObject()][$field->getAlias()]['operators'] = 'default';
         }
     }
     foreach ($choices as $key => $choice) {
         $cmp = function ($a, $b) {
             return strcmp($a['label'], $b['label']);
         };
         uasort($choice, $cmp);
         $choices[$key] = $choice;
     }
     foreach ($choices as $object => $choiceObject) {
         foreach ($choiceObject as $key => $choice) {
             if (array_key_exists('operators', $choice) && is_string($choice['operators']) && array_key_exists($choice['operators'], $operators)) {
                 $choices[$object][$key]['operators'] = $operators[$choice['operators']];
             }
         }
     }
     return $choices;
 }