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
Forms contact tab #5685
Changes from 9 commits
bb709ca
20c7369
c9960a2
67b8776
373dd59
e5f2858
5b90ae3
1c7d54b
f7e8741
4d349df
d16e358
decaed4
623c2e8
86f0cdf
8251a90
b671a17
4fcc328
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"}) | ||
|
@@ -204,6 +209,11 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) | |
->nullable() | ||
->build(); | ||
|
||
$builder->createField('inContactTab', 'boolean') | ||
->columnName('in_contact_tab') | ||
->nullable() | ||
->build(); | ||
|
||
$builder->createOneToMany('submissions', 'Submission') | ||
->setOrderBy(['dateSubmitted' => 'DESC']) | ||
->mappedBy('form') | ||
|
@@ -290,6 +300,7 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata) | |
'actions', | ||
'template', | ||
'inKioskMode', | ||
'inContactTab', | ||
'renderStyle', | ||
'formType', | ||
'postAction', | ||
|
@@ -735,6 +746,22 @@ public function setInKioskMode($inKioskMode) | |
$this->inKioskMode = $inKioskMode; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getInContactTab() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it really return If it will be bool, it would be nice to call this method |
||
{ | ||
return $this->inContactTab; | ||
} | ||
|
||
/** | ||
* @param mixed $inContactTab | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1130,4 +1130,89 @@ protected function validateActionCallbacks(SubmissionEvent $event, &$validationE | |||
|
||||
unset($args, $actions, $availableActions); | ||||
} | ||||
|
||||
/** | ||||
* Return Forms with results to contacts tab | ||||
*ľ. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type hint should have been |
||||
* @param bool $inContactTab | ||||
* | ||||
* @return array | ||||
*/ | ||||
public function getFormsWithResults($leadId = null, $inContactTab = false) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the first if necessary here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's from here. I am gonna fixed it
|
||||
$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); | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the indentation of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 12 spaces before the |
||
<?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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a one liner. See for example https://github.com/mautic/mautic/blob/staging/app/bundles/WebhookBundle/Entity/Log.php#L73.