Esempio n. 1
0
 public function previewAction()
 {
     /**
      * @var ExpenseTicket $expenseService
      */
     $expenseService = $this->getServiceLocator()->get('service_finance_expense_expense_ticket');
     $attachmenType = $this->params()->fromQuery('type', ExpenseTicket::ATTACHMENT_PREVIEW_TYPE_TICKET);
     $id = $this->params()->fromQuery('id', null);
     $width = $this->params()->fromQuery('width', 100);
     $height = $this->params()->fromQuery('height', 100);
     switch ($attachmenType) {
         case ExpenseTicket::ATTACHMENT_PREVIEW_TYPE_TICKET:
             $path = $expenseService->getAttachmentPathById($id);
             break;
         case ExpenseTicket::ATTACHMENT_PREVIEW_TYPE_ITEM:
             $path = $expenseService->getItemAttachmentPathById($id);
             break;
     }
     list($imageWidth, $imageHeight) = getimagesize($path);
     if ($imageWidth && $imageHeight) {
         if ($imageWidth > $imageHeight) {
             $width = $height * $imageWidth / $imageHeight;
         } else {
             $height = $width * $imageHeight / $imageWidth;
         }
     }
     header('Pragma: public');
     header('Cache-Control: max-age = 604800');
     header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT');
     Helper::thumbnail($path, $width, $height);
 }