Пример #1
0
 public function executeDailyLog(sfWebRequest $request)
 {
     $this->form = new ReportDailyLogForm();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             $month = $this->form->getValue('date_month');
             $this->year = $year = $this->form->getValue('date_year');
             $first_day = mktime(0, 0, 0, $month, 1, $year);
             $last_day = strtotime('+1 month -1 second', $first_day);
             $c = new Criteria();
             // only in this date range (the month selected)
             $c->add(NoteEntryPeer::SERVICE_DATE, $first_day, Criteria::GREATER_EQUAL);
             $c->addAnd(NoteEntryPeer::SERVICE_DATE, $last_day, Criteria::LESS_EQUAL);
             // include absent? lets go with no
             $c->add(NoteEntryPeer::ABSENT, 0);
             // sort by kids name
             $c->addAscendingOrderByColumn(ClientPeer::LAST_NAME);
             $c->addAscendingOrderByColumn(NoteEntryPeer::SERVICE_DATE);
             $c->addAscendingOrderByColumn(NoteEntryPeer::TIME_IN);
             // only the selected type
             if ($this->form->getValue('service_type')) {
                 $c->add(ClientServicePeer::OBJECT_TYPE, $this->form->getValue('service_type'));
             }
             $entries = NoteEntryPeer::doSelectJoinAll($c);
             // build array of all entries in the selected time period indexed by ID
             $this->all_entries = array();
             foreach ($entries as $entry) {
                 $this->all_entries[$entry->getId()] = $entry;
             }
             // build an array of overlaps of client
             $this->overlaps = array();
             $client_entry_times = array();
             $provider_entry_times = array();
             foreach ($this->all_entries as $anEntry) {
                 // skip grouped kids, for now
                 if (!$anEntry->inGroup()) {
                     if (!array_key_exists($anEntry->getEmployeeId(), $provider_entry_times)) {
                         $provider_entry_times[$anEntry->getEmployeeId()] = array();
                     }
                     $provider_entry_times[$anEntry->getEmployeeId()][$anEntry->getId()] = array($anEntry->getTimeIn('U'), $anEntry->getTimeOut('U'));
                 }
                 if (!array_key_exists($anEntry->getClientId(), $client_entry_times)) {
                     $client_entry_times[$anEntry->getClientId()] = array();
                 }
                 $client_entry_times[$anEntry->getClientId()][$anEntry->getId()] = array($anEntry->getTimeIn('U'), $anEntry->getTimeOut('U'));
             }
             // find clients with overlapping times
             foreach ($client_entry_times as $client_id => $client_entries) {
                 $entry_times[$client_id] = sort2d($client_entries, 0);
                 $previous = array(0, 0, 0);
                 foreach ($entry_times[$client_id] as $entry_id => $times) {
                     // this in time happened before previous out time.. we have a overlap
                     if ($times[0] < $previous[1] && $entry_id != $previous[2]) {
                         $this->overlaps[$entry_id] = $previous[2];
                         $this->overlaps[$previous[2]] = $entry_id;
                     }
                     $previous = array($times[0], $times[1], $entry_id);
                 }
             }
             // find providers with overlapping times
             foreach ($provider_entry_times as $client_id => $client_entries) {
                 $entry_times[$client_id] = sort2d($client_entries, 0);
                 $previous = array(0, 0, 0);
                 foreach ($entry_times[$client_id] as $entry_id => $times) {
                     // this in time happened before previous out time.. we have a overlap
                     if ($times[0] < $previous[1] && $entry_id != $previous[2]) {
                         $this->overlaps[$entry_id] = $previous[2];
                         $this->overlaps[$previous[2]] = $entry_id;
                     }
                     $previous = array($times[0], $times[1], $entry_id);
                 }
             }
             // initialize
             $this->classrooms = array();
             //        foreach($this->overlaps as $key => $blah) { echo $key .' => '. $blah->getId() .'<br />'; }
             //        die();
             foreach ($this->all_entries as $entry) {
                 // only kids that have been serviced by this employee
                 if (!$this->form->getValue('employee_id') || $this->form->getValue('employee_id') == $entry->getEmployeeId()) {
                     $office = $entry->getOffice();
                     $client = $entry->getClient();
                     $week = $entry->getServiceDate('W');
                     if (!is_object($office)) {
                         $office = new Office();
                         $office->setName('N/A');
                     }
                     // let's see if we have entered any for this classroom yet
                     if (!array_key_exists($office->getName(), $this->classrooms)) {
                         $this->classrooms[$office->getName()] = array_fill_keys(range(date('W', $first_day), date('W', $last_day)), array());
                     }
                     // initialize the row for this kid
                     if (!array_key_exists($week, $this->classrooms[$office->getName()]) || !array_key_exists($client->getFullName(), $this->classrooms[$office->getName()][$week])) {
                         $days = array();
                         for ($day = 1; $day <= 5; $day++) {
                             $days[date('m/d/Y', strtotime($entry->getServiceDate('Y') . "W" . $week . $day))] = array();
                         }
                         $this->classrooms[$office->getName()][$week][$client->getFullName()] = $days;
                     }
                     // save the entry to the appropriate cell in the table
                     $this->classrooms[$office->getName()][$week][$client->getFullName()][$entry->getServiceDate('m/d/Y')][] = $entry;
                 }
             }
             //        $weeks = array(
             //            'week_num' => array(
             //                'client_name' => array(
             //                    'date' => array(
             //                        'service_type' => 'cell data, time, absent, etc.'
             //                    )
             //                )
             //            )
             //        );
             return 'Report';
         }
     }
 }