The ContentUserDataManager takes care of saving user data and states. It only contains storage-agnostic functionality and depends on a ContentUserDataStorage object to do the actual persistence.

Constructors

Methods

  • Saves the contentUserData for given contentId, dataType and subContentId

    Parameters

    • contentId: string

      The id of the content to load user data from

    • dataType: string

      Used by the h5p.js client

    • subContentId: string

      The id provided by the h5p.js client call

    • userState: string

      The userState as string

    • invalidate: boolean
    • preload: boolean
    • actingUser: IUser

      The user who is currently active; normally this is also the owner of the user data

    • OptionalcontextId: string

      an arbitrary value that can be used to save multiple states for one content - user tuple

    • OptionalasUserId: string

      if the acting user is different from the owner of the user data, you can specify the owner here

    Returns Promise<void>

    the saved state as string

  • Deletes all states of a content object. Normally called when the content object is deleted.

    Parameters

    • contentId: string
    • actingUser: IUser

    Returns Promise<void>

  • Deletes a contentUserData object for given contentId and user id. Throws errors if something goes wrong.

    Parameters

    • forUserId: string

      the user for which the contentUserData object should be deleted

    • actingUser: IUser

      the user who is currently active

    Returns Promise<void>

  • Deletes all finished data for a content object

    Parameters

    • contentId: string

      the id of the content object

    • actingUser: IUser

      the currently active user

    Returns Promise<void>

  • Deletes all user data of a content object, if its "invalidate" flag is set. This method is normally called, if a content object was changed and the user data has become invalid because of that.

    Parameters

    • contentId: string

    Returns Promise<void>

  • Loads the content user data for given contentId and user. The returned data is an array of IContentUserData where the position in the array corresponds with the subContentId or undefined if there is no content user data.

    Parameters

    • contentId: string

      The id of the content to load user data from

    • actingUser: IUser

      The user who is accessing the h5p. Normally this is also the user for who the integration should be generated.

    • OptionalcontextId: string

      an arbitrary value that can be used to save multiple states for one content - user tuple

    • OptionalasUserId: string

      the user for which the integration should be generated, if they are different from the user who is accessing the state

    Returns Promise<ISerializedContentUserData[]>

    an array of IContentUserData or undefined if no content user data is found.

  • Loads the contentUserData for given contentId, dataType and subContentId

    Parameters

    • contentId: string

      The id of the content to load user data from

    • dataType: string

      Used by the h5p.js client

    • subContentId: string

      The id provided by the h5p.js client call

    • actingUser: IUser

      The user who is accessing the h5p. Normally this is also the user for who the state should be fetched.

    • OptionalcontextId: string

      an arbitrary value that can be used to save multiple states for one content - user tuple

    • OptionalasUserId: string

      If set, the state of this user will be fetched instead of the one of `actingUser'

    Returns Promise<IContentUserData>

    the saved state as string or undefined when not found

  • Saves data when a user completes content.

    Parameters

    • contentId: string

      The content id to delete.

    • score: number

      the score the user reached as an integer

    • maxScore: number

      the maximum score of the content

    • openedTimestamp: number

      the time the user opened the content as UNIX time

    • finishedTimestamp: number

      the time the user finished the content as UNIX time

    • completionTime: number

      the time the user needed to complete the content (as integer)

    • actingUser: IUser

      The user who triggers this method via /setFinished

    Returns Promise<void>