<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $user_ = new User(); $userMapper = new \UserMapper(); $userObject = $userMapper->selectUser(); $userArray = extractData($userObject); if (!empty($userArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($userArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "user", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($userArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $user_ = new \User(); $userMapper = new \UserMapper(); if ($userMapper->deleteUser()) { Rest::sendResponse(200);
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $userMapper = new UserMapper(); $userMessageObject = $userMapper->getMessage(); $userMessageArray = extractData($userMessageObject, array(), true); if (!empty($userMessageArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($userMessageArray), 'application/json'); } else { 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)) {
<?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:
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $announcementMapper = new \AnnouncementMapper(); $announcementObject = $announcementMapper->selectAnnouncement(); $announcementArray = extractData($announcementObject); if (!empty($announcementArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($announcementArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "announcement", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($announcementArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $announcementMapper = new \AnnouncementMapper(); if ($announcementMapper->deleteAnnouncement()) { Rest::sendResponse(200); } break;
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $message_ = new Message(); $messageMapper = new \MessageMapper(); $messageObject = $messageMapper->selectMessage(); $messageArray = extractData($messageObject); if (!empty($messageArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($messageArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "message", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($messageArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $messageMapper = new \MessageMapper(); if ($messageMapper->deleteMessage()) { Rest::sendResponse(200); }
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $comment_ = new Comment(); $commentMapper = new \CommentMapper(); $commentObject = $commentMapper->selectComment(); $commentArray = extractData($commentObject); if (!empty($commentArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($commentArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "comment", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($commentArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $commentMapper = new \CommentMapper(); if ($commentMapper->deleteComment()) { Rest::sendResponse(200); }
<?php $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $commentMapper = new CommentMapper(); $commentsObject = $commentMapper->selectComment(true); $result = true; if (is_array($commentsObject) && !is_null($commentsObject)) { foreach ($commentsObject as $commentObject) { $result = emptyObject($commentObject); } } if (!$result) { foreach ($commentsObject as $commentObject) { $commentsArray[] = extractData($commentObject); } if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($commentsArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "comment"); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($commentsArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'post':
function cmp($a, $b) { return strcmp($a['arret'], $b['arret']); } usort($data, 'cmp'); return $data; } function findTime($data, $arret, $direction) { foreach ($data as $line) { if ($line['arret'] == $arret && $line['direction'] == $direction) { return $line['min']; } } return ["", ""]; } $raw = getRawHtml('699', $ligneA['arrets']); $data = extractData($raw, $ligneA['arrets']); $bdd = new PDO(); $i = 0; foreach ($ligneA['arrets'] as $nom => $arret) { $ljm_min = findTime($data, $nom, 'LJM'); $v_min = findTime($data, $nom, 'V'); $req = $bdd->prepare('UPDATE tram SET ljm1 = :ljm1, ljm2 = :ljm2, v1 = :v1, v2 = :v2 WHERE id = :id'); $req->execute(array('ljm1' => $ljm_min[0], 'ljm2' => $ljm_min[1], 'v1' => $v_min[0], 'v2' => $v_min[1], 'id' => $i)); $i++; } ?> <p>Wokay, c'est dans la database!</p> </body> </html>
<?php $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $incomingMapper = new \IncomingMapper(); $incomingsObject = $incomingMapper->selectIncoming(true); $result = true; if (is_array($incomingsObject) && !is_null($incomingsObject)) { foreach ($incomingsObject as $incomingObject) { $result = emptyObject($incomingObject); } } if (!$result) { foreach ($incomingsObject as $incomingObject) { $incomingsArray[] = extractData($incomingObject); } if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($incomingsArray), 'application/json'); } else { 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':
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $userMapper = new UserMapper(); $userFollowerObject = $userMapper->getFollower(); $userFollowerArray = extractData($userFollowerObject); if (!empty($userFollowerArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($userFollowerArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "user_follower", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($userFollowerArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $userMapper = new UserMapper(); if ($userMapper->stopFollow($url->getIdFirstPart(), $url->getIdSecondPart())) { Rest::sendResponse(200); } break;
/** * * @param string $table_ * @param $object_ * @param array $where_ * @throws InvalidArgumentException */ public function update($table_, $object_, $where_ = null) { try { $set = array(); $data = extractData($object_); if (isset($data) && empty($data) || is_null($data)) { throw new InvalidArgumentException('Must 1 or more arguments to execute an update query !'); } foreach ($data as $column => $value) { unset($data[$column]); $data[":" . $column] = $value; $set[] = $column . " = :" . $column; } $query = 'UPDATE ' . $table_ . ' SET ' . implode(', ', $set) . ' ' . ($where_ ? ' WHERE ' . $where_ : ' '); return $this->statement->prepare($query)->execute($data); } catch (InvalidArgumentException $e) { print $e->getMessage(); exit; } catch (PDOException $e) { print $e->getMessage(); exit; } }
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $incoming_ = new Incoming(); $incomingMapper = new \IncomingMapper(); $incomingObject = $incomingMapper->selectIncoming(); $incomingArray = extractData($incomingObject); if (!empty($incomingArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($incomingArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "incoming", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($incomingArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $incoming_ = new Incoming(); $incomingMapper = new \IncomingMapper(); if ($incomingMapper->deleteIncoming()) { Rest::sendResponse(200);
* Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $announcementMapper = new \AnnouncementMapper(); $announcementsObject = $announcementMapper->selectAnnouncement(true); $result = true; if (is_array($announcementsObject) && !is_null($announcementsObject)) { foreach ($announcementsObject as $announcementObject) { $result = emptyObject($announcementObject); } } if (!$result) { foreach ($announcementsObject as $announcementObject) { $announcementsArray[] = extractData($announcementObject); } if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($announcementsArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "announcement"); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($announcementsArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'post':
<?php $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $announcementMapper = new AnnouncementMapper(); $tagsObject = $announcementMapper->getTags(); $result = true; if (is_array($tagsObject) && !is_null($tagsObject)) { foreach ($tagsObject as $tagObject) { $result = emptyObject($tagObject); } } if (!$result) { foreach ($tagsObject as $tagObject) { $tagsArray[] = extractData($tagObject); } if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($tagsArray), 'application/json'); } else { 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':
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $userMapper = new UserMapper(); $userCommentObject = $userMapper->getComment(); $userCommentArray = extractData($userCommentObject); if (!empty($userCommentArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($userCommentArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "user_comment", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($userCommentArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $userMapper = new UserMapper(); if ($userMapper->stopFollow($url->getIdFirstPart(), $url->getIdSecondPart())) { Rest::sendResponse(200); } break;
*/ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $user_ = new User(); $userMapper = new \UserMapper(); $usersObject = $userMapper->selectUser(true); $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; case 'post':
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 { Rest::sendResponse(204); } break; default:
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $picture_ = new Picture(); $pictureMapper = new \PictureMapper(); $pictureObject = $pictureMapper->selectPicture(); $pictureArray = extractData($pictureObject); if (!empty($pictureArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($pictureArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "picture", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($pictureArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $picture_ = new Picture(); $pictureMapper = new \PictureMapper(); if ($pictureMapper->deletePicture()) { Rest::sendResponse(200);
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $tag_ = new Tag(); $tagMapper = new \TagMapper(); $tagObject = $tagMapper->selectTag(); $tagArray = extractData($tagObject); if (!empty($tagArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($tagArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "tag", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($tagArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $tag_ = new \Tag(); $tagMapper = new \TagMapper(); if ($tagMapper->deleteTag()) { Rest::sendResponse(200);