public function __invoke(Reservation $reservation, $dateStart = null, $dateEnd = null, $search = null) { $view = $this->getView(); $html = ''; $booking = $reservation->needExtra('booking'); switch ($booking->need('status')) { case 'cancelled': $attr = ' class="gray"'; break; default: $attr = null; break; } $html .= sprintf('<tr %s>', $attr); $html .= sprintf('<td class="status-col right-text">%s</td>', $view->t($booking->getStatus())); $html .= sprintf('<td>%s</td>', $booking->need('bid')); if ($booking->getExtra('user')) { $userName = $booking->getExtra('user')->get('alias'); } else { $userName = $booking->need('uid'); } $html .= sprintf('<td><b>%s</b></td>', $userName); /* Date and time col */ $date = new \DateTime($reservation->get('date')); $fullDate = $view->dateFormat($date, \IntlDateFormatter::FULL); $fullDateParts = explode(', ', $fullDate); $html .= sprintf('<td>%s</td>', $fullDateParts[0]); $html .= sprintf('<td>%s</td>', $view->dateFormat($date, \IntlDateFormatter::MEDIUM)); $html .= sprintf('<td>%s</td>', $view->timeRange($reservation->get('time_start'), $reservation->get('time_end'), '%s to %s')); /* Square col */ if ($booking->get('sid')) { $squareName = $this->squareManager->get($booking->get('sid'))->get('name'); } else { $squareName = '-'; } $html .= sprintf('<td>%s</td>', $squareName); /* Notes col */ $notes = $booking->getMeta('notes'); if ($notes) { if (strlen($notes) > 48) { $notes = substr($notes, 0, 48) . '…'; } $notes = '<span class="small-text">' . $notes . '</span>'; } else { $notes = '-'; } $html .= sprintf('<td class="notes-col">%s</td>', $notes); /* Actions col */ if ($booking->get('status') == 'cancelled') { $html .= '<td class="actions-col no-print"> </td>'; } else { $html .= sprintf('<td class="actions-col no-print"><a href="%s" class="unlined gray symbolic symbolic-edit">%s</a></td>', $view->url('backend/booking/edit', [], ['query' => ['ds' => $date->format('Y-m-d'), 'ts' => substr($reservation->get('time_start'), 0, 5), 'te' => substr($reservation->get('time_end'), 0, 5), 's' => $booking->get('sid'), 'r' => $reservation->get('rid')]]), $view->t('Edit')); } $html .= '</tr>'; return $html; }
/** * Deletes one reservation and all respective meta properties (through database foreign keys). * * @param int|Reservation $reservation * @return int * @throws InvalidArgumentException */ public function delete($reservation) { if ($reservation instanceof Reservation) { $rid = $reservation->need('rid'); } else { $rid = $reservation; } if (!(is_numeric($rid) && $rid > 0)) { throw new InvalidArgumentException('Reservation id must be numeric'); } $reservation = $this->get($rid); $deletion = $this->reservationTable->delete(array('rid' => $rid)); $this->getEventManager()->trigger('delete', $reservation); return $deletion; }