initial commit
[namibia] / module / PriceGuide / src / PriceGuide / DataBin / Member.php
1 <?php
2 namespace PriceGuide\DataBin;
3
4
5
6 /**
7  * Manage Member data.
8  * @author andre.fourie
9  */
10 class Member extends \Workspace\Service\DataBin
11 {
12
13         /**
14          * @var array
15          */
16         protected $meta = array(
17                         'Base'        => 'Member',
18                         'DatasetName' => 'models',
19                         'Entity'      => '\PriceGuide\Entity\Member',
20                         'References'  => array(
21                                         'allowedMember'   => '\PriceGuide\Entity\AllowedMember',
22                                         'company'         => '\Company\Entity\Company',
23                                         'profile'         => '\User\Entity\Profile',
24                                         'club'            => '\PriceGuide\Entity\Club',
25                                         'fromYear'        => '\Stock\Entity\Year',
26                                         'toYear'          => '\Stock\Entity\Year'
27                         ),
28                         'Dependants'  => array(
29                                         'makes' => '\Stock\Entity\Make'
30                         )
31         );
32         /**
33          * @var array
34         */
35         protected $metaGrid = array(
36                         'Type'          => 'Grid',
37                         'Contract'      => 'Recurring',
38                         'RequiredInput' => array(),
39                         'OptionalInput' => array(
40                                         'Grid' => array(
41                                                         'NumberOfRecords' => 'Integer',
42                                                         'Page'            => 'Integer',
43                                                         'Filter'          => 'Array',
44                                                         'OrderBy'         => 'Array',
45                                         )
46                         ),
47                         'Base'            => 'mmbr',
48                         'NumberOfRecords' => 10,
49                         'Query'           => 'SELECT [SELECTION]
50                                                                 FROM \PriceGuide\Entity\Member mmbr
51                                                                 JOIN mmbr.club club
52                                                                 JOIN club.company company
53                                                                 JOIN mmbr.company allowedCompany
54                                                                 JOIN allowedCompany.contact contact
55                                                                 [WHERE] [ORDER]',
56                         'Selection'       => 'mmbr, club, allowedCompany, contact',
57                         'Filter'          => array(
58                                                                         'club.archived' => false,
59                                                                         'mmbr.archived' => false
60                                                                 ),
61                         'OrderBy'         => array(
62                                                                         'contact.firstName' => 'ASC',
63                                                                         'contact.familyName' => 'ASC',
64                                                                 ),
65                         'Fields'          => array(
66                                                                         'id',
67                                                                         'status',
68                                                                         'created' => 'DateTime',
69                                                                         'club' => array(
70                                                                                 'id'
71                                                                         ),
72                                                                         'company' => array(
73                                                                                 'name',
74                                                                                 'contact' => array(
75                                                                                                 'firstName',
76                                                                                                 'familyName',
77                                                                                                 'email'
78                                                                                 )
79                                                                         )
80                                                                 )
81         );
82         /**
83          * @var array
84         */
85         protected $metaMembershipGrid = array(
86                         'Type'          => 'Grid',
87                         'Contract'      => 'Recurring',
88                         'RequiredInput' => array(),
89                         'OptionalInput' => array(
90                                         'Grid' => array(
91                                                         'NumberOfRecords' => 'Integer',
92                                                         'Page'            => 'Integer',
93                                                         'Filter'          => 'Array',
94                                                         'OrderBy'         => 'Array',
95                                         )
96                         ),
97                         'Base'            => 'mmbr',
98                         'NumberOfRecords' => 10,
99                         'Query'           => 'SELECT [SELECTION]
100                                                                 FROM \PriceGuide\Entity\Member mmbr
101                                                                 JOIN mmbr.club club
102                                                                 JOIN club.company company
103                                                                 JOIN mmbr.company memberCompany
104                                                                 JOIN memberCompany.contact contact
105                                                                 [WHERE] [ORDER]',
106                         'Selection'       => 'mmbr, memberCompany, club, contact, company',
107                         'Filter'          => array(
108                                                                         'club.archived' => false,
109                                                                         'mmbr.archived' => false
110                                                                 ),
111                         'OrderBy'         => array(
112                                                                         'club.name' => 'ASC'
113                                                                 ),
114                         'Fields'          => array(
115                                                                         'id',
116                                                                         'status',
117                                                                         'allMakes',
118                                                                         'emailNotification',
119                                                                         'smsNotification',
120                                                                         'status',
121                                                                         'created' => 'DateTime',
122                                                                         'club' => array(
123                                                                                 'name'
124                                                                         ),
125                                                                         'memberCompany' => array(
126                                                                                 'name'
127                                                                         ),
128                                                                         'contact' => array(
129                                                                                 'firstName',
130                                                                                 'familyName',
131                                                                                 'email'
132                                                                         )
133                                                                 )
134         );
135         /**
136          * @var array
137         */
138         protected $metaInvite = array(
139                         'Type'          => 'Create',
140                         'Contract'      => 'Recurring',
141                         'RequiredInput' => array(
142                                         'Member' => array(
143                                                         'club'    => 'Id',
144                                                         'company' => 'Id'
145                                         )
146                         ),
147                         'OptionalInput' => array()
148         );
149         /**
150          * @var array
151         */
152         protected $metaAccept = array(
153                         'Type'          => 'Update',
154                         'Contract'      => 'UseOnce',
155                         'ExecuteAfter'  => array(
156                                         'acceptInvite'
157                         ),
158                         'RequiredInput' => array(),
159                         'OptionalInput' => array()
160         );
161         /**
162          * @var array
163         */
164         protected $metaDecline = array(
165                         'Type'          => 'Update',
166                         'Contract'      => 'UseOnce',
167                         'ExecuteAfter'  => array(
168                                         'declineInvite'
169                         ),
170                         'RequiredInput' => array(),
171                         'OptionalInput' => array()
172         );
173         /**
174          * @var array
175         */
176         protected $metaActivate = array(
177                         'Type'          => 'Update',
178                         'Contract'      => 'UseOnce',
179                         'ExecuteAfter'  => array(
180                                         'activateMembership'
181                         ),
182                         'RequiredInput' => array(),
183                         'OptionalInput' => array()
184         );
185         /**
186          * @var array
187         */
188         protected $metaDeactivate = array(
189                         'Type'          => 'Update',
190                         'Contract'      => 'UseOnce',
191                         'ExecuteAfter'  => array(
192                                         'deactivateMembership'
193                         ),
194                         'RequiredInput' => array(),
195                         'OptionalInput' => array()
196         );
197         /**
198          * @var array
199         */
200         protected $metaUpdate = array(
201                         'Type'          => 'Update',
202                         'Contract'      => 'UseOnce',
203                         'ExecuteAfter'  => array(
204                                 'checkApplyAll'
205                         ),
206                         'RequiredInput' => array(),
207                         'OptionalInput' => array(
208                                         'Member' => array(
209                                                         'makes'             => 'Array',
210                                                         'allMakes'          => 'Boolean',
211                                                         'fromYear'          => 'Id',
212                                                         'toYear'            => 'Id',
213                                                         'fromKm'            => 'Integer',
214                                                         'toKm'              => 'Integer',
215                                                         'emailNotification' => 'Boolean',
216                                                         'smsNotification'   => 'Boolean',
217                                                         'status'            => 'String25',
218                                                         'applyToAll'        => 'Boolean'
219                                         )
220                         )
221         );
222         /**
223          * @var array
224         */
225         protected $metaUpdateStatus = array(
226                         'Type'          => 'Update',
227                         'Contract'      => 'UseOnce',
228                         'Expand'        => array(
229                                         'company',
230                                         'profile'
231                         ),
232                         'RequiredInput' => array(),
233                         'OptionalInput' => array(
234                                         'Member' => array(
235                                                         'status' => 'String25'
236                                         )
237                         )
238         );
239         /**
240          * @var array
241         */
242         protected $metaArchive = array(
243                         'Type'          => 'Update',
244                         'Contract'      => 'UseOnce',
245                         'ExecuteAfter'  => array(
246                                         'archiveMember'
247                         ),
248                         'RequiredInput' => array(),
249                         'OptionalInput' => array()
250         );
251
252
253
254         /**
255          * Add some dynamic filtering to our grids.
256          */
257         public function __construct()
258         {
259                 $authData = \Utility\Registry::getAuthData();
260                 switch (\Utility\Registry::getUserType())
261                 {
262                         case 'B4C User':
263                                 $groupFilter = \Utility\Registry::getSudo('Group', false);
264                                 $groupFilter
265                                         && $this->metaGrid['Filter']['IDENTITY(company.group)'] = $groupFilter;
266                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
267                                 $divisionFilter
268                                         && $this->metaGrid['Filter']['IDENTITY(company.groupDivision)'] = $divisionFilter;
269                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
270                                 if ($companyFilter)
271                                 {
272                                         $this->metaGrid['Filter']['company.id'] = $companyFilter;
273                                         $this->metaMembershipGrid['Filter']['memberCompany.id'] = $companyFilter;
274                                 }
275                                 break;
276                         case 'Group User':
277                                 $this->metaGrid['Filter']['IDENTITY(company.group)'] = $authData['company']['group']['id'];
278                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
279                                 $divisionFilter
280                                         && $this->metaGrid['Filter']['IDENTITY(company.groupDivision)'] = $divisionFilter;
281                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
282                                 if ($companyFilter)
283                                 {
284                                         $this->metaGrid['Filter']['company.id'] = $companyFilter;
285                                         $this->metaMembershipGrid['Filter']['memberCompany.id'] = $companyFilter;
286                                 }
287                                 break;
288                         case 'Dealer Principle':
289                                 $this->metaGrid['Filter']['IDENTITY(company.groupDivision)'] = $authData['company']['groupDivision']['id'];
290                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
291                                 if ($companyFilter)
292                                 {
293                                         $this->metaGrid['Filter']['company.id'] = $companyFilter;
294                                         $this->metaMembershipGrid['Filter']['memberCompany.id'] = $companyFilter;
295                                 }
296                                 break;
297                         default:
298                                 $this->metaGrid['Filter']['company.id'] = $authData['company']['id'];
299                                 $this->metaMembershipGrid['Filter']['memberCompany.id'] = $authData['company']['id'];
300                                 break;
301                 }
302         }
303
304 }