/** * * @param Tag $tag_ * @throws InvalidArgumentException */ public function updateTag(Tag $tag_) { try { if (is_null($this->table)) { throw new InvalidArgumentException('Attribute "table" can\'t be NULL !'); } if (isset($this->id) && !is_null($this->id)) { $where = 'id = ' . $this->id; } $tagMapper = new TagMapper(); $tagMapper->setId($this->getFirstId()); $tag = $tagMapper->selectTag(); if (!is_null($tag->getId())) { return parent::update($this->table, $tag_, $where); } elseif (is_null($tag->getId())) { throw new Exception('Tag does not exist !'); } } catch (InvalidArgumentException $e) { print $e->getMessage(); exit; } catch (Exception $e) { print $e->getMessage(); exit; } }
public function testDelete() { $tagMapper = new TagMapper(); $tagMapper->setId(50); $tagMapper->deleteTag(); $this->assertEquals(new Tag(), $tagMapper->selectTag()); }
<?php $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $tagMapper = new \TagMapper(); $tagsObject = $tagMapper->selectTag(true); $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':
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; } }
<?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);