/** * Update an experience * @param String $id: id of the SharcExperience * @param String $objExperience: a json object of SharcExperience * @param String $designerId: id of the designer */ public static function updateExperience($id, $objExperience, $designerId) { $response = array(); try { $experience = SharcExperience::find($id); if ($experience->designerId != $designerId) { $response["status"] = FAILED; $response["data"] = EXPERIENCE_NOT_AUTHORIZED; return $response; } if ($experience != null) { $experience->name = $objExperience['name']; $experience->description = $objExperience['description']; $experience->lastPublishedDate = date('Y-m-d'); $experience->isPublished = $objExperience['isPublished']; $experience->moderationMode = $objExperience['moderationMode']; $experience->latLng = $objExperience['latLng']; $experience->summary = $objExperience['summary']; $experience->snapshotPath = $objExperience['snapshotPath']; $experience->thumbnailPath = $objExperience['thumbnailPath']; //$experience->size = SharcMediaExperience::where('experienceId', $objExperience['experienceId'])->sum('size'); $experience->size = MediaService::getMediaSizeForExperience($designerId, $objExperience['id']); if ($experience->size == 0) { $experience->size = 1; } $experience->theme = $objExperience['theme']; $result = $experience->save(); if ($result) { //= 1 success $response["status"] = SUCCESS; $response["data"] = $experience->toArray(); } else { //error $response["status"] = ERROR; $response["data"] = INTERNAL_SERVER_ERROR; } } else { //fail AS cant find the experience $response["status"] = FAILED; $response["data"] = EXPERIENCE_NOT_EXIST; } } catch (Exception $e) { $response["status"] = ERROR; $response["data"] = Utils::getExceptionMessage($e); } return $response; }
$rs = UserService::checkAuthentication($app->request->headers->get('apiKey')); if ($rs["status"] != SUCCESS) { Utils::echoResponse($rs); return; } $userId = $rs['data']->id; //So even with a valid apiKey, the designer can access her own resources only $response = ExperienceService::getExperienceOfConsumer($userId); Utils::echoResponse($response); }); //Get content of an experience for SPVT $app->get('/experienceSnapshotForSpvt/:experienceId/:userId', function ($experienceId, $userId) use($app) { $rs = UserService::checkAuthentication($app->request->headers->get('apiKey')); if ($rs["status"] != SUCCESS) { Utils::echoResponse($rs); return; } $userId = $rs['data']->id; //So even with a valid apiKey, the designer can access her own resources only $response = ExperienceService::getExperienceSnapshotForSpvt($experienceId, $userId); Utils::echoResponse($response); }); $app->map('/hello', function () { echo "Welcome to SHARC 2.0 RESTful Web services"; })->via('GET', 'POST'); $app->map('/test/:designerId/:experienceId', function ($designerId, $experienceId) { //$results = Capsule::se DB::s:select('select * from SharcUsers where id = ?', array(5)); //echo $results->toJson(); echo MediaService::getMediaSizeForExperience($designerId, $experienceId); })->via('GET'); $app->run();