/** * @param CalendarService $calendarService * * @return CalendarPdf */ public function render(CalendarService $calendarService) { $pdf = new CalendarPdf(); $pdf->setTemplate($this->getModuleOptions()->getCalendarContactTemplate()); $pdf->addPage(); $pdf->SetFontSize(9); $twig = $this->getServiceLocator()->get('ZfcTwigRenderer'); $calendarContacts = $calendarService->findCalendarContactsByCalendar($calendarService->getCalendar()); //Create chunks of arrays per 13, as that amount fits on the screen $paginatedContacts = array_chunk($calendarContacts, 13); $minAmountOfPages = max(sizeof($paginatedContacts), 2); for ($i = 0; $i < $minAmountOfPages; $i++) { /* * Use the NDA object to render the filename */ $contactListContent = $twig->render('calendar/pdf/calendar-contact', ['calendarService' => $calendarService, 'calendarContacts' => isset($paginatedContacts[$i]) ? $paginatedContacts[$i] : []]); $pdf->writeHTMLCell(0, 0, 14, 42, $contactListContent); /* * Don't add a new page on the last iteration */ if ($i < $minAmountOfPages - 1) { $pdf->addPage(); } } return $pdf; }
/** * @param CalendarService $calendarService * @param ContactService $contactService */ public function __construct(CalendarService $calendarService, ContactService $contactService) { parent::__construct(); $this->setAttribute('method', 'post'); $this->setAttribute('class', 'form-horizontal'); $this->setAttribute('action', ''); $contacts = []; foreach ($contactService->findPossibleContactByCalendar($calendarService->getCalendar()) as $contact) { $contacts[$contact->getId()] = $contact->getDisplayName(); } $this->add(['type' => 'Zend\\Form\\Element\\MultiCheckbox', 'name' => 'contact', 'options' => ['value_options' => $contacts, 'label' => _("txt-contact-name")]]); $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-update")]]); $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'cancel', 'attributes' => ['class' => "btn btn-warning", 'value' => _("txt-cancel")]]); }