• PHP reference
  • Models

Community

class Community extends AttributedModel

Community model.

Properties

integer $id

ModelRelations $relations

Theme $theme

The community's UI theme.

Users $users

User management.

string $url

The community main URL.

Modules $modules

string $name

string $title

string $style_color

string $style_logo_large

string $style_login_bg

int $max_users

int $max_storage

int $termin_start

string $domain

int $reseller

string $xero_id

int $suspended

Methods

boolean get_from_name($source, Org $org = null)

Get community by name (subdomain).

Parameters

  • $source
  • Org $org

Return Value

  • boolean

boolean get_from_domain($source)

Get community by custom domain name.

Parameters

  • $source

Return Value

  • boolean

string get_domain(boolean $force = false)

Get the domain of this community, depending on where it is accessed from.

Parameters

  • boolean $force

Return Value

  • string

string get_default_domain()

Get the main domain for this community, which can be either a Scholica or reseller subdomain, or a custom domain name.

Return Value

  • string

integer stat_get(string $key)

Get the value of a stat for this community.

Parameters

  • string $key

Return Value

  • integer

stat_inc(string $key)

Increase the value of a stat for this community.

Parameters

  • string $key

integer space_occupied()

Get the total space occupied by this community in bytes.

Return Value

  • integer

Model|null|Org org()

Get the Org that this Community is part of.

Return Value

boolean has_custom_primary_domain()

Whether this community uses a external domain as their primary domain.

Return Value

  • boolean

array get_domains()

Get all domains from which this community is accessible.

Return Value

  • array

set_primary_domain(string $domain)

Set a domain that should be regarded as the main domain for this community.

Parameters

  • string $domain

boolean add_domain(string $domain)

Add a domain that is recognised as belonging to this community.

Parameters

  • string $domain

Return Value

  • boolean

remove_domain(string $domain)

Remove a domain from this community.

Parameters

  • string $domain

integer|string group_add_user(integer $id, integer|User $user, string $initiator = 'prog')

Add a user to a user group.

Parameters

  • integer $id
  • integer|User $user
  • string $initiator

Return Value

  • integer|string

boolean feature(string $feature, boolean $val = null)

Check if a feature with this name is enabled for this community, or set it to enabled/disabled by passing the second parameter.

Parameters

  • string $feature
  • boolean $val

Return Value

  • boolean

string|false logo()

Convenience method for quickly getting the Community icon URL.

Return Value

  • string|false

string|false logo_large()

Convenience method for quickly getting the Community logo URL.

Return Value

  • string|false

User[] users(boolean $includeManagers = false)

Get all users in community. Returns an array of User objects.

Parameters

  • boolean $includeManagers whether to include community managers (defaults to false)

Return Value

boolean installModule(Module $module, boolean $default_permissions = true)

Install a module for the current community.

Parameters

  • Module $module Module to install
  • boolean $default_permissions Whether to automatically enable for all users

Return Value

  • boolean

Exceptions

boolean hasModule(integer $module_id)

Check if the community has a certain module installed.

Parameters

  • integer $module_id

Return Value

  • boolean

do(callable $callable)

Execute within the context of a certain community. Any references to community() within the callable will refer to this community, which is not necessarily the same as the community the outer code is being run in.

Parameters

  • callable $callable

Inherited from Fillable

static boolean|Fillable create($fields)

Insert a new entry into the model's database table.

Parameters

  • $fields

Return Value

Inherited from Model

__construct(mixed $source = null, boolean $disable_global = false)

Model constructor. Pass in an ID (numeric) or object to start the model.

Parameters

  • mixed $source
  • boolean $disable_global

static Model[] getAll(integer $limit = null)

Get array of all table rows as model instances.

Parameters

  • integer $limit Maximum number of entries to retrieve

Return Value

static integer getCount(array|string $where = null)

Get the number of items in the model that match the query.

Parameters

  • array|string $where Array or SQL query component to build a WHERE ... query.

Return Value

  • integer

static Model|null find(integer $id)

Get the item of this model with the given ID if it exists. Returns null otherwise.

Note that any value passed to this function is converted into an integer!

Parameters

  • integer $id

Return Value

static Model|null findWith(string|array $field, mixed $value = null)

Check if an item with a given field value (exact match) exists.

Parameters

  • string|array $field
  • mixed $value

Return Value

static Model|null getBy(string|array $field, mixed $value = null)

Get item by a specific field (exact match). Returns null on failure.

Parameters

  • string|array $field
  • mixed $value

Return Value

static Model[] getManyBy(string|array $field, mixed $value = null)

Get array of items that have a specific field value (exact match).

Parameters

  • string|array $field
  • mixed $value

Return Value

static boolean exists(integer $id)

Check if an item with a given ID exists.

Parameters

  • integer $id

Return Value

  • boolean

static boolean existsWith(string $field, mixed $value = null)

Check if an item with a given field value (exact match) exists.

Parameters

  • string $field
  • mixed $value

Return Value

  • boolean

boolean update(string|array $field, mixed $value = null)

Update a field of this entry.

Parameters

  • string|array $field
  • mixed $value

Return Value

  • boolean

boolean del()

Delete the resource from the database.

Return Value

  • boolean

object barebones()

Get a bare bones version of the Model (without db, relations, etc.).

Return Value

  • object

Inherited from AttributedModel

mixed attr(string $key, null $value = null)

Get or set a value on the model object.

Parameters

  • string $key
  • null $value

Return Value

  • mixed

mixed val(string $key, null $value = null)

Get or set a value on the model object. Alias for attr().

Parameters

  • string $key
  • null $value

Return Value

  • mixed

array attributes()

Get all metadata values for a model object.

Return Value

  • array

array vals()

Get all metadata values for a model object. Alias for attributes().

Return Value

  • array

static mixed|null getAttribute(string $type, integer $modelId, string $attributeKey, null $scope = null, boolean $cache = true)

Static function to get a parameter without having to retrieve the base model.

Parameters

  • string $type
  • integer $modelId
  • string $attributeKey
  • null $scope
  • boolean $cache

Return Value

  • mixed|null

boolean is(string $key)

Convenience method for testing if a model value is truthy (bool true, string 'true', int 1, string '1').

Parameters

  • string $key

Return Value

  • boolean

Inherited from HasPrivateDatabase

array getDatabaseCredentials()

Get an array containing keys database, hostname, username, password, which can be used to create a connection to the private database from a module.

Return Value

  • array

DB getDatabase()

Get a database instance that is connected to the model-specific private database.

Return Value

See also

  • https://docs.includable.com/components/community-databases/