5bf1fd8c0000a553ec8c0a0bba60499a9c71cfe4
[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
32                 $session->Contact['firstName']=$session->Profile['firstName'];
33                 $session->Contact['familyName']=$session->Profile['familyName'];
34                 $session->Contact['email']=$session->Profile['email'];
35                 $session->Contact['mobile']=$session->Profile['mobile'];
36
37
38                 $contact = $contactService->create($session->Contact);
39                 $session->Company['contact'] = $contact->id;
40                 $session->Company['name']= $session->Profile['firstName'].' '.$session->Profile['familyName'];
41                 $session->Company['businessName']= $session->Profile['firstName'].' '.$session->Profile['familyName'];
42                 $session->Company['group']= '3';
43                 $session->Company['groupDivision']= '3';
44 //              $session->Company['region']= '1';
45 //              $session->Company['city']= '1';
46 //              if (isset($session->BillingContact))
47 //              {
48 //              //\Utility\Debug::errorLog('create billing contact', $session->BillingContact);
49 //                      $billingContact = $contactService->create($session->BillingContact);
50 //                      $session->Company['contbillingContactact'] = $billingContact->id;
51 //              }
52                 //\Utility\Debug::errorLog('create company', $session->Company);
53                 $company = $companyService->create($session->Company);
54                 $session->Profile['company'] = $company->id;
55 //              if ($session->Profile['permissions'] < 5 || $session->Profile['permissions'] > 8)
56 //              {
57 //                      $session->Profile['permissions'] = 5;
58 //              }
59                 $session->Profile['permissions'] = 12;
60                 \Utility\Debug::errorLog('create profile', $session->Profile);
61                 $profile = $profileService->create($session->Profile);
62
63                 $toCompanyId    = '';
64                 $toProfileId    = $profile->id;
65                 $email                  = $profile->email;
66                 $mobile                 = null;
67                 $subject                = null;
68                 $templateName   = 'activation-pending';
69
70                 $params = array();
71                 $params['firstName']    = $profile->firstName;
72                 $params['familyName']   = $profile->familyName;
73                 $params['message']              = 'Thank you for registering. Your registration was submitted for approval '
74                                                                 . 'and you will receive email confirmation once your account has been verified.'
75                                                                 . 'Please note that if any documents were not uploaded they need to be emailed'
76                                                                 . ' (info@bid4cars.com.na) or faxed (086 618 5584) before we can approve your '
77                                                                 . 'account.';
78
79                 #-> Send welcome notification to User.
80                 $oNotify = new \Utility\Comms\Notification();
81                 $oNotify->sendFromTemplate(
82                                 null, null,
83                                 $toCompanyId, $toProfileId,
84                                 $email, $mobile,
85                                 $subject,
86                                 $templateName,
87                                 $params
88                 );
89                 
90                 
91                 #-> Send welcome notification to Admin.
92                 $oNotify = new \Utility\Comms\Notification();
93                 $oNotify->sendFromTemplate(
94                                 null, null,
95                                 $toCompanyId, $toProfileId,
96                                 'info@bid4cars.com.na', $mobile,
97                                 $subject,
98                                 $templateName,
99                                 $params
100                 );
101         }
102
103 }