Commit 8aca0f03 authored by Yan Loetzer's avatar Yan Loetzer Committed by Paul Smith
Browse files

By yanniboi: Ticket Printing additions.

parent fc923ccc
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
ticket_printing:
  css:
    theme:
      css/print.css: {}

ticket_viewing:
  css:
    theme:
      css/print.css: { media: print }
+81 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Primary module hooks for Contacts Events Printing module.
 */

use Drupal\contacts_events\Entity\EventType;
use Drupal\contacts_events\Entity\Ticket;
use Drupal\contacts_events\Entity\TicketType;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
@@ -13,6 +14,63 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\entity\BundleFieldDefinition;

/**
 * Implements hook_theme().
 */
function contacts_events_printing_theme() {
  return [
    'ticket_printing_content' => [
      'template' => 'ticket-printing-content',
      'variables' => [
        'ticket' => NULL,
        'show_badge' => FALSE,
        'show_address' => FALSE,
        'logo' => '',
        'badge_logo' => '',
        'badge_image' => '',
        'order_id' => '',
        'contact_id' => '',
        'ticket_id' => '',
        'team' => '',
        'address' => '',
        'name' => '',
        'first_name' => '',
        'event_name' => '',
        'event_date' => '',
        'booking_reference' => '',
        'ticket_class' => '',
        'barcode' => '',
        'letter_text' => '',
        'company_address' => '',
        'company_registration' => '',
        'segments' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_entity_type_build().
 */
function contacts_events_printing_entity_type_build(array &$entity_types) {
  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  $entity_types['contacts_ticket']->setLinkTemplate('booking_ticket', '/booking/{commerce_order}/ticket/{contacts_ticket}');
  $entity_types['contacts_ticket']->setLinkTemplate('booking_ticket_print', '/booking/{commerce_order}/ticket/{contacts_ticket}/print');
}

/**
 * Implements hook_theme_registry_alter().
 *
 * Add ticket printing specific page template alter suggestion.
 */
function contacts_events_printing_theme_registry_alter(&$theme_registry) {
  $theme_registry['page__booking__ticket__render'] = [
    'template' => 'page--booking--ticket--render',
    'path' => drupal_get_path('module', 'contacts_events_printing') . '/templates',
    'base hook' => 'page',
  ];
}

/**
 * Implements hook_entity_field_storage_info().
 */
@@ -77,6 +135,13 @@ function contacts_events_printing_entity_extra_field_info() {
    ];
  }

  foreach (EventType::loadMultiple() as $bundle) {
    $extra['contacts_event'][$bundle->id()]['form']['settings_ticket_printing'] = [
      'label' => new TranslatableMarkup('Enable Ticket Printing'),
      'visible' => FALSE,
    ];
  }

  return $extra;
}

@@ -90,3 +155,19 @@ function contacts_events_printing_contacts_events_ticket_form_alter(array &$form
    $form['print_log']['#weight'] = $options['weight'];
  }
}

/**
 * Implements hook_contacts_event_form_alter().
 */
function contacts_events_printing_form_contacts_event_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  /** @var \Drupal\contacts_events\Entity\EventInterface $entity */
  $entity = $form_state->getFormObject()->getEntity();
  $form['settings_ticket_printing'] = [
    '#type' => 'checkbox',
    '#title' => new TranslatableMarkup('Enable Ticket Printing'),
    '#description' => new TranslatableMarkup('Booking managers and Ticket holders can download paid in full tickets.'),
    '#default_value' => $entity->getSetting('printing.enabled'),
    '#parents' => array_merge($form['#parents'] ?? [],
      ['settings', 'printing', 'enabled']),
  ];
}
+70 −0
Original line number Diff line number Diff line
# Ticket printing routes.
entity.contacts_ticket.booking_ticket:
  path: '/booking/ticket/{contacts_ticket}'
  defaults:
    _controller: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::viewTicket'
    _title_callback: '\Drupal\Core\Entity\Controller\EntityController::title'
  requirements:
    _custom_access: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::ticketAccess'
  options:
    parameters:
      commerce_order:
        type: 'entity:commerce_order'
      contacts_ticket:
        type: 'entity:contacts_ticket'

entity.contacts_ticket.booking_ticket_print:
  path: '/booking/ticket/{contacts_ticket}/print'
  defaults:
    _controller: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::printTicket'
  requirements:
    _custom_access: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::ticketAccess'
  options:
    parameters:
      commerce_order:
        type: 'entity:commerce_order'
      contacts_ticket:
        type: 'entity:contacts_ticket'

