|
1
|
|
|
<?php |
|
2
|
|
|
namespace ModPleio; |
|
3
|
|
|
|
|
4
|
|
|
class AccessRequest { |
|
5
|
|
|
public function __construct($data) { |
|
6
|
|
|
$this->id = (int) $data->id; |
|
|
|
|
|
|
7
|
|
|
$this->user = unserialize($data->user); |
|
|
|
|
|
|
8
|
|
|
$this->time_created = $data->time_created; |
|
|
|
|
|
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
public function getURL() { |
|
12
|
|
|
return $this->user["url"]; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function getIconURL() { |
|
16
|
|
|
return $this->user["icon"]; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function getType() { |
|
20
|
|
|
return "accessRequest"; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function approve() { |
|
24
|
|
|
$resourceOwner = new ResourceOwner($this->user); |
|
25
|
|
|
$loginHandler = new LoginHandler($resourceOwner); |
|
26
|
|
|
$site = elgg_get_site_entity(); |
|
27
|
|
|
|
|
28
|
|
|
try { |
|
29
|
|
|
$user = $loginHandler->createUser(); |
|
30
|
|
|
if ($user) { |
|
31
|
|
|
$this->remove(); |
|
32
|
|
|
$this->sendEmail( |
|
33
|
|
|
elgg_echo("pleio:approved:subject", [$site->name]), |
|
34
|
|
|
elgg_echo("pleio:approved:body", [ |
|
35
|
|
|
$user->name, |
|
36
|
|
|
$site->name, |
|
37
|
|
|
$site->url |
|
38
|
|
|
]) |
|
39
|
|
|
); |
|
40
|
|
|
return true; |
|
41
|
|
|
} |
|
42
|
|
|
} catch (\RegistrationException $e) { |
|
43
|
|
|
register_error($e->getMessage()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function decline() { |
|
50
|
|
|
$site = elgg_get_site_entity(); |
|
51
|
|
|
$resourceOwner = new ResourceOwner($this->user); |
|
52
|
|
|
|
|
53
|
|
|
if ($this->remove()) { |
|
|
|
|
|
|
54
|
|
|
$this->sendEmail( |
|
55
|
|
|
elgg_echo("pleio:declined:subject", [$site->name]), |
|
56
|
|
|
elgg_echo("pleio:declined:body", [ |
|
57
|
|
|
$resourceOwner->getName(), |
|
58
|
|
|
$site->name |
|
59
|
|
|
]) |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function remove() { |
|
69
|
|
|
return delete_data("DELETE FROM pleio_request_access WHERE id = {$this->id}"); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function sendEmail($subject, $body, $params = null) { |
|
73
|
|
|
$site = elgg_get_site_entity(); |
|
74
|
|
|
|
|
75
|
|
|
if ($site->email) { |
|
76
|
|
|
$from = $site->email; |
|
77
|
|
|
} else { |
|
78
|
|
|
$from = "noreply@" . get_site_domain($site->guid); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return elgg_send_email($from, $this->user["email"], $subject, $body, $params); |
|
82
|
|
|
} |
|
83
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: