Added some other keys in the configuration file. Now
[breadcrumbs.git] / src / lib / Bcd / Data / FoundersTrusts.pm
blob53fd324a56fea1f9cc03d83c8932c851ab4649bd
1 package Bcd::Data::FoundersTrusts;
3 # This file is part of the breadcrumbs daemon (bcd).
4 # Copyright (C) 2007 Pasqualino Ferrentino
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # Contact: lino.ferrentino@yahoo.it (in Italian, English or German).
23 #this module is responsible to create the new ant nests in the system
25 use strict;
26 use warnings;
27 use Data::Dumper;
29 use constant{
31 SELECT_DIRECT_FOUNDER_TRUST_FIRST =>
32 qq{select trust_u1_u2 as trust FROM ant_nests_founders_trusts WHERE u1 = ? AND u2 = ?},
34 UPDATE_SECOND_FOUNDER_TRUST =>
35 qq{UPDATE ant_nests_founders_trusts SET trust_u2_u1 = ? WHERE u1 = ? AND u2 = ?},
37 INSERT_FIRST_FOUNDER_TRUST =>
38 qq{INSERT INTO ant_nests_founders_trusts(u1,u2,trust_u1_u2) VALUES(?,?,?)},
40 SELECT_ALL_TRUSTS_USER =>
41 qq{SELECT * FROM ant_nests_founders_trusts WHERE u1 = ?},
46 sub get_all_trusts_for_this_user_arr{
47 my ($class, $stash, $user) = @_;
49 my $st = $stash->prepare_cached(SELECT_ALL_TRUSTS_USER);
50 $st->bind_param(1, $user);
51 $st->execute();
53 return $st->fetchall_arrayref();
56 #ok, the main function is the function that adds a trust.
57 sub add_founder_trust{
58 my ($class, $stash, $user1, $user2, $trust_1_2) = @_;
60 #first of all I see if there is a direct trust between 2 and 1.
61 my $st = $stash->prepare_cached(SELECT_DIRECT_FOUNDER_TRUST_FIRST);
62 $st->bind_param(1, $user2);
63 $st->bind_param(2, $user1);
65 $st->execute();
66 my $row = $st->fetchrow_arrayref();
67 $st->finish();
69 if (defined($row)){
70 #ok, I should simply update this row...
71 $st = $stash->prepare_cached(UPDATE_SECOND_FOUNDER_TRUST);
72 $st->bind_param(1, $trust_1_2);
73 $st->bind_param(2, $user2);
74 $st->bind_param(3, $user1);
75 $st->execute();
76 } else {
77 #there is not a row, I should insert a row with this user as the first
78 #in the relationship
79 $st = $stash->prepare_cached(INSERT_FIRST_FOUNDER_TRUST);
80 $st->bind_param(1, $user1);
81 $st->bind_param(2, $user2);
82 $st->bind_param(3, $trust_1_2);
83 $st->execute();
85 #ok, all done.