This class only contains static functions which are there to hook into the classes you derive from the MidgardSchema DB types like (New)MidgardArticle.

The static members will invoke a number of callback methods so that you should normally never have to override the base midgard methods like update or the like.

package midcom.baseclasses

 Methods

cast_object (\midcom_core_dbaobject $newobject, \midcom_core_dbaobject $oldobject)

Copies values from oldobject to newobject in case the types are compatible
Static

Parameters

$newobject

\midcom_core_dbaobjectA class inherited from one of the MgdSchema driven Midgard classes supporting the above callbacks.

$oldobject

\midcom_core_dbaobjecta parent object (usually a midgard_* base class) which to copy.

Returns

boolIndicating success.

create (\midcom_core_dbaobject $object)

Execute a DB create of the object passed.
Static

This will call the corresponding event handlers. Calling sequence with method signatures:

  1. Validate privileges using can_do. The user needs midgard:create privilege to the parent object or in general, if there is no parent.
  2. bool $object->_on_creating() is executed. If it returns false, create is aborted.
  3. bool $object->__exec_create() is executed to do the actual DB create. This has to execute parent::create() and return its value, nothing else.
  4. void $object->_on_created() is executed to notify the class from a successful DB creation.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating success.

create_attachment (\midcom_core_dbaobject $object, string $name, string $title, string $mimetype)

Creates a new attachment at the current object and returns it for usage.
Static

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$name

stringThe name of the attachment.

$title

stringThe title of the attachment.

$mimetype

stringThe MIME-Type of the attachment.

Returns

\midcom_db_attachmentThe created attachment or false on failure.

create_new_privilege_object (\midcom_core_dbaobject $object, string $name, mixed $assignee, int $value, string $classname)

This helper function will create a new privilege object for the object in question.
Static

It will initialize the privilege with the values given in the arguments, as outlined below.

This call requires the midgard:privileges privilege.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$name

stringThe name of the privilege to add.

$assignee

mixedA valid assignee suitable for midcom_core_privilege::set_privilege(). This defaults to the currently active user if authenticated or to 'EVERYONE' otherwise.

$value

intThe privilege value, this defaults to MIDCOM_PRIVILEGE_ALLOW.

$classname

stringAn optional class name to which a SELF privilege gets restricted to. Only valid for SELF privileges.

Returns

\midcom_core_privilegeThe newly created privilege record or false on failure.

create_post_ops (\midcom_core_dbaobject $object)

Post object creation operations for create
Static

Separated so that dbfactory->import() can reuse the code

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

create_pre_checks (\midcom_core_dbaobject $object)

"Pre-flight" checks for create method
Static

Separated so that dbfactory->import() can reuse the code

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

delete (\midcom_core_dbaobject $object)

Execute a DB delete of the object passed.
Static

This will call the corresponding event handlers. Calling sequence with method signatures:

  1. Validate privileges using can_do. The user needs midgard:delete privilege on the content object.
  2. bool $object->_on_deleting() is executed. If it returns false, delete is aborted.
  3. All extensions of the object are deleted
  4. bool $object->__exec_delete() is executed to do the actual DB delete. This has to execute parent::delete() and return its value, nothing else.
  5. void $object->_on_deleted() is executed to notify the class from a successful DB deletion.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating success.

delete_attachment (\midcom_core_dbaobject $object, string $name)

Delete an attachment on an arbitrary object by its name.
Static

If multiple attachments match the name (should not happen in reality), the first match will be deleted.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$name

stringThe name of the attachment to delete.

Returns

boolIndicating success.

delete_parameter (\midcom_core_dbaobject $object, string $domain, string $name)

Delete a parameter of a given object to the value specified.
Static

Current implementation note: Deletion is not yet implemented in MgdSchema. Therefore we set the parameters to an empty string for now, which should have almost the same effect for most cases and thus is good enough for now. Note, that empty string parameters are filtered in the getter methods until this matter is resolved.

The user needs both update and parameter manipulationpermission on the parent object for updates.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$domain

stringThe Parameter Domain.

$name

stringThe Parameter name.

Returns

boolIndicating success.

delete_post_ops (\midcom_core_dbaobject $object)

Post object creation operations for delete
Static

Separated so that dbfactory->import() can reuse the code

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

delete_pre_checks (\midcom_core_dbaobject $object)

"Pre-flight" checks for delete method
Static

Separated so that dbfactory->import() can reuse the code

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

delete_tree (\midcom_core_dbaobject $object)

Execute a DB delete of the object passed and delete its descendants.
Static

This will call the corresponding event handlers. Calling sequence with method signatures:

  1. Get all of the child objects
  2. Delete them recursively starting from the top, working towards the root
  3. Finally delete the root object

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

booleanIndicating success.

get_attachment (\midcom_core_dbaobject $object, string $name)

Retrieves an attachment on an arbitrary object by its name.
Static

If multiple attachments match the name (should not happen in reality), the first match will be returned.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$name

stringThe name of the attachment to look up.

Returns

\midcom_db_attachmentThe attachment found, or false on failure.

get_attachment_qb (\midcom_core_dbaobject $object)

Returns a prepared query builder that is already limited to the attachments of the given object.
Static

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

\midgard_query_builderPrepared Query Builder or false on failure.

get_by_guid (\midcom_core_dbaobject $object, string $guid)

This call wraps the original get_by_guid call to provide access control.
Static

The calling sequence is as with the corresponding constructor.

Parameters

$object

\midcom_core_dbaobject&$object The DBA object we're working on

$guid

stringThe guid of the object to load from the database.

Returns

boolIndicating Success

get_by_id (\midcom_core_dbaobject $object, int $id)

This call wraps the original get_by_id call to provide access control.
Static

The calling sequence is as with the corresponding constructor.

Parameters

$object

\midcom_core_dbaobject&$object The DBA object we're working on

$id

intThe id of the object to load from the database.

Returns

boolIndicating Success

get_by_path (\midcom_core_dbaobject $object, string $path)

This call wraps the original get_by_guid call to provide access control.
Static

The calling sequence is as with the corresponding constructor.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$path

stringThe path of the object to load from the database.

Returns

boolIndicating Success

get_parameter (\midcom_core_dbaobject $object, string $domain, string $name)

Return a parameter from the database.
Static

No event handlers are called here yet.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$domain

stringThe parameter domain.

$name

stringThe parameter name.

Returns

stringThe parameter value or false otherwise (remember typesafe comparisons to protect against '' strings).

get_privilege (\midcom_core_dbaobject $object, string $privilege, mixed $assignee, string $classname)

Looks up a privilege by its parameters.
Static

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$privilege

stringThe name of the privilege.

$assignee

mixedEither a valid magic assignee (SELF, EVERYONE, USERS, ANONYMOUS), a midcom_core_user or a midcom_core_group object or subtype thereof.

$classname

stringAn optional class name to which a SELF privilege is restricted to.

Returns

\midcom_core_privilegeThe privilege record from the database.

get_privileges (\midcom_core_dbaobject $object)

Read all privilege records from the object in question and return them accordingly.
Static

You need privilege access to get this information (midgard:read (tested during construction) and midgard:privileges) otherwise, the call will fail.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

ArrayA list of midcom_core_privilege objects or false on failure.

is_object_visible_onsite (\midcom_core_dbaobject $object)

This is a metadata helper that maps to the metadata onsite visibility check function, making checks against visibility far easier.
Static

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating visibility state.

list_attachments (\midcom_core_dbaobject $object)

Returns a complete list of attachments for the current object.
Static

If there are no attachments, an empty array is returned.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

ArrayA list of midcom_db_attachment objects or false on failure.

list_parameters (\midcom_core_dbaobject $object, string $domain)

List the parameters of an object.
Static

This will either list the parameters of a single domain or the complete set of parameters, depending on the value of $domain.

It delegates the actual execution to two separate helper functions.

No event handlers are called here yet.

In case of a complete query, the result will be an associative array indexed by the domain name and containing another array with parameter name/value pairs. For example:

Array
(
    [Asgard] => Array
    (
        [lang] => en_US
        [act] => view
        [actloc] => tree
    )
    [AsgardTreeHost] => Array
    (
        [selected] => host0
    )
)

If you query only a single domain, the result will be a single associative array containing the parameter name/value pairs. For example:

Array
(
    [lang] => en_US
    [act] => view
    [actloc] => tree
)

In both cases an empty Array will indicate that no parameter was found, while false will indicate a failure while querying the database.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$domain

stringThe parameter domain to query, this may be null to indicate a full listing.

Returns

ArrayParameter list (see above for details) or false on failure.

post_db_load_checks (\midcom_core_dbaobject $object)

After we instantiated the midgard object do some post processing and ACL checks
Static
see \load()

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating success.

purge (array $guids, string $type)

Helper method for purging objects
Static

Parameters

$guids

array

$type

string

Returns

booleanIndicating success

purge_attachments (string $guid)

Purge the attachments related to a deleted object
Static

Parameters

$guid

string

Returns

booleanIndicating success

purge_parameters (string $guid)

Purge the parameters related to a deleted object
Static

Parameters

$guid

string

Returns

booleanIndicating success

refresh (\midcom_core_dbaobject $object)

This is a simple wrapper with (currently) no additional functionality over get_by_id that resynchronizes the object state with the database.
Static

Use this if you think that your current object is stale. It does full access control.

On any failure, the object is cleared.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating Success

set_parameter (\midcom_core_dbaobject $object, string $domain, string $name, string $value)

Set a parameter of a given object to the value specified.
Static

This is either a create or an update operation depending on whether there was already a parameter of that domain/name present, or not.

The user needs both update and parameter manipulationpermission on the parent object for updates.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$domain

stringThe Parameter Domain.

$name

stringThe Parameter name.

$value

stringThe Parameter value. If this is empty, the corresponding parameter is deleted.

Returns

boolIndicating success.

set_privilege (\midcom_core_dbaobject $object, mixed $privilege, mixed $assignee, int $value, string $classname)

Set a privilege on an object.
Static

This requires both midgard:update and midgard:privileges.

You can either pass a ready made privilege record or a privilege/assignee/value combination suitable for usage with create_new_privilege_object() (see there).

see \midcom_services_auth

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$privilege

mixedEither the full privilege object (midcom_core_privilege) to set or the name of the privilege (string). If the name was specified, the other parameters must be specified as well.

$assignee

mixedA valid assignee suitable for midcom_core_privilege::set_privilege(). This defaults to the currently active user if authenticated or to 'EVERYONE' otherwise (invalid if $privilege is a midcom_core_privilege).

$value

intThe privilege value, this defaults to MIDCOM_PRIVILEGE_ALLOW (invalid if $privilege is a midcom_core_privilege).

$classname

stringAn optional class name to which a SELF privilege gets restricted to. Only valid for SELF privileges (invalid if $privilege is a midcom_core_privilege).

Returns

boolIndicating success.

undelete (array $guids, string $type)

Helper method for undeleting objects
Static
todo We should only undelete parameters & attachments deleted inside some small window of the main objects delete

Parameters

$guids

array

$type

string

Returns

booleanIndicating success

undelete_attachments (string $guid)

Recover the attachments related to a deleted object
Static
todo We should only undelete parameters & attachments deleted inside some small window of the main objects delete

Parameters

$guid

string

Returns

booleanIndicating success

undelete_parameters (string $guid)

Recover the parameters related to a deleted object
Static
todo We should only undelete parameters & attachments deleted inside some small window of the main objects delete

Parameters

$guid

string

Returns

booleanIndicating success

unset_all_privileges (\midcom_core_dbaobject $object)

Unsets all privilege on an object .
Static

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating success.

unset_privilege (\midcom_core_dbaobject $object, mixed $privilege, mixed $assignee, string $classname)

Unset a privilege on an object (e.g.
Static

set it to INHERIT).

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$privilege

mixedEither the full privilege object (midcom_core_privilege) to set or the name of the privilege (string). If the name was specified, the other parameters must be specified as well.

$assignee

mixedA valid assignee suitable for midcom_core_privilege::set_privilege(). This defaults to the currently active user if authenticated or to 'EVERYONE' otherwise (invalid if $privilege is a midcom_core_privilege).

$classname

stringAn optional class name to which a SELF privilege gets restricted to. Only valid for SELF privileges (invalid if $privilege is a midcom_core_privilege).

Returns

boolIndicating Success.

update (\midcom_core_dbaobject $object)

Execute a DB update of the object passed.
Static

This will call the corresponding event handlers. Calling sequence with method signatures:

  1. Validate privileges using can_do. The user needs midgard:update privilege on the content object.
  2. bool $object->_on_updating() is executed. If it returns false, update is aborted.
  3. bool $object->__exec_update() is executed to do the actual DB update. This has to execute parent::update() and return its value, nothing else.
  4. void $object->_on_updated() is executed to notify the class from a successful DB update.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating success.

update_post_ops (\midcom_core_dbaobject $object)

Post object creation operations for create
Static

Separated so that dbfactory->import() can reuse the code

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

update_pre_checks (\midcom_core_dbaobject $object)

"Pre-flight" checks for update method
Static

Separated so that dbfactory->import() can reuse the code

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

_clear_object (\midcom_core_dbaobject $object)

This method is deprecated.
Static

It does nothing.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

_delete_privileges (\midcom_core_dbaobject $object)

Internal helper function, called upon successful delete.
Static

It will unconditionally drop all privileges assigned to the given object.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

boolIndicating Success.

_list_parameters_all (\midcom_core_dbaobject $object)

List all parameters of an object.
Static

No event handlers are called here yet.

see \list_parameters()

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

ArrayParameter listing or false on failure.

_list_parameters_domain (\midcom_core_dbaobject $object, string $domain)

List the parameters of a single domain of an object.
Static

No event handlers are called here yet.

see \list_parameters()

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

$domain

stringThe parameter domain to query.

Returns

ArrayParameter listing or false on failure.

_set_owner_privileges (\midcom_core_dbaobject $object)

This is an internal helper adds full privileges to the owner of the object.
Static

This is essentially sets the midgard:owner privilege for the current user.

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

 Properties

 

mixed $parameter_cache