Implementations can implement the IContentUserDataStorage interface and pass it to the constructor of H5PEditor or H5PPlayer if they wish to keep the user state and allows users to continue where they left off. It also tracks content completion.

interface IContentUserDataStorage {
    createOrUpdateContentUserData(userData: IContentUserData): Promise<void>;
    createOrUpdateFinishedData(finishedData: IFinishedUserData): Promise<void>;
    deleteAllContentUserDataByContentId(contentId: string): Promise<void>;
    deleteAllContentUserDataByUser(user: IUser): Promise<void>;
    deleteFinishedDataByContentId(contentId: string): Promise<void>;
    deleteFinishedDataByUser(user: IUser): Promise<void>;
    deleteInvalidatedContentUserData(contentId: string): Promise<void>;
    getContentUserData(
        contentId: string,
        dataType: string,
        subContentId: string,
        userId: string,
        contextId?: string,
    ): Promise<IContentUserData>;
    getContentUserDataByContentIdAndUser(
        contentId: string,
        userId: string,
        contextId?: string,
    ): Promise<IContentUserData[]>;
    getContentUserDataByUser(user: IUser): Promise<IContentUserData[]>;
    getFinishedDataByContentId(contentId: string): Promise<IFinishedUserData[]>;
    getFinishedDataByUser(user: IUser): Promise<IFinishedUserData[]>;
}

Implemented by

Methods

  • Deletes all userContentData objects for a given contentId. (Used when deleting content) Throws errors if something goes wrong.

    Parameters

    • contentId: string

      The content id to delete.

    Returns Promise<void>

  • Deletes a contentUserData object. (Useful for implementing GDPR rights functionality.) Throws errors if something goes wrong.

    Parameters

    • user: IUser

      the user of the content user data that should be deleted

    Returns Promise<void>

  • Deletes all finished user data of a content object. (Called when the content object is deleted)

    Parameters

    • contentId: string

    Returns Promise<void>

  • Deletes all finished user data for a specific user (across all content objects). (Useful for implementing GDPR rights functionality.)

    Parameters

    Returns Promise<void>

  • Deletes all content userData which has the invalidate field set to true. This method is called from the editor when content is changed and the saved contentUserData becomes invalidated.

    Parameters

    • contentId: string

      The id of the content which to delete

    Returns Promise<void>

  • 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

    • userId: string
    • OptionalcontextId: string

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

    Returns Promise<IContentUserData>

    the data

  • Lists all associated contentUserData for a given contentId and user.

    Parameters

    • contentId: string

      The id of the content to load user data from

    • userId: string
    • OptionalcontextId: string

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

    Returns Promise<IContentUserData[]>

    An array of objects containing the dataType, subContentId and the contentUserState as string in the data field.