entity.commerce_order.booking_print:
  path: '/booking/order/{commerce_order}/print'
  defaults:
    _controller: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::printBooking'
  requirements:
    _custom_access: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::bookingAccess'
  options:
    parameters:
      commerce_order:
        type: 'entity:commerce_order'
      contacts_ticket:
        type: 'entity:contacts_ticket'

entity.contacts_ticket.booking_ticket_print_render:
  path: '/booking/ticket/{contacts_ticket}/{token}/render'
  defaults:
    _controller: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::renderTicket'
  requirements:
    _custom_access: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::renderTicketAccess'
  options:
    parameters:
      contacts_ticket:
        type: 'entity:contacts_ticket'
      token:
        type: 'string'
    no_cache: 'TRUE'

entity.commerce_order.booking_print_render:
  path: '/booking/order/{commerce_order}/{token}/render'
  defaults:
    _controller: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::renderBooking'
  requirements:
    _custom_access: '\Drupal\contacts_events_printing\Controller\TicketPrintingController::renderBookingAccess'
  options:
    parameters:
      commerce_order:
        type: 'entity:commerce_order'
      contacts_ticket:
        type: 'entity:contacts_ticket'
      token:
        type: 'string'
    no_cache: 'TRUE'
+22 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Views hook implementations for Contacts Events Printing.
 */

use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Implements hook_views_data().
 */
function contacts_events_printing_views_data() {
  $data['commerce_order']['ticket_link'] = [
    'group' => new TranslatableMarkup('Order'),
    'title' => new TranslatableMarkup("Download ticket link"),
    'real field' => 'order_id',
    'field' => ['id' => 'contacts_events_printing_ticket_link'],
  ];

  return $data;
}
+306 −0
Original line number Diff line number Diff line
/** Hide website bits we don't want **/
@font-face {
  font-family: "DejaVuSans";
  src: url("../fonts/DejaVu-Sans.ttf.woff") format("woff");
}

body {
  padding: 0;
  margin: 0;
  background: none !important;
  font-family: "DejaVuSans";
  font-size: 14px;
  line-height: 1.2;
}

.toolbar-horizontal {
  padding: 0;
}

header,
.checkout-progress,
.breadcrumb-wrapper,
.toolbar {
  display: none !important;
}

p {
  margin: 0;
}
p + p {
  margin-top: 1em;
}

/* Set up the page */
@page {
  height: 29.7cm;
  width: 21cm;

  -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;    /* Firefox, other Gecko */
  box-sizing: border-box;         /* Opera/IE 8+ */
}

.ticket-letter {
  height: 29.7cm;
  width: 21cm;
  padding: 1cm 1.25cm;
  margin: 0;

  -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;    /* Firefox, other Gecko */
  box-sizing: border-box;         /* Opera/IE 8+ */

  page-break-after: always;
  position: relative;
}

.preview .ticket-letter:after {
  content: "Preview";
  color: rgba(32, 41, 106, 0.3);
  font-size: 16em;

  position: absolute;
  left: 0;
  right: 0;

  text-align: center;
  overflow: hidden;
}

/* General layout */
.ticket-letter-header {
  border-bottom: solid black 2px;
  height: 4cm;
  margin-bottom: 10pt;
}

.ticket-letter-top {
  margin-bottom: 4pt;
}

.ticket-letter-top .name,
.ticket-letter-top .contacts-id,
.ticket-letter-top .booking-ref,
.ticket-letter-top .ticket-class,
.ticket-letter-top .ticket-team,
.ticket-letter-top .ticket-id {
}

.ticket-letter-ticket {
  background: #fff;

  height: 5.9cm;
  width: 9cm;
  padding: 0.5cm;
  position: absolute;
  bottom: 0;
  border: 1px dashed #000000;

  -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;    /* Firefox, other Gecko */
  box-sizing: border-box;         /* Opera/IE 8+ */
}

/* Specific styling */
.ticket-letter-header .logo {
  position: absolute;
  top: 0.5cm;
  right: 1.25cm;
}
.ticket-letter-header .headline {
  position: absolute;
  top: 0.5cm;
  width: 90%;
  text-align: center;
}

.pane-ticket-badge > h2 {
  font-size: inherit;
  font-weight: normal;
  position: absolute;
  top: 9.5em;
  right: -22em;
  margin: 0;
  text-align: center;
}

/** Ticket Badge **/
.pane-ticket-badge .panel-col-top {
}

.pane-ticket-badge .panel-col-top {
  padding-left: 145px;
}

.pane-ticket-badge .panel-col-top:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}

.pane-ticket-badge .panel-col-top .logo {
  float:left;
  margin-left: -145px;
  margin-top: -10px;
}

.pane-ticket-badge .panel-col-top .barcode {
  margin-top: -10px;
  float: left;
}

.pane-ticket-badge .panel-col-top p + p {
  margin: 0;
}

.pane-ticket-badge .panel-col-top .pane-commerce-booking-ticket-commerce-booking-ticket-class {
  font-weight: bold;
}

.pane-ticket-badge .panel-col-top .commerce-booking-ticket-reg-no {
  font-size: 1.3em;
}

.pane-ticket-badge .panel-col-top .commerce-booking-ticket-ticket-id {
  font-size: 0.75em;
}

.pane-ticket-badge .center-wrapper:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}

.pane-ticket-badge .center-wrapper .panel-col-first {
  width: 50%;
  text-align: center;
  float: left;
}
.pane-ticket-badge .center-wrapper .panel-col-first .commerce-booking-ticket-holder-name {
  font-size: 2em;
  max-height: 3em;
  overflow: hidden;
  word-wrap: normal;
}

.pane-ticket-badge .center-wrapper .panel-col-last {
  margin-top: -30px;
  width: auto;
  float: right;
}

.pane-ticket-badge .panel-col-bottom {
  text-align: center;
}

.pane-ticket-badge .commerce-booking-ticket-holder-name  p {
  margin: 0;
}

/** Tables in Ticket Letters **/
.ticket-letter table {
  border: none;
  border-bottom: solid #000000 2px;
  padding-bottom: 5px;
  width: 100%;
  border-collapse:collapse;
}

.ticket-letter thead th, div.ticket-letter th {
  background: none;
  color: #000000;
  text-align: left;
  border-bottom: none;
}
.ticket-letter thead th {
  border-bottom: solid #000000 2px;
}

.ticket-letter tr.even, div.ticket-letter tr.odd {
  background: none;
  border: none;
  color: #000000;
}

.ticket-letter tr.even td, div.ticket-letter tr.odd td {
  background: none;
}

/** Order Summary specific tweaks **/
.commerce-order-print .ticket-letter-top-left {
  padding: 0;
}

.ticket-letter .booking-summary-title h3 {
  font-size: 2em;
}

/* Summer ticket badge tweaks */
.pane-ticket-badge-summer .panel-col-top .commerce-booking-ticket-holder-name,
.pane-ticket-badge-summer .pane-ce-printing-ticket-badge-event .title {
  font-size: 1.4em;
  line-height: 1.4em;
  font-family: "Playfair Display";
  overflow: hidden;
  height: 27.44px;
}

.pane-ticket-badge-summer .panel-col-top .commerce-booking-ticket-holder-name{
  font-size: 1.7em;
  margin-top: 0.2cm;
}

.pane-ticket-badge-summer .pane-ticket-class {
  border-bottom: 0.2cm solid #fff;
}

.ticket-badge-summer-under-18 .pane-ticket-class {
  border-bottom-color: black;
}

.pane-ticket-badge-summer .panel-col-top {
  padding-left: 5px;
}

.pane-ticket-badge.pane-ticket-badge-summer .field-name-contacts-indiv-photo {
  float: left;
}
.pane-ticket-badge.pane-ticket-badge-summer .logo {
  float: right;
  margin-left: 20px;
}

.pane-ticket-badge.pane-ticket-badge-summer .logo img {
  width: 70px !important;
}

.pane-ticket-badge-summer .panel-col-top .commerce-booking-ticket-reg-no {
  font-size: 1em;
  margin-bottom: 0.2cm;
  margin-top: 0.1cm;
}

.pane-ticket-badge-summer .panel-col-top .commerce-booking-ticket-holder-name,
.pane-ticket-badge-summer .pane-ce-printing-ticket-badge-event .title,
.pane-ticket-badge-summer .pane-ce-printing-ticket-badge-event .subtitle {
  font-weight: 900;
}

.pane-ticket-badge-summer .pane-ce-printing-ticket-badge-event .subtitle {
  text-transform: uppercase;
  font-size: 1em;
  padding: 2px 0px;
  margin-left: -2px;
}

.pane-ticket-badge-summer .pane-ce-printing-ticket-badge-event .subtitle-alt {
  background: black;
  padding: 2px 4px;
  color: white;
  margin-left: 0px;
}
Loading