summaryrefslogtreecommitdiff
path: root/server/core/Image.php
diff options
context:
space:
mode:
authorEole <EoleDev@outlook.fr>2016-04-27 16:42:28 +0200
committerEole <EoleDev@outlook.fr>2016-04-27 16:42:28 +0200
commit49f416dc5061032e0514ea0cfeceaca37d13e432 (patch)
tree1202ac2a6fa860b8929afdc886c94fc50bd0a1de /server/core/Image.php
parentc7edd70b5e5b0f5159c78ce3d924d4e7f60db816 (diff)
parentc9202d9113210981ae47df40511645da2ee140df (diff)
Merge branch 'develop' into Eole_Graph
Conflicts: client/index.html client/js/controllers/home/home.js client/partials/home/home.html
Diffstat (limited to 'server/core/Image.php')
-rwxr-xr-xserver/core/Image.php780
1 files changed, 408 insertions, 372 deletions
diff --git a/server/core/Image.php b/server/core/Image.php
index d37c828..b256d4c 100755
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -5,23 +5,21 @@
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
-* @author Yogg 'yogg at epsina . com'
+* @author Evan Pisani 'yogg at epsina . com'
*
-* @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
*
-* ADD CLASS DESCRIPTION
+* Management of images
*
*/
class image implements Core{
@@ -29,7 +27,7 @@ class image implements Core{
/** @var App $app protected, contains the main app object */
protected $app;
- /** @var OpenStack\Identity $libClass protected, contains the library Identity object */
+ /** @var OpenStack\Image $libClass protected, contains the library Image object */
protected $libClass;
/**
@@ -37,13 +35,11 @@ class image implements Core{
*
* @param App $app the main app object
*
- * @throws [Type] [<description>]
- *
- * @return Image
+ * @return image Object
*/
public function __construct($app){
if(!isset($app)){
- $this->app->setOutput("Error", "Incorrect parameter");
+ $this->app->setOutput("Error", "Incorrect parameter app");
}
$this->app = $app;
$this->libClass = $app->getLibClass("Image");
@@ -58,47 +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)
*
- **/
+ * @return void
+ */
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
- $imagesList = listImage();
- if(isset($images)){
- foreach($imagesList as $image){
- if(strcmp($image->name, $opt['name']) == 0){
-
- }
- }
- }
+ // Check the image name
+ if(isset($opt['name'])){
+ $imagesList = $this->listImage();
+ if(isset($imagesList)){
+ foreach($imagesList as $image){
+ if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error
+ $this->app->setOutput("Error", "Image name already exists");
+ }
+ }
+ }
+ $options['name'] = $opt['name'];
}
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'];
}
@@ -123,20 +118,22 @@ class image implements Core{
if(isset($opt['protected'])){ // boolean
$options['protected'] = $opt['protected'];
}
- if(isset($opt['properties'])){ // type dict ?
+ if(isset($opt['properties'])){ // type dict
$options['properties'] = $opt['properties'];
}
$image = $this->libClass->createImage($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(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);
}
@@ -144,7 +141,7 @@ class image implements Core{
/**
* List the images of the server
*
- * @return the list with all images on the server
+ * @return void
*/
private function listImage(){
try{
@@ -155,13 +152,15 @@ class image implements Core{
}
}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(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", $result);
@@ -170,45 +169,48 @@ class image implements Core{
/**
* Details about an image
*
- * @param string $id
- * identifier of the image
- *
- **/
+ * @param String $id Identifier of the image
+ *
+ * @return void
+ */
private function detailsImage(){
$id = $this->app->getPostParam("id");
+
if(!isset($id)){
$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");
+ 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{
+ $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);
}
-
- $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);
- }
+ }
}
/**
- * Details about an image
- *
- * @param string $id
- * id of the image
+ * Update informations about an image
*
- * @param array $opt
- * options for the image creation
- **/
+ * @param String $id id of the image
+ * @param array $opt Options for the image creation
+ *
+ * @return void
+ */
private function updateImage(){
$id = $this->app->getPostParam("id");
@@ -217,395 +219,425 @@ class image implements Core{
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{
+ $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'];
+ // 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);
}
- $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);
- }
- $this->app->setOutput("Images", $image);
+ $this->app->setOutput("Images", $image);
+ }
}
/**
* Delete an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @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
+ * Reactive an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @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");
+ 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);
}
- $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);
- }
+ }
}
/**
- * Desactive an image
+ * Desactivaate an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @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");
+ 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->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);
}
- $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);
- }
+ }
}
/**
* Upload an image
*
- * @param string $id
- * identifier of the image
- *
- * @param string $file_name
- * path of the image
- **/
+ * @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");
-
-
+ $file = $this->app->getPostParam("file");
+ error_log(print_r($file, true), 0);
+
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");
+ 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");
+ }
+ $stream = \GuzzleHttp\Psr7\stream_for($file);
+ $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);
}
- $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);
- }
+ }
}
/**
* Download an image
*
- * @param string $id
- * identifier of the image
- **/
+ * @param String $id Identifier of the image
+ *
+ * @return void
+ */
private function downloadImage(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
- $this->app->setOutput("Error", "Incorrect parameter");
+ $this->app->setOutput("Error", "Incorrect id parameter");
+ }
+ 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");
+ }
+ $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);
}
- 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);
- }
- $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
- **/
+ * @param String $image_id Identifier of the image
+ * @param String $member_id Identifier of the member
+ *
+ * @return void
+ */
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");
+ $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);
}
- $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);
- }
+ }
}
/**
* List members of an image
*
- * @param string $image_id
- * identifier of the image
- **/
+ * @param String $image_id identifier of the image
+ *
+ * @return void
+ */
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{
+ $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);
- }
- $this->app->setOutput("Images", $member);
}
/**
* 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
- **/
+ * @return void
+ */
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);
- }
- $this->app->setOutput("Images", $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
- **/
+ * @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");
+ 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);
}
- $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);
- }
+ }
}
/**
* Update a member of an image
*
- * @param string $image_id
- * identifier of the image
- *
- * @param string $member_id
- * identifier of the member
+ * @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 $status
- * new status for the member
+ * @return void
**/
private function updateMemberImage(){
$image_id = $this->app->getPostParam("image_id");
@@ -613,33 +645,37 @@ class image implements Core{
$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");
+ $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);
}
- $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);
- }
+ }
}
}
-?> \ No newline at end of file
+?>