diff --git a/marketplace/code/infrastructure/active_records/CompanyService.php b/marketplace/code/infrastructure/active_records/CompanyService.php index d746669..29d9299 100644 --- a/marketplace/code/infrastructure/active_records/CompanyService.php +++ b/marketplace/code/infrastructure/active_records/CompanyService.php @@ -63,7 +63,7 @@ class CompanyService public function isDraft() { - return false; + return 0; } public function setCompany(ICompany $company) diff --git a/marketplace/code/infrastructure/active_records/CompanyServiceDraft.php b/marketplace/code/infrastructure/active_records/CompanyServiceDraft.php index 9f61a3e..b62a343 100644 --- a/marketplace/code/infrastructure/active_records/CompanyServiceDraft.php +++ b/marketplace/code/infrastructure/active_records/CompanyServiceDraft.php @@ -53,7 +53,7 @@ class CompanyServiceDraft public function isDraft() { - return true; + return 1; } public function setCompany(ICompany $company) diff --git a/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php index 3af1fcb..ad7928b 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/ApplianceCrudApi.php @@ -80,9 +80,10 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { // filters ... $this_var = $this; $current_user = $this->current_user; - $repository = $this->appliance_draft_repository; + $repository = $this->appliance_repository; + $draft_repository = $this->appliance_draft_repository; - $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user,$repository){ + $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user){ $data = $this_var->getJsonRequest(); if (!$data) return $this_var->serverError(); @@ -99,9 +100,11 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { return $this_var->permissionFailure(); }); - $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository){ + $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository,$draft_repository){ $company_service_id = intval($request->param('COMPANY_SERVICE_ID')); - $company_service = $repository->getById($company_service_id); + $is_draft = intval($this->request->param('IS_DRAFT')); + $company_service = ($is_draft) ? $draft_repository->getById($company_service_id) : $repository->getById($company_service_id); + if(!$current_user->isMarketPlaceAdminOfCompany(IAppliance::MarketPlaceGroupSlug, $company_service->getCompany()->getIdentifier())) return $this_var->permissionFailure(); }); @@ -113,7 +116,7 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { */ static $url_handlers = array( 'GET $COMPANY_SERVICE_ID!' => 'getAppliance', - 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', + 'DELETE $COMPANY_SERVICE_ID!/$IS_DRAFT!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', @@ -178,8 +181,24 @@ final class ApplianceCrudApi extends CompanyServiceCrudApi { public function deleteCompanyService(){ try { - parent::deleteCompanyService(); - return parent::deleteCompanyServiceDraft(); + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $is_draft = intval($this->request->param('IS_DRAFT')); + + if ($is_draft) { + $this->draft_manager->unRegister($this->draft_factory->buildCompanyServiceById($company_service_id)); + } else { + $this->manager->unRegister($this->factory->buildCompanyServiceById($company_service_id)); + $company_service_draft = $this->appliance_draft_repository->getByLiveServiceId($company_service_id); + if ($company_service_draft) { + $this->draft_manager->unRegister($company_service_draft); + } + } + + return $this->deleted(); + } + catch (NotFoundEntityException $ex1) { + SS_Log::log($ex1,SS_Log::ERR); + return $this->notFound($ex1->getMessage()); } catch (Exception $ex) { SS_Log::log($ex,SS_Log::ERR); diff --git a/marketplace/code/interfaces/restfull_api/marketplace/CompanyServiceCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/CompanyServiceCrudApi.php index 169c8e2..f008d5e 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/CompanyServiceCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/CompanyServiceCrudApi.php @@ -171,38 +171,30 @@ abstract class CompanyServiceCrudApi } } - /** - * @return SS_HTTPResponse - */ - public function deleteCompanyServiceDraft(){ - try { - $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); - $this->draft_manager->unRegister($this->draft_factory->buildCompanyServiceById($company_service_id)); - return $this->deleted(); - } - catch (NotFoundEntityException $ex1) { - SS_Log::log($ex1,SS_Log::ERR); - return $this->notFound($ex1->getMessage()); - } - catch (Exception $ex) { - SS_Log::log($ex,SS_Log::ERR); - return $this->serverError(); - } - } - /** * @return SS_HTTPResponse */ public function publishCompanyService(){ try { - $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $company_service_live_id = intval($this->request->param('COMPANY_SERVICE_ID')); $data = $this->getJsonRequest(); if (!$data) return $this->serverError(); - //save the draft - $this->draft_manager->updateCompanyService($data); //save the live version - $data['id'] = $data['live_service_id']; - $this->manager->updateCompanyService($data); + if ($company_service_live_id == 0) { // this means is a draft without a live version yet + $data['live_service_id'] = $this->manager->addCompanyService($data)->getIdentifier(); + //save the draft + if ($data['id']) { //it could be that the draft was never saved yet, in that case id should be 0 + $this->draft_manager->updateCompanyService($data); + } else { + $this->draft_manager->addCompanyService($data); + } + + } else { //if there is a live version of this draft, update it + $this->draft_manager->updateCompanyService($data); + $data['id'] = $data['live_service_id']; + $this->manager->updateCompanyService($data); + } + return $this->published(); } catch (EntityAlreadyExistsException $ex1) { diff --git a/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php index a8ddc8f..a3c1e43 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/ConsultantsCrudApi.php @@ -15,11 +15,14 @@ * Class ConsultantsCrudApi */ final class ConsultantsCrudApi extends CompanyServiceCrudApi { - + + /** + * @var array + */ static $url_handlers = array( 'GET languages' => 'getLanguages', 'GET $COMPANY_SERVICE_ID!' => 'getConsultant', - 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', + 'DELETE $COMPANY_SERVICE_ID!/$IS_DRAFT!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', @@ -131,9 +134,10 @@ final class ConsultantsCrudApi extends CompanyServiceCrudApi { // filters ... $this_var = $this; $current_user = $this->current_user; - $repository = $this->consultant_repository; + $repository = $this->consultant_repository; + $draft_repository = $this->consultant_draft_repository; - $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user, $repository){ + $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user){ $data = $this_var->getJsonRequest(); if (!$data) return $this->serverError(); $company_id = intval(@$data['company_id']); @@ -148,14 +152,17 @@ final class ConsultantsCrudApi extends CompanyServiceCrudApi { return $this_var->permissionFailure(); }); - $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository){ + $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository,$draft_repository){ $company_service_id = intval($request->param('COMPANY_SERVICE_ID')); - $company_service = $repository->getById($company_service_id); + $is_draft = intval($this->request->param('IS_DRAFT')); + $company_service = ($is_draft) ? $draft_repository->getById($company_service_id) : $repository->getById($company_service_id); + if(!$current_user->isMarketPlaceAdminOfCompany(IConsultant::MarketPlaceGroupSlug, $company_service->getCompany()->getIdentifier())) return $this_var->permissionFailure(); }); } + public function getConsultant(){ $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); $consultant = $this->consultant_repository->getById($company_service_id); @@ -216,8 +223,24 @@ final class ConsultantsCrudApi extends CompanyServiceCrudApi { public function deleteCompanyService(){ try { - parent::deleteCompanyService(); - return parent::deleteCompanyServiceDraft(); + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $is_draft = intval($this->request->param('IS_DRAFT')); + + if ($is_draft) { + $this->draft_manager->unRegister($this->draft_factory->buildCompanyServiceById($company_service_id)); + } else { + $this->manager->unRegister($this->factory->buildCompanyServiceById($company_service_id)); + $company_service_draft = $this->consultant_draft_repository->getByLiveServiceId($company_service_id); + if ($company_service_draft) { + $this->draft_manager->unRegister($company_service_draft); + } + } + + return $this->deleted(); + } + catch (NotFoundEntityException $ex1) { + SS_Log::log($ex1,SS_Log::ERR); + return $this->notFound($ex1->getMessage()); } catch (Exception $ex) { SS_Log::log($ex,SS_Log::ERR); diff --git a/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php index a325978..8e24253 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/DistributionCrudApi.php @@ -78,11 +78,12 @@ final class DistributionCrudApi extends CompanyServiceCrudApi { parent::__construct($manager,$draft_manager,new DistributionFactory,new DistributionDraftFactory); // filters ... - $this_var = $this; - $current_user = $this->current_user; - $repository = $this->distribution_draft_repository; + $this_var = $this; + $current_user = $this->current_user; + $repository = $this->distribution_repository; + $draft_repository = $this->distribution_draft_repository; - $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user, $repository){ + $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user){ $data = $this_var->getJsonRequest(); if (!$data) return $this->serverError(); $company_id = intval(@$data['company_id']); @@ -97,9 +98,11 @@ final class DistributionCrudApi extends CompanyServiceCrudApi { return $this_var->permissionFailure(); }); - $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository){ + $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository,$draft_repository){ $company_service_id = intval($request->param('COMPANY_SERVICE_ID')); - $company_service = $repository->getById($company_service_id); + $is_draft = intval($this->request->param('IS_DRAFT')); + $company_service = ($is_draft) ? $draft_repository->getById($company_service_id) : $repository->getById($company_service_id); + if(!$current_user->isMarketPlaceAdminOfCompany(IDistribution::MarketPlaceGroupSlug, $company_service->getCompany()->getIdentifier())) return $this_var->permissionFailure(); }); @@ -109,11 +112,11 @@ final class DistributionCrudApi extends CompanyServiceCrudApi { * @var array */ static $url_handlers = array( - 'GET $COMPANY_SERVICE_ID!' => 'getDistribution', - 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', - 'POST ' => 'addCompanyService', - 'PUT ' => 'updateCompanyService', - 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', + 'GET $COMPANY_SERVICE_ID!' => 'getDistribution', + 'DELETE $COMPANY_SERVICE_ID!/$IS_DRAFT!' => 'deleteCompanyService', + 'POST ' => 'addCompanyService', + 'PUT ' => 'updateCompanyService', + 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', ); /** @@ -175,8 +178,24 @@ final class DistributionCrudApi extends CompanyServiceCrudApi { public function deleteCompanyService(){ try { - parent::deleteCompanyService(); - return parent::deleteCompanyServiceDraft(); + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $is_draft = intval($this->request->param('IS_DRAFT')); + + if ($is_draft) { + $this->draft_manager->unRegister($this->draft_factory->buildCompanyServiceById($company_service_id)); + } else { + $this->manager->unRegister($this->factory->buildCompanyServiceById($company_service_id)); + $company_service_draft = $this->distribution_draft_repository->getByLiveServiceId($company_service_id); + if ($company_service_draft) { + $this->draft_manager->unRegister($company_service_draft); + } + } + + return $this->deleted(); + } + catch (NotFoundEntityException $ex1) { + SS_Log::log($ex1,SS_Log::ERR); + return $this->notFound($ex1->getMessage()); } catch (Exception $ex) { SS_Log::log($ex,SS_Log::ERR); diff --git a/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php index d4d98ea..59d3512 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/PrivateCloudCrudApi.php @@ -100,14 +100,15 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { SapphireTransactionManager::getInstance() ); - parent::__construct($manager,$draft_manager,new PublicCloudFactory,new PublicCloudDraftFactory); + parent::__construct($manager,$draft_manager,new PrivateCloudFactory,new PrivateCloudDraftFactory); // filters ... $this_var = $this; $current_user = $this->current_user; - $repository = $this->private_cloud_repository; + $repository = $this->private_cloud_repository; + $draft_repository = $this->private_cloud_draft_repository; - $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user, $repository){ + $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user){ $data = $this_var->getJsonRequest(); if (!$data) return $this_var->serverError(); $company_id = intval(@$data['company_id']); @@ -122,9 +123,11 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { return $this_var->permissionFailure(); }); - $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository){ + $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository,$draft_repository){ $company_service_id = intval($request->param('COMPANY_SERVICE_ID')); - $company_service = $repository->getById($company_service_id); + $is_draft = intval($this->request->param('IS_DRAFT')); + $company_service = ($is_draft) ? $draft_repository->getById($company_service_id) : $repository->getById($company_service_id); + if(!$current_user->isMarketPlaceAdminOfCompany(IPrivateCloudService::MarketPlaceGroupSlug, $company_service->getCompany()->getIdentifier())) return $this_var->permissionFailure(); }); @@ -136,7 +139,7 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { */ static $url_handlers = array( 'GET $COMPANY_SERVICE_ID!' => 'getPrivateCloud', - 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', + 'DELETE $COMPANY_SERVICE_ID!/$IS_DRAFT!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', @@ -217,8 +220,24 @@ final class PrivateCloudCrudApi extends CompanyServiceCrudApi { public function deleteCompanyService(){ try { - parent::deleteCompanyService(); - return parent::deleteCompanyServiceDraft(); + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $is_draft = intval($this->request->param('IS_DRAFT')); + + if ($is_draft) { + $this->draft_manager->unRegister($this->draft_factory->buildCompanyServiceById($company_service_id)); + } else { + $this->manager->unRegister($this->factory->buildCompanyServiceById($company_service_id)); + $company_service_draft = $this->private_cloud_draft_repository->getByLiveServiceId($company_service_id); + if ($company_service_draft) { + $this->draft_manager->unRegister($company_service_draft); + } + } + + return $this->deleted(); + } + catch (NotFoundEntityException $ex1) { + SS_Log::log($ex1,SS_Log::ERR); + return $this->notFound($ex1->getMessage()); } catch (Exception $ex) { SS_Log::log($ex,SS_Log::ERR); diff --git a/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php b/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php index b8282b7..3fd9bf7 100644 --- a/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php +++ b/marketplace/code/interfaces/restfull_api/marketplace/PublicCloudCrudApi.php @@ -105,9 +105,10 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { // filters ... $this_var = $this; $current_user = $this->current_user; - $repository = $this->public_cloud_repository; + $repository = $this->public_cloud_repository; + $draft_repository = $this->public_cloud_draft_repository; - $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user, $repository){ + $this->addBeforeFilter('addCompanyService','check_add_company',function ($request) use($this_var, $current_user){ $data = $this_var->getJsonRequest(); if (!$data) return $this->serverError(); $company_id = intval(@$data['company_id']); @@ -122,9 +123,11 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { return $this_var->permissionFailure(); }); - $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository){ + $this->addBeforeFilter('deleteCompanyService','check_delete_company',function ($request) use($this_var, $current_user,$repository,$draft_repository){ $company_service_id = intval($request->param('COMPANY_SERVICE_ID')); - $company_service = $repository->getById($company_service_id); + $is_draft = intval($this->request->param('IS_DRAFT')); + $company_service = ($is_draft) ? $draft_repository->getById($company_service_id) : $repository->getById($company_service_id); + if(!$current_user->isMarketPlaceAdminOfCompany(IPublicCloudService::MarketPlaceGroupSlug, $company_service->getCompany()->getIdentifier())) return $this_var->permissionFailure(); }); @@ -136,7 +139,7 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { */ static $url_handlers = array( 'GET $COMPANY_SERVICE_ID!' => 'getPublicCloud', - 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', + 'DELETE $COMPANY_SERVICE_ID!/$IS_DRAFT!' => 'deleteCompanyService', 'POST ' => 'addCompanyService', 'PUT ' => 'updateCompanyService', 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService', @@ -217,8 +220,24 @@ class PublicCloudCrudApi extends CompanyServiceCrudApi { public function deleteCompanyService(){ try { - parent::deleteCompanyService(); - return parent::deleteCompanyServiceDraft(); + $company_service_id = intval($this->request->param('COMPANY_SERVICE_ID')); + $is_draft = intval($this->request->param('IS_DRAFT')); + + if ($is_draft) { + $this->draft_manager->unRegister($this->draft_factory->buildCompanyServiceById($company_service_id)); + } else { + $this->manager->unRegister($this->factory->buildCompanyServiceById($company_service_id)); + $company_service_draft = $this->public_cloud_draft_repository->getByLiveServiceId($company_service_id); + if ($company_service_draft) { + $this->draft_manager->unRegister($company_service_draft); + } + } + + return $this->deleted(); + } + catch (NotFoundEntityException $ex1) { + SS_Log::log($ex1,SS_Log::ERR); + return $this->notFound($ex1->getMessage()); } catch (Exception $ex) { SS_Log::log($ex,SS_Log::ERR); diff --git a/marketplace/code/model/base_entities/CompanyServiceManager.php b/marketplace/code/model/base_entities/CompanyServiceManager.php index d4af9cf..29d766a 100644 --- a/marketplace/code/model/base_entities/CompanyServiceManager.php +++ b/marketplace/code/model/base_entities/CompanyServiceManager.php @@ -250,6 +250,10 @@ abstract class CompanyServiceManager { $company_service = $repository->getById($id); if(!$company_service) throw new NotFoundEntityException('CompanyService',sprintf("id %s",$id)); $company_service->setName($data['name']); + if ($company_service->isDraft()) { + $live_service_id = (isset($data['live_service_id'])) ? $data['live_service_id'] : 0; + $company_service->setLiveServiceId($live_service_id); + } $query = new QueryObject($company_service); $query->addAddCondition(QueryCriteria::equal('Name',$company_service->getName())); diff --git a/marketplace/code/ui/admin/MarketPlaceAdminPage.php b/marketplace/code/ui/admin/MarketPlaceAdminPage.php index 7725e45..e8c0774 100644 --- a/marketplace/code/ui/admin/MarketPlaceAdminPage.php +++ b/marketplace/code/ui/admin/MarketPlaceAdminPage.php @@ -302,9 +302,15 @@ class MarketPlaceAdminPage_Controller extends Page_Controller public function getCurrentDistribution() { $distribution_id = intval($this->request->getVar('id')); + $is_draft = intval($this->request->getVar('is_draft')); $distribution = false; if ($distribution_id > 0) { - $distribution = $this->distribution_draft_repository->getByLiveServiceId($distribution_id); + if ($is_draft) { + $distribution = $this->distribution_draft_repository->getById($distribution_id); + } else { + $distribution = $this->distribution_draft_repository->getByLiveServiceId($distribution_id); + } + //if no draft found we pull the live one to create the draft from it when saved if (!$distribution) { $distribution = $this->distribution_repository->getById($distribution_id); @@ -316,9 +322,16 @@ class MarketPlaceAdminPage_Controller extends Page_Controller public function getCurrentAppliance() { $appliance_id = intval($this->request->getVar('id')); + $is_draft = intval($this->request->getVar('is_draft')); + $appliance = false; if ($appliance_id > 0) { - $appliance = $this->appliance_draft_repository->getByLiveServiceId($appliance_id); + if ($is_draft) { + $appliance = $this->appliance_draft_repository->getById($appliance_id); + } else { + $appliance = $this->appliance_draft_repository->getByLiveServiceId($appliance_id); + } + //if no draft found we pull the live one to create the draft from it when saved if (!$appliance) { $appliance = $this->appliance_repository->getById($appliance_id); @@ -531,81 +544,113 @@ class MarketPlaceAdminPage_Controller extends Page_Controller return new ArrayList($list); } + public function sortCompanyService(&$query, $sort, $dir) + { + switch ($sort) { + case 'company': { + $query->addAlias(QueryAlias::create('Company')); + if ($dir == 'asc') + $query->addOrder(QueryOrder::asc('Company.Name')); + else + $query->addOrder(QueryOrder::desc('Company.Name')); + } + break; + case 'name': { + if ($dir == 'asc') + $query->addOrder(QueryOrder::asc('Name')); + else + $query->addOrder(QueryOrder::desc('Name')); + } + case 'type': { + $query->addAlias(QueryAlias::create('MarketPlaceType')); + if ($dir == 'asc') { + $query->addOrder(QueryOrder::asc('MarketPlaceType.Name')); + } else { + $query->addOrder(QueryOrder::desc('MarketPlaceType.Name')); + } + } + case 'status': { + if ($dir == 'asc') + $query->addOrder(QueryOrder::asc('Active')); + else + $query->addOrder(QueryOrder::desc('Active')); + } + break; + case 'updated': { + if ($dir == 'asc') + $query->addOrder(QueryOrder::asc('LastEdited')); + else + $query->addOrder(QueryOrder::desc('LastEdited')); + } + break; + case 'updatedby': { + $query->addAlias(QueryAlias::create('Member')); + if ($dir == 'asc') + $query->addOrder(QueryOrder::asc('Member.Email')); + else + $query->addOrder(QueryOrder::desc('Member.Email')); + } + break; + default: { + if ($dir == 'asc') + $query->addOrder(QueryOrder::asc('ID')); + else + $query->addOrder(QueryOrder::desc('ID')); + } + break; + } + } + public function getConsultants() { $product_name = trim(Convert::raw2sql($this->request->getVar('name'))); $company_id = intval($this->request->getVar('company_id')); $sort = $this->request->getVar('sort'); $query = new QueryObject(new CompanyService); + $query_draft = new QueryObject(new CompanyServiceDraft); + $query_draft->addAddCondition(QueryCriteria::equal('LiveServiceID', 0)); //only drafts without live version + $query->addAlias(QueryAlias::create('Company')); + $query_draft->addAlias(QueryAlias::create('Company')); + if (!empty($product_name)) { $query->addOrCondition(QueryCriteria::like('CompanyService.Name', $product_name)); $query->addOrCondition(QueryCriteria::like('Company.Name', $product_name)); + $query_draft->addOrCondition(QueryCriteria::like('CompanyService.Name', $product_name)); + $query_draft->addOrCondition(QueryCriteria::like('Company.Name', $product_name)); } if ($company_id > 0) { $query->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); + $query_draft->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); } //set sorting if (!empty($sort)) { $dir = $this->getSortDir('consultants'); - switch ($sort) { - case 'company': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Company.Name')); - else - $query->addOrder(QueryOrder::desc('Company.Name')); - } - break; - case 'name': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Name')); - else - $query->addOrder(QueryOrder::desc('Name')); - } - case 'status': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Active')); - else - $query->addOrder(QueryOrder::desc('Active')); - } - break; - case 'updated': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('LastEdited')); - else - $query->addOrder(QueryOrder::desc('LastEdited')); - } - break; - case 'updatedby': { - $query->addAlias(QueryAlias::create('Member')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Member.Email')); - else - $query->addOrder(QueryOrder::desc('Member.Email')); - } - break; - default: { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('ID')); - else - $query->addOrder(QueryOrder::desc('ID')); - } - break; - } + $this->sortCompanyService($query,$sort,$dir); + $this->sortCompanyService($query_draft,$sort,$dir); } //get consultants - list($list, $size) = $this->consultant_repository->getAll($query, 0, 1000); + list($list1, $size1) = $this->consultant_repository->getAll($query, 0, 1000); + list($list2, $size2) = $this->consultant_draft_repository->getAll($query_draft, 0, 1000); + //return on view model - return new ArrayList($list); + return new ArrayList(array_merge($list1,$list2)); + } public function getCurrentConsultant() { $consultant_id = intval($this->request->getVar('id')); + $is_draft = intval($this->request->getVar('is_draft')); $consultant = false; if ($consultant_id > 0) { - $consultant = $this->consultant_draft_repository->getByLiveServiceId($consultant_id); + if ($is_draft) { + $consultant = $this->consultant_draft_repository->getById($consultant_id); + } else { + $consultant = $this->consultant_draft_repository->getByLiveServiceId($consultant_id); + } + //if no draft found we pull the live one to create the draft from it when saved if (!$consultant) { $consultant = $this->consultant_repository->getById($consultant_id); @@ -647,83 +692,47 @@ class MarketPlaceAdminPage_Controller extends Page_Controller $company_id = intval($this->request->getVar('company_id')); $sort = $this->request->getVar('sort'); - $query = new QueryObject(new CompanyService); + $query = new QueryObject(new CompanyService); + $query_draft = new QueryObject(new CompanyServiceDraft); + $query_draft->addAddCondition(QueryCriteria::equal('LiveServiceID', 0)); + if (!empty($product_name)) { $query->addAddCondition(QueryCriteria::like('Name', $product_name)); + $query_draft->addAddCondition(QueryCriteria::like('Name', $product_name)); } if ($implementation_type_id > 0) { $query->addAddCondition(QueryCriteria::equal('MarketPlaceType.ID', $implementation_type_id)); + $query_draft->addAddCondition(QueryCriteria::equal('MarketPlaceType.ID', $implementation_type_id)); } if ($company_id > 0) { $query->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); + $query_draft->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); } //set sorting if (!empty($sort)) { $dir = $this->getSortDir('distributions'); - switch ($sort) { - case 'company': { - $query->addAlias(QueryAlias::create('Company')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Company.Name')); - else - $query->addOrder(QueryOrder::desc('Company.Name')); - } - break; - case 'name': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Name')); - else - $query->addOrder(QueryOrder::desc('Name')); - } - break; - case 'type': { - $query->addAlias(QueryAlias::create('MarketPlaceType')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('MarketPlaceType.Name')); - else - $query->addOrder(QueryOrder::desc('MarketPlaceType.Name')); - } - break; - case 'status': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Active')); - else - $query->addOrder(QueryOrder::desc('Active')); - } - break; - case 'updated': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('LastEdited')); - else - $query->addOrder(QueryOrder::desc('LastEdited')); - } - break; - case 'updatedby': { - $query->addAlias(QueryAlias::create('Member')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Member.Email')); - else - $query->addOrder(QueryOrder::desc('Member.Email')); - } - break; - default: { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('ID')); - else - $query->addOrder(QueryOrder::desc('ID')); - } - break; - } + $this->sortCompanyService($query,$sort,$dir); + $this->sortCompanyService($query_draft,$sort,$dir); } //get distributions $list1 = array(); $list2 = array(); - if ($this->canAdmin('distributions')) - list($list1, $size1) = $this->distribution_repository->getAll($query, 0, 1000); - if ($this->canAdmin('appliances')) - list($list2, $size2) = $this->appliance_repository->getAll($query, 0, 1000); - //return on view model - return new ArrayList(array_merge($list1,$list2)); + + $list3 = array(); + + if ($this->canAdmin('distributions')) { + list($list1, $size1) = $this->distribution_repository->getAll($query, 0, 1000); + list($list2, $size2) = $this->distribution_draft_repository->getAll($query_draft, 0, 1000); + } + + if ($this->canAdmin('appliances')) { + list($list3, $size3) = $this->appliance_repository->getAll($query, 0, 1000); + list($list4, $size4) = $this->appliance_draft_repository->getAll($query_draft, 0, 1000); + } + + //return on view model + return new ArrayList(array_merge($list1,$list2,$list3,$list4)); + } /** @@ -736,77 +745,47 @@ class MarketPlaceAdminPage_Controller extends Page_Controller $company_id = intval($this->request->getVar('company_id')); $sort = $this->request->getVar('sort'); $query = new QueryObject(new CompanyService); + $query_draft = new QueryObject(new CompanyServiceDraft); + $query_draft->addAddCondition(QueryCriteria::equal('LiveServiceID', 0)); if (!empty($product_name)) { $query->addAddCondition(QueryCriteria::like('Name', $product_name)); + $query_draft->addAddCondition(QueryCriteria::like('Name', $product_name)); } if ($company_id > 0) { $query->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); + $query_draft->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); } //set sorting if (!empty($sort)) { $dir = $this->getSortDir('public.clouds'); - switch ($sort) { - case 'company': { - $query->addAlias(QueryAlias::create('Company')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Company.Name')); - else - $query->addOrder(QueryOrder::desc('Company.Name')); - } - break; - case 'name': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Name')); - else - $query->addOrder(QueryOrder::desc('Name')); - } - break; - case 'status': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Active')); - else - $query->addOrder(QueryOrder::desc('Active')); - } - break; - case 'updated': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('LastEdited')); - else - $query->addOrder(QueryOrder::desc('LastEdited')); - } - break; - case 'updatedby': { - $query->addAlias(QueryAlias::create('Member')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Member.Email')); - else - $query->addOrder(QueryOrder::desc('Member.Email')); - } - break; - default: { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('ID')); - else - $query->addOrder(QueryOrder::desc('ID')); - } - break; - } + $this->sortCompanyService($query,$sort,$dir); + $this->sortCompanyService($query_draft,$sort,$dir); } //get public clouds - list($list, $size) = $this->public_clouds_repository->getAll($query, 0, 1000); + list($list1, $size1) = $this->public_clouds_repository->getAll($query, 0, 1000); + list($list2, $size2) = $this->public_clouds_draft_repository->getAll($query_draft, 0, 1000); + //return on view model - return new ArrayList($list); + + return new ArrayList(array_merge($list1,$list2)); + } public function getCurrentPublicCloud() { $public_cloud_id = intval($this->request->getVar('id')); + $is_draft = intval($this->request->getVar('is_draft')); $public_cloud = false; if ($public_cloud_id > 0) { - $public_cloud = $this->public_clouds_draft_repository->getByLiveServiceId($public_cloud_id); + if ($is_draft) { + $public_cloud = $this->public_clouds_draft_repository->getById($public_cloud_id); + } else { + $public_cloud = $this->public_clouds_draft_repository->getByLiveServiceId($public_cloud_id); + } + //if no draft found we pull the live one to create the draft from it when saved if (!$public_cloud) { $public_cloud = $this->public_clouds_repository->getById($public_cloud_id); @@ -833,77 +812,47 @@ class MarketPlaceAdminPage_Controller extends Page_Controller $company_id = intval($this->request->getVar('company_id')); $sort = $this->request->getVar('sort'); $query = new QueryObject(new CompanyService); + $query_draft = new QueryObject(new CompanyServiceDraft); + $query_draft->addAddCondition(QueryCriteria::equal('LiveServiceID', 0)); if (!empty($product_name)) { $query->addAddCondition(QueryCriteria::like('Name', $product_name)); + $query_draft->addAddCondition(QueryCriteria::like('Name', $product_name)); } if ($company_id > 0) { $query->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); + $query_draft->addAddCondition(QueryCriteria::equal('Company.ID', $company_id)); } //set sorting if (!empty($sort)) { $dir = $this->getSortDir('private.clouds'); - switch ($sort) { - case 'company': { - $query->addAlias(QueryAlias::create('Company')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Company.Name')); - else - $query->addOrder(QueryOrder::desc('Company.Name')); - } - break; - case 'name': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Name')); - else - $query->addOrder(QueryOrder::desc('Name')); - } - break; - case 'status': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Active')); - else - $query->addOrder(QueryOrder::desc('Active')); - } - break; - case 'updated': { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('LastEdited')); - else - $query->addOrder(QueryOrder::desc('LastEdited')); - } - break; - case 'updatedby': { - $query->addAlias(QueryAlias::create('Member')); - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('Member.Email')); - else - $query->addOrder(QueryOrder::desc('Member.Email')); - } - break; - default: { - if ($dir == 'asc') - $query->addOrder(QueryOrder::asc('ID')); - else - $query->addOrder(QueryOrder::desc('ID')); - } - break; - } + $this->sortCompanyService($query,$sort,$dir); + $this->sortCompanyService($query_draft,$sort,$dir); } //get public clouds - list($list, $size) = $this->private_clouds_repository->getAll($query, 0, 1000); + list($list1, $size1) = $this->private_clouds_repository->getAll($query, 0, 1000); + list($list2, $size2) = $this->private_clouds_draft_repository->getAll($query_draft, 0, 1000); + //return on view model - return new ArrayList($list); + + return new ArrayList(array_merge($list1,$list2)); + } public function getCurrentPrivateCloud() { $private_cloud_id = intval($this->request->getVar('id')); + $is_draft = intval($this->request->getVar('is_draft')); $private_cloud = false; if ($private_cloud_id > 0) { - $private_cloud = $this->private_clouds_draft_repository->getByLiveServiceId($private_cloud_id); + if ($is_draft) { + $private_cloud = $this->private_clouds_draft_repository->getById($private_cloud_id); + } else { + $private_cloud = $this->private_clouds_draft_repository->getByLiveServiceId($private_cloud_id); + } + //if no draft found we pull the live one to create the draft from it when saved if (!$private_cloud) { $private_cloud = $this->private_clouds_repository->getById($private_cloud_id); @@ -1316,7 +1265,6 @@ class MarketPlaceAdminPage_Controller extends Page_Controller return $static_map_url; } - public function getCurrentOfficesLocationsStaticMapDraftForPDF() { $static_map_url = "http://maps.googleapis.com/maps/api/staticmap?zoom=1&size=300x200&maptype=roadmap"; diff --git a/marketplace/code/ui/admin/js/appliance.js b/marketplace/code/ui/admin/js/appliance.js index 51124cd..cae718e 100644 --- a/marketplace/code/ui/admin/js/appliance.js +++ b/marketplace/code/ui/admin/js/appliance.js @@ -40,7 +40,7 @@ jQuery(document).ready(function($){ } //this is a draft - if (appliance.live_service_id) { + if (typeof(appliance.live_service_id) != 'undefined') { $("#id",form).val(appliance.id); $("#live_id",form).val(appliance.live_service_id); } else { //its not a draft is the live version, so we remove the id and set the live_service_id diff --git a/marketplace/code/ui/admin/js/consultant.js b/marketplace/code/ui/admin/js/consultant.js index 7687831..e0e23f4 100644 --- a/marketplace/code/ui/admin/js/consultant.js +++ b/marketplace/code/ui/admin/js/consultant.js @@ -43,7 +43,7 @@ jQuery(document).ready(function($){ } //this is a draft - if (consultant.live_service_id) { + if (typeof(consultant.live_service_id) != 'undefined') { $("#id",form).val(consultant.id); $("#live_id",form).val(consultant.live_service_id); } else { //its not a draft is the live version, so we remove the id and set the live_service_id @@ -162,10 +162,9 @@ jQuery(document).ready(function($){ contentType: "application/json; charset=utf-8", dataType: "json", success: function (data,textStatus,jqXHR) { - //window.location = listing_url; - if(consultant.id < 1) $("#id",form).val(data); $('.publish-consultant').prop('disabled',false); $('.save-consultant').prop('disabled',false); + window.location = listing_url; ajaxIndicatorStop(); }, error: function (jqXHR, textStatus, errorThrown) { diff --git a/marketplace/code/ui/admin/js/consultants.js b/marketplace/code/ui/admin/js/consultants.js index 3983b04..b357df3 100644 --- a/marketplace/code/ui/admin/js/consultants.js +++ b/marketplace/code/ui/admin/js/consultants.js @@ -32,9 +32,11 @@ jQuery(document).ready(function($){ event.preventDefault(); event.stopPropagation(); if(confirm("Are you sure to delete this?")){ - var id = $(this).attr('data-id'); - var url = 'api/v1/marketplace/consultants' - url = url+'/'+id; + var id = $(this).attr('data-id'); + var is_draft = $(this).attr('data-is_draft'); + var url = 'api/v1/marketplace/consultants' + url = url+'/'+id+'/'+is_draft; + $.ajax({ type: "DELETE", url: url, diff --git a/marketplace/code/ui/admin/js/distribution.js b/marketplace/code/ui/admin/js/distribution.js index 7682785..4c3a0b7 100644 --- a/marketplace/code/ui/admin/js/distribution.js +++ b/marketplace/code/ui/admin/js/distribution.js @@ -41,7 +41,7 @@ jQuery(document).ready(function($){ } //this is a draft - if (distribution.live_service_id) { + if (typeof(distribution.live_service_id) != 'undefined') { $("#id",form).val(distribution.id); $("#live_id",form).val(distribution.live_service_id); } else { //its not a draft is the live version, so we remove the id and set the live_service_id @@ -110,10 +110,9 @@ jQuery(document).ready(function($){ contentType: "application/json; charset=utf-8", dataType: "json", success: function (data,textStatus,jqXHR) { - //window.location = listing_url; - if(distribution.id < 1) $("#id",form).val(data); $('.publish-distribution').prop('disabled',false); $('.save-distribution').prop('disabled',false); + window.location = listing_url; }, error: function (jqXHR, textStatus, errorThrown) { $('.save-distribution').prop('disabled',false); diff --git a/marketplace/code/ui/admin/js/implementations.js b/marketplace/code/ui/admin/js/implementations.js index 33d2173..2defb9b 100644 --- a/marketplace/code/ui/admin/js/implementations.js +++ b/marketplace/code/ui/admin/js/implementations.js @@ -37,10 +37,12 @@ jQuery(document).ready(function($){ event.preventDefault(); event.stopPropagation(); if(confirm("Are you sure to delete this?")){ - var id = $(this).attr('data-id'); - var type = $(this).attr('data-class'); - var url = type=='distribution'?'api/v1/marketplace/distributions':'api/v1/marketplace/appliances' - url = url+'/'+id; + var id = $(this).attr('data-id'); + var is_draft = $(this).attr('data-is_draft'); + var type = $(this).attr('data-class'); + var url = type=='distribution'?'api/v1/marketplace/distributions':'api/v1/marketplace/appliances' + url = url+'/'+id+'/'+is_draft; + $.ajax({ type: "DELETE", url: url, diff --git a/marketplace/code/ui/admin/js/private_cloud.js b/marketplace/code/ui/admin/js/private_cloud.js index a032ce9..9d9c393 100644 --- a/marketplace/code/ui/admin/js/private_cloud.js +++ b/marketplace/code/ui/admin/js/private_cloud.js @@ -45,7 +45,7 @@ jQuery(document).ready(function($){ } //this is a draft - if (private_cloud.live_service_id) { + if (typeof(private_cloud.live_service_id) != 'undefined') { $("#id",form).val(private_cloud.id); $("#live_id",form).val(private_cloud.live_service_id); } else { //its not a draft is the live version, so we remove the id and set the live_service_id @@ -150,10 +150,9 @@ jQuery(document).ready(function($){ contentType: "application/json; charset=utf-8", dataType: "json", success: function (data,textStatus,jqXHR) { - //window.location = listing_url; - if(private_cloud.id < 1) $("#id",form).val(data); $('.publish-private-cloud').prop('disabled',false); $('.save-private-cloud').prop('disabled',false); + window.location = listing_url; ajaxIndicatorStop(); }, error: function (jqXHR, textStatus, errorThrown) { diff --git a/marketplace/code/ui/admin/js/private_clouds.js b/marketplace/code/ui/admin/js/private_clouds.js index f0359fc..01f36f3 100644 --- a/marketplace/code/ui/admin/js/private_clouds.js +++ b/marketplace/code/ui/admin/js/private_clouds.js @@ -31,9 +31,11 @@ jQuery(document).ready(function($){ event.preventDefault(); event.stopPropagation(); if(confirm("Are you sure to delete this?")){ - var id = $(this).attr('data-id'); - var url = 'api/v1/marketplace/private-clouds' - url = url+'/'+id; + var id = $(this).attr('data-id'); + var is_draft = $(this).attr('data-is_draft'); + var url = 'api/v1/marketplace/private-clouds' + url = url+'/'+id+'/'+is_draft; + $.ajax({ type: "DELETE", url: url, diff --git a/marketplace/code/ui/admin/js/public_cloud.js b/marketplace/code/ui/admin/js/public_cloud.js index 16a061a..b81adaf 100644 --- a/marketplace/code/ui/admin/js/public_cloud.js +++ b/marketplace/code/ui/admin/js/public_cloud.js @@ -45,7 +45,7 @@ jQuery(document).ready(function($){ } //this is a draft - if (public_cloud.live_service_id) { + if (typeof(public_cloud.live_service_id) != 'undefined') { $("#id",form).val(public_cloud.id); $("#live_id",form).val(public_cloud.live_service_id); } else { //its not a draft is the live version, so we remove the id and set the live_service_id @@ -152,10 +152,9 @@ jQuery(document).ready(function($){ contentType: "application/json; charset=utf-8", dataType: "json", success: function (data,textStatus,jqXHR) { - //window.location = listing_url; - if(public_cloud.id < 1) $("#id",form).val(data); $('.publish-public-cloud').prop('disabled',false); $('.save-public-cloud').prop('disabled',false); + window.location = listing_url; ajaxIndicatorStop(); }, error: function (jqXHR, textStatus, errorThrown) { diff --git a/marketplace/code/ui/admin/js/public_clouds.js b/marketplace/code/ui/admin/js/public_clouds.js index 989ff0d..0e2a135 100644 --- a/marketplace/code/ui/admin/js/public_clouds.js +++ b/marketplace/code/ui/admin/js/public_clouds.js @@ -31,9 +31,11 @@ jQuery(document).ready(function($){ event.preventDefault(); event.stopPropagation(); if(confirm("Are you sure to delete this?")){ - var id = $(this).attr('data-id'); - var url = 'api/v1/marketplace/public-clouds' - url = url+'/'+id; + var id = $(this).attr('data-id'); + var is_draft = $(this).attr('data-is_draft'); + var url = 'api/v1/marketplace/public-clouds' + url = url+'/'+id+'/'+is_draft; + $.ajax({ type: "DELETE", url: url, diff --git a/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss b/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss index 00132fc..00fc19f 100644 --- a/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss +++ b/marketplace/templates/Layout/Includes/MarketPlaceAdminPage_consultants_list.ss @@ -41,6 +41,7 @@