Git Repository Public Repository

namibia

URLs

Copy to Clipboard
 
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
namespace Retail\Service;

class RetailService
{
	/**
	 * Return Hello World!
	 * @return string
	 */
	public function hello()
	{
		return "Hello world!";
	}

	/**
	 * Return Hello whatever
	 * @param string $name
	 * @return string
	 */
	public function helloBob($name)
	{
		return "Hello " . (string) $name;
	}

	/**
	 * Return all retail data for a given retailer based on their authtoken.
	 * @param string $authToken
	 * @return array
	 */
	public function getVehicleListing($authToken)
	{
		$dataSet = \Utility\Registry::getEntityManager()
			->createQuery(
					  'SELECT stock, company, retailers, type, model, make, fuelType, transmissionType,'
					. ' exteriorColour, interiorColour, condition, vehicleYear, upholstery,'
					. ' papers, natis, fsh, introYear, discYear,'
					. ' mainImage, frontImage, rightImage, leftImage,'
					. ' backImage, interiorImage, engineImage, natisImage,'
					. ' accessories, accessory, damages, damage '
					. 'FROM \Stock\Entity\Stock stock '
					. 'JOIN stock.company company '
					. 'JOIN company.retailers retailers '
					. 'JOIN retailers.retail retail '
					. 'JOIN stock.type type '
					. 'JOIN type.model model '
					. 'JOIN model.make make '
					. 'LEFT JOIN type.introYear introYear '
					. 'LEFT JOIN type.discYear discYear '
					. 'LEFT JOIN stock.fuelType fuelType '
					. 'LEFT JOIN stock.transmissionType transmissionType '
					. 'LEFT JOIN stock.exteriorColour exteriorColour '
					. 'LEFT JOIN stock.interiorColour interiorColour '
					. 'LEFT JOIN stock.condition condition '
					. 'LEFT JOIN stock.vehicleYear vehicleYear '
					. 'LEFT JOIN stock.upholstery upholstery '
					. 'LEFT JOIN stock.papers papers '
					. 'LEFT JOIN stock.natis natis '
					. 'LEFT JOIN stock.fullServiceHistory fsh '
					. 'LEFT JOIN stock.mainImage mainImage '
					. 'LEFT JOIN stock.frontImage frontImage '
					. 'LEFT JOIN stock.rightImage rightImage '
					. 'LEFT JOIN stock.leftImage leftImage '
					. 'LEFT JOIN stock.backImage backImage '
					. 'LEFT JOIN stock.interiorImage interiorImage '
					. 'LEFT JOIN stock.engineImage engineImage '
					. 'LEFT JOIN stock.natisImage natisImage '
					. 'LEFT JOIN stock.accessories accessories '
					. 'LEFT JOIN accessories.accessory accessory '
					. 'LEFT JOIN stock.damages damages '
					. 'LEFT JOIN damages.damage damage '
					. 'WHERE stock.jobState=\'Retail\' '
					. ' AND retail.authToken = \'' . addslashes($authToken) . '\' '
					. ' AND stock.archived = 0'
					. ' AND company.archived = 0'
					. ' AND retailers.archived = 0'
			)
			->getArrayResult();
		$data = array();
		$imgUrl = \Utility\Registry::getConfigParam('Host') . '/img/bin/';
		foreach ($dataSet as $row)
		{
			\Utility\Debug::errorLog('DATA for XMLRPC api', $row);
			$accessories = array();
			foreach ($row['accessories'] as $acc)
			{
				$accessories[] = $acc['accessory']['name'];
			}
			$damages = array();
			foreach ($row['damages'] as $dmg)
			{
				$damages[] = array(
						'component' 		=> null,
						'part'				=> null,
						'type'				=> $dmg['damage']['name'],
						'estimated_repair' 	=> $dmg['amount'],
						'photo_url'			=> false
				);
			}
			$data[] = array(
				'id' 							=> $row['id'],
				'registration_number' 			=> $row['registrationNumber'],
				'vehicle_year' 					=> $row['vehicleYear']['name'],
				'stock_number' 					=> $row['stockNumber'],
				'km' 							=> $row['km'],
				'specific_color' 				=> !is_null($row['exteriorColour'])
													? $row['exteriorColour']['name']
													: null,
				'vin_number' 					=> $row['vinNumber'],
				'engine_number' 				=> $row['engineNumber'],
				'full_service_history_notes' 	=> $row['fshNotes'],
				'mm_code' 						=> $row['type']['mmCode'],
				'stand_in_value' 				=> null,
				'reserve_price' 				=> $row['retailAmountRequired'],
				'remarks' 						=> '',
				'faults_explenation' 			=> '',
				'previous_repair_notes' 		=> $row['previousRepairsNotes'],
				'accessory_remarks' 			=> $row['accessoryNotes'],
				'dealer_retail_account_no' 		=> $row['company']['retailers'][0]['username'],
				'main_photo_url' 				=> !is_null($row['mainImage'])
													? $imgUrl . $row['mainImage']['filename']
													: false,
				'first_additional_photo_url' 	=> !is_null($row['frontImage'])
													? $imgUrl . $row['frontImage']['filename']
													: false,
				'second_additional_photo_url' 	=> !is_null($row['rightImage'])
													? $imgUrl . $row['rightImage']['filename']
													: false,
				'third_additional_photo_url' 	=> !is_null($row['leftImage'])
													? $imgUrl . $row['leftImage']['filename']
													: false,
				'fourth_additional_photo_url' 	=> !is_null($row['backImage'])
													? $imgUrl . $row['backImage']['filename']
													: false,
				'fifth_additional_photo_url' 	=> !is_null($row['interiorImage'])
													? $imgUrl . $row['interiorImage']['filename']
													: false,
				'sixth_additional_photo_url' 	=> !is_null($row['engineImage'])
													? $imgUrl . $row['engineImage']['filename']
													: false,
				'seventh_additional_photo_url' 	=> !is_null($row['natisImage'])
													? $imgUrl . $row['natisImage']['filename']
													: false,
				'full_service_history' 			=> !is_null($row['fullServiceHistory'])
													? $row['fullServiceHistory']['name']
													: '',
				'vehicle_spare_key' 			=> is_null($row['spareKeys'])
													? null
													: ($row['spareKeys'] ? true : false),
				'vehicle_paper' 				=> !is_null($row['papers'])
													? $row['papers']['name']
													: null,
				'condition' 					=> !is_null($row['condition'])
													? $row['condition']['name']
													: null,
				'make' 							=> $row['type']['model']['make']['name'],
				'model' 						=> $row['type']['model']['name'],
				'type' 							=> $row['type']['name'],
				'base_color' 					=> !is_null($row['exteriorColour'])
													? $row['exteriorColour']['name']
													: null,
				'interior' 						=> !is_null($row['upholstery'])
													? $row['upholstery']['name']
													: null,
				'interior_color' 				=> !is_null($row['interiorColour'])
													? $row['interiorColour']['name']
													: null,
				'natis' 						=> !is_null($row['natis'])
													? $row['natis']['name']
													: null,
				'vehicle_intro_year' 			=> !is_null($row['type']['introYear'])
													? $row['type']['introYear']['name']
													: null,
				'vehicle_intro_month' 			=> $row['type']['introMonth'],
				'vehicle_disc_year' 			=> !is_null($row['type']['discYear'])
													? $row['type']['discYear']['name']
													: null,
				'vehicle_disc_month' 			=> $row['type']['discMonth'],
				'vehicle_cyl' 					=> $row['type']['cylinders'],
				'vehicle_cubic_capacity' 		=> $row['type']['cubicCapacity'],
				'vehicle_kilowatts' 			=> $row['type']['kilowatts'],
				'vehicle_body_type' 			=> $row['type']['bodyType'],
				'vehicle_number_of_doors' 		=> $row['type']['doors'],
				'fuel_type' 					=> !is_null($row['fuelType'])
													? $row['fuelType']['name']
													: null,
				'transmission_type' 			=> !is_null($row['transmissionType'])
													? $row['transmissionType']['name']
													: null,
				'accessories' 					=> $accessories,
				'damages' 						=> $damages
			);
		}
		return $data;
	}
}

Commits for namibiamodule/Retail/src/Retail/Service/RetailService.php

Diff revisions: vs.
Revision Author Commited Message
df0489 ... Mark Fri 14 Oct, 2016 10:01:00 +0000

initial commit