/** * Allows a user access to download a document from a workshop * */ public function downloadDocumentAction() { $get = Zend_Registry::get('getFilter'); if (!isset($get->workshopDocumentId)) { throw new Ot_Exception_Input('msg-error-workshopIdsNotSet'); } $document = new Workshop_Document(); $thisDocument = $document->find($get->workshopDocumentId); if (is_null($thisDocument)) { throw new Ot_Exception_Data('msg-error-noDocument'); } $config = Zend_Registry::get('config'); if (!is_readable($config->user->fileUploadPathWorkshop->val)) { throw new Ot_Exception_Data('msg-error-targetDirNotReadable'); } $target = $config->user->fileUploadPathWorkshop->val . '/' . $thisDocument->workshopId . '/' . $thisDocument->name; if (!is_file($target)) { throw new Ot_Exception_Data('msg-error-fileNotFound'); } $this->_helper->viewRenderer->setNeverRender(); $this->view->layout()->disableLayout(); header('Content-Type: application/octetstream'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; ' . 'filename="' . $thisDocument->name . '"'); readfile($target); }
public function getEventsForUser($accountId) { $config = Zend_Registry::get('config'); $attendee = new Event_Attendee(); $instructor = new Event_Instructor(); $location = new Location(); $document = new Workshop_Document(); $account = new Ot_Account(); $eu = new Evaluation_User(); $stayOpen = new Zend_Date(); $stayOpen->subHour($config->user->numHoursEvaluationAvailability->val); $locationCache = array(); $reservations = $attendee->getEventsForAttendee($accountId); $time = time(); foreach ($reservations as &$r) { $r['active'] = false; // we determine if the class is open $startDt = new Zend_Date(strtotime($r['date'] . ' ' . $r['startTime'])); $endDt = new Zend_Date(strtotime($r['date'] . ' ' . $r['endTime'])); $endDt->addHour($config->user->numHoursEvaluationAvailability->val); $r['evaluatable'] = $this->isEvaluatable($r['eventId']); // checks to see if its possible that the class is open for evaluation if ($r['evaluatable'] && !$eu->hasCompleted($accountId, $r['eventId'])) { $r['active'] = true; } elseif ($startDt->getTimestamp() > $time) { $r['active'] = true; } $r = array_merge(array('startDt' => $startDt->getTimestamp()), $r); $r['hasHandouts'] = false; $documents = $document->getDocumentsForWorkshop($r['workshopId']); if (count($documents) > 0) { $r['hasHandouts'] = true; } $r['cancelable'] = false; if ($r['active']) { $startDt->subHour($config->user->numHoursEventCancel->val); $r['cancelable'] = $startDt->getTimestamp() > $time; if ($r['status'] == 'waitlist') { $waiting = $attendee->getAttendeesForEvent($r['eventId'], 'waitlist'); $position = 1; foreach ($waiting as $w) { if ($accountId == $w['accountId']) { break; } $position++; } $r['waitlistPosition'] = $position; } } } // Get presently taught classes $teaching = $instructor->getEventsForInstructor($accountId); foreach ($teaching as &$t) { $startDt = new Zend_Date(strtotime($t['date'] . ' ' . $t['startTime'])); $endDt = new Zend_Date(strtotime($t['date'] . ' ' . $t['endTime'])); $endDt->addHour($config->user->numHoursEvaluationAvailability->val); $t = array_merge(array('startDt' => $startDt->getTimestamp()), $t); $t['active'] = false; // checks to see if its possible that the class is open for evaluation if ($endDt->getTimestamp() > $time) { $t['active'] = true; } $t['status'] = 'instructor'; } $events = array_merge($reservations, $teaching); // sort by event order $eDates = array(); foreach ($events as $key => $value) { $eDates[$key] = $value['startDt']; } asort($eDates); $newEvents = array(); foreach (array_keys($eDates) as $key) { $newEvents[] = $events[$key]; } $events = $newEvents; $currentEvents = array(); $pastEvents = array(); foreach ($events as $e) { $where = $instructor->getAdapter()->quoteInto('eventId = ?', $e['eventId']); $instructors = $instructor->fetchAll($where); $instructorIds = array(); foreach ($instructors as $i) { $instructorIds[] = $i->accountId; } if (count($instructorIds) != 0) { $accounts = $account->fetchAll($account->getAdapter()->quoteInto('accountId IN (?)', $instructorIds), array('lastName', 'firstName')); foreach ($accounts as $a) { $e['instructors'][] = $a->firstName . ' ' . $a->lastName; } } if (isset($locationCache[$e['locationId']])) { $e['location'] = $locationCache[$e['locationId']]; } else { $thisLocation = $location->find($e['locationId']); if (is_null($thisLocation)) { throw new Ot_Exception_Data('Location not found'); } $e['location'] = $thisLocation->toArray(); $locationCache[$e['locationId']] = $e['location']; } if ($e['active']) { $currentEvents[] = $e; } else { if ($e['status'] != 'waitlist') { $pastEvents[] = $e; } } } $ret = array('currentEvents' => $currentEvents, 'pastEvents' => array_reverse($pastEvents)); return $ret; }