Commit 661c4edaeedd9e3bd4075679474669a796e85ebe

Authored by Rodrigo Gonçalves
1 parent 71c2f26d
Exists in master

Suporte a campos dinamicos.

Envio para a fila adequada conforme unidade selecionada.
InPersonTicket.sopm
1 <?xml version="1.0" encoding="utf-8" ?> 1 <?xml version="1.0" encoding="utf-8" ?>
2 <otrs_package version="1.0"> 2 <otrs_package version="1.0">
3 <Name>InPersonTicket</Name> 3 <Name>InPersonTicket</Name>
4 - <Version>1.1.0</Version> 4 + <Version>1.3.0</Version>
5 <ChangeLog Version="1.0.1" Date="22/05/2015">First version</ChangeLog> 5 <ChangeLog Version="1.0.1" Date="22/05/2015">First version</ChangeLog>
6 <ChangeLog Version="1.1.0" Date="2016-01-26">Fixes for OTRS 5.0.x</ChangeLog> 6 <ChangeLog Version="1.1.0" Date="2016-01-26">Fixes for OTRS 5.0.x</ChangeLog>
  7 + <ChangeLog Version="1.2.0" Date="2016-06-10">Support for dynamic fields</ChangeLog>
  8 + <ChangeLog Version="1.3.0" Date="2016-06-10">Support for custom queues</ChangeLog>
7 <Framework>5.0.x</Framework> 9 <Framework>5.0.x</Framework>
8 <Vendor>SeTIC-UFSC</Vendor> 10 <Vendor>SeTIC-UFSC</Vendor>
9 <URL>setic.ufsc.br</URL> 11 <URL>setic.ufsc.br</URL>
Kernel/Config/Files/InPersonTicket.xml
@@ -21,7 +21,18 @@ @@ -21,7 +21,18 @@
21 </Setting> 21 </Setting>
22 </ConfigItem> 22 </ConfigItem>
23 23
24 - 24 +
  25 + <ConfigItem Name="Ticket::Frontend::InPersonTicket###DynamicFields"
  26 + Required="1" Valid="1">
  27 + <Description>Dynamic Fields IDs to Include (comma separated) - place * before fields that should use the last value for new tickets</Description>
  28 + <Group>Ticket</Group>
  29 + <SubGroup>Frontend::Agent::InPersonTicket</SubGroup>
  30 + <Setting>
  31 + <String Regex=""></String>
  32 + </Setting>
  33 + </ConfigItem>
  34 +
  35 +
25 <ConfigItem Name="Ticket::Frontend::InPersonTicket###TypeID" 36 <ConfigItem Name="Ticket::Frontend::InPersonTicket###TypeID"
26 Required="1" Valid="1"> 37 Required="1" Valid="1">
27 <Description>Default type ID for tickets</Description> 38 <Description>Default type ID for tickets</Description>
@@ -82,4 +93,24 @@ @@ -82,4 +93,24 @@
82 </Setting> 93 </Setting>
83 </ConfigItem> 94 </ConfigItem>
84 95
  96 +<ConfigItem Name="Ticket::Frontend::InPersonTicket###QueuePrefix"
  97 + Required="0" Valid="1">
  98 + <Description>When the queue comes from a field in the form, a prefix can be attached to the value while searching for the queue. A space is added between this and the queue name.</Description>
  99 + <Group>Ticket</Group>
  100 + <SubGroup>Frontend::Agent::InPersonTicket</SubGroup>
  101 + <Setting>
  102 + <String Regex="">Primeiro nível -</String>
  103 + </Setting>
  104 + </ConfigItem>
  105 +
  106 + <ConfigItem Name="Ticket::Frontend::InPersonTicket###QueueField"
  107 + Required="0" Valid="1">
  108 + <Description>Name of the field in the form which indicates the queue to send the ticket.</Description>
  109 + <Group>Ticket</Group>
  110 + <SubGroup>Frontend::Agent::InPersonTicket</SubGroup>
  111 + <Setting>
  112 + <String Regex="">DF_unidade</String>
  113 + </Setting>
  114 + </ConfigItem>
  115 +
