initial commit
[namibia] / module / PriceGuide / src / PriceGuide / DataBin / Invite.php
1 <?php
2 namespace PriceGuide\DataBin;
3
4
5
6 /**
7  * Manage Member Invites.
8  * @author andre.fourie
9  */
10 class Invite extends \Workspace\Service\DataBin
11 {
12
13         /**
14          * @var array
15          */
16         protected $meta = array(
17                         'Session'     => 'Invite',
18                         'Base'        => 'Member',
19                         'DatasetName' => 'models',
20                         'Entity'      => '\PriceGuide\Entity\Member',
21                         'References'  => array(
22                                         'allowedMember'   => '\PriceGuide\Entity\AllowedMember',
23                                         'company'         => '\Company\Entity\Company',
24                                         'profile'         => '\User\Entity\Profile',
25                                         'club'            => '\Company\Entity\Company',
26                                         'fromYear'        => '\Stock\Entity\Year',
27                                         'toYear'          => '\Stock\Entity\Year'
28                         ),
29                         'Dependants'  => array(
30                                         'makes' => '\Stock\Entity\Make'
31                         )
32         );
33         /**
34          * @var array
35         */
36         protected $metaGrid = array(
37                         'Type'          => 'Grid',
38                         'Contract'      => 'Recurring',
39                         'RequiredInput' => array(),
40                         'OptionalInput' => array(
41                                         'Grid' => array(
42                                                         'NumberOfRecords' => 'Integer',
43                                                         'Page'            => 'Integer',
44                                                         'Filter'          => 'Array',
45                                                         'OrderBy'         => 'Array',
46                                         )
47                         ),
48                         'Base'            => 'mmbr',
49                         'NumberOfRecords' => 10,
50                         'Query'           => 'SELECT [SELECTION]
51                                                                 FROM \PriceGuide\Entity\Member mmbr
52                                                                 JOIN mmbr.club club
53                                                                 JOIN mmbr.allowedMember allowedMember
54                                                                 LEFT JOIN mmbr.company company
55                                                                 LEFT JOIN mmbr.profile profile
56                                                                 [WHERE] [ORDER]',
57                         'Selection'       => 'mmbr, club, allowedMember, company',
58                         'Filter'          => array(
59                                                                         'club.archived' => false,
60                                                                         'mmbr.archived' => false
61                                                                 ),
62                         'OrderBy'         => array(
63                                                                         'company.name' => 'ASC',
64                                                                         'club.name' => 'ASC',
65                                                                 ),
66                         'Fields'          => array(
67                                                                         'id',
68                                                                         'status',
69                                                                         'created' => 'DateTime',
70                                                                         'club' => array(
71                                                                                 'name'
72                                                                         ),
73                                                                         'allowedMember' => array(
74                                                                                 'email'
75                                                                         ),
76                                                                         'company' => array(
77                                                                                 'name'
78                                                                         )
79                                                                 )
80         );
81         /**
82          * @var array
83          */
84         protected $metaView = array(
85                         'Type'      => 'View',
86                         'Expand'    => array(
87                                         'makes',
88                                         'fromYear',
89                                         'toYear'
90                         ),
91                         'Intersect' => array()
92         );
93         /**
94          * @var array
95         */
96         protected $metaAccept = array(
97                         'Type'          => 'Update',
98                         'Contract'      => 'UseOnce',
99                         'ExecuteAfter'  => array(
100                                         'acceptInvite'
101                         ),
102                         'RequiredInput' => array(),
103                         'OptionalInput' => array()
104         );
105         /**
106          * @var array
107         */
108         protected $metaDecline = array(
109                         'Type'          => 'Update',
110                         'Contract'      => 'UseOnce',
111                         'ExecuteAfter'  => array(
112                                         'declineInvite'
113                         ),
114                         'RequiredInput' => array(),
115                         'OptionalInput' => array()
116         );
117         /**
118          * @var array
119         */
120         protected $metaArchive = array(
121                         'Type'          => 'Update',
122                         'Contract'      => 'UseOnce',
123                         'ExecuteAfter'  => array(
124                                         'archiveMember'
125                         ),
126                         'RequiredInput' => array(),
127                         'OptionalInput' => array()
128         );
129         /**
130          * @var array
131         */
132         protected $metaUpdate = array(
133                         'Type'          => 'Update',
134                         'Contract'      => 'UseOnce',
135                         'Options'       => array(
136                                         'Boolean' => array(
137                                                 'ApplyToAll' => false
138                                         )
139                         ),
140                         'ExecuteAfter'  => array(
141                                         'applyFilterToAll'
142                         ),
143                         'RequiredInput' => array(),
144                         'OptionalInput' => array(
145                                         'Member' => array(
146                                                         'makes'             => 'Array',
147                                                         'allMakes'          => 'Boolean',
148                                                         'fromYear'          => 'Id',
149                                                         'toYear'            => 'Id',
150                                                         'emailNotification' => 'Boolean',
151                                                         'smsNotification'   => 'Boolean'
152                                         )
153                         )
154         );
155
156
157
158         /**
159          * Add some dynamic filtering to our grids.
160          */
161         public function __construct()
162         {
163                 $authData = \Utility\Registry::getAuthData();
164                 $this->metaGrid['Filter']['ownership'] = array(
165                                 'allowedMember.email' => $authData['email']
166                 );
167                 switch (\Utility\Registry::getUserType())
168                 {
169                         case 'B4C User':
170                                 $groupFilter = \Utility\Registry::getSudo('Group', false);
171                                 $groupFilter
172                                         && $this->metaGrid['Filter']['ownership']['IDENTITY(company.group)'] = $groupFilter;
173                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
174                                 $divisionFilter
175                                         && !$groupFilter
176                                         && $this->metaGrid['Filter']['ownership']['IDENTITY(company.groupDivision)'] = $divisionFilter;
177                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
178                                 $companyFilter
179                                         && !$groupFilter
180                                         && !$divisionFilter
181                                         && $this->metaGrid['Filter']['ownership']['company.id'] = $companyFilter;
182                                 break;
183                         case 'Group User':
184                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
185                                 $divisionFilter
186                                         && $this->metaGrid['Filter']['ownership']['IDENTITY(company.groupDivision)'] = $divisionFilter;
187                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
188                                 $companyFilter
189                                         && !$divisionFilter
190                                         && $this->metaGrid['Filter']['ownership']['company.id'] = $companyFilter;
191                                 !$companyFilter
192                                         && !$divisionFilter
193                                         && $this->metaGrid['Filter']['ownership']['IDENTITY(company.group)'] = $authData['company']['group']['id'];
194                                 break;
195                         case 'Dealer Principle':
196                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
197                                 $companyFilter
198                                         && $this->metaGrid['Filter']['ownership']['company.id'] = $companyFilter;
199                                 !$companyFilter
200                                         && $this->metaGrid['Filter']['ownership']['IDENTITY(company.groupDivision)'] = $authData['company']['groupDivision']['id'];
201                                 break;
202                         default:
203                                 $this->metaGrid['Filter']['ownership']['company.id'] = $authData['company']['id'];
204                                 break;
205                 }
206         }
207
208 }