예제 #1
0
 /**
  * Processes data via HTTP POST. Reads php://input and creates a temporary image out of it.
  */
 public function uploadCam()
 {
     $tempFile = tempnam("/tmp", "PWC") . ".jpg";
     $result = file_put_contents($tempFile, file_get_contents('php://input'));
     $image = new TempUploadedFile();
     $image->replace($tempFile);
     $image->setOriginalFilename(sprintf(PartKeepr::i18n("Cam photo of %s"), date("Y-m-d H:i:s")) . ".jpg");
     PartKeepr::getEM()->persist($image);
     PartKeepr::getEM()->flush();
     return array("id" => $image->getId(), "extension" => $image->getExtension(), "size" => $image->getSize(), "originalFilename" => $image->getOriginalFilename());
 }
예제 #2
0
 /**
  * Prints the selected storage locations to a dedicated file
  * and returns the url to this file.
  */
 public function startExport()
 {
     $this->requireParameter("ids");
     $this->requireParameter("configuration");
     $this->requireParameter("objectType");
     $ids = explode(',', $this->getParameter("ids"));
     $configurationId = $this->getParameter("configuration");
     $objectType = $this->getParameter("objectType");
     $printerUser = null;
     if ($this->hasParameter("target") && $this->getParameter("target") != "") {
         $printerUser = UserManager::getInstance()->getUser($this->getParameter("target"));
     }
     // check object type for valid object types for security reasons.
     // See Select query below and be aware of SQL injection!
     if (!array_key_exists($objectType, $this->availableObjectTypes)) {
         throw new RendererNotFoundException("Object type is forbidden!", $objectType, array_keys($this->availableObjectTypes));
     }
     $configuration = PrintingJobConfigurationManager::getInstance()->getEntity($configurationId);
     $query = PartKeepr::getEM()->createQuery("SELECT s FROM {$objectType} s WHERE s.id IN (?1)");
     $query->setParameter(1, $ids);
     $dataToRender = $query->getResult();
     $renderingObjects = array();
     if ($configuration->getPageLayout() !== null) {
         $renderingObjects[] = $configuration->getPageLayout();
     }
     $renderer = RendererFactoryRegistry::getInstance()->getRendererFactory($configuration->getExportRenderer())->createInstance($renderingObjects, $configuration->getRendererConfiguration());
     $renderer->passRenderingData($dataToRender);
     $tempFile = tempnam("/tmp", "PWC");
     $renderer->storeResult($tempFile);
     $tmpFile = new TempUploadedFile();
     $tmpFile->replace($tempFile);
     $tmpFile->setOriginalFilename("generatedFile." . $renderer->getSuggestedExtension());
     PartKeepr::getEM()->persist($tmpFile);
     PartKeepr::getEM()->flush();
     //Create a job if we have a valid printer target
     if ($printerUser !== null) {
         $job = new PrintingJob();
         $job->setData($tmpFile);
         $job->setTarget($printerUser);
         PartKeepr::getEM()->persist($job);
         PartKeepr::getEM()->flush();
     }
     return array("fileid" => $tmpFile->getId());
 }