init III
This commit is contained in:
1971
Perl OTRS/Kernel/System/FAQ/Category.pm
Normal file
1971
Perl OTRS/Kernel/System/FAQ/Category.pm
Normal file
File diff suppressed because it is too large
Load Diff
418
Perl OTRS/Kernel/System/FAQ/Language.pm
Normal file
418
Perl OTRS/Kernel/System/FAQ/Language.pm
Normal file
@@ -0,0 +1,418 @@
|
||||
# --
|
||||
# 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::System::FAQ::Language;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::FAQ::Language - sub module of Kernel::System::FAQ
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All FAQ language functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 LanguageAdd()
|
||||
|
||||
add a language
|
||||
|
||||
my $Success = $FAQObject->LanguageAdd(
|
||||
Name => 'Some Language',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success = 1; # or undef if language could not be added
|
||||
|
||||
=cut
|
||||
|
||||
sub LanguageAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Name UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
INSERT INTO faq_language (name)
|
||||
VALUES (?)',
|
||||
Bind => [ \$Param{Name} ],
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LanguageDelete()
|
||||
|
||||
Delete a language.
|
||||
|
||||
my $DeleteSuccess = $FAQObject->LanguageDelete(
|
||||
LanguageID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns
|
||||
|
||||
$DeleteSuccess = 1; # or undef if language could not be deleted
|
||||
|
||||
=cut
|
||||
|
||||
sub LanguageDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Attribute (qw(LanguageID UserID)) {
|
||||
if ( !$Param{$Attribute} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Attribute!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# delete the language
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
DELETE FROM faq_language
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{LanguageID} ],
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LanguageDuplicateCheck()
|
||||
|
||||
check a language
|
||||
|
||||
my $Exists = $FAQObject->LanguageDuplicateCheck(
|
||||
Name => 'Some Name',
|
||||
LanguageID => 1, # for update
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Exists = 1; # if language already exists, or 0 if does not exist
|
||||
|
||||
=cut
|
||||
|
||||
sub LanguageDuplicateCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# build SQL
|
||||
my @Bind = ( \$Param{Name} );
|
||||
my $SQL = '
|
||||
SELECT id
|
||||
FROM faq_language
|
||||
WHERE name = ?';
|
||||
if ( defined $Param{LanguageID} ) {
|
||||
push @Bind, \$Param{LanguageID};
|
||||
$SQL .= " AND id != ?";
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# prepare SQL statement
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => $SQL,
|
||||
Limit => 1,
|
||||
Bind => \@Bind,
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my $Exists;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$Exists = 1;
|
||||
}
|
||||
|
||||
return $Exists;
|
||||
}
|
||||
|
||||
=head2 LanguageGet()
|
||||
|
||||
get a language details as a hash
|
||||
|
||||
my %Language = $FAQObject->LanguageGet(
|
||||
LanguageID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
%Language = (
|
||||
LanguageID => '1',
|
||||
Name => 'en',
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LanguageGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(LanguageID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# SQL
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, name
|
||||
FROM faq_language
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{LanguageID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
%Data = (
|
||||
LanguageID => $Row[0],
|
||||
Name => $Row[1],
|
||||
);
|
||||
}
|
||||
|
||||
return %Data;
|
||||
}
|
||||
|
||||
=head2 LanguageList()
|
||||
|
||||
get the language list as a hash
|
||||
|
||||
my %Languages = $FAQObject->LanguageList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
%Languages = (
|
||||
1 => 'en',
|
||||
2 => 'de',
|
||||
3 => 'es',
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LanguageList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# build SQL
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, name
|
||||
FROM faq_language',
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %List;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$List{ $Row[0] } = $Row[1];
|
||||
}
|
||||
|
||||
return %List;
|
||||
}
|
||||
|
||||
=head2 LanguageLookup()
|
||||
|
||||
This method does a lookup for a FAQ language.
|
||||
If a language id is given, it returns the name of the language.
|
||||
If the name of the language is given, the language id is returned.
|
||||
|
||||
my $LanguageName = $FAQObject->LanguageLookup(
|
||||
LanguageID => 1,
|
||||
);
|
||||
|
||||
my $LanguageID = $FAQObject->LanguageLookup(
|
||||
Name => 'en',
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$LanguageName = 'en';
|
||||
|
||||
$LanguageID = 1;
|
||||
|
||||
=cut
|
||||
|
||||
sub LanguageLookup {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check if both parameters are given
|
||||
if ( $Param{LanguageID} && $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need LanguageID or Name - not both!',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# check if both parameters are not given
|
||||
if ( !$Param{LanguageID} && !$Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need LanguageID or Name - none is given!',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# check if LanguageID is a number
|
||||
if ( $Param{LanguageID} && $Param{LanguageID} !~ m{ \A \d+ \z }xms ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "LanguageID must be a number! (LanguageID: $Param{LanguageID})",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# prepare SQL statements
|
||||
if ( $Param{LanguageID} ) {
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT name
|
||||
FROM faq_language
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{LanguageID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
elsif ( $Param{Name} ) {
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id
|
||||
FROM faq_language
|
||||
WHERE name = ?',
|
||||
Bind => [ \$Param{Name} ],
|
||||
Limit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
# fetch the result
|
||||
my $Lookup;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$Lookup = $Row[0];
|
||||
}
|
||||
|
||||
return $Lookup;
|
||||
}
|
||||
|
||||
=head2 LanguageUpdate()
|
||||
|
||||
update a language
|
||||
|
||||
my $Success = $FAQObject->LanguageUpdate(
|
||||
LanguageID => 1,
|
||||
Name => 'de',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success = 1; # or undef if language could not be updated
|
||||
|
||||
=cut
|
||||
|
||||
sub LanguageUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(LanguageID Name UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# build SQL
|
||||
return if !$DBObject->Do(
|
||||
SQL => '
|
||||
UPDATE faq_language
|
||||
SET name = ?
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{Name}, \$Param{LanguageID} ],
|
||||
);
|
||||
|
||||
# delete all cache, as FAQGet() will be also affected.
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
|
||||
Type => 'FAQ',
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
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
|
||||
413
Perl OTRS/Kernel/System/FAQ/RelatedArticle.pm
Normal file
413
Perl OTRS/Kernel/System/FAQ/RelatedArticle.pm
Normal file
@@ -0,0 +1,413 @@
|
||||
# --
|
||||
# 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::System::FAQ::RelatedArticle;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::HTMLUtils',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::FAQ::RelatedArticle - sub module of Kernel::System::FAQ
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All related faq article functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 RelatedAgentArticleList()
|
||||
|
||||
Get the related faq article list for the given subject and body.
|
||||
|
||||
my @RelatedAgentArticleList = $FAQObject->RelatedAgentArticleList(
|
||||
Subject => 'Title Example',
|
||||
Body => 'Text Example', # possible with html tags (will be removed for the search)
|
||||
Languages =>[ 'en' ], # optional
|
||||
Limit => 10, # optional
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns
|
||||
|
||||
my @RelatedAgentArticleList = (
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub RelatedAgentArticleList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return $Self->_RelatedArticleList(%Param);
|
||||
}
|
||||
|
||||
=head2 RelatedCustomerArticleList()
|
||||
|
||||
Get the related faq article list for the given subject and body.
|
||||
|
||||
my @RelatedCustomerArticleList = $FAQObject->RelatedCustomerArticleList(
|
||||
Subject => 'Title Example',
|
||||
Body => 'Text Example', # possible with html tags (will be removed for the search)
|
||||
Languages =>[ 'en' ], # optional
|
||||
Limit => 10, # optional
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns
|
||||
|
||||
my @RelatedCustomerArticleList = (
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub RelatedCustomerArticleList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return $Self->_RelatedArticleList(
|
||||
%Param,
|
||||
CustomerUser => $Param{UserID},
|
||||
UserID => 1,
|
||||
);
|
||||
}
|
||||
|
||||
=head1 PRIVATE FUNCTIONS
|
||||
|
||||
=head2 _RelatedArticleList()
|
||||
|
||||
Get the related faq article list for the given subject and body.
|
||||
|
||||
my @RelatedArticleList = $FAQObject->_RelatedArticleList(
|
||||
Subject => 'Title Example',
|
||||
Body => 'Text Example', # possible with html tags (will be removed for the search)
|
||||
Languages =>[ 'en' ], # optional
|
||||
Limit => 10, # optional
|
||||
CustomerUser => 'joe' # optional
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns
|
||||
|
||||
my @RelatedArticleList = (
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _RelatedArticleList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my @Content;
|
||||
|
||||
FIELD:
|
||||
for my $Field (qw(Subject Body)) {
|
||||
|
||||
# Get ASCII content form the given body, to have no html tags for the check.
|
||||
if ( $Field eq 'Body' ) {
|
||||
$Param{$Field} = $Kernel::OM->Get('Kernel::System::HTMLUtils')->ToAscii(
|
||||
String => $Param{$Field},
|
||||
);
|
||||
}
|
||||
|
||||
next FIELD if !$Param{$Field};
|
||||
|
||||
push @Content, $Param{$Field};
|
||||
}
|
||||
|
||||
return if !@Content;
|
||||
|
||||
# To save the keywords and the counter for the different keywords.
|
||||
my %ContentKeywords = $Self->_BuildKeywordCounterFromContent(
|
||||
Content => \@Content
|
||||
);
|
||||
|
||||
return if !%ContentKeywords;
|
||||
|
||||
# Get the keyword article list for the given languages.
|
||||
my %FAQKeywordArticleList = $Self->FAQKeywordArticleList(%Param);
|
||||
|
||||
return if !%FAQKeywordArticleList;
|
||||
|
||||
return $Self->_BuildRelatedFAQArticleList(
|
||||
ContentKeywords => \%ContentKeywords,
|
||||
KeywordArticleList => \%FAQKeywordArticleList,
|
||||
Limit => $Param{Limit},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
=head2 _BuildRelatedFAQArticleList()
|
||||
|
||||
Build the related faq article list from the given content keywords and article keyword relation.
|
||||
|
||||
my @RelatedArticleList = $FAQObject->_BuildRelatedFAQArticleList(
|
||||
ContentKeywords => {
|
||||
example => 1,
|
||||
test => 3,
|
||||
faq => 6,
|
||||
},
|
||||
KeywordArticleList => {
|
||||
'ExampleKeyword' => [
|
||||
12,
|
||||
13,
|
||||
],
|
||||
'TestKeyword' => [
|
||||
876,
|
||||
],
|
||||
},
|
||||
Limit => 10, # optional
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns
|
||||
|
||||
my @RelatedArticleList = (
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
{
|
||||
ItemID => 123,
|
||||
Title => 'FAQ Title',
|
||||
CategoryName => 'Misc',
|
||||
Created => '2014-10-10 10:10:00',
|
||||
},
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _BuildRelatedFAQArticleList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return if !IsHashRefWithData( $Param{ContentKeywords} );
|
||||
return if !IsHashRefWithData( $Param{KeywordArticleList} );
|
||||
|
||||
# Save given parameters in own variables for better usage.
|
||||
my %ContentKeywords = %{ $Param{ContentKeywords} };
|
||||
my %KeywordArticleList = %{ $Param{KeywordArticleList} };
|
||||
|
||||
# Build the related faq articles and save a quantifier for the different articles with the relevance
|
||||
# from the keyword, which is related to the faq article.
|
||||
# E.g.
|
||||
# - FAQArticle 1 with keywords: 'itsm', 'changemanagement', 'ticket'
|
||||
# - FAQArticle 2 with keywords: 'itsm', 'changemangement'
|
||||
# - FAQArticle 3 with keywords: 'ticket'
|
||||
# Given Keyword from text (with counter):
|
||||
# - changemanagement (5)
|
||||
# - ticket (4)
|
||||
# - itsm (1)
|
||||
# Result (FAQArticleID => Calculated Quantifier):
|
||||
# - FAQArticle 1 => 11
|
||||
# - FAQArticle 2 => 6
|
||||
# - FAQArticle 3 => 4
|
||||
my %LookupRelatedFAQArticles;
|
||||
|
||||
CONTENTKEYWORD:
|
||||
for my $ContentKeyword ( sort keys %ContentKeywords ) {
|
||||
|
||||
next CONTENTKEYWORD if !IsArrayRefWithData( $KeywordArticleList{$ContentKeyword} );
|
||||
|
||||
FAQARTICLEID:
|
||||
for my $FAQArticleID ( @{ $KeywordArticleList{$ContentKeyword} } ) {
|
||||
|
||||
if ( !$LookupRelatedFAQArticles{$FAQArticleID} ) {
|
||||
|
||||
my %FAQArticleData = $Self->FAQGet(
|
||||
ItemID => $FAQArticleID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( $FAQArticleData{Votes} ) {
|
||||
$FAQArticleData{StarCounter} = int( $FAQArticleData{VoteResult} * 0.05 );
|
||||
|
||||
# Add 1 because lowest value should be always 1.
|
||||
if ( $FAQArticleData{StarCounter} < 5 ) {
|
||||
$FAQArticleData{StarCounter}++;
|
||||
}
|
||||
}
|
||||
|
||||
# Add the FAQ article data to the related FAQ articles.
|
||||
$LookupRelatedFAQArticles{$FAQArticleID} = {
|
||||
%FAQArticleData,
|
||||
KeywordCounter => $ContentKeywords{$ContentKeyword},
|
||||
};
|
||||
}
|
||||
else {
|
||||
|
||||
# Increase the quantifier, if the article has more then one relevant keyword.
|
||||
$LookupRelatedFAQArticles{$FAQArticleID}->{KeywordCounter} += $ContentKeywords{$ContentKeyword};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# To save the related faq article from the lookup hash.
|
||||
my @RelatedFAQArticleList = map { $LookupRelatedFAQArticles{$_} } sort keys %LookupRelatedFAQArticles;
|
||||
|
||||
# Sort the results from the plug-ins by 'keyword quantifier', 'change time' and 'id (create time)'.
|
||||
@RelatedFAQArticleList = sort {
|
||||
$b->{KeywordCounter} <=> $a->{KeywordCounter}
|
||||
|| $b->{Changed} cmp $a->{Changed}
|
||||
|| int $b->{ID} <=> int $a->{ID}
|
||||
} @RelatedFAQArticleList;
|
||||
|
||||
# Cut the not needed articles from the array, if a limit is given.
|
||||
if ( $Param{Limit} && scalar @RelatedFAQArticleList > $Param{Limit} ) {
|
||||
splice @RelatedFAQArticleList, $Param{Limit};
|
||||
}
|
||||
|
||||
return @RelatedFAQArticleList;
|
||||
}
|
||||
|
||||
=head2 _BuildKeywordCounterFromContent()
|
||||
|
||||
Build the keywords for the given content.
|
||||
|
||||
my $Content = $FAQObject->_BuildKeywordCounterFromContent(
|
||||
Content => 'Some Text with a link. More text. [1] https://otrs.com/',
|
||||
);
|
||||
|
||||
Returns
|
||||
|
||||
%ContentKeywords = (
|
||||
example => 1,
|
||||
test => 3,
|
||||
faq => 6,
|
||||
...
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub _BuildKeywordCounterFromContent {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return if !IsArrayRefWithData( $Param{Content} );
|
||||
|
||||
my %ContentKeywords;
|
||||
|
||||
# Strip not wanted stuff from the given subject and body.
|
||||
for my $Content ( @{ $Param{Content} } ) {
|
||||
|
||||
$Content ||= '';
|
||||
|
||||
# Remove the links from the content.
|
||||
$Content = $Self->_RemoveLinksFromContent(
|
||||
Content => $Content,
|
||||
);
|
||||
|
||||
# Split the text in word and save the word as the given keywords (separator is a whitespace).
|
||||
$Content =~ s{[\.\,\;\:](\s|\s? \Z )}{ }xmsg;
|
||||
my @FieldKeywords = ( $Content =~ m{ [\w\x{0980}-\x{09FF}\-]+\.?[\w\x{0980}-\x{09FF}\-]* }xmsg );
|
||||
|
||||
KEYWORD:
|
||||
for my $Keyword (@FieldKeywords) {
|
||||
|
||||
# Save the keywords always as lower case.
|
||||
$Keyword = lc $Keyword;
|
||||
|
||||
# Increase the keyword counter from the text content, to increase the relevance for this keyword.
|
||||
$ContentKeywords{$Keyword}++;
|
||||
}
|
||||
}
|
||||
|
||||
return %ContentKeywords;
|
||||
}
|
||||
|
||||
=head2 _RemoveLinksFromContent()
|
||||
|
||||
Remove links from the given content.
|
||||
|
||||
my $Content = $FAQObject->_RemoveLinksFromContent(
|
||||
Content => 'Some Text with a link. More text. [1] https://otrs.com/',
|
||||
);
|
||||
|
||||
Returns
|
||||
|
||||
$Content = 'Some Text with a link. More text.';
|
||||
|
||||
=cut
|
||||
|
||||
sub _RemoveLinksFromContent {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Param{Content} =~ s{ \[\d*\] }{}xmsg;
|
||||
$Param{Content} =~ s{ https://[^\s]* }{}xmsg;
|
||||
|
||||
return $Param{Content};
|
||||
}
|
||||
|
||||
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
|
||||
421
Perl OTRS/Kernel/System/FAQ/State.pm
Normal file
421
Perl OTRS/Kernel/System/FAQ/State.pm
Normal file
@@ -0,0 +1,421 @@
|
||||
# --
|
||||
# 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::System::FAQ::State;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::FAQ::State - sub module of Kernel::System::FAQ
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All FAQ state functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 StateAdd()
|
||||
|
||||
add a state
|
||||
|
||||
my $Success = $FAQObject->StateAdd(
|
||||
Name => 'public',
|
||||
TypeID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success = 1; # or undef if state could not be added
|
||||
|
||||
=cut
|
||||
|
||||
sub StateAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Name TypeID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
INSERT INTO faq_state (name, type_id)
|
||||
VALUES ( ?, ? )',
|
||||
Bind => [ \$Param{Name}, \$Param{TypeID} ],
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 StateGet()
|
||||
|
||||
get a state as hash
|
||||
|
||||
my %State = $FAQObject->StateGet(
|
||||
StateID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
%State = (
|
||||
StateID => 1,
|
||||
Name => 'internal (agent)',
|
||||
TypeID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub StateGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(StateID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# SQL
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id, name, type_id
|
||||
FROM faq_state
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{StateID} ],
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
%Data = (
|
||||
StateID => $Row[0],
|
||||
Name => $Row[1],
|
||||
TypeID => $Row[2],
|
||||
);
|
||||
}
|
||||
|
||||
return %Data;
|
||||
}
|
||||
|
||||
=head2 StateList()
|
||||
|
||||
get the state list as hash
|
||||
|
||||
my %States = $FAQObject->StateList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
optional, get state list for some state types:
|
||||
|
||||
my $StateTypeHashRef = $FAQObject->StateTypeList(
|
||||
Types => [ 'public', 'internal'],
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
%States = (
|
||||
1 => 'internal (agent)',
|
||||
2 => 'external (customer)',
|
||||
3 => 'public (all)',
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub StateList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
my $SQL = '
|
||||
SELECT id, name
|
||||
FROM faq_state';
|
||||
|
||||
# Filter state list by type id if available.
|
||||
if ( IsArrayRefWithData( $Param{Types} ) ) {
|
||||
my $StateTypeHashRef = $Self->StateTypeList(
|
||||
Types => $Param{Types},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
if ( IsHashRefWithData($StateTypeHashRef) ) {
|
||||
$SQL .= ' WHERE type_id IN ( ' . join( ', ', sort keys %{$StateTypeHashRef} ) . ' )';
|
||||
}
|
||||
}
|
||||
|
||||
return if !$DBObject->Prepare( SQL => $SQL );
|
||||
|
||||
my %List;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$List{ $Row[0] } = $Row[1];
|
||||
}
|
||||
|
||||
return %List;
|
||||
}
|
||||
|
||||
=head2 StateUpdate()
|
||||
|
||||
update a state
|
||||
|
||||
my Success = $FAQObject->StateUpdate(
|
||||
StateID => 1,
|
||||
Name => 'public',
|
||||
TypeID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
Success = 1; # or undef if state could not be updated
|
||||
|
||||
=cut
|
||||
|
||||
sub StateUpdate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(StateID Name TypeID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# SQL
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
UPDATE faq_state
|
||||
SET name = ?, type_id = ?,
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{Name}, \$Param{TypeID}, \$Param{StateID} ],
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 StateTypeGet()
|
||||
|
||||
get a state as hash reference
|
||||
|
||||
my $StateTypeHashRef = $FAQObject->StateTypeGet(
|
||||
StateID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Or
|
||||
|
||||
my $StateTypeHashRef = $FAQObject->StateTypeGet(
|
||||
Name => 'internal',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$StateTypeHashRef = {
|
||||
'StateID' => 1,
|
||||
'Name' => 'internal',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub StateTypeGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need UserID!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my $SQL = '
|
||||
SELECT id, name
|
||||
FROM faq_state_type
|
||||
WHERE';
|
||||
my @Bind;
|
||||
my $CacheKey = 'StateTypeGet::';
|
||||
if ( defined $Param{StateID} ) {
|
||||
$SQL .= ' id = ?';
|
||||
push @Bind, \$Param{StateID};
|
||||
$CacheKey .= 'ID::' . $Param{StateID};
|
||||
}
|
||||
elsif ( defined $Param{Name} ) {
|
||||
$SQL .= ' name = ?';
|
||||
push @Bind, \$Param{Name};
|
||||
$CacheKey .= 'Name::' . $Param{Name};
|
||||
}
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'FAQ',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
|
||||
return $Cache if $Cache;
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# SQL
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => $SQL,
|
||||
Bind => \@Bind,
|
||||
);
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
%Data = (
|
||||
StateID => $Row[0],
|
||||
Name => $Row[1],
|
||||
);
|
||||
}
|
||||
|
||||
# cache result
|
||||
$CacheObject->Set(
|
||||
Type => 'FAQ',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => 60 * 60 * 24 * 2,
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 StateTypeList()
|
||||
|
||||
get the state type list as hash reference
|
||||
|
||||
my $StateTypeHashRef = $FAQObject->StateTypeList(
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
optional, get state type list for some states:
|
||||
|
||||
my $StateTypeHashRef = $FAQObject->StateTypeList(
|
||||
Types => [ 'public', 'internal'],
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$StateTypeHashRef = {
|
||||
1 => 'internal',
|
||||
3 => 'public',
|
||||
2 => 'external',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub StateTypeList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# build SQL
|
||||
my $SQL = '
|
||||
SELECT id, name
|
||||
FROM faq_state_type';
|
||||
|
||||
# types are given
|
||||
if ( $Param{Types} ) {
|
||||
|
||||
if ( ref $Param{Types} ne 'ARRAY' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Types should be an array reference!',
|
||||
);
|
||||
}
|
||||
|
||||
# call StateTypeList without parameters to validate Types
|
||||
my $StateTypeList = $Self->StateTypeList( UserID => $Param{UserID} );
|
||||
my %StateTypes = reverse %{ $StateTypeList || {} };
|
||||
my @Types;
|
||||
|
||||
# only add types to list that exist
|
||||
TYPE:
|
||||
for my $Type ( @{ $Param{Types} } ) {
|
||||
next TYPE if !$StateTypes{$Type};
|
||||
push @Types, "'$Type'";
|
||||
}
|
||||
|
||||
# create string
|
||||
if (@Types) {
|
||||
$SQL .= ' WHERE name IN ( ' . join( ', ', @Types ) . ' )';
|
||||
}
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# prepare SQL
|
||||
return if !$DBObject->Prepare( SQL => $SQL );
|
||||
|
||||
# fetch the result
|
||||
my %List;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$List{ $Row[0] } = $Row[1];
|
||||
}
|
||||
|
||||
return \%List;
|
||||
}
|
||||
|
||||
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
|
||||
345
Perl OTRS/Kernel/System/FAQ/Vote.pm
Normal file
345
Perl OTRS/Kernel/System/FAQ/Vote.pm
Normal file
@@ -0,0 +1,345 @@
|
||||
# --
|
||||
# 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::System::FAQ::Vote;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Cache',
|
||||
'Kernel::System::DB',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::FAQ::Vote - sub module of Kernel::System::FAQ
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
All FAQ vote functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 VoteAdd()
|
||||
|
||||
add a vote
|
||||
|
||||
my $Success = $FAQObject->VoteAdd(
|
||||
CreatedBy => 'Some Text',
|
||||
ItemID => '123456',
|
||||
IP => '54.43.30.1',
|
||||
Interface => 'Some Text',
|
||||
Rate => 100,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success = 1; # or undef if vote could not be added
|
||||
|
||||
=cut
|
||||
|
||||
sub VoteAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(CreatedBy ItemID IP Interface UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
INSERT INTO faq_voting (created_by, item_id, ip, interface, rate, created )
|
||||
VALUES ( ?, ?, ?, ?, ?, current_timestamp )',
|
||||
Bind => [
|
||||
\$Param{CreatedBy}, \$Param{ItemID}, \$Param{IP}, \$Param{Interface},
|
||||
\$Param{Rate},
|
||||
],
|
||||
);
|
||||
|
||||
# delete cache
|
||||
my $CacheKey = 'ItemVoteDataGet::' . $Param{ItemID};
|
||||
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
|
||||
Type => 'FAQ',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 VoteDelete()
|
||||
|
||||
delete a vote
|
||||
|
||||
my $DeleteSuccess = $FAQObject->VoteDelete(
|
||||
VoteID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$DeleteSuccess = 1; # or undef if vote could not be deleted
|
||||
|
||||
=cut
|
||||
|
||||
sub VoteDelete {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(VoteID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
|
||||
SQL => '
|
||||
DELETE FROM faq_voting
|
||||
WHERE id = ?',
|
||||
Bind => [ \$Param{VoteID} ],
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 VoteGet()
|
||||
|
||||
get a vote information
|
||||
|
||||
my %VoteData = $FAQObject->VoteGet(
|
||||
CreateBy => 'Some Text',
|
||||
ItemID => '123456',
|
||||
IP => '127.0.0.1',
|
||||
Interface => 'Some Text',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
%VoteData = (
|
||||
ItemID => 23,
|
||||
Rate => 50, # or 0 or 25 or 75 or 100
|
||||
IP => '192.168.0.1',
|
||||
Interface => 1, # interface ID
|
||||
CreatedBy => 1,
|
||||
Created => '2011-06-14 12:32:03',
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub VoteGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(CreateBy ItemID Interface IP UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my @Values;
|
||||
my $SQL = '
|
||||
SELECT created_by, item_id, interface, ip, created, rate
|
||||
FROM faq_voting
|
||||
WHERE';
|
||||
|
||||
# public
|
||||
if ( $Param{Interface} eq '3' ) {
|
||||
$SQL .= '
|
||||
ip = ?
|
||||
AND item_id = ?';
|
||||
push @Values, ( \$Param{IP}, \$Param{ItemID} );
|
||||
}
|
||||
|
||||
# customer
|
||||
elsif ( $Param{Interface} eq '2' || $Param{Interface} eq '1' ) {
|
||||
$SQL .= '
|
||||
created_by = ?
|
||||
AND item_id = ?';
|
||||
push @Values, ( \$Param{CreateBy}, \$Param{ItemID} );
|
||||
}
|
||||
|
||||
# leave a space between AND condition and ORDER BY statement
|
||||
$SQL .= '
|
||||
ORDER BY created DESC';
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => $SQL,
|
||||
Bind => \@Values,
|
||||
Limit => 1,
|
||||
);
|
||||
|
||||
my %Data;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
%Data = (
|
||||
CreatedBy => $Row[0],
|
||||
ItemID => $Row[1],
|
||||
Interface => $Row[2],
|
||||
IP => $Row[3],
|
||||
Created => $Row[4],
|
||||
Rate => $Row[5],
|
||||
);
|
||||
}
|
||||
|
||||
return if !%Data;
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
=head2 VoteSearch()
|
||||
|
||||
returns an array with VoteIDs
|
||||
|
||||
my $VoteIDArrayref = $FAQObject->VoteSearch(
|
||||
ItemID => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$VoteIDArrayref = [
|
||||
23,
|
||||
45,
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub VoteSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(ItemID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT id
|
||||
FROM faq_voting
|
||||
WHERE item_id = ?',
|
||||
Bind => [ \$Param{ItemID} ],
|
||||
Limit => $Param{Limit} || 500,
|
||||
);
|
||||
|
||||
my @VoteIDs;
|
||||
while ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
push @VoteIDs, $Row[0];
|
||||
}
|
||||
|
||||
return \@VoteIDs;
|
||||
}
|
||||
|
||||
=head2 ItemVoteDataGet()
|
||||
|
||||
Returns a hash reference with the number of votes and the vote result.
|
||||
|
||||
my $VoteDataHashRef = $FAQObject->ItemVoteDataGet(
|
||||
ItemID => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$VoteDataHashRef = {
|
||||
Result => 75.0000,
|
||||
Votes => 5
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ItemVoteDataGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(ItemID UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
|
||||
|
||||
# check cache
|
||||
my $CacheKey = 'ItemVoteDataGet::' . $Param{ItemID};
|
||||
my $Cache = $CacheObject->Get(
|
||||
Type => 'FAQ',
|
||||
Key => $CacheKey,
|
||||
);
|
||||
|
||||
return $Cache if $Cache;
|
||||
|
||||
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
|
||||
|
||||
# get vote from db
|
||||
return if !$DBObject->Prepare(
|
||||
SQL => '
|
||||
SELECT count(*), avg(rate)
|
||||
FROM faq_voting
|
||||
WHERE item_id = ?',
|
||||
Bind => [ \$Param{ItemID} ],
|
||||
Limit => $Param{Limit} || 500,
|
||||
);
|
||||
|
||||
# fetch the result
|
||||
my %Data;
|
||||
if ( my @Row = $DBObject->FetchrowArray() ) {
|
||||
$Data{Votes} = $Row[0];
|
||||
$Data{Result} = $Row[1];
|
||||
}
|
||||
|
||||
# cache result
|
||||
$CacheObject->Set(
|
||||
Type => 'FAQ',
|
||||
Key => $CacheKey,
|
||||
Value => \%Data,
|
||||
TTL => 60 * 60 * 24 * 2,
|
||||
);
|
||||
|
||||
return \%Data;
|
||||
}
|
||||
|
||||
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