public function testDelete() { $announcementMapper = new AnnouncementMapper(); $announcementMapper->setId(1); $announcementMapper->deleteAnnouncement(); $this->assertEquals(new Announcement(), $announcementMapper->selectAnnouncement()); }
/** * * @param Comment $comment_ * @param array $arrayFilter * @throws InvalidArgumentException */ public function insertComment(Comment $comment_, array $arrayFilter = array()) { try { if (is_null($this->table)) { throw new InvalidArgumentException('Attribute "table" can\'t be NULL !'); } $userMapper = new UserMapper(); $announcementMapper = new AnnouncementMapper(); $userMapper->setId($comment_->getIdUser()); $user = $userMapper->selectUser(); $announcementMapper->setId($comment_->getIdAnnouncement()); $announcement = $announcementMapper->selectAnnouncement(); if (!is_null($user->getId()) && !is_null($announcement->getId())) { return parent::insert($this->table, $comment_, $arrayFilter); } elseif (is_null($user->getId())) { throw new Exception('User is inexistant !'); } elseif (is_null($announcement->getId())) { throw new Exception('Announcement is inexistant !'); } } catch (InvalidArgumentException $e) { print $e->getMessage(); exit; } catch (Exception $e) { print $e->getMessage(); exit; } }
$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; }
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; }
<?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; } }
$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': try { $announcement = new Announcement(); $data_announcement = $http->getRequestVars(); $announcementsObject = initObject($data_announcement, $announcement, true); if (!emptyObject($announcementsObject)) { $announcementMapper = new \AnnouncementMapper(); if ($announcementMapper->insertAnnouncement($announcementsObject)) { Rest::sendResponse(200); } } else { throw new InvalidArgumentException('Need arguments to POST data !'); } } catch (InvalidArgumentException $e) { $e->getMessage(); exit; } break; default: Rest::sendResponse(501); break; }