/** * Format an answer attachment * @param \array $attachment * @param \Jazzee\Entity\Page $page * * @return array */ protected function arrayAnswerAttachment(array $attachment, \Jazzee\Entity\Page $page) { $attachment['filePath'] = false; $attachment['thumbnailPath'] = false; $base = $page->getTitle() . '_attachment_' . $attachment['id']; //remove slashes in path to fix an apache issues with encoding slashes in redirects $base = str_replace(array('/', '\\'), 'slash', $base); $pdfName = $base . '.pdf'; $pngName = $base . 'preview.png'; \Jazzee\Globals::getFileStore()->createSessionFile($pdfName, $attachment['attachmentHash']); $attachment['filePath'] = \Jazzee\Globals::path('file/' . \urlencode($pdfName)); if (!empty($attachment['thumbnailHash'])) { \Jazzee\Globals::getFileStore()->createSessionFile($pngName, $arr['thumbnailHash']); $attachment['thumbnailPath'] = \Jazzee\Globals::path('file/' . \urlencode($pngName)); } else { $attachment['thumbnailPath'] = \Jazzee\Globals::path('resource/foundation/media/default_pdf_logo.png'); } $attachment['displayValue'] = "<a href='{$attachment['filePath']}'><img src='{$attachment['thumbnailPath']}' /></a>"; return $attachment; }
/** * Copy a Page * @param \Doctrine\ORM\EntityManager $em * @param \Jazzee\Entity\Page $page * @return \Jazzee\Entity\Page */ public function copyPage(\Doctrine\ORM\EntityManager $em, \Jazzee\Entity\Page $page) { $newPage = new \Jazzee\Entity\Page(); $newPage->setTitle($page->getTitle()); $newPage->setMax($page->getMax()); $newPage->setInstructions($page->getInstructions()); $newPage->setLeadingText($page->getLeadingText()); $newPage->setTrailingText($page->getTrailingText()); $newPage->setFixedId($page->getFixedId()); $newPage->setType($em->getRepository('\\Jazzee\\Entity\\PageType')->findOneByClass($page->getType()->getClass())); if ($page->isGlobal()) { $newPage->makeGlobal(); } else { $newPage->notGlobal(); } if ($page->isRequired()) { $newPage->required(); } else { $newPage->optional(); } foreach ($page->getChildren() as $child) { $newPage->addChild($this->copyPage($em, $child)); } foreach ($page->getVariables() as $variable) { $newPage->setVar($variable->getName(), $variable->getValue()); } foreach ($newPage->getVariables() as $variable) { $em->persist($variable); } foreach ($page->getElements() as $element) { $newElement = new \Jazzee\Entity\Element(); $newElement->setType($em->getRepository('\\Jazzee\\Entity\\ElementType')->findOneByClass($element->getType()->getClass())); $newElement->setWeight($element->getWeight()); $newElement->setFixedId($element->getFixedId()); $newElement->setTitle($element->getTitle()); $newElement->setMax($element->getMax()); $newElement->setMin($element->getMin()); $newElement->setInstructions($element->getInstructions()); $newElement->setDefaultValue($element->getDefaultValue()); $newElement->setFormat($element->getFormat()); if ($element->isRequired()) { $newElement->required(); } else { $newElement->optional(); } foreach ($element->getListItems() as $item) { $newItem = new \Jazzee\Entity\ElementListItem(); $newItem->setValue($item->getValue()); $newItem->setWeight($item->getWeight()); $newElement->addItem($newItem); $em->persist($newItem); } $em->persist($newElement); $newPage->addElement($newElement); } $em->persist($newPage); return $newPage; }
/** * Add a new page * * Do this in a deperate funciton so it can call itself * @param \Jazzee\Entity\Page $previousPage * @return \Jazzee\Entity\Page */ protected function addPage(\Jazzee\Entity\Page $previousPage) { if ($previousPage->isGlobal()) { $page = $previousPage; } else { $page = new \Jazzee\Entity\Page(); $page->setType($previousPage->getType()); $page->setTitle($previousPage->getTitle()); $page->setMin($previousPage->getMin()); $page->setMax($previousPage->getMax()); if ($previousPage->isRequired()) { $page->required(); } else { $page->optional(); } if ($previousPage->answerStatusDisplay()) { $page->showAnswerStatus(); } else { $page->hideAnswerStatus(); } $page->setInstructions($previousPage->getInstructions()); $page->setLeadingText($previousPage->getLeadingText()); $page->setTrailingText($previousPage->getTrailingText()); $page->notGlobal(); $this->_em->persist($page); foreach ($previousPage->getElements() as $previousElement) { $element = new \Jazzee\Entity\Element(); $element->setType($previousElement->getType()); $element->setFixedId($previousElement->getFixedId()); $element->setTitle($previousElement->getTitle()); $element->setMin($previousElement->getMin()); $element->setMax($previousElement->getMax()); $element->setName($previousElement->getName()); if ($previousElement->isRequired()) { $element->required(); } else { $element->optional(); } $element->setInstructions($previousElement->getInstructions()); $element->setFormat($previousElement->getFormat()); $element->setWeight($previousElement->getWeight()); $page->addElement($element); foreach ($previousElement->getListItems() as $previousItem) { $listItem = new \Jazzee\Entity\ElementListItem(); $listItem->setValue($previousItem->getValue()); $listItem->setWeight($previousItem->getWeight()); $listItem->setName($previousItem->getName()); if ($previousItem->isActive()) { $listItem->activate(); } else { $listItem->deactivate(); } $element->addItem($listItem); $this->_em->persist($listItem); } $this->_em->persist($element); } foreach ($previousPage->getVariables() as $previousVar) { $var = $page->setVar($previousVar->getName(), $previousVar->getValue()); $this->_em->persist($var); } foreach ($previousPage->getChildren() as $previousChild) { $childPage = $this->addPage($previousChild); $page->addChild($childPage); } } return $page; }
/** * Render standrad LOR pdf section * @param \Jazzee\ApplicantPDF $pdf * @param \Jazzee\Entity\Page $page * @param \Jazzee\Entity\Answer $answer */ public function renderLorPdfAnswer(\Jazzee\ApplicantPDF $pdf, \Jazzee\Entity\Page $page, \Jazzee\Entity\Answer $answer) { $pdf->addText($page->getTitle() . "\n", 'h5'); $this->renderPdfAnswer($pdf, $page, $answer); }
/** * Create an xml node for a page * * Calls itself recursivly to capture all children * @param DomDocument $xml * @param \Jazzee\Entity\Page $page */ public function pageXml(DOMDocument $dom, $page) { $pxml = $dom->createElement('page'); $pxml->setAttribute('title', htmlentities($page->getTitle(), ENT_COMPAT, 'utf-8')); $pxml->setAttribute('min', $page->getMin()); $pxml->setAttribute('max', $page->getMax()); $pxml->setAttribute('required', $page->isRequired()); $pxml->setAttribute('answerStatusDisplay', $page->answerStatusDisplay()); $pxml->appendChild($this->createCdataElement($dom, 'instructions', $page->getInstructions())); $pxml->appendChild($this->createCdataElement($dom, 'leadingText', $page->getLeadingText())); $pxml->appendChild($this->createCdataElement($dom, 'trailingText', $page->getTrailingText())); if ($page instanceof \Jazzee\Entity\ApplicationPage) { $pxml->setAttribute('weight', $page->getWeight()); $pxml->setAttribute('kind', $page->getKind()); $pxml->setAttribute('name', $page->getName()); $page = $page->getPage(); if ($page->isGlobal()) { $pxml->setAttribute('globalPageUuid', $page->getUuid()); } } $pxml->setAttribute('class', $page->getType()->getClass()); $elements = $pxml->appendChild($dom->createElement('elements')); foreach ($page->getElements() as $element) { $exml = $dom->createElement('element'); $exml->setAttribute('title', $element->getTitle()); $exml->setAttribute('name', $element->getName()); $exml->setAttribute('class', $element->getType()->getClass()); $exml->setAttribute('fixedId', $element->getFixedId()); $exml->setAttribute('weight', $element->getWeight()); $exml->setAttribute('min', $element->getMin()); $exml->setAttribute('max', $element->getMax()); $exml->setAttribute('required', $element->isRequired()); $exml->setAttribute('instructions', htmlentities($element->getInstructions(), ENT_COMPAT, 'utf-8')); $exml->setAttribute('format', htmlentities($element->getFormat(), ENT_COMPAT, 'utf-8')); $exml->setAttribute('defaultValue', $element->getDefaultValue()); $listItems = $exml->appendChild($dom->createElement('listitems')); foreach ($element->getListItems() as $item) { //only export active items if ($item->isActive()) { $ixml = $this->createCdataElement($dom, 'item', $item->getValue()); $ixml->setAttribute('active', (int) $item->isActive()); $ixml->setAttribute('weight', $item->getWeight()); $ixml->setAttribute('name', $item->getName()); $listItems->appendChild($ixml); unset($ixml); } } $elements->appendChild($exml); } $children = $pxml->appendChild($dom->createElement('children')); foreach ($page->getChildren() as $child) { $children->appendChild($this->pageXml($dom, $child)); } $variables = $pxml->appendChild($dom->createElement('variables')); foreach ($page->getVariables() as $var) { $variable = $dom->createElement('variable', (string) $var->getValue()); $variable->setAttribute('name', $var->getName()); $variables->appendChild($variable); } return $pxml; }
/** * Render branching LOR pdf section * @param \Jazzee\ApplicantPDF $pdf * @param \Jazzee\Entity\Page $page * @param \Jazzee\Entity\Answer $answer */ public function renderLorPdfAnswer(\Jazzee\ApplicantPDF $pdf, \Jazzee\Entity\Page $page, \Jazzee\Entity\Answer $answer) { $childAnswer = $answer->getChildren()->first(); $childPage = $childAnswer->getPage(); $pdf->addText($page->getTitle() . "\n", 'h5'); $pdf->addText("{$page->getVar('branchingElementLabel')}: ", 'b'); $pdf->addText("{$childPage->getTitle()}\n", 'p'); $this->renderPdfAnswer($pdf, $childPage, $childAnswer); }