$issue->setEnteredByPerson_id($id); } } if (!empty($i['reportedByPerson']['_id'])) { $id = getPersonIdFromCrosswalk($i['reportedByPerson']['_id']); if ($id) { $issue->setReportedByPerson_id($id); } } if (!empty($i['labels'])) { $issue->setLabels($i['labels']); } $issue->save(); if (isset($i['history'])) { foreach ($i['history'] as $h) { createHistory($issue, $h); } } if (isset($i['responses'])) { foreach ($i['responses'] as $res) { $response = new Response(); $response->setIssue($issue); if (!empty($res['date'])) { $d = DateTime::createFromFormat('U', $res['date']->sec); $response->setDate($d->format('Y-m-d H:i:s')); } if (!empty($res['contactMethod'])) { handleContactMethod($response, $res, 'contactMethod'); } if (!empty($res['notes'])) { $response->setNotes($res['notes']);
function cacheHistory($stream) { if ($stream['song'] == 'Not found') { return; } $year = date('Y'); $month = date('m'); $day = date('d'); if (!is_dir('history')) { mkdir('history', 0777); } if (!is_dir('history/' . $year)) { mkdir('history/' . $year); } if (!is_dir('history/' . $year . '/' . $month)) { mkdir('history/' . $year . '/' . $month); } $file = 'history/' . $year . '/' . $month . '/' . $day . '.json'; $history['time'] = gmdate('c'); $history['artist'] = $stream['info']['artist']; $history['song'] = $stream['info']['song']; $history['image'] = $stream['album']['image_s']; $history['itunes'] = $stream['track']['buylink']['download']['iTunes']['link']; $history['Amazon'] = $stream['track']['buylink']['download']['Amazon']['link']; $history = array_encode($history); file_put_contents($file, json_encode($history)); createHistory(); }