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

PRESIDECMS-2976 formbuilder without websiteusers feature #1552

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions system/handlers/admin/FormBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ component extends="preside.system.base.AdminHandler" {

var theQuestion = formBuilderService.getQuestion( questionId );

if ( !isFeatureEnabled( "websiteUsers" ) ) {
exportFields = ListDeleteAt( exportFields, ListFind( exportFields, "submitted_by" ) );
}
if ( !theQuestion.recordCount ) {
event.adminNotFound();
}
Expand Down Expand Up @@ -415,6 +418,10 @@ component extends="preside.system.base.AdminHandler" {
var exportFields = args.exportFields ?: "id,submission_type,submission_reference,submitted_by,datecreated,is_website_user,parent_name";
var exporter = args.exporter ?: "Excel"

if ( !isFeatureEnabled( "websiteUsers" ) ) {
exportFields = ListDeleteAt( exportFields, ListFind( exportFields, "submitted_by" ) );
}

formBuilderService.exportQuestionResponses(
questionId = questionId
, exportFields = exportFields
Expand Down Expand Up @@ -741,6 +748,10 @@ component extends="preside.system.base.AdminHandler" {
var viewSubmissionTitle = translateResource( "formbuilder:view.submission.modal.title" );
var deleteSubmissionTitle = translateResource( "formbuilder:delete.submission.prompt" );

if ( !isFeatureEnabled( "websiteUsers" ) ) {
ArrayDelete( gridFields, "submitted_by" );
}

for( var record in records ){
for( var field in gridFields ){
records[ field ][ records.currentRow ] = renderField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ component displayname="Form builder: global question response" extends="preside.
property name="website_user" relationship="many-to-one" relatedto="website_user" required=false excludeDataExport=true adminRenderer="none" feature="websiteUsers";
property name="admin_user" relationship="many-to-one" relatedto="security_user" required=false excludeDataExport=true adminRenderer="none" feature="admin";

property name="is_website_user" type="boolean" dbtype="boolean" formula="case when ${prefix}website_user is not null then 1 else 0 end" adminRenderer="none";
property name="is_admin_user" type="boolean" dbtype="boolean" formula="case when ${prefix}admin_user is not null then 1 else 0 end" adminRenderer="none";
property name="is_website_user" type="boolean" dbtype="boolean" formula="case when ${prefix}website_user is not null then 1 else 0 end" adminRenderer="none" feature="websiteUsers";
property name="is_admin_user" type="boolean" dbtype="boolean" formula="case when ${prefix}admin_user is not null then 1 else 0 end" adminRenderer="none" feature="admin";

property name="parent_name" type="string" dbtype="varchar" formula="case when ${prefix}submission_type='formbuilder' then ${prefix}submission$form.name else '' end " adminRenderer="none";

Expand Down
4 changes: 2 additions & 2 deletions system/services/formbuilder/FormBuilderFilterService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,9 @@ component {
) {
var submissionsDao = $getPresideObject( "formbuilder_formsubmission" );
var filter = {};
var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" );

if ( Len( arguments.userId ) ) {
if ( websiteUsers && Len( arguments.userId ) ) {
filter.submitted_by = arguments.userId;
}

Expand Down Expand Up @@ -551,7 +552,6 @@ component {
);
}


public array function prepareFilterForUserHasSubmittedFormFilter(
required array formId
, boolean _has = true
Expand Down
152 changes: 94 additions & 58 deletions system/services/formbuilder/FormBuilderService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,13 @@ component {
var extraFilters = [];
var sortBy = ListFirst( arguments.orderBy, " " );
var sortOrder = ListLast( arguments.orderBy, " " );
var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" );

switch( sortBy ) {
case "submitted_by":
sortBy = "submitted_by.display_name";
if ( websiteUsers ) {
sortBy = "submitted_by.display_name";
}
break;
case "datecreated":
case "instanceId":
Expand All @@ -1205,10 +1208,14 @@ component {
}

if ( Len( Trim( arguments.searchQuery ) ) ) {
extraFilters.append({
filter = "submitted_by.display_name like :q or formbuilder_formsubmission.form_instance like :q or formbuilder_formsubmission.submitted_data like :q"
var searchFilter = "formbuilder_formsubmission.form_instance like :q or formbuilder_formsubmission.submitted_data like :q";
if ( websiteUsers ) {
searchFilter = "submitted_by.display_name like :q or " & searchFilter;
}
extraFilters.append( {
filter = searchFilter
, filterParams = { q = { type="cf_sql_varchar", value="%#arguments.searchQuery#%" } }
});
} );
}
if ( Len( Trim( sFilterExpression ?: "" ) ) ) {

Expand All @@ -1229,19 +1236,22 @@ component {
}
}

var selectFields = [
"formbuilder_formsubmission.id"
, "formbuilder_formsubmission.submitted_data"
, "formbuilder_formsubmission.form_instance"
, "formbuilder_formsubmission.datecreated"
];
if ( websiteUsers ) {
ArrayAppend( selectFields, "submitted_by.id as submitted_by" );
}
result.records = submissionsDao.selectData(
filter = { form = arguments.formId }
, extraFilters = extraFilters
, startRow = arguments.startRow
, maxRows = arguments.maxRows
, orderBy = "#sortby# #sortorder#"
, selectFields = [
"formbuilder_formsubmission.id"
, "formbuilder_formsubmission.submitted_data"
, "formbuilder_formsubmission.form_instance"
, "formbuilder_formsubmission.datecreated"
, "submitted_by.id as submitted_by"
]
, selectFields = selectFields
);

result.totalRecords = submissionsDao.selectData(
Expand Down Expand Up @@ -1439,7 +1449,6 @@ component {

switch( sortBy ) {
case "submitted_by":
sortBy = "submitted_by";
break;
case "datecreated":
case "instanceId":
Expand Down Expand Up @@ -1470,10 +1479,10 @@ component {
}

if ( Len( Trim( arguments.searchQuery ) ) ) {
extraFilters.append({
extraFilters.append( {
filter = "submitted_by like :q or formbuilder_question_response.response like :q"
, filterParams = { q = { type="cf_sql_varchar", value="%#arguments.searchQuery#%" } }
});
} );
}

if ( Len( Trim( arguments.savedFilterExpIdLists ?: "" ) ) ) {
Expand All @@ -1485,29 +1494,38 @@ component {
}
}

var selectFields = [
"formbuilder_question_response.id"
, "formbuilder_question_response.submission"
, "formbuilder_question_response.question"
, "formbuilder_question_response.response"
, "formbuilder_question_response.datecreated"
, "formbuilder_question_response.submitted_by"
, "formbuilder_question_response.submission_type"
, "formbuilder_question_response.submission_reference"
, "submission$form.name as form_name"
, "question.item_type"
];
if ( $helpers.isFeatureEnabled( "websiteUsers" ) ) {
ArrayAppend( selectFields, [
"formbuilder_question_response.website_user"
, "formbuilder_question_response.is_website_user"
], true );
}
if ( $helpers.isFeatureEnabled( "admin" ) ) {
ArrayAppend( selectFields, [
"formbuilder_question_response.admin_user"
, "formbuilder_question_response.is_admin_user"
], true );
}
result.records = questionResponsesDao.selectData(
filter = { question = arguments.questionId }
, extraFilters = extraFilters
, startRow = arguments.startRow
, maxRows = arguments.maxRows
, orderBy = "#sortby# #sortorder#"
, groupBy = "submission, question"
, selectFields = [
"formbuilder_question_response.id"
, "formbuilder_question_response.submission"
, "formbuilder_question_response.question"
, "formbuilder_question_response.response"
, "formbuilder_question_response.datecreated"
, "formbuilder_question_response.submitted_by"
, "formbuilder_question_response.website_user"
, "formbuilder_question_response.is_website_user"
, "formbuilder_question_response.admin_user"
, "formbuilder_question_response.is_admin_user"
, "formbuilder_question_response.submission_type"
, "formbuilder_question_response.submission_reference"
, "submission$form.name as form_name"
, "question.item_type"
]
, selectFields = selectFields
);

if ( arguments.startRow eq 1 and result.records.recordCount lt arguments.maxRows ) {
Expand Down Expand Up @@ -1552,18 +1570,23 @@ component {
var canLog = StructKeyExists( arguments, "logger" );
var canInfo = canLog && logger.canInfo();
var canReportProgress = StructKeyExists( arguments, "progress" );
var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" );
var renderingService = _getFormBuilderRenderingService();
var formItems = getFormItems( arguments.formId );
var spreadsheetLib = _getSpreadsheetLib();
var workbook = spreadsheetLib.new();
var headers = [ "Submission ID", "Submission date", "Submitted by logged in user", "Form instance ID" ];
var headers = [ "Submission ID", "Submission date", "Form instance ID" ];
var itemColumnMap = {};
var itemsToRender = [];
var submissions = $getPresideObject( "formbuilder_formsubmission" ).selectData(
filter = { form = arguments.formId }
, orderBy = "datecreated"
);

if ( websiteUsers ) {
ArrayInsertAt( headers, 3, "Submitted by logged in user" );
}

if ( canInfo ) {
logger.info( "Fetched [#NumberFormat( submissions.recordcount )#] submissions, preparing to export..." );
}
Expand Down Expand Up @@ -1591,12 +1614,14 @@ component {

var row = 1;
for( var submission in submissions ) {
var column = 4;
var submittedBy = Len( submission.submitted_by ) ? $renderLabel( "website_user", submission.submitted_by ) : "";
var column = 4;
row++;
spreadsheetLib.setCellValue( workbook, submission.id, row, 1, "string" );
spreadsheetLib.setCellValue( workbook, DateTimeFormat( submission.datecreated, "yyyy-mm-dd HH:nn:ss" ), row, 2, "string" );
spreadsheetLib.setCellValue( workbook, submittedBy, row, 3, "string" );
if ( websiteUsers ) {
var submittedBy = Len( submission.submitted_by ) ? $renderLabel( "website_user", submission.submitted_by ) : "";
spreadsheetLib.setCellValue( workbook, submittedBy, row, 3, "string" );
}
spreadsheetLib.setCellValue( workbook, submission.form_instance, row, 4, "string" );

if ( itemsToRender.len() ) {
Expand Down Expand Up @@ -1705,7 +1730,8 @@ component {
, any progress
) {
var questionDefinition = getQuestion( arguments.questionId );
var exportFieldList = listToArray( arguments.exportFields );
var exportFieldList = listToArray( arguments.exportFields );
var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" );

if ( !questionDefinition.recordCount ) {
if ( canReportProgress ) {
Expand Down Expand Up @@ -1756,8 +1782,7 @@ component {

var row = 1;
for( var response in responses ) {
var column = 0;
var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : "";
var column = 0;
row++;

if ( ArrayContains( exportFieldList, "id" ) ) {
Expand All @@ -1769,13 +1794,14 @@ component {
if ( ArrayContains( exportFieldList, "submission_reference" ) ) {
spreadsheetLib.setCellValue( workbook, response.submission_reference, row, ++column, "string" );
}
if ( ArrayContains( exportFieldList, "submitted_by" ) ) {
spreadsheetLib.setCellValue( workbook, response.submitted_by, row, ++column, "string" );
if ( websiteUsers && ArrayContains( exportFieldList, "submitted_by" ) ) {
var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : "";
spreadsheetLib.setCellValue( workbook, submittedBy, row, ++column, "string" );
}
if ( ArrayContains( exportFieldList, "datecreated" ) ) {
spreadsheetLib.setCellValue( workbook, DateTimeFormat( response.datecreated, "yyyy-mm-dd HH:nn:ss" ), row, ++column, "string" );
}
if ( ArrayContains( exportFieldList, "is_website_user" ) ) {
if ( websiteUsers && ArrayContains( exportFieldList, "is_website_user" ) ) {
spreadsheetLib.setCellValue( workbook, response.is_website_user, row, ++column, "string" );
}
if ( ArrayContains( exportFieldList, "parent_name" ) ) {
Expand Down Expand Up @@ -1870,7 +1896,8 @@ component {
, any progress
) {
var questionDefinition = getQuestion( arguments.questionId );
var exportFieldList = listToArray( arguments.exportFields );
var exportFieldList = listToArray( arguments.exportFields );
var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" );

if ( !questionDefinition.recordCount ) {
if ( canReportProgress ) {
Expand All @@ -1890,6 +1917,9 @@ component {
var writer = _getCsvWriter().newWriter( tmpFile, "," );

for ( var field in exportFields ) {
if ( !websiteUsers && ArrayFind( [ "submitted_by", "is_website_user" ], field ) ) {
continue;
}
headers.append( $translateResource( uri="preside-objects.formbuilder_question_response:field.#field#.title" ) );
}

Expand Down Expand Up @@ -1927,7 +1957,6 @@ component {
var rowNumber=1;
for( var response in responses ) {
row=[];
var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : "";


if ( ArrayContains( exportFieldList, "id" ) ) {
Expand All @@ -1939,13 +1968,14 @@ component {
if ( ArrayContains( exportFieldList, "submission_reference" ) ) {
row.append( response.submission_reference );
}
if ( ArrayContains( exportFieldList, "submitted_by" ) ) {
row.append( response.submitted_by );
if ( websiteUsers && ArrayContains( exportFieldList, "submitted_by" ) ) {
var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : "";
row.append( submittedBy );
}
if ( ArrayContains( exportFieldList, "datecreated" ) ) {
row.append( DateTimeFormat( response.datecreated, "yyyy-mm-dd HH:nn:ss" ) );
}
if ( ArrayContains( exportFieldList, "is_website_user" ) ) {
if ( websiteUsers && ArrayContains( exportFieldList, "is_website_user" ) ) {
row.append( response.is_website_user );
}
if ( ArrayContains( exportFieldList, "parent_name" ) ) {
Expand Down Expand Up @@ -2371,25 +2401,31 @@ component {
}
}

var selectFields = [
"formbuilder_question_response.id"
, "formbuilder_question_response.submission"
, "formbuilder_question_response.question"
, "formbuilder_question_response.response"
, "formbuilder_question_response.datecreated"
, "formbuilder_question_response.submitted_by"
, "formbuilder_question_response.submission_type"
, "formbuilder_question_response.submission_reference"
, "formbuilder_question_response.parent_name"
];
if ( $helpers.isFeatureEnabled( "websiteUsers" ) ) {
ArrayAppend( selectFields, "formbuilder_question_response.is_website_user" );
}
if ( $helpers.isFeatureEnabled( "admin" ) ) {
ArrayAppend( selectFields, "formbuilder_question_response.is_admin_user" );
}

var questionResponsesDao = $getPresideObject( "formbuilder_question_response" );
var responses = questionResponsesDao.selectData(
filter = { question = arguments.questionId }
, orderBy = "datecreated"
, groupBy = "submission, question"
, extraFilters = extraFilters
, selectFields = [
"formbuilder_question_response.id"
, "formbuilder_question_response.submission"
, "formbuilder_question_response.question"
, "formbuilder_question_response.response"
, "formbuilder_question_response.datecreated"
, "formbuilder_question_response.submitted_by"
, "lformbuilder_question_response.is_website_user"
, "formbuilder_question_response.is_admin_user"
, "formbuilder_question_response.submission_type"
, "formbuilder_question_response.submission_reference"
, "formbuilder_question_response.parent_name"
]
, selectFields = selectFields
);

return responses;
Expand Down
14 changes: 9 additions & 5 deletions system/views/admin/formbuilder/submissions.cfm
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<!---@feature admin and formbuilder--->
<cfscript>
theForm = prc.form ?: QueryNew( '' );
formId = theForm.id;
canDelete = prc.canDelete = hasCmsPermission( "formbuilder.deleteSubmissions" );
v2Form = isTrue( theForm.uses_global_questions ?: "" );
theForm = prc.form ?: QueryNew( '' );
formId = theForm.id;
canDelete = prc.canDelete = hasCmsPermission( "formbuilder.deleteSubmissions" );
v2Form = isTrue( theForm.uses_global_questions ?: "" );
gridFields = [ "datecreated", "form_instance", "submitted_data" ];
if ( isFeatureEnabled( "websiteUsers" ) ) {
ArrayPrepend( gridFields, "submitted_by" );
}
</cfscript>

<cfoutput>
Expand All @@ -21,7 +25,7 @@
, useMultiActions = canDelete
, multiActionUrl = event.buildAdminLink( linkTo='formbuilder.deleteSubmissionsAction', querystring="formId=#formId#" )
, datasourceUrl = event.buildAdminLink( linkTo='formbuilder.listSubmissionsForAjaxDataTable', querystring="formId=#formId#" )
, gridFields = [ "submitted_by", "datecreated", "form_instance", "submitted_data" ]
, gridFields = gridFields
, allowSearch = true
, filterContextData = { formId=formId }
, excludeFilterExpressionTags = v2Form ? "formbuilderV1Form" : "formbuilderV2Form"
Expand Down
Loading
Loading