Example #1
0
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "user");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($usersArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $user = new User();
         $data_user = $http->getRequestVars();
         $user = initObject($data_user, $user, true, array('password'));
         if (!emptyObject($user)) {
             $userMapper = new \UserMapper();
             if ($userMapper->insertUser($user)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $picture_ = new Picture();
     $pictureMapper = new \PictureMapper();
     if ($pictureMapper->deletePicture()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $picture_ = new Picture();
         $data_picture_ = $http->getRequestVars();
         $pictureObject = initObject($data_picture_, $picture_, true);
         if (!emptyObject($pictureObject)) {
             $pictureMapper = new \PictureMapper();
             if ($pictureMapper->updatePicture($pictureObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
Example #3
0
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "tag");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($tagsArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $tag = new Tag();
         $data_tag = $http->getRequestVars();
         $tagObject = initObject($data_tag, $tag, true);
         if (!emptyObject($tagObject)) {
             $tagMapper = new TagMapper();
             if ($tagMapper->insertTag($tagObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "tag");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($tagsArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $announcement = new Announcement();
         $data = $http->getRequestVars();
         $toAssociate = initObject($data, new stdClass(), true);
         if (!emptyObject($toAssociate)) {
             $announcementMapper = new AnnouncementMapper();
             if ($announcementMapper->goAssociate($toAssociate)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
Example #5
0
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $user_ = new \User();
     $userMapper = new \UserMapper();
     if ($userMapper->deleteUser()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $user = new \User();
         $data_user = $http->getRequestVars();
         $userObject = initObject($data_user, $user, true);
         if (!emptyObject($userObject)) {
             $userMapper = new \UserMapper();
             if ($userMapper->updateUser($userObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, "defaultTagName" => "user_message", XML_SERIALIZER_OPTION_RETURN_RESULT => true);
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($userMessageArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $message = new Message();
         $data_message = $http->getRequestVars();
         $messageObject = initObject($data_message, $message, true);
         if (!emptyObject($messageObject)) {
             $userMapper = new UserMapper();
             if ($userMapper->sendMessage($messageObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
<?php

$http = Rest::initProcess();
switch ($http->getMethod()) {
    case 'get':
        $userMapper = new UserMapper();
        $messagesObject = $userMapper->getMessages();
        $result = true;
        if (is_array($messagesObject) && !is_null($messagesObject)) {
            foreach ($messagesObject as $messageObject) {
                $result = emptyObject($messageObject);
            }
        }
        if (!$result) {
            foreach ($messagesObject as $messageObject) {
                $messagesArray[] = extractData($messageObject);
            }
            if ($http->getHttpAccept() == 'json') {
                Rest::sendResponse(200, json_encode($messagesArray), 'application/json');
            } else {
                if ($http->getHttpAccept() == 'xml') {
                    $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "message");
                    $serializer = new XML_Serializer($options);
                    Rest::sendResponse(200, $serializer->serialize($messagesArray), 'application/xml');
                }
            }
        } else {
            Rest::sendResponse(204);
        }
        break;
    default:
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $announcementMapper = new \AnnouncementMapper();
     if ($announcementMapper->deleteAnnouncement()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $announcement = new Announcement();
         $data_announcement = $http->getRequestVars();
         $announcementObject = initObject($data_announcement, $announcement, true);
         if (!emptyObject($announcementObject)) {
             $announcementMapper = new \AnnouncementMapper();
             if ($announcementMapper->updateAnnouncement($announcementObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $commentMapper = new \CommentMapper();
     if ($commentMapper->deleteComment()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $comment_ = new Comment();
         $data_comment_ = $http->getRequestVars();
         $commentObject = initObject($data_comment_, $comment_, true);
         if (!emptyObject($commentObject)) {
             $commentMapper = new \CommentMapper();
             if ($commentMapper->updateComment($commentObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getComment();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
<?php

$http = Rest::initProcess();
switch ($http->getMethod()) {
    case 'get':
        $announcementMapper = new AnnouncementMapper();
        $announcementObject = $announcementMapper->selectAnnouncement();
        if (!emptyObject($announcementObject)) {
            $pictureMapper = new PictureMapper($announcementMapper);
            $picturesObject = $announcementMapper->getPictures($pictureMapper);
        }
        $result = true;
        if (is_array($picturesObject) && !is_null($picturesObject)) {
            foreach ($picturesObject as $pictureObject) {
                $result = emptyObject($pictureObject);
            }
        }
        if (!$result) {
            foreach ($picturesObject as $pictureObject) {
                $picturesArray[] = extractData($pictureObject);
            }
            if ($http->getHttpAccept() == 'json') {
                Rest::sendResponse(200, json_encode($picturesArray), 'application/json');
            } else {
                if ($http->getHttpAccept() == 'xml') {
                    $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "user");
                    $serializer = new XML_Serializer($options);
                    Rest::sendResponse(200, $serializer->serialize($picturesArray), 'application/xml');
                }
            }
        } else {
 public function goAssociate(stdClass $object_)
 {
     try {
         if (isset($object_) && !emptyObject($object_)) {
             $announcementMapper = new AnnouncementMapper();
             $announcementMapper->setId($object_->id_announcement);
             $announcement = $announcementMapper->selectAnnouncement();
             $tagMapper = new TagMapper();
             $tagMapper->setId($object_->id_tag);
             $tag = $tagMapper->selectTag();
             if (!is_null($announcement->getId()) && !is_null($tag->getId())) {
                 if (is_null($user->getId())) {
                     return parent::insert('TO_ASSOCIATE', $object_);
                 } else {
                     throw new Exception('The user is already followed by this user !');
                 }
                 return parent::insert($this->table, $message_, $arrayFilter);
             } elseif (is_null($announcement->getId())) {
                 throw new Exception('Announcement is inexistant !');
             } elseif (is_null($tag->getId())) {
                 throw new Exception('Tag is inexistant !');
             }
         } elseif (empty($id_announcement_)) {
             throw new Exception('Id announcement is required !');
         } elseif (empty($id_tag_)) {
             throw new Exception('Id tag is required !');
         }
     } catch (Exception $e) {
         print $e->getMessage();
         exit;
     }
 }
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "incoming");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($incomingsArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $incoming = new Incoming();
         $data_incoming = $http->getRequestVars();
         $incoming = initObject($data_incoming, $incoming, true);
         if (!emptyObject($incoming)) {
             $incomingMapper = new IncomingMapper();
             if ($incomingMapper->insertIncoming($incoming)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
     break;
<?php

$http = Rest::initProcess();
switch ($http->getMethod()) {
    case 'get':
        $userMapper = new UserMapper();
        $usersObject = $userMapper->getFollowers();
        $result = true;
        if (is_array($usersObject) && !is_null($usersObject)) {
            foreach ($usersObject as $userObject) {
                $result = emptyObject($userObject);
            }
        }
        if (!$result) {
            foreach ($usersObject as $userObject) {
                $usersArray[] = extractData($userObject);
            }
            if ($http->getHttpAccept() == 'json') {
                Rest::sendResponse(200, json_encode($usersArray), 'application/json');
            } else {
                if ($http->getHttpAccept() == 'xml') {
                    $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "user");
                    $serializer = new XML_Serializer($options);
                    Rest::sendResponse(200, $serializer->serialize($usersArray), 'application/xml');
                }
            }
        } else {
            Rest::sendResponse(204);
        }
        break;
    default: