public function draft_preview()
 {
     $marketplace_type = $this->request->param('MARKETPLACETYPE');
     $instance_id = intval($this->request->param('ID'));
     $query = new QueryObject();
     $query->addAndCondition(QueryCriteria::id('ID', $instance_id));
     Requirements::block("marketplace/code/ui/admin/css/marketplace.admin.css");
     Requirements::block(Director::protocol() . "code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css");
     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;
             return $render->draw();
             break;
         case 'appliance':
             $appliance = $this->appliance_draft_repository->getBy($query);
             $appliance->IsPreview = true;
             $render = new ApplianceSapphireRender($appliance);
             return $render->draw();
             break;
         case 'public_cloud':
             $public_cloud = $this->public_clouds_draft_repository->getBy($query);
             $public_cloud->IsPreview = true;
             $public_cloud->IsDraft = true;
             if (!$public_cloud) {
                 throw new NotFoundEntityException('', '');
             }
             $render = new PublicCloudSapphireRender($public_cloud);
             return $render->draw();
             break;
         case 'private_cloud':
             $private_cloud = $this->private_clouds_draft_repository->getBy($query);
             $private_cloud->IsPreview = true;
             $private_cloud->IsDraft = true;
             $render = new PrivateCloudSapphireRender($private_cloud);
             return $render->draw();
             break;
         case 'consultant':
             $consultant = $this->consultant_draft_repository->getBy($query);
             if (!$consultant) {
                 throw new NotFoundEntityException('', '');
             }
             $consultant->IsPreview = true;
             $consultant->IsDraft = true;
             $render = new ConsultantSapphireRender($consultant);
             return $render->draw();
             break;
         default:
             $this->httpError(404);
             break;
     }
 }
 function renderCloud()
 {
     try {
         $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));
         $this->current_cloud = $this->cloud_repository->getBy($query);
         if (!$this->current_cloud) {
             throw new NotFoundEntityException('', '');
         }
         if ($this->current_cloud->getCompany()->URLSegment != $company_url_segment) {
             throw new NotFoundEntityException('', '');
         }
         // we need this for reviews.
         $this->company_service_ID = $this->current_cloud->getIdentifier();
         $render = new PrivateCloudSapphireRender($this->current_cloud);
         return $render->draw();
     } catch (Exception $ex) {
         return $this->httpError(404, 'Sorry that Private Cloud  could not be found!.');
     }
 }