public function appliance()
 {
     try {
         $params = $this->request->allParams();
         $company_url_segment = Convert::raw2sql($params["ID"]);
         $slug = Convert::raw2sql($params["Slug"]);
         $query = new QueryObject();
         $query->addAndCondition(QueryCriteria::equal('Slug', $slug));
         $appliance = $this->appliance_repository->getBy($query);
         if (!$appliance) {
             throw new NotFoundEntityException('', '');
         }
         $this->company_service_ID = $appliance->getIdentifier();
         if ($appliance->getCompany()->URLSegment != $company_url_segment) {
             throw new NotFoundEntityException('', '');
         }
         $render = new ApplianceSapphireRender($appliance);
         return $render->draw();
     } catch (Exception $ex) {
         return $this->httpError(404, 'Sorry that Appliance could not be found!.');
     }
 }
 public function draft_pdf()
 {
     $html_inner = '';
     $marketplace_type = $this->request->param('MARKETPLACETYPE');
     $instance_id = intval($this->request->param('ID'));
     $base = Director::baseFolder();
     $query = new QueryObject();
     $query->addAndCondition(QueryCriteria::id('ID', $instance_id));
     switch (strtolower($marketplace_type)) {
         case 'distribution':
             $distribution = $this->distribution_draft_repository->getBy($query);
             if (!$distribution) {
                 throw new NotFoundEntityException('', '');
             }
             $render = new DistributionSapphireRender($distribution);
             $distribution->IsPreview = true;
             $html_inner = $render->pdf();
             $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css");
             break;
         case 'appliance':
             $appliance = $this->appliance_draft_repository->getBy($query);
             $appliance->IsPreview = true;
             $render = new ApplianceSapphireRender($appliance);
             $html_inner = $render->pdf();
             $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css");
             break;
         case 'public_cloud':
             $public_cloud = $this->public_clouds_draft_repository->getBy($query);
             $public_cloud->IsPreview = true;
             if (!$public_cloud) {
                 throw new NotFoundEntityException('', '');
             }
             $render = new PublicCloudSapphireRender($public_cloud);
             $html_inner = $render->pdf();
             $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css");
             break;
         case 'private_cloud':
             $private_cloud = $this->private_clouds_draft_repository->getBy($query);
             $private_cloud->IsPreview = true;
             $render = new PrivateCloudSapphireRender($private_cloud);
             $html_inner = $render->pdf();
             $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css");
             break;
         case 'consultant':
             $consultant = $this->consultant_draft_repository->getBy($query);
             if (!$consultant) {
                 throw new NotFoundEntityException('', '');
             }
             $consultant->IsPreview = true;
             $render = new ConsultantSapphireRender($consultant);
             $html_inner = $render->pdf();
             $css = @file_get_contents($base . "/marketplace/code/ui/admin/css/pdf.css");
             break;
         default:
             $this->httpError(404);
             break;
     }
     //create pdf
     $file = FileUtils::convertToFileName('preview') . '.pdf';
     $html_outer = sprintf("<html><head><style>%s</style></head><body><div class='container'>%s</div></body></html>", str_replace("@host", $base, $css), $html_inner);
     try {
         $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(15, 5, 15, 5));
         //$html2pdf->addFont('Open Sans', '', $base.'/themes/openstack/assets/fonts/PT-Sans/PTC75F-webfont.ttf');
         $html2pdf->setTestIsImage(false);
         $html2pdf->WriteHTML($html_outer);
         //clean output buffer
         ob_end_clean();
         $html2pdf->Output($file, "D");
     } catch (HTML2PDF_exception $e) {
         $message = array('errno' => '', 'errstr' => $e->__toString(), 'errfile' => 'UserStory.php', 'errline' => '', 'errcontext' => '');
         SS_Log::log($message, SS_Log::ERR);
         $this->httpError(404, 'There was an error on PDF generation!');
     }
 }