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

Forms contact tab #5685

Closed
wants to merge 17 commits into from
27 changes: 27 additions & 0 deletions app/bundles/FormBundle/Entity/Form.php
Expand Up @@ -100,6 +100,11 @@ class Form extends FormEntity
*/
private $renderStyle = false;

/**
* @var bool
*/
private $inContactTab = false;

/**
* @ORM\OneToMany(targetEntity="Submission", mappedBy="form", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"dateSubmitted" = "DESC"})
Expand Down Expand Up @@ -204,6 +209,11 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
->nullable()
->build();

$builder->createField('inContactTab', 'boolean')
->columnName('in_contact_tab')
->nullable()
->build();
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


$builder->createOneToMany('submissions', 'Submission')
->setOrderBy(['dateSubmitted' => 'DESC'])
->mappedBy('form')
Expand Down Expand Up @@ -290,6 +300,7 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata)
'actions',
'template',
'inKioskMode',
'inContactTab',
'renderStyle',
'formType',
'postAction',
Expand Down Expand Up @@ -735,6 +746,22 @@ public function setInKioskMode($inKioskMode)
$this->inKioskMode = $inKioskMode;
}

/**
* @return mixed
*/
public function getInContactTab()
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really return mixed? The $inContactTab property is annotated as bool. (the same in the setter)

If it will be bool, it would be nice to call this method isInContactTab() as it makes it more human friendly :)

{
return $this->inContactTab;
}

/**
* @param mixed $inContactTab
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the type hint here too

*/
public function setInContactTab($inContactTab)
{
$this->inContactTab = $inContactTab;
}

/**
* @param mixed $renderStyle
*/
Expand Down
7 changes: 7 additions & 0 deletions app/bundles/FormBundle/Form/Type/FormType.php
Expand Up @@ -106,6 +106,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
]);

$builder->add('inContactTab', 'yesno_button_group', [
'label' => 'mautic.form.form.contacttab',
'attr' => [
'tooltip' => 'mautic.form.form.contacttab.tooltip',
],
]);

// Render style for new form by default
if ($options['data']->getId() === null) {
$options['data']->setRenderStyle(true);
Expand Down
85 changes: 85 additions & 0 deletions app/bundles/FormBundle/Model/SubmissionModel.php
Expand Up @@ -1130,4 +1130,89 @@ protected function validateActionCallbacks(SubmissionEvent $event, &$validationE

unset($args, $actions, $availableActions);
}

/**
* Return Forms with results to contacts tab
*ľ.
Copy link
Sponsor Member

@escopecz escopecz Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this Slovak weirdo doing here? 🤣 (and bellow too)

*
* @param null $leadId
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type hint should have been int|null, right?

* @param bool $inContactTab
*
* @return array
*/
public function getFormsWithResults($leadId = null, $inContactTab = false)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, can we make the $leadId parameter required? Because the rest of the code expects it's configured. Update the annotation too please.

{
$formResults = [];
$viewOnlyFields = $this->formModel->getCustomComponents()['viewOnlyFields'];

$filters = [];

if ($inContactTab) {
$filters[] = ['column' => 'f.inContactTab', 'expr' => 'eq', 'value' => 1];
}

$permissions = $this->security->isGranted(
['form:forms:viewown', 'form:forms:viewother'],
'RETURN_ARRAY'
);
if ($permissions['form:forms:viewown'] || $permissions['form:forms:viewother']) {
if (!$permissions['form:forms:viewother']) {
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the first if necessary here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's from here. I am gonna fixed it

$permissions = $security->isGranted(['form:forms:viewown', 'form:forms:viewother'], 'RETURN_ARRAY');

$filters[] = ['column' => 'f.createdBy', 'expr' => 'eq', 'value' => $this->userHelper->getUser()->getId()];
}
}

$formEntities = $this->formModel->getEntities(
[
'filter' => ['force' => $filters],
]
);

foreach ($formEntities as $key => $entity) {
$formResults[$key]['entity'] = $entity[0];
$form = $entity[0];
$start = 0;
$limit = 999;
$orderBy = 's.date_submitted';
$orderByDir = 'DESC';
$filters = [];
$filters[] = ['column' => 's.form_id', 'expr' => 'eq', 'value' => $form->getId()];
$filters[] = ['column' => 's.lead_id', 'expr' => 'eq', 'value' => $leadId];

//get the results
$submissionEntities = $this->getEntities(
[
'start' => $start,
'limit' => $limit,
'filter' => ['force' => $filters],
'orderBy' => $orderBy,
'orderByDir' => $orderByDir,
'form' => $form,
'withTotalCount' => true,
]
);

if (empty($submissionEntities['count'])) {
unset($formResults[$key]);
continue;
}

$formResults[$key]['results'] = $submissionEntities;
$formResults[$key]['content'] = $this->templatingHelper->getTemplating()->render(
'MauticFormBundle:Result:list-condensed.html.php',
[
'items' => $submissionEntities['results'],
'filters' => $filters,
'form' => $form,
'page' => 1,
'totalCount' => $submissionEntities['count'],
'limit' => $limit,
'tmpl' => '',
'canDelete' => false,
'viewOnlyFields' => $viewOnlyFields,
]
);
}

return array_values($formResults);
}
}
2 changes: 2 additions & 0 deletions app/bundles/FormBundle/Translations/en_US/messages.ini
Expand Up @@ -129,6 +129,8 @@ mautic.form.form.help.manualcopy.script="Copy and paste into the document's head
mautic.form.form.help.searchcommands="<strong>Search commands</strong><br />ids:ID1,ID2 (comma separated IDs, no spaces)<br />is:mine<br />is:published<br />is:unpublished<br />has:results<br />name:*<br />is:uncategorized<br />category:{category alias}"
mautic.form.form.kioskmode="Kiosk Mode"
mautic.form.form.kioskmode.tooltip="If set to yes, form submissions will not generate new contact tracking cookies or assign the IP address to created/updated contacts."
mautic.form.form.contacttab="Show results in contacts tab"
mautic.form.form.contacttab.tooltip="If set to yes, form results will show in contacts detail tab."
mautic.form.form.renderstyle="Render Style"
mautic.form.form.renderstyle.tooltip="Disable CSS rendering"
mautic.form.form.modalheader="Form Component Details"
Expand Down
1 change: 1 addition & 0 deletions app/bundles/FormBundle/Views/Builder/index.html.php
Expand Up @@ -196,6 +196,7 @@
echo $view['form']->row($form['isPublished']);
echo $view['form']->row($form['publishUp']);
echo $view['form']->row($form['publishDown']);
echo $view['form']->row($form['inContactTab']);
echo $view['form']->row($form['inKioskMode']);
echo $view['form']->row($form['renderStyle']);
echo $view['form']->row($form['template']);
Expand Down
71 changes: 71 additions & 0 deletions app/bundles/FormBundle/Views/Result/list-condensed.html.php
@@ -0,0 +1,71 @@
<?php

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

