validate($request); $range_id = self::arrayGet($json, 'data.relationships.range.data.id'); $range = get_object_by_range_id($range_id); if (!$range) { throw new RecordNotFoundException(); } if (!CoreForum::isModerator($range->id)) { throw new AuthorizationFailedException(); } $topic_ids = self::arrayGet($json, 'data.attributes.topic-ids'); Topic::findEachBySQL( function (Topic $topic) use ($topic_ids) { $topic->position = (int) array_search($topic->topic_id, $topic_ids); $topic->store(); }, "topic_id IN (:topic_ids) AND range_id = :course_id", [ "topic_ids" => $topic_ids, "course_id" => $range->id ] ); return $this->getCodeResponse(204); } protected function validateResourceDocument($json, $data) { $required_keys = [ 'data.attributes.topic-ids' => 'Missing `data.attributes.topic-ids`', 'data.relationships.range.data.id' => 'Missing `data.relationships.range.data.id`', ]; foreach ($required_keys as $key => $error_message) { if (!self::arrayHas($json, $key)) { return $error_message; } } return null; } }