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

Feat/survey open ticket #261

Open
wants to merge 22 commits into
base: rel-6_1
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Kernel/Modules/AgentSurveyEditQuestions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ sub Run {
elsif ( $Self->{Subaction} eq 'AnswerAdd' ) {

my $Answer = $ParamObject->GetParam( Param => "Answer" );
my $OpenTicket = $ParamObject->GetParam( Param => "OpenTicket" );
my $QueueID = $ParamObject->GetParam( Param => "QueueID" );

# check if survey and question exists
if ( $SurveyExists ne 'Yes' || $QuestionExists ne 'Yes' ) {
Expand All @@ -287,6 +289,8 @@ sub Run {
QuestionID => $GetParam{QuestionID},
Answer => $Answer,
UserID => $Self->{UserID},
OpenTicket => $OpenTicket eq 'on' ? 1 : 0,
QueueID => $QueueID || 0,
);

return $Self->_MaskQuestionEdit(
Expand Down
62 changes: 62 additions & 0 deletions Kernel/Modules/PublicSurvey.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ sub Run {
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');



# ------------------------------------------------------------ #
# public survey vote
# ------------------------------------------------------------ #
if ( $Self->{Subaction} eq 'PublicSurveyVote' ) {
my $PublicSurveyKey = $ParamObject->GetParam( Param => 'PublicSurveyKey' );

my $OpenTicketQuestionsText = undef;
my $OpenTicketQueueID = 0;

# get survey from public key
my %Survey = $SurveyObject->PublicSurveyGet(
PublicSurveyKey => $PublicSurveyKey,
);

if ( $Survey{SurveyID} ) {
@QuestionList = $SurveyObject->QuestionList(
SurveyID => $Survey{SurveyID},
Expand All @@ -79,6 +85,22 @@ sub Run {
Param => "PublicSurveyVote2[$Question->{QuestionID}]"
);

my %AnswerData = $SurveyObject->AnswerGet(
AnswerID => $PublicSurveyVote2,
);

if($AnswerData{OpenTicket} eq 1){
my %RequestData = $SurveyObject->RequestGet(
PublicSurveyKey => $PublicSurveyKey,
);

$OpenTicketQueueID = $AnswerData{QueueID};

$OpenTicketQuestionsText = 'Pergunta: '.$Question->{Question}.' - Resposta: '.$AnswerData{Answer}. "\n";

}


if (
$Question->{AnswerRequired}
&& ( !$PublicSurveyVote2 || !length $PublicSurveyVote2 )
Expand Down Expand Up @@ -331,6 +353,46 @@ sub Run {
Title => 'Survey',
);

if($OpenTicketQuestionsText){
my $RequestData = $SurveyObject->RequestGet(
PublicSurveyKey => $PublicSurveyKey,
);

my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
TicketID => $RequestData{TicketID},
);

my $Return = $Kernel::OM->Get('Kernel::System::Ticket')->TicketCreate(
Title => 'Pesquisa de Satisfação - '.$Ticket{TicketNumber},
QueueID => $OpenTicketQueueID,
UserID => 1,
PriorityID => 3,
StateID => 1,
CustomerID => $Ticket{CustomerID},
CustomerUser => $Ticket{CustomerUser},
OwnerID => 1,
TypeID => 1,
ServiceID => $Ticket{ServiceID},
Lock => 'unlock',
Body => $OpenTicketQuestionsText,
);

my $ArticleObject = $Kernel::OM->Get('Kernel::System::Ticket::Article');
my $ArticleBackendObject= $ArticleObject->BackendForChannel(ChannelName => 'Phone');

my $ArticleID = $ArticleBackendObject->ArticleCreate(
TicketID => $Return,
SenderType => 'agent',
IsVisibleForCustomer => 1,
UserID => 1,
Subject => 'Pesquisa de Satisfação - '.$Ticket{TicketNumber},
Body => $OpenTicketQuestionsText,
HistoryType => 'OwnerUpdate',
HistoryComment => 'Pesquisa de Satisfação',
ContentType => 'text/plain; charset=utf8',
);
}

# print the main table.
$LayoutObject->Block(
Name => 'PublicSurveyMessage',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@
<label for="Answer" class="Mandatory"><span class="Marker">*</span> [% Translate("Add Answer") | html %]:</label>
<div class="Field">
<input type="text" id="Answer" name="Answer" size="60" class="Validate_Required [% Data.AnswerServerError | html %] "/>
<button class="CallForAction Plus" type="submit" value="[% Translate("Add") | html %]"> <span><i class="fa fa-plus-square"></i> [% Translate("Add") | html %]</button>
</div>

<div id="AnswerError" class="TooltipErrorMessage">
Expand All @@ -277,6 +276,23 @@
<p>[% Translate("This field is required.") | html %]</p>
</div>

</fieldset>
<fieldset class="TableLike FixedLabel">
<label for="OpenTicket"> [% Translate("Open Ticket") | html %]:</label>
<div class="Field">
<input type="checkbox" id="OpenTicket" name="OpenTicket"/>
</div>
</fieldset>
<fieldset class="TableLike FixedLabel">
<label for="QueueID"> [% Translate("Queue ID") | html %]:</label>
<div class="Field">
<input type="text" id="QueueID" name="QueueID" size="60"/>
</div>
</fieldset>
<fieldset class="TableLike FixedLabel">
<div class="Field">
<button class="CallForAction Plus" type="submit" value="[% Translate("Add") | html %]"> <span><i class="fa fa-plus-square"></i> [% Translate("Add") | html %]</button>
</div>
</fieldset>
</form>
[% RenderBlockEnd("QuestionEditAddAnswer") %]
Expand All @@ -293,6 +309,8 @@
<thead>
<tr>
<th> [% Translate("Description") | html %] </th>
<th> [% Translate("Generate Ticket") | html %] </th>
<th> [% Translate("Ticket Queue ID") | html %] </th>
<th> [% Translate("Up") | html %] </th>
<th> [% Translate("Down") | html %] </th>
[% RenderBlockStart("QuestionEditTableDelete") %]
Expand All @@ -306,6 +324,12 @@
<tr>
<td>
<a class="AsBlock" href="[% Env("Baselink") %]Action=[% Env("Action") %];Subaction=AnswerEdit;SurveyID=[% Data.SurveyID | uri %];QuestionID=[% Data.QuestionID | uri %];AnswerID=[% Data.AnswerID | uri %]"> [% Data.Answer | truncate(90) | html %] </a>
</td>
<td>
[% Data.OpenTicket | truncate(90) | html %]
</td>
<td>
[% Data.QueueID | truncate(90) | html %]
</td>
<td class="Center">
<a class="AsBlock ArrowUp[% Data.ClassUp | html %]" href="[% Env("Baselink") %]Action=[% Env("Action") %];Subaction=AnswerUp;SurveyID=[% Data.SurveyID | uri %];QuestionID=[% Data.QuestionID | uri %];AnswerID=[% Data.AnswerID | uri %]">
Expand Down
14 changes: 9 additions & 5 deletions Kernel/System/Survey/Answer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ sub AnswerAdd {
return $Kernel::OM->Get('Kernel::System::DB')->Do(
SQL => '
INSERT INTO survey_answer (question_id, answer, position, create_time, create_by,
change_time, change_by)
VALUES ( ?, ?, 255, current_timestamp, ?, current_timestamp, ?)',
Bind => [ \$Param{QuestionID}, \$Param{Answer}, \$Param{UserID}, \$Param{UserID}, ],
change_time, change_by, open_ticket, queue_id)
VALUES ( ?, ?, 255, current_timestamp, ?, current_timestamp, ?, ?, ?)',
Bind => [ \$Param{QuestionID}, \$Param{Answer}, \$Param{UserID}, \$Param{UserID}, \$Param{OpenTicket}, \$Param{QueueID}, ],
);
}

Expand Down Expand Up @@ -138,7 +138,7 @@ sub AnswerGet {
# get answer
return if !$DBObject->Prepare(
SQL => '
SELECT id, question_id, answer, position, create_time, create_by, change_time, change_by
SELECT id, question_id, answer, position, create_time, create_by, change_time, change_by, open_ticket, queue_id
FROM survey_answer
WHERE id = ?',
Bind => [ \$Param{AnswerID} ],
Expand All @@ -156,6 +156,8 @@ sub AnswerGet {
$Data{CreateBy} = $Row[5];
$Data{ChangeTime} = $Row[6];
$Data{ChangeBy} = $Row[7];
$Data{OpenTicket} = $Row[8];
$Data{QueueID} = $Row[9];
}

return %Data;
Expand Down Expand Up @@ -240,7 +242,7 @@ sub AnswerList {
# get answer list
return if !$DBObject->Prepare(
SQL => '
SELECT id, question_id, answer
SELECT id, question_id, answer, open_ticket, queue_id
FROM survey_answer
WHERE question_id = ?
ORDER BY position',
Expand All @@ -254,6 +256,8 @@ sub AnswerList {
$Data{AnswerID} = $Row[0];
$Data{QuestionID} = $Row[1];
$Data{Answer} = $Row[2];
$Data{OpenTicket} = $Row[3];
$Data{QueueID} = $Row[4];

push @List, \%Data;
}
Expand Down
15 changes: 15 additions & 0 deletions scripts/database/migrations/20240131171910_SurveyOpenTicket.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Migrations>
<DatabaseInstall Type="post">
<TableAlter Type="post" Name="survey_answer">
<ColumnAdd Default="0" Name="open_ticket" Required="false" Size="1" Type="SMALLINT"></ColumnAdd>
<ColumnAdd Default="0" Name="queue_id" Required="false" Size="1" Type="INTEGER"></ColumnAdd>
</TableAlter>
</DatabaseInstall>

<DatabaseUninstall Type="pre">
<TableAlter Type="pre" Name="survey_answer">
<ColumnDrop Name="open_ticket"></ColumnDrop>
<ColumnDrop Name="queue_id"></ColumnDrop>
</TableAlter>
</DatabaseUninstall>
</Migrations>