$formId = $form->getId();

?>
<div class="table-responsive table-responsive-force">
<table class="table table-hover table-striped table-bordered formresult-list">
<thead>
<tr>
<?php
echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [
'sessionVar' => 'formresult.'.$formId,
'text' => 'mautic.form.result.thead.date',
'class' => 'col-formresult-date',
'default' => true,
'dataToggle' => 'date',
]);

$fields = $form->getFields();
$fieldCount = ($canDelete) ? 4 : 3;
foreach ($fields as $f):
if (in_array($f->getType(), $viewOnlyFields) || $f->getSaveResult() === false) {
continue;
}
echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [
'sessionVar' => 'formresult.'.$formId,
'text' => $f->getLabel(),
'class' => 'col-formresult-field col-formresult-field'.$f->getId(),
]);
++$fieldCount;
endforeach;
?>
</tr>
</thead>
<tbody>
<?php if (count($items)): ?>
<?php foreach ($items as $item): ?>
<?php $item['name'] = $view['translator']->trans('mautic.form.form.results.name', ['%id%' => $item['id']]); ?>
<tr>
<td>
<?php echo $view['date']->toFull($item['dateSubmitted']); ?>
</td>
<?php foreach ($item['results'] as $key => $r): ?>
<?php $isTextarea = $r['type'] === 'textarea'; ?>
<td <?php echo $isTextarea ? 'class="long-text"' : ''; ?>>
<?php if ($isTextarea) : ?>
<?php echo nl2br($r['value']); ?>
<?php elseif ($r['type'] === 'file') : ?>
<a href="<?php echo $view['router']->path('mautic_form_file_download', ['submissionId' => $item['id'], 'field' => $key]); ?>">
<?php echo $r['value']; ?>
</a>
<?php else : ?>
<?php echo $r['value']; ?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
1 change: 1 addition & 0 deletions app/bundles/LeadBundle/Controller/LeadController.php
Expand Up @@ -370,6 +370,7 @@ public function viewAction($objectId)
'integrations' => $integrationRepo->getIntegrationEntityByLead($lead->getId()),
'auditlog' => $this->getAuditlogs($lead),
'doNotContact' => $emailRepo->checkDoNotEmail($fields['core']['email']['value']),
'leadForms' => $this->getModel('form.submission')->getFormsWithResults($lead->getId(), true),
'leadNotes' => $this->forward(
'MauticLeadBundle:Note:index',
[
Expand Down
1 change: 1 addition & 0 deletions app/bundles/LeadBundle/Translations/en_US/messages.ini
Expand Up @@ -329,6 +329,7 @@ mautic.lead.lead.tab.auditlog="Audit log"
mautic.lead.lead.tab.socialactivity="Public Activity"
mautic.lead.lead.tab.socialprofile="Public Profile"
mautic.lead.lead.tab.places="Places"
mautic.lead.lead.tab.forms="Forms"
mautic.lead.lead.thead.action="Triggering Action"
mautic.lead.lead.thead.city="City"
mautic.lead.lead.thead.country="Country"
Expand Down
23 changes: 23 additions & 0 deletions app/bundles/LeadBundle/Views/Form/list.html.php
@@ -0,0 +1,23 @@
<!-- tabs controls -->
<ul class="nav nav-tabs pr-md pl-md mt-10">
<?php foreach ($leadForms as $key=>$leadForm): ?>
<li<?php if ($key == 0): ?> class="active"<?php endif; ?>>
<a href="#form-<?php echo $leadForm['entity']->getAlias()?>" role="tab" data-toggle="tab">
<span class="label label-primary mr-sm" id="form-label-<?php echo $leadForm['entity']->getAlias()?>">
<?php echo $leadForm['results']['count']; ?>
</span>
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the indentation of the <span\> element please.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 12 spaces before the <span tag compared to the line above it. Should be only 4.

<?php echo $leadForm['entity']->getName(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<div class="tab-content pa-md">

<?php foreach ($leadForms as $key=>$leadForm):
?>
<div class="tab-pane fade bdr-w-0 <?php if ($key == 0): ?> active in<?php endif; ?>" id="form-<?php echo $leadForm['entity']->getAlias()?>">
<?php echo $leadForm['content']; ?>
</div>
<?php endforeach; ?>

</div>
22 changes: 22 additions & 0 deletions app/bundles/LeadBundle/Views/Lead/lead.html.php
Expand Up @@ -313,6 +313,17 @@
</a>
</li>
<?php endif; ?>

<?php if (!empty($leadForms)): ?>
<li class="">
<a href="#form-container" role="tab" data-toggle="tab">
<span class="label label-primary mr-sm" id="FormCount">
<?php echo count($leadForms); ?>
</span>
<?php echo $view['translator']->trans('mautic.lead.lead.tab.forms'); ?>
</a>
</li>
<?php endif; ?>

<?php echo $view['content']->getCustomContent('tabs', $mauticTemplateVars); ?>
</ul>
Expand Down Expand Up @@ -391,6 +402,17 @@
</div>
<?php endif; ?>
<!--/ #place-container -->
<!-- #device-container -->
<?php if (!empty($leadForms)): ?>
<div class="tab-pane fade bdr-w-0 row" id="form-container">
<?php
echo $view->render('MauticLeadBundle:Form:list.html.php',
[
'leadForms' => $leadForms,
]); ?>
</div>
<?php endif; ?>
<!--/ #device-container -->
</div>
<!--/ end: tab-content -->
</div>
Expand Down
53 changes: 53 additions & 0 deletions app/migrations/Version20180206225101.php
@@ -0,0 +1,53 @@
<?php

/*
* @package Mautic
* @copyright 2018 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\Migrations;

use Doctrine\DBAL\Migrations\SkipMigrationException;
use Doctrine\DBAL\Schema\Schema;
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180206225101 extends AbstractMauticMigration
{
/**
* @param Schema $schema
*
* @throws SkipMigrationException
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function preUp(Schema $schema)
{
if ($schema->getTable(MAUTIC_TABLE_PREFIX.'forms')->hasColumn('in_contact_tab')) {
throw new SkipMigrationException('Schema includes this migration');
}
}

/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE '.$this->prefix.'forms ADD COLUMN in_contact_tab bool DEFAULT NULL');
}

/**
* @param Schema $schema
*/
public function postUp(Schema $schema)
{
$q = $this->connection->createQueryBuilder();
$q->update(MAUTIC_TABLE_PREFIX.'forms')
->set('in_contact_tab', 0)
->execute();
}
}