/**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $textfields = array('firstname', 'lastname', 'company', 'position', 'gender', 'email', 'title', 'phone', 'mobile', 'fax', 'address1', 'address2', 'city', 'state', 'zipcode', 'country', 'website', 'twitter', 'facebook', 'googleplus', 'linkedin', 'skype', 'instagram', 'foursquare');
     $leadsSchema = $this->container->get('mautic.factory')->getSchemaHelper('column', 'leads');
     foreach ($textfields as $key => $name) {
         $entity = new LeadField();
         $entity->setLabel(ucfirst($name));
         if (in_array($name, array('title', 'company', 'city', 'zipcode'))) {
             $type = 'lookup';
         } elseif ($name == 'country') {
             $type = 'country';
         } elseif ($name == 'state') {
             $type = 'region';
         } elseif (in_array($name, array('phone', 'mobile', 'fax'))) {
             $type = 'tel';
         } elseif ($name == 'website') {
             $type = 'url';
         } elseif ($name == 'email') {
             $type = 'email';
             $entity->setIsUniqueIdentifer(true);
         } else {
             $type = 'text';
         }
         if ($name == 'title') {
             $entity->setProperties(array("list" => "|Mr|Mrs|Miss"));
         }
         $entity->setType($type);
         $fixed = in_array($name, array('title', 'firstname', 'lastname', 'position', 'company', 'email', 'phone', 'mobile', 'address1', 'address2', 'country', 'city', 'state', 'zipcode')) ? true : false;
         $entity->setIsFixed($fixed);
         $entity->setOrder($key + 1);
         $entity->setAlias($name);
         $listable = in_array($name, array('address1', 'address2', 'fax', 'phone', 'twitter', 'facebook', 'googleplus', 'linkedin', 'skype', 'foursquare', 'instagram', 'mobile', 'website')) ? false : true;
         $entity->setIsListable($listable);
         $shortVisible = in_array($name, array('firstname', 'lastname', 'email')) ? true : false;
         $entity->setIsShortVisible($shortVisible);
         $group = in_array($name, array('twitter', 'facebook', 'googleplus', 'linkedin', 'skype', 'instagram', 'foursquare')) ? 'social' : 'core';
         $entity->setGroup($group);
         $manager->persist($entity);
         $manager->flush();
         //add the column to the leads table
         $leadsSchema->addColumn(array('name' => $name, 'type' => 'text', 'options' => array('notnull' => false)));
         $this->addReference('leadfield-' . $name, $entity);
     }
     $leadsSchema->executeChanges();
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }
Exemple #3
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $fieldGroups['lead'] = FieldModel::$coreFields;
     $fieldGroups['company'] = FieldModel::$coreCompanyFields;
     $translator = $this->container->get('translator');
     $indexesToAdd = [];
     foreach ($fieldGroups as $object => $fields) {
         if ($object == 'company') {
             /** @var ColumnSchemaHelper $companiesSchema */
             $schema = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('column', 'companies');
         } else {
             /** @var ColumnSchemaHelper $companiesSchema */
             $schema = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('column', 'leads');
         }
         $order = 1;
         foreach ($fields as $alias => $field) {
             $type = isset($field['type']) ? $field['type'] : 'text';
             $entity = new LeadField();
             $entity->setLabel($translator->trans('mautic.lead.field.' . $alias, [], 'fixtures'));
             $entity->setGroup(isset($field['group']) ? $field['group'] : 'core');
             $entity->setOrder($order);
             $entity->setAlias($alias);
             $entity->setIsRequired(isset($field['required']) ? $field['required'] : false);
             $entity->setType($type);
             $entity->setObject($field['object']);
             $entity->setIsUniqueIdentifer(!empty($field['unique']));
             $entity->setProperties(isset($field['properties']) ? $field['properties'] : []);
             $entity->setIsFixed(!empty($field['fixed']));
             $entity->setIsListable(!empty($field['listable']));
             $entity->setIsShortVisible(!empty($field['short']));
             $manager->persist($entity);
             $manager->flush();
             $schema->addColumn(FieldModel::getSchemaDefinition($alias, $type, $entity->getIsUniqueIdentifier()));
             $indexesToAdd[$object][] = $alias;
             $this->addReference('leadfield-' . $alias, $entity);
             ++$order;
         }
         $schema->executeChanges();
     }
     foreach ($indexesToAdd as $object => $indexes) {
         if ($object == 'company') {
             /** @var IndexSchemaHelper $indexHelper */
             $indexHelper = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('index', 'companies');
         } else {
             /** @var IndexSchemaHelper $indexHelper */
             $indexHelper = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('index', 'leads');
         }
         foreach ($indexes as $name) {
             $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : 'text';
             if ('textarea' != $type) {
                 $indexHelper->addIndex([$name], $name . '_search');
             }
         }
         if ($object == 'lead') {
             // Add an attribution index
             $indexHelper->addIndex(['attribution', 'attribution_date'], 'contact_attribution');
         } else {
             $indexHelper->addIndex(['companyname', 'companyemail'], 'company_filter');
             $indexHelper->addIndex(['companyname', 'companycity', 'companycountry', 'companystate'], 'company_match');
         }
         $indexHelper->executeChanges();
     }
 }
Exemple #4
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $fields = FieldModel::$coreFields;
     $translator = $this->container->get('translator');
     $indexesToAdd = [];
     /** @var ColumnSchemaHelper $leadsSchema */
     $leadsSchema = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('column', 'leads');
     $order = 1;
     foreach ($fields as $alias => $field) {
         $type = isset($field['type']) ? $field['type'] : 'text';
         $entity = new LeadField();
         $entity->setLabel($translator->trans('mautic.lead.field.' . $alias, [], 'fixtures'));
         $entity->setGroup(isset($field['group']) ? $field['group'] : 'core');
         $entity->setOrder($order);
         $entity->setAlias($alias);
         $entity->setType($type);
         $entity->setIsUniqueIdentifer(!empty($field['unique']));
         $entity->setProperties(isset($field['properties']) ? $field['properties'] : []);
         $entity->setIsFixed(!empty($field['fixed']));
         $entity->setIsListable(!empty($field['listable']));
         $entity->setIsShortVisible(!empty($field['short']));
         $manager->persist($entity);
         $manager->flush();
         //add the column to the leads table
         $leadsSchema->addColumn(FieldModel::getSchemaDefinition($alias, $type, $entity->getIsUniqueIdentifier()));
         $indexesToAdd[] = $alias;
         $this->addReference('leadfield-' . $alias, $entity);
         $order++;
     }
     $leadsSchema->executeChanges();
     /** @var IndexSchemaHelper $indexHelper */
     $indexHelper = $this->container->get('mautic.schema.helper.factory')->getSchemaHelper('index', 'leads');
     foreach ($indexesToAdd as $name) {
         $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : 'text';
         if ('textarea' != $type) {
             $indexHelper->addIndex([$name], MAUTIC_TABLE_PREFIX . $name . '_search');
         }
     }
     // Add an attribution index
     $indexHelper->addIndex(['attribution', 'attribution_date'], MAUTIC_TABLE_PREFIX . '_contact_attribution');
     $indexHelper->executeChanges();
 }