public function getAttendeesForEvent($eventId, $status = 'all', $attended = false) { $where = $this->getAdapter()->quoteInto('eventId = ?', $eventId); if ($status != 'all') { $where .= ' AND ' . $this->getAdapter()->quoteInto('status = ?', $status); } if ($attended) { $where .= ' AND ' . $this->getAdapter()->quoteInto('attended = ?', $attended); } $result = $this->fetchAll($where, 'timestamp ASC')->toArray(); $accountIds = array(); foreach ($result as $r) { $accountIds[] = $r['accountId']; } if (count($accountIds) == 0) { return array(); } $account = new Ot_Account(); $where = $account->getAdapter()->quoteInto('accountId IN (?)', $accountIds); $accounts = $account->fetchAll($where, array('lastName', 'firstName'))->toArray(); $accountMap = array(); foreach ($accounts as $a) { $accountMap[$a['accountId']] = $a; } foreach ($result as &$r) { if (!isset($accountMap[$r['accountId']])) { $accountMap[$r['accountId']] = array('firstName' => 'Unavailable', 'lastName' => 'Unavailable', 'username' => 'Unavailable'); } $r = array_merge($r, $accountMap[$r['accountId']]); } return $result; }
public function getInstructorsForEvent($eventId) { $where = $this->getAdapter()->quoteInto('eventId = ?', $eventId); $result = $this->fetchAll($where); $accountIds = array(); foreach ($result as $r) { $accountIds[] = $r->accountId; } if (count($accountIds) == 0) { return array(); } $account = new Ot_Account(); $where = $account->getAdapter()->quoteInto('accountId IN (?)', $accountIds); return $account->fetchAll($where, array('lastName', 'firstName'))->toArray(); }
/** * Allows a user to view the details of a workshop * */ public function detailsAction() { $get = Zend_Registry::get('getFilter'); if (!isset($get->workshopId)) { throw new Ot_Exception_Input('msg-error-workshopIdNotSet'); } $workshop = new Workshop(); $thisWorkshop = $workshop->find($get->workshopId); if (is_null($thisWorkshop)) { throw new Ot_Exception_Data('msg-error-noWorkshop'); } $document = new Workshop_Document(); $this->view->documents = $document->getDocumentsForWorkshop($thisWorkshop->workshopId); $tag = new Tag(); $this->view->tags = $tag->getTagsForAttribute('workshopId', $thisWorkshop->workshopId); $event = new Event(); $events = $event->getEvents($thisWorkshop->workshopId, null, null, time(), null, 'open')->toArray(); $auth = Zend_Auth::getInstance(); foreach ($events as &$e) { if ($auth->hasIdentity()) { $e['status'] = $event->getStatusOfUserForEvent($auth->getIdentity()->accountId, $e['eventId']); } else { $e['status'] = ''; } $e['workshop'] = $thisWorkshop->toArray(); } $this->view->events = $events; $wl = new Workshop_Link(); $this->view->links = $wl->getLinksForWorkshop($thisWorkshop->workshopId)->toArray(); $location = new Location(); $locations = $location->fetchAll(); $locs = array(); foreach ($locations as $l) { $locs[$l->locationId] = $l->toArray(); } $this->view->locations = $locs; $we = new Workshop_Editor(); $isEditor = false; if ($this->_helper->hasAccess('edit-all-workshops')) { $isEditor = true; } elseif ($auth->hasIdentity()) { $isEditor = $we->isEditor($thisWorkshop->workshopId, $auth->getIdentity()->accountId); } $this->view->acl = array('edit' => $isEditor, 'addDocuments' => $isEditor, 'editDocument' => $isEditor, 'deleteDocument' => $isEditor, 'addLink' => $isEditor, 'deleteLink' => $isEditor, 'editLink' => $isEditor, 'reorderLink' => $isEditor, 'addEvent' => $this->_helper->hasAccess('index', 'workshop_schedule'), 'options' => $this->_helper->hasAccess('options')); if ($this->view->acl['edit']) { $we = new Workshop_Editor(); $where = $we->getAdapter()->quoteInto('workshopId = ?', $thisWorkshop->workshopId); $results = $we->fetchAll($where); $currentEditors = array(); foreach ($results as $r) { $currentEditors[] = $r->accountId; } if (count($currentEditors) != 0) { $account = new Ot_Account(); $accounts = $account->fetchAll($account->getAdapter()->quoteInto('accountId IN (?)', $currentEditors), array('lastName', 'firstName')); $currentEditors = $accounts->toArray(); } $this->view->editors = $currentEditors; } $category = new Category(); $thisCategory = $category->find($thisWorkshop->categoryId); $this->view->layout()->setLayout('twocolumn'); $this->view->layout()->rightContent = $this->view->render('index/right.phtml'); $this->view->messages = $this->_helper->flashMessenger->getMessages(); $this->view->title = $thisWorkshop->title; $this->view->workshop = $thisWorkshop->toArray(); $this->view->category = $thisCategory; }
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; }