Skip to content

Methods ~ database queries

Dragos Gaftoneanu edited this page Oct 24, 2019 · 1 revision

Definition: /resources/core/database.php

Table of contents

Methods

__construct()

Description: This method initiates $conn object which is used by the class for database operations.

createResource($scimType, $type)

Description: This method creates a new entry for the resource inside the resources table and returns the universally unique identifier (UUID) of the resource.

Parameters:

  • $scimType
    • what is the SCIM version of the resource
    • possible values: "1.1" (for SCIM 1.1) or "2.0" (for SCIM 2.0)
  • $type
    • what is the type of the resource
    • possible values: 0 (for Users) or 1 (for Groups)

Returns: string

deleteResource($resourceID)

Description: This method receives the UUID of the resource and then deletes all entries related to it from the database.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: null

listResources($scimType, $type, $options, $countAll=false)

Description: This method returns a list of resources based on the parameters passed when called.

Parameters:

  • $scimType
    • what is the SCIM version of the resource
    • possible values: "1.1" (for SCIM 1.1) or "2.0" (for SCIM 2.0)
  • $type
    • what is the type of the resource
    • possible values: 0 (for Users) or 1 (for Groups)
  • $options
    • an array containing the SCIM options used for listing the resources
    • usually, this parameter takes the value from $_GET
  • $countAll=false
    • if this parameter is passed with true, instead of returning an array of resources, the function will return the total result of resources as integer, useful when returning the totalResults

Returns: array if $countAll is false, otherwise integer

addResourceAttribute($resourceID, $attribute, $value)

Description: This method add an attribute for a resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $attribute
    • the name of the attribute (eg. "displayName")
  • $value
    • the value of the attribute (eg. "Test User")

Returns: null

getResourceAttributes($resourceID)

Description: This method retrieves all the attributes for a resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: array

deleteResourceAttribute($resourceID, $attribute)

Description: This method deletes a specific attribute for a specific resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $attribute
    • the name of the attribute (eg. "displayName")

Returns: null

deleteResourceAttributes($resourceID)

Description: This method deletes all attributes for a specific resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: null

addResourceSchema($resourceID, $value)

Description: This method add a schema for a resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $value
    • the value of the schema (eg. "urn:scim:schemas:custom:schema")

Returns: null

getResourceSchemas($resourceID)

Description: This method retrieves all the schemas for a resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: array

deleteResourceSchema($resourceID, $schema)

Description: This method deletes a specific schema for a specific resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $schema
    • the value of the schema (eg. "urn:scim:schemas:custom:schema")

Returns: null

deleteResourceSchemas($resourceID)

Description: This method deletes all schemas for a specific resource.

Parameters:

  • $resourceID
    • the UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: null

userExists($userNameOrID, $scimType)

Description: This method checks if a user exists in the database based on the user's username or UUID.

Parameters:

  • $userNameOrID
    • user's username (eg. "[email protected]") or UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $scimType
    • what is the SCIM version of the resource
    • possible values: "1.1" (for SCIM 1.1) or "2.0" (for SCIM 2.0)

Returns: bool

getUserID($username, $scimType)

Description: This method returns the user's UUID based on his username.

Parameters:

  • $username
  • $scimType
    • what is the SCIM version of the resource
    • possible values: "1.1" (for SCIM 1.1) or "2.0" (for SCIM 2.0)

Returns: string

groupExists($groupNameOrID, $scimType)

Description: This method checks if a group exists based on it's display name or UUID.

Parameters:

  • $groupNameOrID
    • group's display name (eg. "Everyone") or UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $scimType
    • what is the SCIM version of the resource
    • possible values: "1.1" (for SCIM 1.1) or "2.0" (for SCIM 2.0)

Returns: bool

getGroupID($group, $scimType)

Description: This method returns the group's UUID based on it's display name.

Parameters:

  • $group
    • group's display name (eg. "Everyone")
  • $scimType
    • what is the SCIM version of the resource
    • possible values: "1.1" (for SCIM 1.1) or "2.0" (for SCIM 2.0)

Returns: string

addGroupMember($groupID, $userID)

Description: This method adds a user to a group if he does not already exist in it.

Parameters:

  • $groupID
    • group's UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $userID
    • user's UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: null

getGroupMembers($groupID)

Description: This method returns the UUID of all users that are part of a group.

Parameters:

  • $groupID
    • group's UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: array

getGroupMemberships($userID)

Description: This method returns the UUID of all groups in which a user is member.

Parameters:

  • $userID
    • user's UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: array

deleteGroupMembership($groupID, $userID)

Description: This method removes a user from a group.

Parameters:

  • $groupID
    • group's UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")
  • $userID
    • user's UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: null

deleteAllGroupMembership($groupID)

Description: This method removes all users from a group.

Parameters:

  • $groupID
    • group's UUID (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: null

updateTimestamp($resourceID)

Description: This method updates the timestamp of a resource.

Parameters:

  • $resourceID
    • UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: null

getMetadata($resourceID)

Description: This method returns the created and lastUpdated timestamps for a resource.

Parameters:

  • $resourceID
    • UUID of the resource (eg. "69abb139-ded6-4703-bda7-62e82210a048")

Returns: array

gen_uuid()

Description: This method generates and returns a random UUID.

Returns: string