public function createZone() { REST::requireRequestMethod('PUT'); $requiredParameters = array('polygon'); if (Util::isValid($requiredParameters, $values, $this->params)) { extract($values); $polygonData = explode('|', $polygon); if (count($polygonData) < 3) { REST::sendResponse(400); } $waypoints = array(); foreach ($polygonData as $polygonDate) { $waypointData = explode(';', $polygonDate); if (count($waypointData) != 2) { REST::sendResponse(400); } $waypoints[] = array('lat' => $waypointData[0], 'lon' => $waypointData[1]); } $db = new MySQL(); $zoneID = Model::createZone($type); if ($zoneID > 0) { foreach ($waypoints as $waypoint) { if (!Model::createWaypoint($zoneID, $waypoint['lat'], $waypoint['lon'])) { REST::sendResponse(500); } } REST::sendResponse(201, $zoneID); } else { REST::sendResponse(500); } } else { REST::sendResponse(400); } }