Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom contacts columns #7511

Merged
merged 8 commits into from Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions app/bundles/LeadBundle/Config/config.php
Expand Up @@ -689,6 +689,12 @@
'class' => \Mautic\LeadBundle\Form\Type\LeadFieldsType::class,
'arguments' => ['mautic.lead.model.field'],
],
'mautic.form.type.lead_columns' => [
'class' => \Mautic\LeadBundle\Form\Type\ContactColumnsType::class,
'arguments' => [
'mautic.lead.columns.dictionary',
],
],
'mautic.form.type.lead_dashboard_leads_in_time_widget' => [
'class' => \Mautic\LeadBundle\Form\Type\DashboardLeadsInTimeWidgetType::class,
],
Expand Down Expand Up @@ -830,6 +836,14 @@
'@doctrine.orm.entity_manager',
],
],
'mautic.lead.columns.dictionary' => [
'class' => \Mautic\LeadBundle\Services\ContactColumnsDictionary::class,
'arguments' => [
'mautic.lead.model.field',
'translator',
'mautic.helper.core_parameters',
],
],
],
'repositories' => [
'mautic.lead.repository.company' => [
Expand Down Expand Up @@ -1301,5 +1315,14 @@
'parameters' => [
'parallel_import_limit' => 1,
'background_import_if_more_rows_than' => 0,
'contact_columns' => [
'0' => 'name',
'1' => 'email',
'2' => 'location',
'3' => 'stage',
'4' => 'points',
'5' => 'last_active',
'6' => 'id',
],
],
];
1 change: 1 addition & 0 deletions app/bundles/LeadBundle/Controller/LeadController.php
Expand Up @@ -182,6 +182,7 @@ public function indexAction($page = 1)
[
'viewParameters' => [
'searchValue' => $search,
'columns' => $this->get('mautic.lead.columns.dictionary')->getColumns(),
'items' => $leads,
'page' => $page,
'totalItems' => $count,
Expand Down
54 changes: 54 additions & 0 deletions app/bundles/LeadBundle/Form/Type/ConfigType.php
Expand Up @@ -14,6 +14,10 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

class ConfigType extends AbstractType
{
Expand All @@ -31,6 +35,56 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
]
);

$formModifier = function (FormInterface $form, $currentColumns) {
$order = [];
$orderColumns = [];
if (!empty($currentColumns)) {
$orderColumns = array_values($currentColumns);
$order = htmlspecialchars(json_encode($orderColumns), ENT_QUOTES, 'UTF-8');
}
$form->add(
'contact_columns',
ContactColumnsType::class,
[
'label' => 'mautic.config.tab.columns',
'label_attr' => ['class' => 'control-label'],
'attr' => [
'class' => 'form-control multiselect',
'data-sortable' => 'true',
'data-order' => $order,
],
'multiple' => true,
'required' => true,
'expanded' => false,
'constraints' => [
new NotBlank(
['message' => 'mautic.core.value.required']
),
],
'data'=> array_flip($orderColumns),
]
);
};

$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($formModifier) {
$data = $event->getData();
$columns = isset($data['contact_columns']) ? $data['contact_columns'] : [];
$formModifier($event->getForm(), $columns);
}
);

// Build the columns selector
$builder->addEventListener(
FormEvents::PRE_SUBMIT,
function (FormEvent $event) use ($formModifier) {
$data = $event->getData();
$columns = isset($data['contact_columns']) ? $data['contact_columns'] : [];
$formModifier($event->getForm(), $columns);
}
);
}

/**
Expand Down
58 changes: 58 additions & 0 deletions app/bundles/LeadBundle/Form/Type/ContactColumnsType.php
@@ -0,0 +1,58 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Mautic\LeadBundle\Form\Type;

use Mautic\LeadBundle\Services\ContactColumnsDictionary;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ContactColumnsType extends AbstractType
{
private $columnsDictionary;

/**
* ContactColumnsType constructor.
*/
public function __construct(ContactColumnsDictionary $columnsDictionary)
{
$this->columnsDictionary = $columnsDictionary;
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'choices' => array_flip($this->columnsDictionary->getFields()),
'label' => false,
'label_attr' => ['class' => 'control-label'],
'required' => false,
'multiple' => true,
'expanded' => false,
'attr' => [
'class' => 'form-control',
],
]
);
}

