public function putModuleData(ModulesRequest $request) { $updateCanvas = false; if (!isset($_SESSION)) { session_start(); } $domain = $_SESSION['domain']; $token = \Crypt::decrypt($_SESSION['userToken']); $courseId = $_SESSION['courseID']; $scope = "module"; $urlPieces = array(); $urlArgs = array(); $urlPieces[] = "https://{$domain}/api/v1/courses/{$courseId}"; $urlPieces[] = "modules/{$request->getModuleId()}"; if ($request->getModuleItem()) { $tags = $request->getModuleItem()->getTags(); if ($tags) { $dbHelper = new DbHelper(); return $dbHelper->updateContentTags($request->getModuleItem()->content_id, $tags, $courseId); } } if ($request->getModuleItemId()) { //updating a module item $updateCanvas = true; $urlPieces[] = "items/{$request->getModuleItemId()}"; $scope = "module_item"; $urlArgs = $this->buildModuleItemUpdateArgs($request->getModuleItem()); } else { if ($request->getModuleId()) { //updating a module $updateCanvas = true; $urlArgs = $this->buildModuleUpdateArgs($request->getModule()); } } if ($updateCanvas) { //Attach token $urlArgs[] = "access_token={$token}"; $url = GuzzleHelper::constructUrl($urlPieces, $urlArgs); $response = GuzzleHelper::makeRequest($request, $url, true); //update DB if request was successful if ($response->getStatusCode() === "200") { $newlyUpdated = \GuzzleHttp\json_decode($response->getBody()); if (isset($newlyUpdated->module_id)) { //it's a module item return $this->processSingleModuleItem($courseId, $newlyUpdated); } else { //it's a module return $this->processSingleModule($newlyUpdated, $courseId); } } } }