summaryrefslogtreecommitdiffstats
path: root/Kernel/System/DefaultTo.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/System/DefaultTo.pm')
-rw-r--r--Kernel/System/DefaultTo.pm321
1 files changed, 321 insertions, 0 deletions
diff --git a/Kernel/System/DefaultTo.pm b/Kernel/System/DefaultTo.pm
new file mode 100644
index 0000000..7a1257b
--- /dev/null
+++ b/Kernel/System/DefaultTo.pm
@@ -0,0 +1,321 @@
+# --
+# Kernel/System/DefaultTo.pm - core module
+# Copyright (C) 2015 Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
+# --
+# This software comes with ABSOLUTELY NO WARRANTY. For details, see
+# the enclosed file COPYING for license information (AGPL). If you
+# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
+# --
+
+package Kernel::System::DefaultTo;
+
+use strict;
+use warnings;
+
+our @ObjectDependencies = qw(
+ Kernel::System::DB
+ Kernel::System::Log
+ Kernel::System::StandardTemplate
+);
+
+sub new {
+ my ( $Type, %Param ) = @_;
+
+ # allocate new hash for object
+ my $Self = {};
+ $Self->{DBObject} = $Kernel::OM->Get('Kernel::System::DB');
+ $Self->{LogObject} = $Kernel::OM->Get('Kernel::System::Log');
+ $Self->{StandardTemplateObject} =
+ $Kernel::OM->Get('Kernel::System::StandardTemplate');
+ bless ($Self, $Type);
+
+ return $Self;
+}
+
+sub Add {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ for my $Needed (qw(Title RemoveDefault AddNew NewAddress)) {
+ if ( !$Param{$Needed} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => "Need $Needed!",
+ );
+ return;
+ }
+ }
+
+ # insert new DefaultTo
+ return if !$Self->{DBObject}->Do(
+ SQL => 'INSERT INTO default_to '
+ . '(title, remove_default, add_new, new_address) '
+ . 'VALUES (?, ?, ?, ?)',
+ Bind => [
+ \$Param{Title},
+ \$Param{RemoveDefault},
+ \$Param{AddNew},
+ \$Param{NewAddress},
+ ],
+ );
+
+ # get new id
+ return if !$Self->{DBObject}->Prepare(
+ SQL => 'SELECT MAX(id) FROM default_to WHERE title = ?',
+ Bind => [ \$Param{Title}, ],
+ Limit => 1,
+ );
+
+ my $ID;
+ while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
+ $ID = $Row[0];
+ }
+
+ # log notice
+ $Self->{LogObject}->Log(
+ Priority => 'notice',
+ Message => "DefaultTo '$ID' created successfully!",
+ );
+
+ return $ID;
+}
+
+sub Update {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ for my $Needed (qw(ID Title RemoveDefault AddNew NewAddress)) {
+ if ( !$Param{$Needed} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => "Need $Needed!",
+ );
+ return;
+ }
+ }
+
+ # insert new DefaultTo
+ return if !$Self->{DBObject}->Do(
+ SQL => 'UPDATE default_to SET title = ?, '
+ . 'remove_default = ?, add_new = ?, new_address = ? '
+ . 'WHERE id = ?',
+ Bind => [
+ \$Param{Title},
+ \$Param{RemoveDefault},
+ \$Param{AddNew},
+ \$Param{NewAddress},
+ \$Param{ID},
+ ],
+ );
+
+ return 1;
+}
+
+sub Get {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ if ( !$Param{ID} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => 'Need ID!',
+ );
+ return;
+ }
+
+ # get RrsponseChangeDefaultTO obejct
+ return if !$Self->{DBObject}->Prepare(
+ SQL => 'SELECT id, title, remove_default, add_new, new_address '
+ . 'FROM default_to WHERE id = ?',
+ Bind => [ \$Param{ID} ],
+ Limit => 1,
+ );
+
+ my %DefaultTo;
+ while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
+ %DefaultTo = (
+ ID => $Data[0],
+ Title => $Data[1],
+ RemoveDefault => $Data[2],
+ AddNew => $Data[3],
+ NewAddress => $Data[4],
+ );
+ }
+
+ # make sure we have a valid object
+ return unless %DefaultTo;
+
+ # get the assigned responses
+ return if !$Self->{DBObject}->Prepare(
+ SQL => 'SELECT id, response_id '
+ . 'FROM response_change_default_to_response '
+ . 'WHERE response_change_default_to_id = ?',
+ Bind => [ \$DefaultTo{ID} ],
+ );
+
+ while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
+ my $Response =
+ $Self->{StandardTemplateObject}->StandardTemplateLookup(
+ StandardTemplateID => $Data[1],
+ );
+
+ if ( $Response ) {
+ $DefaultTo{Responses}->{$Data[0]} = {
+ ID => $Data[1],
+ Name => $Response,
+ };
+ }
+ }
+
+ return %DefaultTo;
+}
+
+sub Delete {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ if ( !$Param{ID} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => 'Need ID!',
+ );
+ return;
+ }
+
+ # delete mapping
+ return if !$Self->{DBObject}->Do(
+ SQL => 'DELETE FROM default_to_response '
+ . 'WHERE default_to_id = ?',
+ Bind => [ \$Param{ID} ],
+ );
+
+ # delete entry
+ return $Self->{DBObject}->Do(
+ SQL => 'DELETE FROM default_to WHERE id = ?',
+ Bind => [ \$Param{ID} ],
+ );
+}
+
+sub List {
+ my ( $Self, %Param ) = @_;
+
+ $Self->{DBObject}->Prepare(
+ SQL => 'SELECT id, title FROM default_to',
+ );
+
+ my %DefaultTo;
+ while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
+ $DefaultTo{ $Data[0] } = $Data[1];
+ }
+
+ return %DefaultTo;
+}
+
+sub MappingAdd {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ for my $Needed (qw(TemplateID DefaultToID)) {
+ if ( !$Param{$Needed} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => "Need $Needed!",
+ );
+ return;
+ }
+ }
+
+ # insert new mapping
+ return if !$Self->{DBObject}->Do(
+ SQL => 'INSERT INTO default_to_response '
+ . '(template_id, default_to_id) VALUES (?, ?)',
+ Bind => [
+ \$Param{TemplateID},
+ \$Param{DefaultToID},
+ ],
+ );
+
+ # get new id
+ return if !$Self->{DBObject}->Prepare(
+ SQL => 'SELECT MAX(id) FROM default_to_response '
+ . 'WHERE template_id = ? AND default_to_id = ?',
+ Bind => [
+ \$Param{TemplateID},
+ \$Param{DefaultToID}, ],
+ Limit => 1,
+ );
+
+ my $ID;
+ while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
+ $ID = $Row[0];
+ }
+
+ # log notice
+ $Self->{LogObject}->Log(
+ Priority => 'notice',
+ Message => "DefaultTo mapping '$ID' "
+ . "created successfully!",
+ );
+
+ return $ID;
+}
+
+sub MappingDelete {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ if ( !$Param{ID} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => 'Need ID!',
+ );
+ return;
+ }
+
+ # delete mapping
+ return $Self->{DBObject}->Do(
+ SQL => 'DELETE FROM default_to_response '
+ . 'WHERE id = ?',
+ Bind => [ \$Param{ID} ],
+ );
+}
+
+sub MappingList {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ if ( !$Param{TemplateID} && !$Param{DefaultToID} ) {
+ $Self->{LogObject}->Log(
+ Priority => 'error',
+ Message => 'Got no TemplateID or DefaultToID!'
+ );
+ return;
+ }
+
+ # find mapped objects
+ if ( $Param{TemplateID} ) {
+ $Self->{DBObject}->Prepare(
+ SQL => 'SELECT id, default_to_id '
+ . 'FROM default_to_response '
+ . 'WHERE template_id = ?',
+ Bind => [ \$Param{TemplateID}, ],
+ );
+ }
+ else {
+ $Self->{DBObject}->Prepare(
+ SQL => 'SELECT id, template_id '
+ . 'FROM default_to_response '
+ . 'WHERE default_to_id = ?',
+ Bind => [ \$Param{DefaultToID}, ],
+ );
+ }
+
+ my %Mapping;
+ while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
+ $Mapping{ $Data[0] } = $Data[1];
+ }
+
+ return %Mapping;
+}
+
+1;