latest update
[namibia] / module / User / src / User / Service / Registration.php
1 <?php
2 namespace User\Service;
3
4
5
6 /**
7  * Registration, login and forgot password functionality.
8  * @author andre.fourie
9  */
10 class Registration extends \User\DataBin\Registration
11 {
12
13         /**
14          * ExecuteAfter: RegisterFinal.
15          * Register a new dealership and its primary user.
16          * @param array $meta
17          * @param object|null $jobRecord
18          * @param object|null $record
19          * @param \Workspace\Utility\ServiceInputParams $contract
20          * @return array
21          */
22         public function RegisterCompany($meta, $jobRecord, $session, \Workspace\Utility\ServiceInputParams $contract)
23         {
24                 $contactService = new \Person\Service\Contact();
25                 $contactService->setWorkflow(new \Person\Workflow());
26                 $companyService = new \Company\Service\Company();
27                 $companyService->setWorkflow(new \Company\Workflow());
28                 $profileService = new \User\Service\Profile();
29                 $profileService->setWorkflow(new \User\Workflow());
30                 //\Utility\Debug::errorLog('create contact', $session->Contact);
31                 $contact = $contactService->create($session->Contact);
32                 $session->Company['contact'] = $contact->id;
33                 if (isset($session->BillingContact))
34                 {
35                 //\Utility\Debug::errorLog('create billing contact', $session->BillingContact);
36                         $billingContact = $contactService->create($session->BillingContact);
37                         $session->Company['contbillingContactact'] = $billingContact->id;
38                 }
39                 //\Utility\Debug::errorLog('create company', $session->Company);
40                 $company = $companyService->create($session->Company);
41                 $session->Profile['company'] = $company->id;
42                 if ($session->Profile['permissions'] < 5 || $session->Profile['permissions'] > 8)
43                 {
44                         $session->Profile['permissions'] = 5;
45                 }
46                 //\Utility\Debug::errorLog('create profile', $session->Profile);
47                 $profile = $profileService->create($session->Profile);
48
49                 $toCompanyId    = $company->id;
50                 $toProfileId    = $profile->id;
51                 $email                  = $profile->email;
52                 $mobile                 = null;
53                 $subject                = null;
54                 $templateName   = 'activation-pending';
55
56                 $params = array();
57                 $params['firstName']    = $profile->firstName;
58                 $params['familyName']   = $profile->familyName;
59                 $params['message']              = 'Thank you for registering. Your registration was submitted for approval '
60                                                                 . 'and you will receive email confirmation once your account has been verified.'
61                                                                 . 'Please note that if any documents were not uploaded they need to be emailed'
62                                                                 . ' (info@bid4cars.com.na) or faxed (086 618 5584) before we can approve your '
63                                                                 . 'account.';
64
65                 #-> Send welcome notification to User.
66                 $oNotify = new \Utility\Comms\Notification();
67                 $oNotify->sendFromTemplate(
68                                 null, null,
69                                 $toCompanyId, $toProfileId,
70                                 $email, $mobile,
71                                 $subject,
72                                 $templateName,
73                                 $params
74                 );
75                 
76                 
77                 #-> Send welcome notification to Admin.
78                 $oNotify = new \Utility\Comms\Notification();
79                 $oNotify->sendFromTemplate(
80                                 null, null,
81                                 $toCompanyId, $toProfileId,
82                                 'info@bid4cars.com.na', $mobile,
83                                 $subject,
84                                 $templateName,
85                                 $params
86                 );
87         }
88
89 }