示例#1
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());
 }
 /**
  * (non-PHPdoc)
  * @see \PartKeepr\Service\RestfulService::destroy()
  */
 public function destroy()
 {
     $this->requireParameter("id");
     PrintingJobConfigurationManager::getInstance()->deleteEntity($this->getParameter("id"));
     return array("data" => null);
 }