Skip to content

Instantly share code, notes, and snippets.

@tareko
Created September 29, 2015 11:45
Show Gist options
  • Save tareko/6fbec0a6a6b478c400d9 to your computer and use it in GitHub Desktop.
Save tareko/6fbec0a6a6b478c400d9 to your computer and use it in GitHub Desktop.
Controller code
function icsView() {
$masterSet = array();
if (strlen(strstr($this->request->referer(), 'wizard'))>0) {
$this->set('id', $this->request->params['named']['id']);
$this->render('ics_link');
}
if (isset($this->request->data['Shift'][0]['id'])) {
$this->request->params['named']['id'] = $this->request->data['Shift'][0]['id'];
}
if (!isset($this->request->params['named']['id'])) {
return $this->setAction('physicianList', 'icsView');
}
$shiftList = $this->Shift->getShiftList(
array (
'Shift.date >=' => date('Y-m-d', strtotime("-6 months")),
'Shift.user_id' => $this->request->params['named']['id'],
)
);
$locationSet = $this->Shift->ShiftsType->Location->getLocations();
$shiftsTypeSetRaw = $this->Shift->ShiftsType->find('all', array(
'fields' => array('ShiftsType.comment', 'ShiftsType.shift_start', 'ShiftsType.shift_end'),
'conditions' => array(
'ShiftsType.expiry_date >=' => date('Y-m-d', strtotime("-6 months")),
),
'recursive' => '0',
)
);
foreach ($shiftsTypeSetRaw as $shiftsTypeSetRaw) {
$shiftsTypeSet[$shiftsTypeSetRaw['ShiftsType']['id']]['comment'] = $shiftsTypeSetRaw['ShiftsType']['comment'];
$shiftsTypeSet[$shiftsTypeSetRaw['ShiftsType']['id']]['shift_start'] = $shiftsTypeSetRaw['ShiftsType']['shift_start'];
$shiftsTypeSet[$shiftsTypeSetRaw['ShiftsType']['id']]['shift_end'] = $shiftsTypeSetRaw['ShiftsType']['shift_end'];
}
$i = 1;
foreach ($shiftList as $shift) {
$masterSet[$i]['id'] = $shift['Shift']['id'];
$masterSet[$i]['date'] = $shift['Shift']['date'];
$masterSet[$i]['location'] = $locationSet[$shift['ShiftsType']['location_id']]['location'];
$masterSet[$i]['shift_start'] = $shiftsTypeSet[$shift['Shift']['shifts_type_id']]['shift_start'];
$masterSet[$i]['shift_end'] = $shiftsTypeSet[$shift['Shift']['shifts_type_id']]['shift_end'];
$masterSet[$i]['comment'] = $shiftsTypeSet[$shift['Shift']['shifts_type_id']]['comment'];
$masterSet[$i]['display_name'] = $shift['User']['Profile']['cb_displayname'];
$i++;
}
$this->set('masterSet', $masterSet);
$this->render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment