diff --git a/api-documentation/editor/swagger.yaml b/api-documentation/editor/swagger.yaml index 014b2e9d..b12aa6d7 100644 --- a/api-documentation/editor/swagger.yaml +++ b/api-documentation/editor/swagger.yaml @@ -664,13 +664,13 @@ paths: $ref: "#/definitions/AddProjectsToCollection" security: - ApiKeyAuth: [] - /collections/remove_project: + /collections/remove_projects: post: tags: - Collections - summary: Remove projects from collection - description: Remove projects from collection - operationId: removeProjectFromCollection + summary: Remove projects from collections + description: Remove projects from collections + operationId: removeProjectsFromCollections consumes: - application/json produces: diff --git a/application/controllers/api/Collections.php b/application/controllers/api/Collections.php index 16e7a072..51cf9567 100644 --- a/application/controllers/api/Collections.php +++ b/application/controllers/api/Collections.php @@ -273,8 +273,8 @@ function remove_projects_post() $this->has_access($resource_='collection',$privilege='edit'); $options=$this->raw_json_input(); - if (!isset($options['collection_id'])){ - throw new Exception("Missing parameter: collection_id"); + if (!isset($options['collections'])){ + throw new Exception("Missing parameter: collections"); } if (!isset($options['projects'])){ @@ -295,11 +295,10 @@ function remove_projects_post() throw new Exception("project was not found"); } - $result=$this->Collection_model->remove_projects($options['collection_id'], $sid_arr); + $this->Collection_model->remove_batch_projects($options['collections'], $sid_arr); $output=array( - 'status'=>'success', - 'result'=>$result + 'status'=>'success' ); $this->set_response($output, REST_Controller::HTTP_OK); diff --git a/application/models/Collection_model.php b/application/models/Collection_model.php index c0f09a40..58891661 100644 --- a/application/models/Collection_model.php +++ b/application/models/Collection_model.php @@ -231,6 +231,31 @@ function collection_project_exists($collection_id,$sid) return $this->db->count_all_results('editor_collection_projects'); } + + /** + * + * Batch remove projects from multiple collections + * + */ + function remove_batch_projects($collections,$sids) + { + $collections=(array)$collections; + $sids=(array)$sids; + $sids = array_map('intval', $sids); + + foreach($collections as $collection_id){ + + //check if collection id exists + $collection_exists=$this->collection_id_exists($collection_id); + + if (!$collection_exists){ + throw new Exception('Collection not found: '.$collection_id); + } + + $this->remove_projects($collection_id,$sids); + } + } + /** * Remove project from collection *