load data from usernet table or create a default instance
[brisk.git] / web / Obj / dbase_base.phh
1 <?php
2   /*
3    *  brisk - dbase_base.phh
4    *
5    *  Copyright (C) 2011-2012 Matteo Nastasi
6    *                          mailto: nastasi@alternativeoutput.it
7    *                                  matteo.nastasi@milug.org
8    *                          web: http://www.alternativeoutput.it
9    *
10    * This program is free software; you can redistribute it and/or modify
11    * it under the terms of the GNU General Public License as published by
12    * the Free Software Foundation; either version 2 of the License, or
13    * (at your option) any later version.
14    *
15    * This program is distributed in the hope that it will be useful, but
16    * WITHOUT ANY WARRANTY; without even the implied warranty of
17    * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18    * General Public License for more details. You should have received a
19    * copy of the GNU General Public License along with this program; if
20    * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21    * Suite 330, Boston, MA 02111-1307, USA.
22    *
23    */
24
25
26 class LoginDBItem {
27     var $code;
28     var $login;
29     var $pass;
30     var $email;
31     var $type;
32     var $last_dona;
33     var $supp_comp;
34     var $tos_vers;
35     var $disa_reas;
36     var $guar_code;
37     var $match_cnt;
38     var $game_cnt;
39
40     function LoginDBItem($code, $login, $pass, $email, $type, $last_dona, $supp_comp, $tos_vers,
41                          $disa_reas, $guar_code, $match_cnt, $game_cnt)
42     {
43         $this->code      = $code;
44         $this->login     = $login;
45         $this->pass      = $pass;
46         $this->email     = $email;
47         $this->type      = $type;
48         $this->last_dona = $last_dona;
49         $this->supp_comp = $supp_comp;
50         $this->tos_vers  = $tos_vers;
51         $this->disa_reas = $disa_reas;
52         $this->guar_code = $guar_code;
53         $this->match_cnt = $match_cnt;
54         $this->game_cnt  = $game_cnt;
55     }
56
57     static function LoginDBItemFromRecord($rec)
58     {
59         $ret = new LoginDBItem($rec->code, $rec->login, $rec->pass,
60                                $rec->email, $rec->type, $rec->last_dona,
61                                $rec->supp_comp, $rec->tos_vers, $rec->disa_reas, $rec->guar_code,
62                                $rec->match_cnt, $rec->game_cnt);
63
64         return ($ret);
65     }
66
67     function code_get()
68     {
69         return $this->code;
70     }
71
72     function login_get()
73     {
74         return $this->login;
75     }
76
77     function pass_get()
78     {
79         return $this->pass;
80     }
81
82     function email_get()
83     {
84         return $this->email;
85     }
86
87     function type_get()
88     {
89         return $this->type;
90     }
91
92     function last_dona_get()
93     {
94         return $this->last_dona;
95     }
96
97     function supp_comp_get()
98     {
99         return $this->supp_comp;
100     }
101     function supp_comp_set($supp_comp)
102     {
103         $this->supp_comp = $supp_comp;
104     }
105
106     function tos_vers_get()
107     {
108         return $this->tos_vers;
109     }
110     function tos_vers_set($tos_vers)
111     {
112         $this->tos_vers = $tos_vers;
113     }
114
115     function disa_reas_get()
116     {
117         return $this->disa_reas;
118     }
119     function disa_reas_set($disa_reas)
120     {
121         $this->disa_reas = $disa_reas;
122     }
123     function guar_code_get()
124     {
125         return $this->guar_code;
126     }
127
128     function match_cnt_get()
129     {
130         return $this->match_cnt;
131     }
132     function match_cnt_add($v)
133     {
134         return $this->match_cnt += $v;
135     }
136
137     function game_cnt_get()
138     {
139         return $this->game_cnt;
140     }
141     function game_cnt_add($v)
142     {
143         return $this->game_cnt += $v;
144     }
145 }
146
147 define('MAIL_TYP_CHECK', 1);
148
149 class MailDBItem {
150     var $code;
151     var $ucode;
152     var $type;
153     var $tstamp;
154     var $subj;
155     var $body_txt;
156     var $body_htm;
157     var $hash;
158
159     function MailDBItem($code, $ucode, $type, $tstamp, $subj, $body_txt, $body_htm, $hash=NULL)
160     {
161         $this->code = $code;
162         $this->ucode = $ucode;
163         $this->type = $type;
164         $this->tstamp = $tstamp;
165         $this->subj = $subj;
166         $this->body_txt = $body_txt;
167         $this->body_htm = $body_htm;
168         $this->hash = $hash;
169     }
170
171     static function MailDBItemFromRecord($rec)
172     {
173         $ret = new MailDBItem($rec->code, $rec->ucode, $rec->type, $rec->tstamp, $rec->subj,
174                               $rec->body_txt, $rec->body_htm, $rec->hash);
175
176         return ($ret);
177     }
178
179     function store($bdb)
180     {
181         return $bdb->mail_add_fromitem($this);
182     }
183 }
184
185 define('USERNET_FRIEND', 0);
186 define('USERNET_CLEVER', 1);
187 define('USERNET_TRUST', 2);
188 class UserNetItem {
189     var $owner;
190     var $target;
191     var $friend;
192     var $clever;
193     var $trust;
194
195     var $from_db;
196
197     function UserNetItem($owner, $target, $friend, $clever, $trust, $from_db)
198     {
199         $this->owner = $owner;
200         $this->target = $target;
201         $this->friend = $friend;
202         $this->clever = $clever;
203         $this->trust = $trust;
204
205         $this->from_db = $from_db;
206     }
207
208     static function UserNetItemFromRecord($rec)
209     {
210         $ret = new UserNetItem($rec->owner, $rec->target, $rec->friend,
211                                $rec->clever, $rec->trust, TRUE);
212
213         return ($ret);
214     }
215
216     static function UserNetItemDefaults($owner, $target)
217     {
218         $ret = new UserNetItem($owner, $target, USERNET_FRIEND,
219                                USERNET_CLEVER, USERNET_TRUST, FALSE);
220
221         return ($ret);
222     }
223
224
225 }
226
227 ?>