public function distribution()
 {
     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));
         $distribution = $this->distribution_repository->getBy($query);
         if (!$distribution) {
             throw new NotFoundEntityException('', '');
         }
         if ($distribution->getCompany()->URLSegment != $company_url_segment) {
             throw new NotFoundEntityException('', '');
         }
         // we need this for reviews.
         $this->company_service_ID = $distribution->getIdentifier();
         $render = new DistributionSapphireRender($distribution);
         return $render->draw();
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->httpError(404, 'Sorry that Distribution could not be found!.');
     }
 }
 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;
     }
 }