Skip to content

Commit c20ad3a

Browse files
committed
Add resolve action to responses
1 parent 5235993 commit c20ad3a

File tree

8 files changed

+113
-8
lines changed

8 files changed

+113
-8
lines changed

src/B2bCode/Bundle/CmsFormBundle/Entity/CmsFormResponse.php

+27
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ class CmsFormResponse extends ExtendCmsFormResponse implements DatesAwareInterfa
102102
*/
103103
protected $visitor;
104104

105+
/**
106+
* @var bool
107+
*
108+
* @ORM\Column(name="is_resolved", type="boolean", nullable=true)
109+
*/
110+
protected $resolved = false;
111+
105112
public function __construct()
106113
{
107114
$this->fieldResponses = new ArrayCollection();
@@ -176,6 +183,26 @@ public function setVisitor(?CustomerVisitor $visitor)
176183
return $this;
177184
}
178185

186+
/**
187+
* @param bool $resolved
188+
*
189+
* @return $this
190+
*/
191+
public function setResolved(?bool $resolved)
192+
{
193+
$this->resolved = (bool) $resolved;
194+
195+
return $this;
196+
}
197+
198+
/**
199+
* @return bool
200+
*/
201+
public function isResolved()
202+
{
203+
return (bool) $this->resolved;
204+
}
205+
179206
/**
180207
* @return array
181208
*/

src/B2bCode/Bundle/CmsFormBundle/Entity/Repository/CmsFieldResponseRepository.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function findGroupedByFormResponses(array $formResponsesIds = [])
2727

2828
$groupedByResponses = [];
2929
foreach ($records as $record) {
30+
// @todo create option 'hide_from_response'
31+
if ($record->getField()->getType() === 'oro-recaptcha-v3') {
32+
continue;
33+
}
3034
$responseId = $record->getFormResponse()->getId();
3135
if (array_key_exists($responseId, $groupedByResponses)) {
3236
$groupedByResponses[$responseId][] = $record;

src/B2bCode/Bundle/CmsFormBundle/Migrations/Schema/B2bCodeCmsFormBundleInstaller.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class B2bCodeCmsFormBundleInstaller implements Installation
2727
*/
2828
public function getMigrationVersion()
2929
{
30-
return 'v1_0';
30+
return 'v1_1';
3131
}
3232

3333
/**
@@ -62,6 +62,7 @@ protected function createB2BCodeCmsFormResponseTable(Schema $schema)
6262
$table->addColumn('visitor_id', 'integer', ['notnull' => false]);
6363
$table->addColumn('created_at', 'datetime', ['comment' => '(DC2Type:datetime)']);
6464
$table->addColumn('updated_at', 'datetime', ['comment' => '(DC2Type:datetime)']);
65+
$table->addColumn('is_resolved', 'boolean', ['notnull' => false]);
6566
$table->addColumn('serialized_data', 'array', ['notnull' => false, 'comment' => '(DC2Type:array)']);
6667
$table->setPrimaryKey(['id']);
6768
$table->addIndex(['visitor_id'], 'idx_eab5a5270bee6d', []);

src/B2bCode/Bundle/CmsFormBundle/Migrations/Schema/v1_0/CreateTables.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
1717

1818
/**
19-
* @todo make it up to date with Installer
19+
* Version 1_0 doesn't need to be present. Left just for BC.
2020
*/
2121
class CreateTables implements Migration
2222
{
@@ -25,12 +25,7 @@ class CreateTables implements Migration
2525
*/
2626
public function up(Schema $schema, QueryBag $queries)
2727
{
28-
/** Tables generation **/
29-
$this->createB2BCodeCmsFormTable($schema);
30-
$this->createB2BCodeCmsFormFieldTable($schema);
31-
32-
/** Foreign keys generation **/
33-
$this->addB2BCodeCmsFormFieldForeignKeys($schema);
28+
return;
3429
}
3530

3631
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace B2bCode\Bundle\CmsFormBundle\Migrations\Schema\v1_1;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
use Oro\Bundle\MigrationBundle\Migration\Migration;
7+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
8+
9+
class AddResolvedField implements Migration
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function up(Schema $schema, QueryBag $queries)
15+
{
16+
if (!$schema->hasTable('b2b_code_cms_form_response')) {
17+
return;
18+
}
19+
20+
$table = $schema->getTable('b2b_code_cms_form_response');
21+
22+
$table->addColumn('is_resolved', 'boolean', ['notnull' => false]);
23+
24+
$queries->addPostQuery('UPDATE b2b_code_cms_form_response SET is_resolved = false');
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
operations:
2+
b2b_code_cms_form.action.resolve:
3+
label: b2bcode.cmsform.actions.resolve.label
4+
enabled: true
5+
applications: [default]
6+
button_options:
7+
icon: fa-check
8+
datagrids:
9+
- b2bcode-cms-form-responses-grid
10+
preconditions:
11+
'@equal': [$.data.resolved, 0]
12+
actions:
13+
- '@assign_value': [$.data.resolved, 1]
14+
- '@flush_entity': [$.data]
15+
- '@flash_message':
16+
message: b2bcode.cmsform.actions.resolve.success
17+
type: 'success'
18+
19+
b2b_code_cms_form.action.unresolve:
20+
label: b2bcode.cmsform.actions.unresolve.label
21+
enabled: true
22+
applications: [default]
23+
button_options:
24+
icon: fa-undo
25+
datagrids:
26+
- b2bcode-cms-form-responses-grid
27+
preconditions:
28+
'@equal': [$.data.resolved, 1]
29+
actions:
30+
- '@assign_value': [$.data.resolved, 0]
31+
- '@flush_entity': [$.data]
32+
- '@flash_message':
33+
message: b2bcode.cmsform.actions.unresolve.success
34+
type: 'success'

src/B2bCode/Bundle/CmsFormBundle/Resources/config/oro/datagrids.yml

+9
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ datagrids:
187187
query:
188188
select:
189189
- response.id
190+
- response.resolved
190191
# - response.visitor
191192
- response.createdAt
192193
from:
@@ -209,10 +210,15 @@ datagrids:
209210
createdAt:
210211
label: oro.ui.created_at
211212
frontend_type: datetime
213+
resolved:
214+
label: b2bcode.cmsformresponse.resolved.label
215+
frontend_type: boolean
212216
sorters:
213217
columns:
214218
id:
215219
data_name: response.id
220+
resolved:
221+
data_name: response.resolved
216222
# visitor:
217223
# data_name: response.visitor
218224
createdAt:
@@ -221,6 +227,9 @@ datagrids:
221227
createdAt: DESC
222228
filters:
223229
columns:
230+
resolved:
231+
type: boolean
232+
data_name: response.resolved
224233
# name:
225234
# type: string
226235
# data_name: cmsForm.name

src/B2bCode/Bundle/CmsFormBundle/Resources/translations/messages.en.yml

+9
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ b2bcode:
135135
form_update: 'Cms Form #%name% - Edit'
136136
field_update: 'Field #%name% - Edit'
137137

138+
actions:
139+
resolve:
140+
label: Resolve
141+
success: Response sucessfully resolved
142+
unresolve:
143+
label: Unresolve
144+
success: Response sucessfully unresolved
145+
138146
field_type:
139147
text.label: Single Line Text
140148
textarea.label: Paragraph Text
@@ -183,6 +191,7 @@ b2bcode:
183191
entity_plural_label: Form Responses
184192

185193
id.label: ID
194+
resolved.label: Resolved
186195
visitor.label: Visitor ID
187196

188197
cmsfieldresponse:

0 commit comments

Comments
 (0)