public function processRemoveScheduleAction() { $weekday = (int) $this->_getParam('weekday') - 1; $scheduleDate = date('Y-m-d', strtotime($this->_getParam('scheduleDate'))); $providerId = (int) $this->_getParam('providerId'); $roomId = (int) $this->_getParam('roomId'); $scheduleEventId = (int) $this->_getParam('id'); $weekDates = ScheduleEvent::computeWeekDates($scheduleDate); $date = $weekDates['start']; if ($weekday > 0) { $date = date('Y-m-d', strtotime("+{$weekday} days", strtotime($date))); } if ($scheduleEventId > 0) { $scheduleEvent = new ScheduleEvent(); $scheduleEvent->scheduleEventId = $scheduleEventId; $scheduleEvent->setPersistMode(WebVista_Model_ORM::DELETE); $scheduleEvent->persist(); } $start = $date . ' 00:00:00'; $end = $date . ' 23:59:59'; $filters = array(); $filters['providerId'] = $providerId; $filters['roomId'] = $roomId; $filters['start'] = $start; $filters['end'] = $end; $scheduleEventIterator = new ScheduleEventIterator(null, false); $scheduleEventIterator->setFilters($filters); $data = array(); foreach ($scheduleEventIterator as $row) { $data[] = $this->_getEvent($row->scheduleEventId); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
public function listEventsAction() { $filters = array(); $filters['start'] = date('Y-m-d 00:00:00'); $filters['providerId'] = (int) $this->_getParam('providerId'); $filters['roomId'] = (int) $this->_getParam('roomId'); $scheduleEventIterator = new ScheduleEventIterator(); $scheduleEventIterator->setFilters($filters); $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(array('rows' => $scheduleEventIterator->toJsonArray('scheduleEventId', array('title', 'start', 'end')))); }
protected function generateEventColumnData($columnIndex) { $columnIndex = (int) $columnIndex; $columnData = array(); $scheduleEventIterator = new ScheduleEventIterator(); $appointmentIterator = new AppointmentIterator(); if (!isset($this->getCurrentDisplayFilter()->columns[$columnIndex])) { throw new Exception(__("Cannot generate column with that index, there is no filter defined for that column Index: ") . $columnIndex); } $this->_session->currentAppointments[$columnIndex] = array(); $filter = $this->getCurrentDisplayFilter(); $filterTimeStart = strtotime($filter->start); $filterTimeEnd = strtotime($filter->end); $paramFilters = $filter->columns[$columnIndex]; if (isset($paramFilters['dateFilter'])) { $filter->date = date('Y-m-d', strtotime($paramFilters['dateFilter'])); } $paramFilters['start'] = $filter->date . ' ' . $filter->start; $paramFilters['end'] = $filter->date . ' ' . $filter->end; $paramFilters['start'] = $filter->date . ' ' . $filter->start; $paramFilters['end'] = $filter->date . ' 23:59:59'; $scheduleEventIterator->setFilter($paramFilters); // we need to get the length of time to create number of rows in the grid $timeLen = ($filterTimeEnd - $filterTimeStart) / 60 / $filter->increment; for ($i = 0; $i <= $timeLen; $i++) { $row = array(); // assign row id as rowNumber and columnIndex $row['id'] = $i . $columnIndex; $row['data'][0] = ''; $columnData[$i] = $row; } $filterToTimeStart = strtotime($paramFilters['start']); $appointmentIterator->setFilter($paramFilters); // hold the temporary data counter $tmpDataCtr = array(); $colMultiplier = 1; $patient = new Patient(); $room = new Room(); $zIndex = 0; foreach ($appointmentIterator as $row) { $startToTime = strtotime($row->start); $endToTime = strtotime($row->end); $tmpStart = date('H:i', $startToTime); $tmpEnd = date('H:i', $endToTime); $timeLen = ($endToTime - $startToTime) / 60 / $filter->increment; $tmpIndex = ($startToTime - $filterToTimeStart) / 60 / $filter->increment; if (!isset($columnData[$tmpIndex])) { break; } $index = $tmpIndex; for ($j = 1; $j <= $timeLen; $j++) { if (!isset($columnData[$index])) { break; } $index++; } $j--; $height = 20 * $j * 1.1; $marginLeft = 8; $multiplier = 1; // generate ranges code inside if ($multiplier === 1) block $incTime = $startToTime; $ranges = array(); for ($ctr = 1; $ctr <= $timeLen; $ctr++) { $ranges[] = date('H:i', $incTime); $incTime = strtotime("+{$filter->increment} minutes", $incTime); } // check for appointment intersection foreach ($tmpDataCtr as $keyCtr => $dataCtr) { if (in_array($tmpStart, $dataCtr['ranges'])) { // merge the ranges if we need to have a nested multiple bookings // uncomment if this is not the case and move the generate ranges to its proper location for code optimization $tmpDataCtr[$keyCtr]['ranges'] = array_merge($dataCtr['ranges'], $ranges); $tmpDataCtr[$keyCtr]['multiplier']++; $multiplier = $tmpDataCtr[$keyCtr]['multiplier']; break; } } if ($multiplier === 1) { $tmpDataCtr[] = array('ranges' => $ranges, 'multiplier' => $multiplier); } else { $marginLeft = ($multiplier - 1) * 250; } if ($multiplier > $colMultiplier) { $colMultiplier = $multiplier; } $patient->setPersonId($row->patientId); $patient->populate(); $person = $patient->person; $room->setRoomId($row->roomId); $room->populate(); $this->_session->currentAppointments[$columnIndex][$row->appointmentId] = $row; $mark = ''; if (strlen($row->appointmentCode) > 0) { $mark = "({$row->appointmentCode})"; } $zIndex++; // where to use room? $columnData[$tmpIndex]['id'] = $row->appointmentId . 'i' . $columnData[$tmpIndex]['id']; $appointmentId = $row->appointmentId; $columnData[$tmpIndex]['data'][0] .= "<div style=\"float:left;position:absolute;margin-top:-11.9px;height:{$height}px;width:230px;overflow:hidden;border:thin solid black;margin-left:{$marginLeft}px;padding-left:2px;background-color:lightgrey;z-index:{$zIndex};\" class=\"dataForeground\" id=\"event{$appointmentId}\" onmouseover=\"expandAppointment({$appointmentId},this);\" onmouseout=\"shrinkAppointment({$appointmentId},this,{$height},{$zIndex});\">{$tmpStart}-{$tmpEnd} <a href=\"\">{$person->last_name}, {$person->first_name} (#{$row->patientId})</a> <div class=\"bottomInner\" id=\"bottomInnerId{$appointmentId}\">{$row->title} {$mark}</div></div>"; $columnData[$tmpIndex]['userdata']['appointmentId'] = $row->appointmentId; } $columnData[0]['userdata']['colMultiplier'] = $colMultiplier; $columnData[0]['userdata']['providerId'] = $paramFilters['providerId']; $roomId = 0; if (isset($paramFilters['roomId'])) { $roomId = $paramFilters['roomId']; } $columnData[0]['userdata']['roomId'] = $roomId; foreach ($scheduleEventIterator as $event) { $x = explode(' ', $event->start); $eventTimeStart = strtotime($x[1]); $x = explode(' ', $event->end); $eventTimeEnd = strtotime($x[1]); // get the starting index $index = ($eventTimeStart - $filterTimeStart) / 60 / $filter->increment; $tmpIndex = $index; $color = $event->provider->color; if ($event->roomId > 0 && strlen($event->room->color) > 0) { $color = $event->room->color; } if (substr($color, 0, 1) != '#') { $color = '#' . $color; } while ($eventTimeStart < $eventTimeEnd) { $eventDateTimeStart = date('Y-m-d H:i:s', $eventTimeStart); $eventTimeStart = strtotime("+{$filter->increment} minutes", $eventTimeStart); $columnData[$tmpIndex]['style'] = 'background-color:' . $color . ';border-color:lightgrey;'; $columnData[$index]['userdata']['title'] = $event->title; $tmpIndex++; } } $ret = array(); $ret['rows'] = $columnData; return $ret; }