Skip to content

Commit

Permalink
update documentation and parameters for endpoint collections/remove_p…
Browse files Browse the repository at this point in the history
…rojects
  • Loading branch information
mah0001 committed Jul 31, 2024
1 parent 1d46324 commit b2cf4c6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
8 changes: 4 additions & 4 deletions api-documentation/editor/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions application/controllers/api/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])){
Expand All @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions application/models/Collection_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit b2cf4c6

Please sign in to comment.