initial commit
[namibia] / module / Auction / src / Auction / DataBin / Question.php
1 <?php
2 namespace Auction\DataBin;
3
4
5
6 /**
7  * Manage Bid data.
8  * @author andre.fourie
9  */
10 class Question extends \Workspace\Service\DataBin
11 {
12
13         /**
14          * @var array
15          */
16         protected $meta = array(
17                         'Base'        => 'Question',
18                         'DatasetName' => 'questions',
19                         'Entity'      => '\Auction\Entity\Question',
20                         'JobField'    => 'auction',
21                         'References'  => array(
22                                         'auction' => '\Auction\Entity\Auction',
23                                         'company' => '\Company\Entity\Company',
24                                         'profile' => '\User\Entity\Profile',
25                                         'reply'   => '\Auction\Entity\Reply'
26                         ),
27                         'Dependants'  => array()
28         );
29         /**
30          * @var array
31         */
32         protected $metaCreate = array(
33                         'Type'          => 'Create',
34                         'Contract'      => 'Recurring',
35                         'ExecuteAfter'  => array(
36                                         'notify'
37                         ),
38                         'RequiredInput' => array(
39                                         'Question' => array(
40                                                         'auction'  => 'Id',
41                                                         'question' => 'String500'
42                                         )
43                         ),
44                         'OptionalInput' => array()
45         );
46         /**
47          * @var array
48         */
49         protected $metaAskedGrid = array(
50             'Type'          => 'Grid',
51                 'Export'        => false,
52             'Contract'      => 'Recurring',
53                 'Options'       => array(),
54             'RequiredInput' => array(),
55             'OptionalInput' => array(
56                 'Grid'  => array(
57                     'NumberOfRecords' => 'Integer',
58                     'Page'            => 'Integer',
59                     'Filter'          => 'Array',
60                     'OrderBy'         => 'Array'
61                 )
62             ),
63             'Base'            => 'question',
64             'NumberOfRecords' => 10,
65         'Query'           => 'SELECT [SELECTION]
66                                               FROM \Auction\Entity\Question question
67                                                           JOIN question.auction auction
68                                                           JOIN auction.company company
69                                                           JOIN auction.stock stock
70                                                           JOIN stock.vehicleYear vehicleYear
71                                                           JOIN stock.type type
72                                                           JOIN type.model model
73                                                           JOIN model.make make
74                                                           LEFT JOIN question.reply reply
75                                                           LEFT JOIN reply.profile profile
76                                               [WHERE] [ORDER]',
77             'Selection'       => 'question, reply, auction, profile, company, stock, vehicleYear, make, model, type',
78             'Filter'          => array(
79                                                 'auction.jobState'  => 'Active',
80                                                 'question.archived' => 0
81                                              ),
82             'OrderBy'         => array('question.updated' => 'DESC'),
83             'Fields'          => array(
84                                                 'id',
85                                                 'created' => 'DateTime',
86                                                 'updated' => 'DateTime',
87                                             'auction' => array(
88                                                 'id',
89                                                 'jobState',
90                                                 'company' => array(
91                                                                 'name'
92                                                 ),
93                                                         'stock' => array(
94                                                             'created' => 'DateTime',
95                                                             'type' => array(
96                                                                 'name',
97                                                                 'model' => array(
98                                                                     'name',
99                                                                     'make' => array(
100                                                                           'name'
101                                                                     )
102                                                                 ),
103                                                             ),
104                                                             'vehicleYear' => array(
105                                                                 'name'
106                                                             ),
107                                                             'km',
108                                                             'tradePrice',
109                                                             'retailPrice',
110                                         'listPrice'
111                                                         )
112                                             ),
113                                             'reply' => array(
114                                                     'profile' => array(
115                                                                 'firstName',
116                                                                 'familyName'
117                                                         )
118                                                 )
119                                             )
120         );
121         /**
122          * @var array
123         */
124         protected $metaToAnswerGrid = array(
125             'Type'          => 'Grid',
126                 'Export'        => false,
127             'Contract'      => 'Recurring',
128                 'Options'       => array(),
129             'RequiredInput' => array(),
130             'OptionalInput' => array(
131                 'Grid'  => array(
132                     'NumberOfRecords' => 'Integer',
133                     'Page'            => 'Integer',
134                     'Filter'          => 'Array',
135                     'OrderBy'         => 'Array'
136                 )
137             ),
138             'Base'            => 'question',
139             'NumberOfRecords' => 10,
140         'Query'           => 'SELECT [SELECTION]
141                                               FROM \Auction\Entity\Question question
142                                                           JOIN question.auction auction
143                                                           JOIN question.profile profile
144                                                           JOIN question.company company
145                                                           JOIN auction.stock stock
146                                                           JOIN auction.company seller
147                                                           JOIN stock.vehicleYear vehicleYear
148                                                           JOIN stock.type type
149                                                           JOIN type.model model
150                                                           JOIN model.make make
151                                                           LEFT JOIN question.reply reply
152                                               [WHERE] [ORDER]',
153             'Selection'       => 'question, reply, auction, profile, company, stock, vehicleYear, make, model, type',
154             'Filter'          => array(
155                                                 'auction.jobState'  => 'Active',
156                                                 'question.archived' => 0
157                                              ),
158             'OrderBy'         => array('question.updated' => 'DESC'),
159             'Fields'          => array(
160                                                 'id',
161                                                 'created' => 'DateTime',
162                                                 'updated' => 'DateTime',
163                                             'reply' => array(
164                                                 'id'
165                                             ),
166                                             'auction' => array(
167                                                 'id',
168                                                 'jobState',
169                                                         'stock' => array(
170                                                             'created' => 'DateTime',
171                                                             'type' => array(
172                                                                 'name',
173                                                                 'model' => array(
174                                                                     'name',
175                                                                     'make' => array(
176                                                                           'name'
177                                                                     )
178                                                                 ),
179                                                             ),
180                                                             'vehicleYear' => array(
181                                                                 'name'
182                                                             ),
183                                                             'km',
184                                                             'tradePrice',
185                                                             'retailPrice',
186                                         'listPrice'
187                                                         )
188                                             ),
189                                                 'company' => array(
190                                                     'name'
191                                                 ),
192                                             'profile' => array(
193                                                         'firstName',
194                                                         'familyName'
195                                                 )
196                                             )
197         );
198         /**
199          * @var array
200          */
201         protected $metaView = array(
202             'Type'        => 'Update',
203             'Contract'    => 'Recurring',
204             'Expand'      => array(
205                                         'reply',
206                                         'auction',
207                                         'company',
208                                         'profile',
209                                                 'stock',
210                                                 'make',
211                                                 'model',
212                                                 'type',
213                                         'vehicleYear'
214             ),
215             'RequiredInput' => array(),
216             'OptionalInput' => array()
217         );
218
219
220
221         /**
222          * Add some dynamic filtering to our grids.
223          */
224         public function __construct()
225         {
226                 $authData = \Utility\Registry::getAuthData();
227                 switch (\Utility\Registry::getUserType())
228                 {
229                         case 'B4C User':
230                                 $groupFilter = \Utility\Registry::getSudo('Group', false);
231                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
232                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
233                                 if ($groupFilter && $divisionFilter && $companyFilter)
234                                 {
235                                         $this->metaAskedGrid['Filter']['IDENTITY(question.company)']   = $companyFilter;
236                                         $this->metaToAnswerGrid['Filter']['IDENTITY(auction.company)'] = $companyFilter;
237                                 }
238                                 break;
239                         case 'Group User':
240                                 $divisionFilter = \Utility\Registry::getSudo('Division', false);
241                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
242                                 if ($divisionFilter && $companyFilter)
243                                 {
244                                         $this->metaAskedGrid['Filter']['IDENTITY(question.company)']   = $companyFilter;
245                                         $this->metaToAnswerGrid['Filter']['IDENTITY(auction.company)'] = $companyFilter;
246                                 }
247                                 break;
248                         case 'Dealer Principle':
249                                 $companyFilter = \Utility\Registry::getSudo('Company', false);
250                                 if ($companyFilter)
251                                 {
252                                         $this->metaAskedGrid['Filter']['IDENTITY(question.company)']   = $companyFilter;
253                                         $this->metaToAnswerGrid['Filter']['IDENTITY(auction.company)'] = $companyFilter;
254                                 }
255                                 break;
256                         default:
257                                 $this->metaAskedGrid['Filter']['IDENTITY(question.company)'] = $authData['company']['id'];
258                                 $this->metaToAnswerGrid['Filter']['IDENTITY(auction.company)'] = $authData['company']['id'];
259                                 break;
260                         }
261         }
262
263 }