Example #1
0
 public function send(User $recipient, $subject, $text, array $attachments = array())
 {
     $fromAddress = $this->configManager->need('mail.address');
     $fromName = $this->optionManager->need('client.name.short') . ' ' . $this->optionManager->need('service.name.full');
     $replyToAddress = $this->optionManager->need('client.contact.email');
     $replyToName = $this->optionManager->need('client.name.full');
     $toAddress = $recipient->need('email');
     $toName = $recipient->need('alias');
     $text = sprintf("%s %s,\r\n\r\n%s\r\n\r\n%s,\r\n%s %s\r\n%s", $this->t('Dear'), $toName, $text, $this->t('Sincerely'), $this->t("Your"), $fromName, $this->optionManager->need('service.website'));
     $this->baseMailService->sendPlain($fromAddress, $fromName, $replyToAddress, $replyToName, $toAddress, $toName, $subject, $text, $attachments);
 }
Example #2
0
 public function __invoke(User $user, $search = null)
 {
     $view = $this->getView();
     $html = '';
     switch ($user->need('status')) {
         case 'placeholder':
             $attr = ' class="gray"';
             break;
         default:
             $attr = null;
             break;
     }
     $html .= sprintf('<tr %s>', $attr);
     $html .= sprintf('<td>%s</td>', $user->need('uid'));
     $html .= sprintf('<td>%s</td>', $user->need('alias'));
     $html .= sprintf('<td>%s</td>', $view->t($user->getStatus()));
     /* Email col */
     $email = $user->get('email');
     if ($email) {
         $email = '<a href="mailto:' . $email . '" class="unlined" style="color: #333; opacity: 1.0;">' . $email . '</a>';
     } else {
         $email = '-';
     }
     $html .= sprintf('<td class="email-col">%s</td>', $email);
     /* Notes col */
     $notes = $user->getMeta('notes');
     if ($notes) {
         if (strlen($notes) > 48) {
             $notes = substr($notes, 0, 48) . '&hellip;';
         }
         $notes = '<span class="small-text">' . $notes . '</span>';
     } else {
         $notes = '-';
     }
     $html .= sprintf('<td class="notes-col">%s</td>', $notes);
     /* Actions col */
     $html .= sprintf('<td class="actions-col no-print"><a href="%s" class="unlined gray symbolic symbolic-edit">%s</a> &nbsp; <a href="%s" class="unlined gray symbolic symbolic-booking">%s</a></td>', $view->url('backend/user/edit', ['uid' => $user->need('uid')], ['query' => ['search' => $search]]), $view->t('Edit'), $view->url('backend/booking', [], ['query' => ['search' => '(uid = ' . $user->need('uid') . ')']]), $view->t('Bookings'));
     $html .= '</tr>';
     return $html;
 }
Example #3
0
 public function __invoke(User $user)
 {
     $view = $this->getView();
     $userBookings = $this->bookingManager->getByValidity(array('uid' => $user->need('uid')));
     if ($userBookings) {
         $this->reservationManager->getByBookings($userBookings);
         $now = new DateTime();
         $lowerLimit = clone $now;
         $lowerLimit->modify('-2 days');
         $upperLimit = clone $now;
         $upperLimit->modify('+28 days');
         $html = '';
         $html .= '<ul style=\'padding: 0px 16px 0px 28px;\'>';
         $bookingsActuallyDisplayed = 0;
         foreach ($userBookings as $booking) {
             $reservations = $booking->needExtra('reservations');
             $bookingDateTimeStart = null;
             $bookingDateTimeEnd = null;
             foreach ($reservations as $reservation) {
                 $tmpDateTimeStart = new DateTime($reservation->need('date') . ' ' . $reservation->need('time_start'));
                 $tmpDateTimeEnd = new DateTime($reservation->need('date') . ' ' . $reservation->need('time_end'));
                 if (is_null($bookingDateTimeStart) || $tmpDateTimeStart < $bookingDateTimeStart) {
                     $bookingDateTimeStart = $tmpDateTimeStart;
                 }
                 if (is_null($bookingDateTimeEnd) || $tmpDateTimeEnd < $bookingDateTimeStart) {
                     $bookingDateTimeEnd = $tmpDateTimeEnd;
                 }
             }
             if ($bookingDateTimeEnd >= $lowerLimit && $bookingDateTimeStart <= $upperLimit) {
                 $square = $this->squareManager->get($booking->need('sid'));
                 $squareType = $view->option('subject.square.type');
                 if ($bookingDateTimeStart < $now) {
                     $html .= sprintf('<li class=\'gray\'><s>%s %s &nbsp; %s</s></li>', $squareType, $view->t($square->need('name')), $view->prettyDate($bookingDateTimeStart));
                 } else {
                     $html .= sprintf('<li><span class=\'my-highlight\'>%s %s</span> &nbsp; %s</li>', $squareType, $view->t($square->need('name')), $view->prettyDate($bookingDateTimeStart));
                 }
                 $bookingsActuallyDisplayed++;
             }
         }
         $html .= '</ul>';
         if (!$bookingsActuallyDisplayed) {
             $html = '<div><em>' . $view->t('You have no imminent bookings.') . '</em></div>';
         }
         return $html;
     } else {
         return '<div><em>' . sprintf($view->t('You have not booked any %s yet.'), $view->option('subject.square.type.plural')) . '</em></div>';
     }
 }
