public function mayCall ($call) { if (SessionManager::getCurrentSession()->getUser()->isAdmin()) { return true; } else { return false; } }
public function mayCall ($call) { if (SessionManager::getCurrentSession()->getUser() === null) { return false; } else { /* @todo: Implement permission checking */ return true; } }
public function deleteStock () { $part = PartManager::getInstance()->getPart($this->getParameter("part")); $user = SessionManager::getCurrentSession()->getUser(); $stock = new StockEntry($part, 0-intval($this->getParameter("stock")), $user); PartKeepr::getEM()->persist($stock); PartKeepr::getEM()->flush(); $part->updateStockLevel(); PartKeepr::getEM()->flush(); return true; }
public static function call () { $request = new Request(array('restful' => true)); $service = $request->getService(); //print_r($request->action); if ($service->hasHeader("call")) { $call = $service->getHeader("call"); } elseif (array_key_exists("call", $_REQUEST) && $_REQUEST["call"] != "") { $call = $_REQUEST["call"]; } elseif ($request->action != "") { $call = $request->action; } else { switch (strtoupper($request->getMethod())) { case "POST": $call = "create"; break; case "GET": $call = "get"; break; case "PUT": $call = "update"; break; case "DELETE": $call = "destroy"; break; default: $call = $request->getMethod(); break; } } $allowCall = true; if (!is_subclass_of($service, "de\\RaumZeitLabor\\PartKeepr\\Service\\AnonService")) { $session = null; if ($service->hasHeader("session")) { $sessionid = $service->getHeader("session"); } if (array_key_exists("session", $_REQUEST) && $session === null) { $sessionid = $_REQUEST["session"]; } if ($sessionid === null) { $session = SessionManager::getInstance()->startSession(); throw new ServiceException("You called a non-anonymous service, but did not pass the 'session' parameter."); } else { $session = SessionManager::getInstance()->resumeSession($sessionid); } if (!$service->mayCall($call)) { $allowCall = false; } } if (!$allowCall) { throw new ServiceException("Permission denied"); } $result = $service->$call(); PartKeepr::getEM()->flush(); return $result; }
public function addOrUpdatePart ($aParameters) { if (!array_key_exists("quantity", $aParameters)) { $aParameters["quantity"] = 0; } if ($aParameters["part"] !== null) { try { $part = $this->getPart($aParameters["part"]); } catch (\Exception $e) { $part = new Part(); $user = SessionManager::getCurrentSession()->getUser(); $stock = new StockEntry($part, $aParameters["quantity"], $user); PartKeepr::getEM()->persist($stock); } } else { $part = new Part(); $user = SessionManager::getCurrentSession()->getUser(); $stock = new StockEntry($part, $aParameters["quantity"], $user); PartKeepr::getEM()->persist($stock); } if (array_key_exists("name", $aParameters)) { $part->setName($aParameters["name"]); } if (array_key_exists("minstock", $aParameters)) { $part->setMinStockLevel($aParameters["minstock"]); } if (array_key_exists("comment", $aParameters)) { $part->setComment($aParameters["comment"]); } if (array_key_exists("footprint", $aParameters)) { if ($aParameters["footprint"] === null) { $part->setFootprint(null); } else { $footprint = FootprintManager::getInstance()->getOrCreateFootprint($aParameters["footprint"]); $part->setFootprint($footprint); } } if (array_key_exists("storagelocation", $aParameters)) { $storageLocation = StorageLocationManager::getInstance()->getOrCreateStorageLocation($aParameters["storagelocation"]); $part->setStorageLocation($storageLocation); } if (array_key_exists("category", $aParameters)) { $category = CategoryManager::getInstance()->getCategory($aParameters["category"]); $part->setCategory($category->getNode()); } /* Process linked changes */ if (array_key_exists("distributorChanges", $aParameters)) { if (is_array($aParameters["distributorChanges"])) { $this->processDistributorChanges($part, $aParameters["distributorChanges"]); } } if (array_key_exists("manufacturerChanges", $aParameters)) { if (is_array($aParameters["manufacturerChanges"])) { $this->processManufacturerChanges($part, $aParameters["manufacturerChanges"]); } } if (array_key_exists("parameterChanges", $aParameters)) { if (is_array($aParameters["parameterChanges"])) { $this->processParameterChanges($part, $aParameters["parameterChanges"]); } } if (array_key_exists("attachmentChanges", $aParameters)) { if (is_array($aParameters["attachmentChanges"])) { $this->processAttachmentChanges($part, $aParameters["attachmentChanges"]); } } if (array_key_exists("partUnit", $aParameters)) { if ($aParameters["partUnit"] === null || $aParameters["partUnit"] === 0) { $part->setPartUnit(null); } else { $part->setPartUnit(PartUnitManager::getInstance()->getPartUnit($aParameters["partUnit"])); } } PartKeepr::getEM()->persist($part); PartKeepr::getEM()->flush(); }