public function itemAction() { $view = strtolower(isset($_GET["view"]) ? $_GET["view"] : "data"); $view = $view == "data" || $view == "html" ? $view : "data"; $id = isset($_GET["id"]) ? $_GET["id"] : null; $swid = isset($_GET["swid"]) ? $_GET["swid"] : null; if ($_SERVER['REQUEST_METHOD'] != "GET" || $_SERVER["Repository_Enabled"] !== 'true' || $view == "html" && is_numeric($this->session->userid) == false || is_numeric($swid) == false && is_numeric($id) == false) { header("Status: 404 Not Found"); return; } if ($id == null && $swid !== null) { $rl = new RestProductReleaseLatestItem(array("swid" => $swid)); } else { $rl = new RestProductReleaseItem(array("id" => $id)); } $res = $rl->getRawData(); if ($view == "data") { $this->_helper->viewRenderer->setNoRender(); if ($rl->getError() != RestErrorEnum::RE_OK) { switch ($rl->getError()) { case RestErrorEnum::RE_ACCESS_DENIED: break; } header("Status: 404 Not Found"); echo $rl->getError(); return; } else { header("Content-Type: text/xml"); echo $rl->get($res); } } else { $this->view->item = $res; } }
/** * handles PUT and POST HTTP methods to REST requests * * @method integer the method enumeration according to RestMethodEnum * * @return iRestResponse * @access private */ private function putpost($method) { $id = $this->getParam("id"); $name = $this->getParam("name"); $value = $this->getParam("value"); $rs = new Repository_Model_MetaProductReleases(); //TODO: replace equals(0) with is(null) if foreign key fixed $rs->filter->id->equals($id); $found = count($rs->items) > 0 ? true : false; if (!$found) { $this->setError(RestErrorEnum::RE_ITEM_NOT_FOUND); return false; } $r = $rs->items[0]; if (!$r instanceof Repository_Model_MetaProductRelease) { $this->setError(RestErrorEnum::RE_BACKEND_ERROR); return false; } db()->beginTransaction(); try { $r->{$name} = $value; $r->save(); db()->commit(); } catch (Exception $e) { db()->rollBack(); $this->setError(RestErrorEnum::RE_BACKEND_ERROR, $e->getMessage()); return false; } $res = new RestProductReleaseItem(array("id" => $id), $this); $ret = $res->get(); return $ret; }