[otrs-cvs] FAQ/Kernel/System FAQ.pm,1.169,1.170
"CVS commits notifications of OTRS.org" <[email protected]> Sun, 30 Jun 2013 01:03:59 +0000
| Newsgroups | gmane.comp.otrs.cvs |
|---|---|
| Message-ID | <[email protected]> |
Comments:
Update of /home/cvs/FAQ/Kernel/System
In directory lancelot:/tmp/cvs-serv16865/Kernel/System
Modified Files:
FAQ.pm
Log Message:
Moved all vote functions to a separated file.
Author: cr
Index: FAQ.pm
===================================================================
RCS file: /home/cvs/FAQ/Kernel/System/FAQ.pm,v
retrieving revision 1.169
retrieving revision 1.170
diff -2 -u -d -r1.169 -r1.170
--- FAQ.pm 30 Jun 2013 00:34:36 -0000 1.169
+++ FAQ.pm 30 Jun 2013 01:03:54 -0000 1.170
@@ -26,5 +26,5 @@
use base
- qw( Kernel::System::FAQ::Language Kernel::System::FAQ::Category Kernel::System::FAQ::State );
+ qw( Kernel::System::FAQ::Language Kernel::System::FAQ::Category Kernel::System::FAQ::State Kernel::System::FAQ::Vote );
use vars qw($VERSION);
@@ -466,69 +466,4 @@
}
-=item 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 ) = @_;
-
- # check needed stuff
- for my $Argument (qw(ItemID UserID)) {
- if ( !$Param{$Argument} ) {
- $Self->{LogObject}->Log(
- Priority => 'error',
- Message => "Need $Argument!",
- );
- return;
- }
- }
-
- # check cache
- my $CacheKey = 'ItemVoteDataGet::' . $Param{ItemID};
- my $Cache = $Self->{CacheObject}->Get(
- Type => 'FAQ',
- Key => $CacheKey,
- );
- return $Cache if $Cache;
-
- # get vote from db
- return if !$Self->{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 = $Self->{DBObject}->FetchrowArray() ) {
- $Data{Votes} = $Row[0];
- $Data{Result} = $Row[1];
- }
-
- # cache result
- $Self->{CacheObject}->Set(
- Type => 'FAQ',
- Key => $CacheKey,
- Value => \%Data,
- TTL => 60 * 60 * 24 * 2,
- );
-
- return \%Data;
-}
-
=item FAQAdd()
@@ -1266,224 +1201,4 @@
}
-=item 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 ) = @_;
-
- # check needed stuff
- for my $Argument (qw(CreatedBy ItemID IP Interface UserID)) {
- if ( !$Param{$Argument} ) {
- $Self->{LogObject}->Log(
- Priority => 'error',
- Message => "Need $Argument!",
- );
- return;
- }
- }
-
- return if !$Self->{DBObject}->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};
- $Self->{CacheObject}->Delete(
- Type => 'FAQ',
- Key => $CacheKey,
- );
-
- return 1;
-}
-
-=item 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 ) = @_;
-
- # check needed stuff
- for my $Argument (qw(CreateBy ItemID Interface IP UserID)) {
- if ( !$Param{$Argument} ) {
- $Self->{LogObject}->Log(
- Priority => 'error',
- Message => "Need $Argument!",
- );
- return;
- }
- }
-
- # db quote
- for my $Argument (qw(CreatedBy Interface IP)) {
- $Param{$Argument} = $Self->{DBObject}->Quote( $Param{$Argument} );
- }
- $Param{ItemID} = $Self->{DBObject}->Quote( $Param{ItemID}, 'Integer' );
-
- my $Ext = "";
- my $SQL = " SELECT created_by, item_id, interface, ip, created, rate FROM faq_voting WHERE";
-
- # public
- if ( $Param{Interface} eq '3' ) {
- $Ext .= " ip = '$Param{IP}' AND item_id = $Param{ItemID}";
- }
-
- # customer
- elsif ( $Param{Interface} eq '2' ) {
- $Ext .= " created_by = '$Param{CreateBy}' AND item_id = $Param{ItemID}";
- }
-
- # internal
- elsif ( $Param{Interface} eq '1' ) {
- $Ext .= " created_by = '$Param{CreateBy}' AND item_id = $Param{ItemID}";
- }
- $SQL .= $Ext;
-
- return if !$Self->{DBObject}->Prepare(
- SQL => $SQL,
- Limit => 1,
- );
-
- my %Data;
- while ( my @Row = $Self->{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;
-}
-
-=item VoteSearch()
-
-returns an array with VoteIDs
-
- my $VoteIDArrayref = $FAQObject->VoteSearch(
- ItemID => 1,
- UserID => 1,
- );
-
-Returns:
-
- $VoteIDArrayref = [
- 23,
- 45,
- ];
-
-=cut
-
-sub VoteSearch {
- my ( $Self, %Param ) = @_;
-
- # check needed stuff
- for my $Argument (qw(ItemID UserID)) {
- if ( !$Param{$Argument} ) {
- $Self->{LogObject}->Log(
- Priority => 'error',
- Message => "Need $Argument!",
- );
- return;
- }
- }
-
- return if !$Self->{DBObject}->Prepare(
- SQL => 'SELECT id FROM faq_voting WHERE item_id = ?',
- Bind => [ \$Param{ItemID} ],
- Limit => $Param{Limit} || 500,
- );
-
- my @VoteIDs;
- while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
- push @VoteIDs, $Row[0];
- }
-
- return \@VoteIDs;
-}
-
-=item 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 ) = @_;
-
- # check needed stuff
- for my $Argument (qw(VoteID UserID)) {
- if ( !$Param{$Argument} ) {
- $Self->{LogObject}->Log(
- Priority => 'error',
- Message => "Need $Argument!",
- );
- return;
- }
- }
-
- return if !$Self->{DBObject}->Do(
- SQL => 'DELETE FROM faq_voting WHERE id = ?',
- Bind => [ \$Param{VoteID} ],
- );
-
- return 1;
-}
-
=item FAQDelete()
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log