-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSignupEmail.php
More file actions
78 lines (67 loc) · 2.31 KB
/
SignupEmail.php
File metadata and controls
78 lines (67 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
class SignupEmail extends DBObject {
static $tableName = 'signup_emails';
static $columns = [
'id'=>['name'=>'id','primary_key'=>true],
'email'=>['name'=>'email'],
'signup_time'=>['name'=>'signup_time'],
'invited_time'=>['name'=>'invited_time'],
'invite_code'=>['name'=>'invite_code']
];
static function getColumns() {
return self::$columns;
}
static function getTableName() {
return self::$tableName;
}
static function getAllSignupEmails() {
$db = DBConnectionFactory::Instance();
$records = $db->select(SignupEmail::$tableName);
$emails = [];
foreach($records as $record) {
$emails[] = new SignupEmail($record,true);
}
return $emails;
}
static function newSignupEmail($email) {
$email = strtolower($email);
$values = ['email'=>$email];
$emailObj = new SignupEmail($values,false);
return $emailObj;
}
static function getEmailObject($email) {
$db = DBConnectionFactory::Instance();
$email = strtolower($email);
$values = [self::$columns['email']['name'] => $email];
$records = $db->select(SignupEmail::$tableName,$values);
$emailObject = false;
if (count($records)>=1) {
$emailObject = new SignupEmail($records[0],true);
}
return $emailObject;
}
static function getByInviteCode($invite_code) {
$db = DBConnectionFactory::Instance();
$values = [self::$columns['invite_code']['name'] => '*'.$invite_code];
$records = $db->select(SignupEmail::$tableName,$values);
$emailObject = false;
if (count($records)>=1) {
$emailObject = new SignupEmail($records[0],true);
}
return $emailObject;
}
public function invite() {
$this->setInviteCode();
$emailer = EmailSenderFactory::Instance();
if ($emailer->sendInviteEmail($this)) {
$this->setValue('invited_time', date('Y-m-d G:i:s'), true);
return true;
} else {
return false;
}
}
public function setInviteCode() {
$this->setValue('invite_code','*'
.md5($this->getValue('id').$this->getValue('email').$this->getValue('signup_time')),true);
}
}