/**
  * @return ISurveyTemplate
  */
 public function getCurrentSurveyTemplate()
 {
     $query = new QueryObject();
     $now = new \DateTime('now', new DateTimeZone('UTC'));
     $query->addAndCondition(QueryCriteria::lowerOrEqual('StartDate', $now->format('Y-m-d H:i:s')));
     $query->addAndCondition(QueryCriteria::greaterOrEqual('EndDate', $now->format('Y-m-d H:i:s')));
     $query->addAndCondition(QueryCriteria::equal('Enabled', 1));
     return $this->template_repository->getBy($query);
 }
 public function getCurrentOfficesStaticMapForPDF()
 {
     $static_map_url = "http://maps.googleapis.com/maps/api/staticmap?zoom=2&size=300x200&maptype=roadmap";
     $params = $this->request->allParams();
     $company_url_segment = Convert::raw2sql($params["Company"]);
     $slug = Convert::raw2sql($params["Slug"]);
     $query = new QueryObject();
     $query->addAndCondition(QueryCriteria::equal('Slug', $slug));
     $consultant = $this->consultant_repository->getBy($query);
     if (!$consultant) {
         throw new NotFoundEntityException('Consultant', 'by slug');
     }
     if ($consultant->getCompany()->URLSegment != $company_url_segment) {
         throw new NotFoundEntityException('', '');
     }
     foreach ($consultant->getOffices() as $office) {
         $static_map_url .= "&markers=" . $office->getLat() . "," . $office->getLng();
     }
     return $static_map_url;
 }
 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!');
     }
 }