forked from StevenJoynt/HumHub-Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Events.php
52 lines (45 loc) · 1.39 KB
/
Events.php
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
<?php
namespace sij\humhub\modules\sponsor;
use Yii;
use yii\helpers\Url;
use sij\humhub\modules\sponsor\widgets\Sponsors;
use sij\humhub\modules\sponsor\models\Sponsor;
class Events
{
public static function onProfileSidebarInit($event)
{
try {
if ( Yii::$app->user->isGuest ) return;
$user = $event->sender->user;
if ( ! $user ) return;
$event->sender->addWidget(
Sponsors::class,
['user' => $user],
['sortOrder' => 500]
);
} catch ( \Throwable $e ) {
Yii::error($e);
}
}
public static function onAfterInsertInvite($event)
{
try {
$identity = Yii::$app->user->getIdentity();
$sponsor = new Sponsor();
$sponsor->invited_email = strtolower(trim($event->sender->email));
$sponsor->created_by = $identity->id;
$sponsor->created_name = $identity->displayName;
$sponsor->created_email = strtolower(trim($identity->email));
$sponsor->save();
} catch ( \Throwable $e ) {
Yii::error($e);
}
}
public static function onAfterRegistration($event)
{
$identity = $event->identity;
$email = strtolower(trim($identity->email));
$user_id = $identity->id;
Sponsor::updateInvitation($email, $user_id);
}
}