186
185
protected function setEventStaffStatus($throwOnError, Doctrine_Connection $conn)
189
187
// always start with any data maps we'll need so they're explicit
190
188
$responses = array();
192
190
// loop through our raw data and build our person language data
191
$this->logInfo('Looping throw the message reponses and retrieving the most recent.');
193
192
foreach ($this->importData as $rowId => $rowData)
195
194
$rd = $rowData['_rawData'];
196
195
if (array_key_exists('resonse', $rd)) {
197
$responses[$rd['unique_id']] = $rd['response'];
201
// @todo foreach $responses doctrine goodness
196
$rVals = array(self::mapResponse($rd['response']), strtotime($rd['time_stamp']));
197
$responses[$rd['unique_id']] = $rVals;
201
// this step is necessary to avoid index constraints
202
$coll = agDoctrineQuery::create()
204
->from('agEventStaffStatus ess')
205
->whereIn(array_keys($responses))
206
->andWhere('EXISTS (SELECT s.id ' .
207
'FROM agEventStaffStatus AS s ' .
208
'WHERE s.event_staff_id = ess.event_staff_id ' .
209
'HAVING MAX(s.time_stamp) = ess.time_stamp)')
212
// loop through all of our event staff and insert for those who already have a status
213
foreach ($coll as $collId => &$rec)
215
// grab that particular response record
216
$rVals = $responses[$rec['event_staff_id']];
218
// @todo Check the timestamp output... this might need to be strtotime'd
219
if ($rec['time_stamp'] == $rVals[1])
221
// if the timestamps were the same, update the response
222
$eventMsg = 'Updating existing response for event staff id {' . $rec['event_staff_id'] .
224
$this->logDebug($eventMsg);
225
$rec['staff_allocation_status_id'] = $rVals[0];
227
else if ($rec['time_stamp'] < $rVals[1])
229
$eventMsg = 'Creating new status record for event staff id {' . $rec['event_staff_id'] .
231
$this->logDebug($eventMsg);
233
// if the db timestamp is older than the import one, make a new record and add it
234
$nRec = new agEventStaffStatus();
235
$nRec['event_staff_id'] = $rec['event_staff_id'];
236
$nRec['time_stamp'] = $rVals[1];
237
$nRec['staff_allocation_status_id'] = $rVals[0];
242
$eventMsg = 'Import timestamp {' . $rVals[1] . '} is older than the current timestamp in' .
243
'the database {' . $rec['time_stamp'] . '}. Skipping insertion of older timestamp.';
244
$this->logWarn($eventMsg);
247
// either way, we can be safely done this response
248
unset($responses[$rec['event_staff_id']]);
251
// as a safety measure, always unset a referenced array value as soon as the loop is over
254
// If we still have members in $responses, they were not event staff as of this execution
255
// NOTE: Theoretically, an event staff person could have an an event staff record but no
256
// event staff status record (the source for the collection), however, operationally, this
257
// case should not occur since all newly generated staff pool members are given a default
260
// Either way, we should warn the user that these records will not be updated
261
$eventMsg = 'Event staff with IDs {' . implode(',', array_keys($responses)) . '} are no ' .
262
'longer valid members of this event. Skipping response updates.';
263
$this->logWarn($eventMsg);
265
// here's the big to-do; let's save!
270
* Method to map a message response to a database-understood status type.
271
* @param string $response
273
protected static function mapResponse( $response )
275
//@todo make this do something
b'\\ No newline at end of file'