85 </otrs_config> 116 </otrs_config>
86 \ No newline at end of file 117 \ No newline at end of file
Kernel/Language/pt_BR_InPersonTicket.pm
@@ -20,6 +20,8 @@ sub Data { @@ -20,6 +20,8 @@ sub Data {
20 $Self->{Translation}->{'Concluded'} = 'Concluído'; 20 $Self->{Translation}->{'Concluded'} = 'Concluído';
21 $Self->{Translation}->{'In person ticket'} = 'Atendimento presencial'; 21 $Self->{Translation}->{'In person ticket'} = 'Atendimento presencial';
22 $Self->{Translation}->{'The ticket has been created with number:'} = 'Chamado criado com número: '; 22 $Self->{Translation}->{'The ticket has been created with number:'} = 'Chamado criado com número: ';
  23 + $Self->{Translation}->{'Dynamic Fields IDs to Include (comma separated)'} = 'IDs dos campos dinâmicos, separados por vírgula - coloque * antes de campos que não devem usar o último valor para novos tickets';
  24 +
23 25
24 return 1; 26 return 1;
25 } 27 }
Kernel/Modules/InPersonTicket.pm
@@ -25,6 +25,9 @@ our @ObjectDependencies = ( @@ -25,6 +25,9 @@ our @ObjectDependencies = (
25 "Kernel::Config", 25 "Kernel::Config",
26 "Kernel::System::CustomerUser", 26 "Kernel::System::CustomerUser",
27 "Kernel::System::Service", 27 "Kernel::System::Service",
  28 + "Kernel::System::DynamicField::Backend",
  29 + "Kernel::System::DynamicField",
  30 + "Kernel::System::User"
28 ); 31 );
29 32
30 sub new { 33 sub new {
@@ -45,8 +48,10 @@ sub Run { @@ -45,8 +48,10 @@ sub Run {
45 my $paramObject = $Kernel::OM->Get("Kernel::System::Web::Request"); 48 my $paramObject = $Kernel::OM->Get("Kernel::System::Web::Request");
46 my $dbObject = $Kernel::OM->Get("Kernel::System::DB"); 49 my $dbObject = $Kernel::OM->Get("Kernel::System::DB");
47 my $serviceObject = $Kernel::OM->Get("Kernel::System::Service"); 50 my $serviceObject = $Kernel::OM->Get("Kernel::System::Service");
48 - 51 +
49 $Self->BuildServiceBlock(); 52 $Self->BuildServiceBlock();
  53 + $Self->BuildDynamicFieldsFields();
  54 +
50 55
51 if ( $paramObject->GetParam( Param => "Subaction" ) && ($paramObject->GetParam( Param => "Subaction" ) eq "GetUserName") ) { 56 if ( $paramObject->GetParam( Param => "Subaction" ) && ($paramObject->GetParam( Param => "Subaction" ) eq "GetUserName") ) {
52 my $content = $Self->GetUserName(UserID => $paramObject->GetParam( Param => "UserID" )); 57 my $content = $Self->GetUserName(UserID => $paramObject->GetParam( Param => "UserID" ));
@@ -89,6 +94,50 @@ sub GetUserName { @@ -89,6 +94,50 @@ sub GetUserName {
89 94
90 } 95 }
91 96
  97 +sub BuildDynamicFieldsFields {
  98 + my ( $Self, %Param ) = @_;
  99 +
  100 + my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
  101 + my $DynamicFieldObject = $Kernel::OM->Get("Kernel::System::DynamicField");
  102 + my $ConfigObject = $Kernel::OM->Get("Kernel::Config");
  103 + my $config = $ConfigObject->Get("Ticket::Frontend::InPersonTicket");
  104 + my $layoutObject = $Kernel::OM->Get("Kernel::Output::HTML::Layout");
  105 + my $paramObject = $Kernel::OM->Get("Kernel::System::Web::Request");
  106 + my $userObject = $Kernel::OM->Get("Kernel::System::User");
  107 + my @dfieldList = @{ $DynamicFieldObject->DynamicFieldListGet( Valid => 1 ) };
  108 + my @dynamicFieldsInuse = split(",", $config->{DynamicFields} || "unidade");
  109 + my %prefs = $userObject->GetPreferences(UserID => $Self->{UserID});
  110 +
  111 + foreach (@dfieldList) {
  112 + my $field = $_;
  113 + if ($field->{Name} ~~ @dynamicFieldsInuse || '*' . $field->{Name} ~~ @dynamicFieldsInuse) {
  114 +
  115 + my $defValue = "";
  116 +
  117 + if ($field->{Name} ~~ @dynamicFieldsInuse) {
  118 + $defValue = $prefs{"IPT_DF_" . $field->{Name}};
  119 + }
  120 +
  121 + my $DynamicFieldHTML = $DynamicFieldBackendObject->EditFieldRender(
  122 + DynamicFieldConfig => $field,
  123 + LayoutObject => $layoutObject,
  124 + ParamObject => $paramObject,
  125 + Value => $defValue,
  126 + );
  127 +
  128 + $layoutObject->Block(
  129 + Name => 'DynamicField',
  130 + Data => {
  131 + Name => $field->{Name},
  132 + Label => $DynamicFieldHTML->{Label},
  133 + Field => $DynamicFieldHTML->{Field},
  134 + },
  135 + );
  136 + }
  137 + }
  138 +
  139 +}
  140 +
92 sub BuildServiceBlock { 141 sub BuildServiceBlock {
93 my ( $Self, %Param ) = @_; 142 my ( $Self, %Param ) = @_;
94 143
@@ -147,19 +196,43 @@ sub GetQueueID() { @@ -147,19 +196,43 @@ sub GetQueueID() {
147 196
148 my $ParamObject = $Kernel::OM->Get("Kernel::System::Web::Request"); 197 my $ParamObject = $Kernel::OM->Get("Kernel::System::Web::Request");
149 my $QueueObject = $Kernel::OM->Get("Kernel::System::Queue"); 198 my $QueueObject = $Kernel::OM->Get("Kernel::System::Queue");
  199 + my $DynamicFieldObject = $Kernel::OM->Get("Kernel::System::DynamicField");
150 my $ConfigObject = $Kernel::OM->Get("Kernel::Config"); 200 my $ConfigObject = $Kernel::OM->Get("Kernel::Config");
  201 + my $LayoutObject = $Kernel::OM->Get("Kernel::Output::HTML::Layout");
  202 + my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
151 203
152 # Gets default Queue 204 # Gets default Queue
153 my $ConfigTicket = $ConfigObject->Get("Ticket::Frontend::CustomerTicketMessage"); 205 my $ConfigTicket = $ConfigObject->Get("Ticket::Frontend::CustomerTicketMessage");
154 206
155 my $QueueDefault = $ConfigTicket->{"QueueDefault"}; 207 my $QueueDefault = $ConfigTicket->{"QueueDefault"};
156 208
157 - # Checks if there is a field for the queue  
158 my %QueueListID = $QueueObject->QueueList( Valid => 1 ); 209 my %QueueListID = $QueueObject->QueueList( Valid => 1 );
159 my %QueueList = reverse $QueueObject->QueueList( Valid => 1 ); 210 my %QueueList = reverse $QueueObject->QueueList( Valid => 1 );
160 my $QueueID = $QueueList{$QueueDefault}; 211 my $QueueID = $QueueList{$QueueDefault};
161 my $Queue = $QueueListID{$QueueID}; 212 my $Queue = $QueueListID{$QueueID};
  213 +
  214 + $Self->{ConfigModule} = $ConfigObject->Get("Ticket::Frontend::InPersonTicket");
  215 +
  216 + # Checks if there is a field for the queue
  217 + my $QueuePrefix = $Self->{ConfigModule}->{"QueuePrefix"};
  218 + my $QueueField = $Self->{ConfigModule}->{"QueueField"};
  219 +
  220 + if ( $QueuePrefix && $QueueField ) {
  221 + my $dynFieldQueue = $DynamicFieldObject->DynamicFieldGet( Name => $QueueField );
  222 + my $QueueSelected = $DynamicFieldBackendObject->EditFieldValueGet(
  223 + DynamicFieldConfig => $dynFieldQueue,
  224 + ParamObject => $ParamObject,
  225 + LayoutObject => $LayoutObject,
  226 + );
  227 +
  228 + my $QueueName = "$QueuePrefix $QueueSelected";
162 229
  230 + if ( $QueueList{$QueueName} ) {
  231 + $QueueID = $QueueList{$QueueName};
  232 + $Queue = $QueueName;
  233 + }
  234 + }
  235 +
163 return ( $Queue, $QueueID ); 236 return ( $Queue, $QueueID );
164 } 237 }
165 238
@@ -174,7 +247,10 @@ sub CreateTicket { @@ -174,7 +247,10 @@ sub CreateTicket {
174 my $DynamicFieldObject = $Kernel::OM->Get("Kernel::System::DynamicField"); 247 my $DynamicFieldObject = $Kernel::OM->Get("Kernel::System::DynamicField");
175 my $CustomerUserObject = $Kernel::OM->Get("Kernel::System::CustomerUser"); 248 my $CustomerUserObject = $Kernel::OM->Get("Kernel::System::CustomerUser");
176 my $LayoutObject = $Kernel::OM->Get("Kernel::Output::HTML::Layout"); 249 my $LayoutObject = $Kernel::OM->Get("Kernel::Output::HTML::Layout");
177 - 250 + my $userObject = $Kernel::OM->Get("Kernel::System::User");
  251 + my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');
  252 +
  253 +
178 # Queue 254 # Queue
179 my ( $Queue, $QueueID ) = $Self->GetQueueID(%Param); 255 my ( $Queue, $QueueID ) = $Self->GetQueueID(%Param);
180 $Data{QueueID} = $QueueID; 256 $Data{QueueID} = $QueueID;
@@ -198,6 +274,38 @@ sub CreateTicket { @@ -198,6 +274,38 @@ sub CreateTicket {
198 UserID => $Self->{ConfigModule}->{DefaultOwnerID}, 274 UserID => $Self->{ConfigModule}->{DefaultOwnerID},
199 ); 275 );
200 276
  277 + my @dfieldList = @{ $DynamicFieldObject->DynamicFieldListGet( Valid => 1 ) };
  278 + my @dynamicFieldsInuse = split(",", $Self->{ConfigModule}->{DynamicFields} || "unidade");
  279 +
  280 + foreach (@dfieldList) {
  281 + my $field = $_;
  282 +
  283 + if ($field->{Name} ~~ @dynamicFieldsInuse || '*' . $field->{Name} ~~ @dynamicFieldsInuse) {
  284 + my $value = $DynamicFieldBackendObject->EditFieldValueGet(
  285 + DynamicFieldConfig => $field,
  286 + ParamObject => $ParamObject,
  287 + LayoutObject => $LayoutObject,
  288 + );
  289 +
  290 + if ($field->{Name} ~~ @dynamicFieldsInuse) {
  291 + $userObject->SetPreferences(
  292 + UserID => $Self->{UserID},
  293 + Key => "IPT_DF_" . $field->{Name},
  294 + Value => $value,
  295 + );
  296 + }
  297 +
  298 + if ($value) {
  299 + $DynamicFieldBackendObject->ValueSet(
  300 + DynamicFieldConfig => $field,
  301 + ObjectID => $TicketID,
  302 + Value => $value,
  303 + UserID => $Self->{UserID},
  304 + );
  305 + }
  306 + }
  307 + }
  308 +
201 my $MimeType = 'text/plain'; 309 my $MimeType = 'text/plain';
202 310
203 # Create article 311 # Create article
Kernel/Output/HTML/Templates/Standard/InPersonTicket.tt
@@ -50,6 +50,19 @@ @@ -50,6 +50,19 @@
50 [% RenderBlockEnd("selectService") %] 50 [% RenderBlockEnd("selectService") %]
51 </select> 51 </select>
52 <div class="Clear"></div> 52 <div class="Clear"></div>
  53 +
  54 +
  55 + [% RenderBlockStart("DynamicField") %]
  56 + [% Data.Label %]
  57 + <div class="Field">
  58 + [% Data.Field %]
  59 + </div>
  60 + <div class="Clear"></div>
  61 +
  62 +
  63 +
  64 + [% RenderBlockEnd("DynamicField") %]
  65 +
53 66
54 <label class="OtherMandatory" for="RichTextDescription"><span class="Marker">*</span> [% Translate("Description") | html %]:</label> 67 <label class="OtherMandatory" for="RichTextDescription"><span class="Marker">*</span> [% Translate("Description") | html %]:</label>
55 <div id="RichTextField" class="RichTextField" > 68 <div id="RichTextField" class="RichTextField" >