This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,385 @@
# --
# 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::Modules::CustomerFAQExplorer;
use strict;
use warnings;
our $ObjectManagerDisabled = 1;
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {%Param};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# get config of frontend module
my $Config = $ConfigObject->Get("FAQ::Frontend::$Self->{Action}");
my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');
# get config data
my $StartHit = int( $ParamObject->GetParam( Param => 'StartHit' ) || 1 );
my $SearchLimit = $Config->{SearchLimit} || 200;
my $SearchPageShown = $Config->{SearchPageShown} || 3;
my $SortBy = $ParamObject->GetParam( Param => 'SortBy' )
|| $Config->{'SortBy::Default'}
|| 'FAQID';
my $OrderBy = $ParamObject->GetParam( Param => 'Order' )
|| $Config->{'Order::Default'}
|| 'Down';
my $CategoryID = $ParamObject->GetParam( Param => 'CategoryID' ) || 0;
my $FAQObject = $Kernel::OM->Get('Kernel::System::FAQ');
# check for non numeric CategoryID
if ( $CategoryID !~ /\d+/ ) {
$CategoryID = 0;
}
# get category by name
my $Category = $ParamObject->GetParam( Param => 'Category' ) || '';
# try to get the Category ID from category name if no Category ID
if ( $Category && !$CategoryID ) {
# get the category tree
my $CategoryTree = $FAQObject->CategoryTreeList(
UserID => $Self->{UserID},
);
# reverse the has for easy lookup
my %ReverseCategoryTree = reverse %{$CategoryTree};
$CategoryID = $ReverseCategoryTree{$Category} || 0;
}
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
# try to get the category data
my %CategoryData;
if ($CategoryID) {
# get category data
%CategoryData = $FAQObject->CategoryGet(
CategoryID => $CategoryID,
UserID => $Self->{UserID},
);
if ( !%CategoryData ) {
return $LayoutObject->CustomerNoPermission(
WithHeader => 'yes',
);
}
# check user permission
my $Permission = $FAQObject->CheckCategoryCustomerPermission(
CustomerUser => $Self->{UserLogin},
CategoryID => $CategoryID,
UserID => $Self->{UserID},
);
if ( !$Permission ) {
return $LayoutObject->CustomerNoPermission(
WithHeader => 'yes',
);
}
}
# store the last screen overview in session
$Kernel::OM->Get('Kernel::System::AuthSession')->UpdateSessionID(
SessionID => $Self->{SessionID},
Key => 'LastScreenOverview',
Value => $Self->{RequestedURL},
);
my $Output = $LayoutObject->CustomerHeader(
Value => '',
);
$Output .= $LayoutObject->CustomerNavigationBar();
# show FAQ path
$LayoutObject->FAQPathShow(
FAQObject => $FAQObject,
CategoryID => $CategoryID,
UserID => $Self->{UserID},
);
# get all direct subcategories of the selected category
my $CategoryIDsRef = $FAQObject->CustomerCategorySearch(
ParentID => $CategoryID,
CustomerUser => $Self->{UserLogin},
Mode => 'Customer',
UserID => $Self->{UserID},
);
# show subcategories list
$LayoutObject->Block(
Name => 'Subcategories',
Data => {},
);
$LayoutObject->Block(
Name => 'OverviewResult',
Data => {},
);
# get interface states list
my $InterfaceStates = $FAQObject->StateTypeList(
Types => $ConfigObject->Get('FAQ::Customer::StateTypes'),
UserID => $Self->{UserID},
);
# check if there are subcategories
if ( $CategoryIDsRef && ref $CategoryIDsRef eq 'ARRAY' && @{$CategoryIDsRef} ) {
# show data for each subcategory
for my $SubCategoryID ( @{$CategoryIDsRef} ) {
my %SubCategoryData = $FAQObject->CategoryGet(
CategoryID => $SubCategoryID,
UserID => $Self->{UserID},
);
# get the number of subcategories of this subcategory
$SubCategoryData{SubCategoryCount} = $FAQObject->CategoryCount(
ParentIDs => [$SubCategoryID],
UserID => $Self->{UserID},
);
# get the number of FAQ articles in this category
$SubCategoryData{ArticleCount} = $FAQObject->FAQCount(
CategoryIDs => [$SubCategoryID],
ItemStates => $InterfaceStates,
OnlyApproved => 1,
Valid => 1,
UserID => $Self->{UserID},
);
# output the category data
$LayoutObject->Block(
Name => 'OverviewResultRow',
Data => {%SubCategoryData},
);
}
}
# otherwise a no data found message is displayed
else {
$LayoutObject->Block(
Name => 'NoCategoryDataFoundMsg',
);
}
# set default interface settings
my $Interface = $FAQObject->StateTypeGet(
Name => 'external',
UserID => $Self->{UserID},
);
# search all FAQ articles within the given category
my @ViewableItemIDs = $FAQObject->FAQSearch(
OrderBy => [$SortBy],
OrderByDirection => [$OrderBy],
Limit => $SearchLimit,
UserID => $Self->{UserID},
States => $InterfaceStates,
Interface => $Interface,
CategoryIDs => [$CategoryID],
);
# set the SortBy Class
my $SortClass;
# this sets the opposite to the OrderBy parameter
if ( $OrderBy eq 'Down' ) {
$SortClass = 'SortAscending';
}
elsif ( $OrderBy eq 'Up' ) {
$SortClass = 'SortDescending';
}
# set the SortBy Class to the correct field
my %CSSSort;
my $CSSSortBy = $SortBy . 'Sort';
$CSSSort{$CSSSortBy} = $SortClass;
my %NewOrder = (
Down => 'Up',
Up => 'Down',
);
# show the FAQ article list
$LayoutObject->Block(
Name => 'FAQItemList',
Data => {
CategoryID => $CategoryID,
%CSSSort,
Order => $NewOrder{$OrderBy},
},
);
my $MultiLanguage = $ConfigObject->Get('FAQ::MultiLanguage');
# show language header
if ($MultiLanguage) {
$LayoutObject->Block(
Name => 'HeaderLanguage',
Data => {
CategoryID => $CategoryID,
%CSSSort,
Order => $NewOrder{$OrderBy},
},
);
}
my $Counter = 0;
if (@ViewableItemIDs) {
for my $ItemID (@ViewableItemIDs) {
$Counter++;
# build search result
if (
$Counter >= $StartHit
&& $Counter < ( $SearchPageShown + $StartHit )
)
{
my %FAQData = $FAQObject->FAQGet(
ItemID => $ItemID,
ItemFields => 0,
UserID => $Self->{UserID},
);
$FAQData{CleanTitle} = $FAQObject->FAQArticleTitleClean(
Title => $FAQData{Title},
Size => $Config->{TitleSize},
);
# add blocks to template
$LayoutObject->Block(
Name => 'Record',
Data => {
%FAQData,
},
);
# add language data
if ($MultiLanguage) {
$LayoutObject->Block(
Name => 'RecordLanguage',
Data => {
%FAQData,
},
);
}
}
}
}
# otherwise a no data found message is displayed
else {
$LayoutObject->Block(
Name => 'NoFAQDataFoundMsg',
);
}
my $Link = 'SortBy=' . $LayoutObject->LinkEncode($SortBy) . ';';
$Link .= 'Order=' . $LayoutObject->LinkEncode($OrderBy) . ';';
# build search navigation bar
my %PageNav = $LayoutObject->PageNavBar(
Limit => $SearchLimit,
StartHit => $StartHit,
PageShown => $SearchPageShown,
AllHits => $Counter,
Action => "Action=CustomerFAQExplorer;CategoryID=$CategoryID",
Link => $Link,
IDPrefix => "CustomerFAQExplorer",
);
if ( $PageNav{TotalHits} =~ m/<span\sclass="PaginationLimit">(\d.*)<\/span>/g ) {
$PageNav{TotalHits} = $1;
}
# show footer filter - show only if more the one page is available
if ( defined $PageNav{TotalHits} && ( $PageNav{TotalHits} > $SearchPageShown ) ) {
$LayoutObject->Block(
Name => 'Pagination',
Data => {
%Param,
%PageNav,
},
);
}
# show QuickSearch
$LayoutObject->FAQShowQuickSearch(
Mode => 'Customer',
CustomerUser => $Self->{UserLogin},
Interface => $Interface,
InterfaceStates => $InterfaceStates,
UserID => $Self->{UserID},
);
# show last added and last updated articles
for my $Type (qw(LastCreate LastChange)) {
my $ShowOk = $LayoutObject->FAQShowLatestNewsBox(
FAQObject => $FAQObject,
Type => $Type,
Mode => 'Customer',
CustomerUser => $Self->{UserLogin},
CategoryID => $CategoryID,
Interface => $Interface,
InterfaceStates => $InterfaceStates,
UserID => $Self->{UserID},
);
if ( !$ShowOk ) {
return $LayoutObject->ErrorScreen();
}
}
# show top ten articles
my $ShowOk = $LayoutObject->FAQShowTop10(
FAQObject => $FAQObject,
Mode => 'Customer',
CustomerUser => $Self->{UserLogin},
CategoryID => $CategoryID,
Interface => $Interface,
InterfaceStates => $InterfaceStates,
UserID => $Self->{UserID},
);
if ( !$ShowOk ) {
return $LayoutObject->ErrorScreen();
}
$Output .= $LayoutObject->Output(
TemplateFile => 'CustomerFAQExplorer',
Data => {
%Param,
CategoryID => $CategoryID,
%CategoryData,
},
);
$Output .= $LayoutObject->CustomerFooter();
return $Output;
}
1;