init III
This commit is contained in:
130
Perl OTRS/Kernel/GenericInterface/Operation/FAQ/LanguageList.pm
Normal file
130
Perl OTRS/Kernel/GenericInterface/Operation/FAQ/LanguageList.pm
Normal file
@@ -0,0 +1,130 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::GenericInterface::Operation::FAQ::LanguageList;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsStringWithData);
|
||||
|
||||
use parent qw(
|
||||
Kernel::GenericInterface::Operation::Common
|
||||
);
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::GenericInterface::Operation::FAQ::LanguageList - GenericInterface FAQ LanguageList Operation backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
usually, you want to create an instance of this
|
||||
by using Kernel::GenericInterface::Operation->new();
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
for my $Needed (qw( DebuggerObject WebserviceID )) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
|
||||
return {
|
||||
Success => 0,
|
||||
ErrorMessage => "Got no $Needed!"
|
||||
};
|
||||
}
|
||||
|
||||
$Self->{$Needed} = $Param{$Needed};
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
perform LanguageList Operation. This will return the current FAQ Languages.
|
||||
|
||||
my $Result = $OperationObject->Run(
|
||||
Data => {},
|
||||
);
|
||||
|
||||
$Result = {
|
||||
Success => 1, # 0 or 1
|
||||
ErrorMessage => '', # In case of an error
|
||||
Data => { # result data payload after Operation
|
||||
Language => [
|
||||
{
|
||||
ID => 1,
|
||||
Name> 'en',
|
||||
},
|
||||
{
|
||||
ID => 2,
|
||||
Name> 'OneMoreLanguage',
|
||||
},
|
||||
# ...
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Set UserID to root because in public interface there is no user.
|
||||
my %Languages = $Kernel::OM->Get('Kernel::System::FAQ')->LanguageList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !IsHashRefWithData( \%Languages ) ) {
|
||||
|
||||
my $ErrorMessage = 'Could not get language data'
|
||||
. ' in Kernel::GenericInterface::Operation::FAQ::LanguageList::Run()';
|
||||
|
||||
return $Self->ReturnError(
|
||||
ErrorCode => 'TicketList.NotLanguageData',
|
||||
ErrorMessage => "TicketList: $ErrorMessage",
|
||||
);
|
||||
}
|
||||
|
||||
my @LanguageList;
|
||||
for my $Key ( sort keys %Languages ) {
|
||||
my %Language = (
|
||||
ID => $Key,
|
||||
Name => $Languages{$Key},
|
||||
);
|
||||
push @LanguageList, {%Language};
|
||||
}
|
||||
|
||||
return {
|
||||
Success => 1,
|
||||
Data => {
|
||||
Language => \@LanguageList,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,140 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::GenericInterface::Operation::FAQ::PublicCategoryList;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsStringWithData);
|
||||
|
||||
use parent qw(
|
||||
Kernel::GenericInterface::Operation::Common
|
||||
);
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::GenericInterface::Operation::FAQ::PublicCategoryList - GenericInterface FAQ PublicCategoryList Operation backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
usually, you want to create an instance of this
|
||||
by using Kernel::GenericInterface::Operation->new();
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
for my $Needed (qw( DebuggerObject WebserviceID )) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
|
||||
return {
|
||||
Success => 0,
|
||||
ErrorMessage => "Got no $Needed!"
|
||||
};
|
||||
}
|
||||
|
||||
$Self->{$Needed} = $Param{$Needed};
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
perform PublicCategoryList Operation. This will return the current FAQ Categories.
|
||||
|
||||
my $Result = $OperationObject->Run(
|
||||
Data => {},
|
||||
);
|
||||
|
||||
$Result = {
|
||||
Success => 1, # 0 or 1
|
||||
ErrorMessage => '', # In case of an error
|
||||
Data => { # result data payload after Operation
|
||||
Category => [
|
||||
{
|
||||
ID => 1,
|
||||
Name> 'Misc',
|
||||
},
|
||||
{
|
||||
ID => 2,
|
||||
Name> 'OneMoreCategory',
|
||||
},
|
||||
# ...
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Set UserID to root because in public interface there is no user.
|
||||
my $CategoryTree = $Kernel::OM->Get('Kernel::System::FAQ')->GetPublicCategoriesLongNames(
|
||||
Valid => 1,
|
||||
Type => 'rw',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
if ( !IsHashRefWithData($CategoryTree) ) {
|
||||
|
||||
my $ErrorMessage = 'Could not get category data'
|
||||
. ' in Kernel::GenericInterface::Operation::FAQ::PublicCategoryList::Run()';
|
||||
|
||||
return $Self->ReturnError(
|
||||
ErrorCode => 'PublicCategoryList.NotCategoryData',
|
||||
ErrorMessage => "PublicCategoryList: $ErrorMessage",
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
my @PublicCategoryList;
|
||||
for my $Key ( sort( keys %{$CategoryTree} ) ) {
|
||||
my %Category = (
|
||||
ID => $Key,
|
||||
Name => $CategoryTree->{$Key},
|
||||
);
|
||||
push @PublicCategoryList, {%Category};
|
||||
}
|
||||
|
||||
# Prepare return data.
|
||||
my $ReturnData = {
|
||||
Success => 1,
|
||||
Data => {},
|
||||
};
|
||||
if ( scalar @PublicCategoryList > 1 ) {
|
||||
$ReturnData->{Data}->{Category} = \@PublicCategoryList;
|
||||
}
|
||||
else {
|
||||
$ReturnData->{Data}->{Category} = $PublicCategoryList[0];
|
||||
}
|
||||
|
||||
return $ReturnData;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
305
Perl OTRS/Kernel/GenericInterface/Operation/FAQ/PublicFAQGet.pm
Normal file
305
Perl OTRS/Kernel/GenericInterface/Operation/FAQ/PublicFAQGet.pm
Normal file
@@ -0,0 +1,305 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::GenericInterface::Operation::FAQ::PublicFAQGet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use MIME::Base64;
|
||||
use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsStringWithData);
|
||||
|
||||
use parent qw(
|
||||
Kernel::GenericInterface::Operation::Common
|
||||
);
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::GenericInterface::Operation::FAQ::PublicFAQGet - GenericInterface FAQ PublicFAQGet Operation backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
usually, you want to create an instance of this
|
||||
by using Kernel::GenericInterface::Operation->new();
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
for my $Needed (qw( DebuggerObject WebserviceID )) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
|
||||
return {
|
||||
Success => 0,
|
||||
ErrorMessage => "Got no $Needed!"
|
||||
};
|
||||
}
|
||||
|
||||
$Self->{$Needed} = $Param{$Needed};
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
perform PublicFAQGet Operation. This will return a Public FAQ entry.
|
||||
|
||||
my $Result = $OperationObject->Run(
|
||||
Data => {
|
||||
ItemID = '32,33',
|
||||
GetAttachmentContents = 1, # 0|1, defaults to 1
|
||||
},
|
||||
);
|
||||
|
||||
$Result = {
|
||||
Success => 1, # 0 or 1
|
||||
ErrorMessage => '', # In case of an error
|
||||
Data => { # result data payload after Operation
|
||||
ItemID => [
|
||||
{
|
||||
ID => 32,
|
||||
ItemID => 32,
|
||||
FAQID => 32,
|
||||
Number => 100032,
|
||||
CategoryID => '2',
|
||||
CategoryName => 'CategoryA::CategoryB',
|
||||
CategoryShortName => 'CategoryB',
|
||||
LanguageID => 1,
|
||||
Language => 'en',
|
||||
Title => 'Article Title',
|
||||
Field1 => 'The Symptoms',
|
||||
Field2 => 'The Problem',
|
||||
Field3 => 'The Solution',
|
||||
Field4 => undef, # Not active by default
|
||||
Field5 => undef, # Not active by default
|
||||
Field6 => 'Comments',
|
||||
Approved => 1, # or 0
|
||||
Keywords => 'KeyWord1 KeyWord2',
|
||||
Votes => 0, # number of votes
|
||||
VoteResult => '0.00', # a number between 0.00 and 100.00
|
||||
StateID => 1,
|
||||
State => 'internal (agent)', # or 'external (customer)' or
|
||||
# 'public (all)'
|
||||
StateTypeID => 1,
|
||||
StateTypeName => 'internal', # or 'external' or 'public'
|
||||
CreatedBy => 1,
|
||||
Changed => '2011-01-05 21:53:50',
|
||||
ChangedBy => '1',
|
||||
Created => '2011-01-05 21:53:50',
|
||||
Name => '1294286030-31.1697297104732', # FAQ Article name or
|
||||
# systemtime + '-' + random number
|
||||
ContentType => 'text/html',
|
||||
Attachment => {
|
||||
{
|
||||
Filesize => '540286', # file size in bytes
|
||||
ContentType => 'image/jpeg',
|
||||
Filename => 'Error.jpg',
|
||||
Content => '...', # base64 content
|
||||
Inline => 0, # specify if is an inline attachment
|
||||
FileID => 34 # FileID for relation with rich text content
|
||||
},
|
||||
{
|
||||
Filesize => '540286', # file size in bytes
|
||||
ContentType => 'image/jpeg',
|
||||
Filename => 'Pencil.jpg',
|
||||
Content => '...', # base64 content
|
||||
Inline => 1, # specify if is an inline attachment
|
||||
FileID => 35 # FileID for relation with rich text content
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID => 33,
|
||||
ItemID => 33,
|
||||
FAQID => 33,
|
||||
Number => 100033,
|
||||
CategoryID => '3',
|
||||
CategoryName => 'CategoryD::CategoryE',
|
||||
CategoryShortName => 'CategoryE',
|
||||
LanguageID => 1,
|
||||
Language => 'en',
|
||||
Title => 'Article Title',
|
||||
Field1 => 'The Symptoms',
|
||||
Field2 => 'The Problem',
|
||||
Field3 => 'The Solution',
|
||||
Field4 => undef, # Not active by default
|
||||
Field5 => undef, # Not active by default
|
||||
Field6 => 'Comments',
|
||||
Approved => 1, # or 0
|
||||
Keywords => 'KeyWord1 KeyWord2',
|
||||
Votes => 0, # number of votes
|
||||
VoteResult => '0.00', # a number between 0.00 and 100.00
|
||||
StateID => 1,
|
||||
State => 'internal (agent)', # or 'external (customer)' or
|
||||
# 'public (all)'
|
||||
StateTypeID => 1,
|
||||
StateTypeName => 'internal', # or 'external' or 'public'
|
||||
CreatedBy => 1,
|
||||
Changed => '2011-01-05 21:53:50',
|
||||
ChangedBy => '1',
|
||||
Created => '2011-01-05 21:53:50',
|
||||
Name => '1294286030-31.1697297104732', # FAQ Article name or
|
||||
# systemtime + '-' + random number
|
||||
},
|
||||
# ...
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{Data}->{ItemID} ) {
|
||||
|
||||
return $Self->ReturnError(
|
||||
ErrorCode => 'PublicFAQGet.MissingParameter',
|
||||
ErrorMessage => "PublicFAQGet: Got no ItemID!",
|
||||
);
|
||||
}
|
||||
if ( !defined( $Param{Data}->{GetAttachmentContents} ) ) {
|
||||
$Param{Data}->{GetAttachmentContents} = 1;
|
||||
}
|
||||
|
||||
my $ErrorMessage = '';
|
||||
|
||||
my $ReturnData = {
|
||||
Success => 1,
|
||||
};
|
||||
|
||||
my @ItemIDs = split( /,/, $Param{Data}->{ItemID} );
|
||||
my @Item;
|
||||
|
||||
# Set UserID to root because in public interface there is no user.
|
||||
my $UserID = 1;
|
||||
|
||||
my $FAQObject = $Kernel::OM->Get('Kernel::System::FAQ');
|
||||
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
|
||||
|
||||
# Get public state types.
|
||||
my $InterfaceStates = $FAQObject->StateTypeList(
|
||||
Types => $ConfigObject->Get('FAQ::Public::StateTypes'),
|
||||
UserID => $UserID,
|
||||
);
|
||||
|
||||
for my $ItemID (@ItemIDs) {
|
||||
|
||||
my %FAQEntry = $FAQObject->FAQGet(
|
||||
ItemID => $ItemID,
|
||||
ItemFields => 1,
|
||||
UserID => $UserID,
|
||||
);
|
||||
|
||||
if ( !IsHashRefWithData( \%FAQEntry ) ) {
|
||||
|
||||
$ErrorMessage = 'Could not get FAQ data'
|
||||
. ' in Kernel::GenericInterface::Operation::FAQ::PublicFAQGet::Run()';
|
||||
|
||||
return $Self->ReturnError(
|
||||
ErrorCode => 'PublicFAQGet.NotValidFAQID',
|
||||
ErrorMessage => "PublicFAQGet: $ErrorMessage",
|
||||
);
|
||||
}
|
||||
|
||||
# Check permissions.
|
||||
my $ApprovalSuccess = 1;
|
||||
if ( $ConfigObject->Get('FAQ::ApprovalRequired') ) {
|
||||
$ApprovalSuccess = $FAQEntry{Approved};
|
||||
}
|
||||
if ( !$ApprovalSuccess || !$InterfaceStates->{ $FAQEntry{StateTypeID} } ) {
|
||||
|
||||
$ErrorMessage = 'Could not get FAQ data'
|
||||
. ' in Kernel::GenericInterface::Operation::FAQ::PublicFAQGet::Run()';
|
||||
|
||||
return $Self->ReturnError(
|
||||
ErrorCode => 'PublicFAQGet.AccessDenied',
|
||||
ErrorMessage => "PublicFAQGet: $ErrorMessage",
|
||||
);
|
||||
}
|
||||
|
||||
my @Index = $FAQObject->AttachmentIndex(
|
||||
ItemID => $ItemID,
|
||||
ShowInline => 1, # ( 0|1, default 1)
|
||||
UserID => $UserID,
|
||||
);
|
||||
|
||||
my %File;
|
||||
if ( IsArrayRefWithData( \@Index ) ) {
|
||||
|
||||
my @Attachments;
|
||||
for my $Attachment (@Index) {
|
||||
|
||||
if ( $Param{Data}->{GetAttachmentContents} ) {
|
||||
%File = $FAQObject->AttachmentGet(
|
||||
ItemID => $ItemID,
|
||||
FileID => $Attachment->{FileID},
|
||||
UserID => $UserID,
|
||||
);
|
||||
|
||||
# Convert content to base64.
|
||||
$File{Content} = encode_base64( $File{Content} );
|
||||
$File{Inline} = $Attachment->{Inline};
|
||||
$File{FileID} = $Attachment->{FileID};
|
||||
}
|
||||
else {
|
||||
%File = (
|
||||
Filename => $Attachment->{Filename},
|
||||
ContentType => $Attachment->{ContentType},
|
||||
Filesize => $Attachment->{Filesize},
|
||||
Content => '',
|
||||
Inline => $Attachment->{Inline},
|
||||
FileID => $Attachment->{FileID}
|
||||
);
|
||||
}
|
||||
push @Attachments, {%File};
|
||||
}
|
||||
|
||||
# Set FAQ entry data.
|
||||
$FAQEntry{Attachment} = \@Attachments;
|
||||
}
|
||||
|
||||
push @Item, \%FAQEntry;
|
||||
}
|
||||
|
||||
if ( !scalar @Item ) {
|
||||
$ErrorMessage = 'Could not get FAQ data'
|
||||
. ' in Kernel::GenericInterface::Operation::FAQ::PublicFAQGet::Run()';
|
||||
|
||||
return $Self->ReturnError(
|
||||
ErrorCode => 'PublicFAQGet.NoFAQData',
|
||||
ErrorMessage => "PublicFAQGet: $ErrorMessage",
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$ReturnData->{Data}->{FAQItem} = \@Item;
|
||||
|
||||
return $ReturnData;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,216 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::GenericInterface::Operation::FAQ::PublicFAQSearch;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use MIME::Base64;
|
||||
use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsStringWithData);
|
||||
|
||||
use parent qw(
|
||||
Kernel::GenericInterface::Operation::Common
|
||||
);
|
||||
|
||||
our $ObjectManagerDisabled = 1;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::GenericInterface::Operation::FAQ::PublicFAQSearch - GenericInterface FAQ PublicFAQSearch Operation backend
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
usually, you want to create an instance of this
|
||||
by using Kernel::GenericInterface::Operation->new();
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
for my $Needed (qw( DebuggerObject WebserviceID )) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
|
||||
return {
|
||||
Success => 0,
|
||||
ErrorMessage => "Got no $Needed!"
|
||||
};
|
||||
}
|
||||
|
||||
$Self->{$Needed} = $Param{$Needed};
|
||||
}
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
perform PublicFAQSearch Operation. This will return a list of public FAQ entries.
|
||||
|
||||
my @IDs = $OperationObject->Run(
|
||||
Data => {
|
||||
|
||||
Number => '*134*', # (optional)
|
||||
Title => '*some title*', # (optional)
|
||||
|
||||
# is searching in Number, Title, Keyword and Field1-6
|
||||
What => '*some text*', # (optional)
|
||||
|
||||
Keyword => '*webserver*', # (optional)
|
||||
LanguageIDs => [ 4, 5, 6 ], # (optional)
|
||||
CategoryIDs => [ 7, 8, 9 ], # (optional)
|
||||
|
||||
OrderBy => [ 'FAQID', 'Title' ], # (optional)
|
||||
|
||||
# Additional information for OrderBy:
|
||||
# The OrderByDirection can be specified for each OrderBy attribute.
|
||||
# The pairing is made by the array indexes.
|
||||
|
||||
OrderByDirection => 'Down', # (Down | Up) # (optional)
|
||||
# default: 'Down'
|
||||
},
|
||||
);
|
||||
|
||||
$Result = {
|
||||
Success => 1, # 0 or 1
|
||||
ErrorMessage => '', # In case of an error
|
||||
Data => { # result data payload after Operation
|
||||
ID => [
|
||||
32,
|
||||
13,
|
||||
12,
|
||||
9,
|
||||
6,
|
||||
5,
|
||||
4,
|
||||
1,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Set SearchLimit on 0 because we need to get all entries.
|
||||
my $SearchLimit = 0;
|
||||
|
||||
my $Config = $Kernel::OM->Get('Kernel::Config')->Get("FAQ::Frontend::PublicFAQSearch");
|
||||
|
||||
my $SortBy = $Param{Data}->{OrderBy}
|
||||
|| $Config->{'SortBy::Default'}
|
||||
|| 'FAQID';
|
||||
|
||||
# The SortBy param could be an ARRAY an SCALAR or an empty value.
|
||||
if ( !IsArrayRefWithData($SortBy) && $SortBy ne '' ) {
|
||||
$SortBy = [$SortBy];
|
||||
}
|
||||
|
||||
my $OrderBy = $Param{Data}->{OrderByDirection}
|
||||
|| $Config->{'Order::Default'}
|
||||
|| 'Down';
|
||||
|
||||
my $CategoryIDs;
|
||||
|
||||
# The CategoryID param could be an ARRAY an SCALAR or an empty value.
|
||||
$Param{Data}->{CategoryIDs} = $Param{Data}->{CategoryIDs} || '';
|
||||
if ( !IsArrayRefWithData( $Param{Data}->{CategoryIDs} ) && $Param{Data}->{CategoryIDs} ne '' ) {
|
||||
$CategoryIDs = [ $Param{Data}->{CategoryIDs} ];
|
||||
}
|
||||
elsif ( $Param{Data}->{CategoryIDs} ne '' ) {
|
||||
$CategoryIDs = $Param{Data}->{CategoryIDs};
|
||||
}
|
||||
|
||||
my $LanguageIDs;
|
||||
|
||||
# The LanguageID param could be an ARRAY an SCALAR or an empty value.
|
||||
$Param{Data}->{LanguageIDs} = $Param{Data}->{LanguageIDs} || '';
|
||||
if ( !IsArrayRefWithData( $Param{Data}->{LanguageIDs} ) && $Param{Data}->{LanguageIDs} ne '' ) {
|
||||
$LanguageIDs = [ $Param{Data}->{LanguageIDs} ];
|
||||
}
|
||||
elsif ( $Param{Data}->{LanguageIDs} ne '' ) {
|
||||
$LanguageIDs = $Param{Data}->{LanguageIDs};
|
||||
}
|
||||
|
||||
my $FAQObject = $Kernel::OM->Get('Kernel::System::FAQ');
|
||||
|
||||
# Set UserID to root because in public interface there is no user.
|
||||
my $UserID = 1;
|
||||
|
||||
# Set default interface settings.
|
||||
my $Interface = $FAQObject->StateTypeGet(
|
||||
Name => 'public',
|
||||
UserID => $UserID,
|
||||
);
|
||||
my $InterfaceStates = $FAQObject->StateTypeList(
|
||||
Types => $Kernel::OM->Get('Kernel::Config')->Get('FAQ::Public::StateTypes'),
|
||||
UserID => $UserID,
|
||||
);
|
||||
|
||||
# Perform FAQ search.
|
||||
my @ViewableItemIDs = $FAQObject->FAQSearch(
|
||||
Number => $Param{Data}->{Number} || '',
|
||||
Title => $Param{Data}->{Title} || '',
|
||||
What => $Param{Data}->{What} || '',
|
||||
Keyword => $Param{Data}->{Keyword} || '',
|
||||
LanguageIDs => $LanguageIDs,
|
||||
CategoryIDs => $CategoryIDs,
|
||||
OrderBy => $SortBy,
|
||||
OrderByDirection => [$OrderBy],
|
||||
Limit => $SearchLimit,
|
||||
UserID => $UserID,
|
||||
States => $InterfaceStates,
|
||||
Interface => $Interface,
|
||||
);
|
||||
if ( !IsArrayRefWithData( \@ViewableItemIDs ) ) {
|
||||
|
||||
my $ErrorMessage = 'Could not get FAQ data'
|
||||
. ' in Kernel::GenericInterface::Operation::FAQ::PublicFAQSearch::Run()';
|
||||
|
||||
return $Self->ReturnError(
|
||||
ErrorCode => 'PublicFAQSearch.NotFAQData',
|
||||
ErrorMessage => "PublicFAQSearch: $ErrorMessage",
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
# Prepare return data.
|
||||
my $ReturnData = {
|
||||
Data => {},
|
||||
Success => 1,
|
||||
};
|
||||
|
||||
# Set FAQ entry data.
|
||||
if ( scalar @ViewableItemIDs > 1 ) {
|
||||
$ReturnData->{Data}->{ID} = \@ViewableItemIDs;
|
||||
}
|
||||
else {
|
||||
$ReturnData->{Data}->{ID} = $ViewableItemIDs[0];
|
||||
}
|
||||
|
||||
return $ReturnData;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user