Example #4
0
 public function createSingle(User $user, Square $square, $quantity, DateTime $dateTimeStart, DateTime $dateTimeEnd, array $bills = array())
 {
     if (!$this->connection->inTransaction()) {
         $this->connection->beginTransaction();
         $transaction = true;
     } else {
         $transaction = false;
     }
     try {
         $booking = new Booking(array('uid' => $user->need('uid'), 'sid' => $square->need('sid'), 'status' => 'single', 'status_billing' => 'pending', 'visibility' => 'public', 'quantity' => $quantity));
         $this->bookingManager->save($booking);
         $reservations = $this->reservationManager->createInRange($booking, $dateTimeStart, $dateTimeEnd);
         $booking->setExtra('reservations', $reservations);
         $pricing = $this->squarePricingManager->getFinalPricingInRange($dateTimeStart, $dateTimeEnd, $square, $quantity);
         if ($pricing) {
             $squareType = $this->optionManager->need('subject.square.type');
             $squareName = $this->t($square->need('name'));
             /** @var $dateRangeHelper DateRange  */
             $dateRangeHelper = $this->viewHelperManager->get('DateRange');
             $description = sprintf('%s %s, %s', $squareType, $squareName, $dateRangeHelper($dateTimeStart, $dateTimeEnd));
             $bookingBill = new Bill(array('description' => $description, 'quantity' => $quantity, 'time' => $pricing['seconds'], 'price' => $pricing['price'], 'rate' => $pricing['rate'], 'gross' => $pricing['gross']));
             array_unshift($bills, $bookingBill);
         }
         if ($bills) {
             $extraBills = array();
             foreach ($bills as $bill) {
                 if (!$bill instanceof Bill) {
                     throw new RuntimeException('Invalid bills array passed');
                 }
                 $bill->set('bid', $booking->need('bid'));
                 $this->billManager->save($bill);
                 $extraBills[$bill->need('bid')] = $bill;
             }
             $booking->setExtra('bills', $extraBills);
         }
         if ($transaction) {
             $this->connection->commit();
         }
         $this->getEventManager()->trigger('create.single', $booking);
         return $booking;
     } catch (Exception $e) {
         if ($transaction) {
             $this->connection->rollback();
         }
         throw $e;
     }
 }
Example #5
0
 /**
  * Deletes one user and all respective meta properties (through database foreign keys).
  *
  * @param int|User $user
  * @return int
  * @throws InvalidArgumentException
  */
 public function delete($user)
 {
     if ($user instanceof User) {
         $uid = $user->need('uid');
     } else {
         $uid = $user;
     }
     if (!(is_numeric($uid) && $uid > 0)) {
         throw new InvalidArgumentException('User id must be numeric');
     }
     $user = $this->get($uid);
     $deletion = $this->userTable->delete(array('uid' => $uid));
     $this->getEventManager()->trigger('delete', $user);
     return $deletion;
 }
Example #6
0
 /**
  * @depends testAbstractEntityConstructor
  * @expectedException \RuntimeException
  */
 public function testAbstractEntityGetNeedFailure(User $user)
 {
     $user->need('invalid');
 }