/**
* @return string|\Symfony\Component\Form\FormTypeInterface|null
*/
public function getParent()
{
return ChoiceType::class;
}
}
73 changes: 73 additions & 0 deletions app/bundles/LeadBundle/Services/ContactColumnsDictionary.php
@@ -0,0 +1,73 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Mautic\LeadBundle\Services;

use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\LeadBundle\Model\FieldModel;
use Symfony\Component\Translation\TranslatorInterface;

class ContactColumnsDictionary
{
protected $fieldModel;

private $translator;

private $coreParametersHelper;

private $fieldList = [];

public function __construct(FieldModel $fieldModel, TranslatorInterface $translator, CoreParametersHelper $coreParametersHelper)
{
$this->fieldModel = $fieldModel;
$this->translator = $translator;
$this->coreParametersHelper = $coreParametersHelper;
}

/**
* @return array
*/
public function getColumns()
{
$columns = array_flip($this->coreParametersHelper->get('contact_columns', []));
$fields = $this->getFields();
foreach ($columns as $alias=>&$column) {
if (isset($fields[$alias])) {
$column = $fields[$alias];
}
}

return $columns;
}

/**
* @return array
*/
public function getFields()
{
if (empty($this->fieldList)) {
$this->fieldList['name'] = sprintf(
'%s %s',
$this->translator->trans('mautic.core.firstname'),
$this->translator->trans('mautic.core.lastname')
);
$this->fieldList['email'] = $this->translator->trans('mautic.core.type.email');
$this->fieldList['location'] = $this->translator->trans('mautic.lead.lead.thead.location');
$this->fieldList['stage'] = $this->translator->trans('mautic.lead.stage.label');
$this->fieldList['points'] = $this->translator->trans('mautic.lead.points');
$this->fieldList['last_active'] = $this->translator->trans('mautic.lead.lastactive');
$this->fieldList['id'] = $this->translator->trans('mautic.core.id');
$this->fieldList = $this->fieldList + $this->fieldModel->getFieldList(false);
}

return $this->fieldList;
}
}
2 changes: 2 additions & 0 deletions app/bundles/LeadBundle/Translations/en_US/messages.ini
Expand Up @@ -205,6 +205,8 @@ mautic.lead.background.import.if.more.rows.than="Automatically import in the bac
mautic.lead.background.import.if.more.rows.than.tooltip="If this option is greater than 0, there will be only one Import button and the browser/background import will be decided based on the CSV row number"
mautic.config.tab.leadconfig="Contact Settings"
mautic.config.tab.importconfig="Import Settings"
mautic.config.tab.contact.list.settings="Contact List Settings"
mautic.config.tab.columns="Columns"
mautic.lead.import.database.exception="There was a database error: %message%. The import was set to delayed state and will be imported later."
mautic.lead.lastactive="Last active"
mautic.lead.lead.anonymous="Anonymous"
Expand Down
Expand Up @@ -11,6 +11,16 @@
?>

<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $view['translator']->trans('mautic.config.tab.contact.list.settings'); ?></h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<?php echo $view['form']->row($form['contact_columns']); ?>
</div>
</div>
</div>
<div class="panel-heading">
<h3 class="panel-title"><?php echo $view['translator']->trans('mautic.config.tab.importconfig'); ?></h3>
</div>
Expand Down
17 changes: 17 additions & 0 deletions app/bundles/LeadBundle/Views/Lead/header/default.html.php
@@ -0,0 +1,17 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [
'sessionVar' => 'lead',
'orderBy' => 'l.'.$column,
'text' => $label,
'class' => 'col-lead-'.$column.' '.$class,
]);
17 changes: 17 additions & 0 deletions app/bundles/LeadBundle/Views/Lead/header/location.html.php
@@ -0,0 +1,17 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [
'sessionVar' => 'lead',
'orderBy' => 'l.city, l.state',
'text' => 'mautic.lead.lead.thead.location',
'class' => 'col-lead-location '.$class,
]);
17 changes: 17 additions & 0 deletions app/bundles/LeadBundle/Views/Lead/header/name.html.php
@@ -0,0 +1,17 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [
'sessionVar' => 'lead',
'orderBy' => 'l.lastname, l.firstname, l.company, l.email',
'text' => 'mautic.core.name',
'class' => 'col-lead-name '.$class,
]);
17 changes: 17 additions & 0 deletions app/bundles/LeadBundle/Views/Lead/header/stage.html.php
@@ -0,0 +1,17 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [
'sessionVar' => 'lead',
'orderBy' => 'l.stage_id',
'text' => 'mautic.lead.stage.label',
'class' => 'col-lead-stage '.$class,
]);