diff options
| author | root <root@kabir-PC> | 2016-03-23 11:31:51 +0100 |
|---|---|---|
| committer | root <root@kabir-PC> | 2016-03-23 11:31:51 +0100 |
| commit | a26989103d70fb0dd3ff6834de107cae246778c3 (patch) | |
| tree | 0f243c83b790ffb57f19261fc2a509131f6776ce /server/core/Image.php | |
| parent | 1342db60283cb61a1c3810993575d35b9fb33ac0 (diff) | |
| parent | 6e78d76f887d1149ea85bfb06db7ee7ad7435f5a (diff) | |
Merge branch 'develop' of https://github.com/manzerbredes/istic-openstack into develop
Diffstat (limited to 'server/core/Image.php')
| -rwxr-xr-x[-rw-r--r--] | server/core/Image.php | 834 |
1 files changed, 454 insertions, 380 deletions
diff --git a/server/core/Image.php b/server/core/Image.php index 4025595..71e19ce 100644..100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -9,10 +9,12 @@ * * @todo Complete the functions with errors detection and finish the descriptions */ -use OpenStack\Common\Error\BadResponseError; -use OpenStack\Common\Error\BaseError; -use OpenStack\Common\Error\NotImplementedError; -use OpenStack\Common\Error\UserInputError; +use OpenCloud\Common\Error\BadResponseError; +use OpenCloud\Common\Error\BaseError; +use OpenCloud\Common\Error\NotImplementedError; +use OpenCloud\Common\Error\UserInputError; + +include("CoreInterface.php"); /** * Image Class of the back-end application @@ -33,26 +35,14 @@ class image implements Core{ * * @param App $app the main app object * - * @throws [Type] [<description>] - * * @return Image */ public function __construct($app){ if(!isset($app)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect parameter app"); } - try{ - $this->app = $app; - $this->libClass = $app->getLibClass("Image"); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + $this->app = $app; + $this->libClass = $app->getLibClass("Image"); } @@ -64,45 +54,46 @@ class image implements Core{ * @return void */ public function action($action){ - - $this->{$action.""}(); - + $this->{$action.""}(); } /** - * Details about an image + * Create a new image * - * @param array $opt - * options for the image creation + * @param array $opt Options for the image creation (name is required, others are optionals) * - **/ - private function createImage(array $opt){ + * @return Image + */ + private function createImage(){ + $opt = $this->app->getPostParam("opt"); if(!isset($opt)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect parameter opt"); } - try{ - // VOIR SI MAUVAIS TYPE $options = Array(); - if(isset($opt['name'])){ // if the image name already exists -> error + + // Check the image name + if(isset($opt['name'])){ $imagesList = listImage(); - if(isset($images)){ + if(isset($imagesList)){ foreach($imagesList as $image){ - if(strcmp($image->name, $opt['name']) == 0){ - + if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error + $this->app->setOutput("Error", "Image name already exists"); } } } } else{ - $this->app->setOutput("Error", "Image name already exists"); + $this->app->setOutput("Error", "Missing parameter 'name' for the new image"); } + + // Check optionals arguments if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error - + $this->app->setOutput("Error", "Image id already exists"); } $options['id'] = $opt['id']; } @@ -135,478 +126,561 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } - return $image; + $this->app->setOutput("Images", $image); + } /** * List the images of the server * - * @return the list with all images on the server + * @return List of Image */ private function listImage(){ try{ + $result = array(); $l = $this->libClass->listImages(); - if(!isset($l)){ // if the list is empty there is no images - $this->app->setOutput("Error", "No image"); + foreach($l as $tmp){ + $result[] = $tmp; } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } - return $l; + + $this->app->setOutput("Images", $result); } /** * Details about an image * - * @param string $id - * identifier of the image - * - **/ - private function detailsImage($id){ + * @param String $id Identifier of the image + * + * @return Image + */ + private function detailsImage(){ + $id = $this->app->getPostParam("id"); + if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } - try{ - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - - return $image; - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + else{ + echo 'toto'; + $this->app->setOutput("Images", $image); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** - * Details about an image + * Update informations about an image * - * @param string $id - * id of the image - * - * @param array $opt - * options for the image creation - **/ - private function updateImage($id, array $opt){ + * @param String $id id of the image + * @param array $opt Options for the image creation + * + * @return Image + */ + + private function updateImage(){ + $id = $this->app->getPostParam("id"); + $opt = $this->app->getPostParam("opt"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($opt)){ + else if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect opt parameter"); } + else{ + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } - try{ - //vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - - $options = Array(); + $options = Array(); - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } - return $image; + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $image); + } } /** * Delete an image * - * @param string $id - * identifier of the image - **/ - private function deleteImage($id){ + * @param String $id Identifier of the image + * + * @return void + */ + private function deleteImage(){ // si protected = true, demander de le mettre a false // vérifier existence image + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } - - try{ - $service = $this->libClass; - $image = $this->libClass->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->delete(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } - + else{ + try{ + $service = $this->libClass; + $image = $this->libClass->getImage($id); + if($image == null){ // if the image doesn't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** * Resactive an image * - * @param string $id - * identifier of the image - **/ - private function reactivateImage($id){ + * @param String $id Identifier of the image + * + * @return void + */ + private function reactivateImage(){ + $id = $this->app->getPostParam("id"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->reactivate(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + else + { + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->reactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** * Desactive an image * - * @param string $id - * identifier of the image - **/ - private function desactivateImage($id){ + * @param String $id Identifier of the image + * + * @return void + */ + private function desactivateImage(){ + $id = $this->app->getPostParam("id"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->deactivate(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + else + { + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->deactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** * Upload an image * - * @param string $id - * identifier of the image - * - * @param string $file_name - * path of the image - **/ - private function uploadImage($id, $file_name){ + * @param String $id Identifier of the image + * @param String $file_name Path of the image + * + * @return void + */ + private function uploadImage(){ + $id = $this->app->getPostParam("id"); + $file_name = $this->app->getPostParam("file_name"); + + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($file_name)){ - $this->app->setOutput("Error", "Incorrect file_name parameter"); + else if(!isset($file_name)){ + $this->app->setOutput("Error", "Incorrect file name parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); - $image->uploadData($stream); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $image->uploadData($stream); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } } } /** * Download an image * - * @param string $id - * identifier of the image - **/ - private function downloadImage($id){ + * @param String $id Identifier of the image + * + * @return Stream + */ + private function downloadImage(){ + $id = $this->app->getPostParam("id"); + if(!isset($id)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = $image->downloadData(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } - return $stream; + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = $image->downloadData(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $stream); + } } /** * Add a member to image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member - **/ - private function addMemberImage($image_id, $member_id){ + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * + * @return Member + */ + private function addMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + else if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member_id = $image->addMember($member_id); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member_id = $image->addMember($member_id); + $this->app->setOutput("Images", $member_id); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** * List members of an image * - * @param string $image_id - * identifier of the image - **/ - private function listMemberImage($image_id, $member_id){ + * @param String $image_id identifier of the image + * + * @return List of Member + */ + private function listMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + else if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect member id parameter"); + } + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $members = $image->listMembers(); + if($members == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "No member"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $members); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($image_id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $members = $image->listMembers(); - if($member == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "No member"); - } - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } - return $members; } /** * Show details of a member of an image * - * @param string $image_id - * identifier of the image + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member * - * @param string $member_id - * identifier of the member - **/ - private function detailMemberImage($image_id, $member_id){ + * @return Member + */ + private function detailMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + else if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->libClass; - - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } + else{ + try{ + $service = $this->libClass; - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } - return $member; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $member); + } } /** * Remove a member of an image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member - **/ - private function removeMemberImage($image_id, $member_id){ + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * + * @return void + */ + private function removeMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + else if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; - - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->delete(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** * Update a member of an image * - * @param string $image_id - * identifier of the image + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * @param String $status New status for the member * - * @param string $member_id - * identifier of the member - * - * @param string $status - * new status for the member + * @return void **/ - private function updateMemberImage($image_id, $member_id, $status){ + private function updateMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + $status = $this->app->getPostParam("status"); + if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + else if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->updateStatus($status); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->updateStatus($status); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } } |
