\midcom_core_collector

MidCOM DBA level wrapper for the Midgard Collector.

This class must be used anyplace within MidCOM instead of the real midgard_collector object within the MidCOM Framework. This wrapper is required for the correct operation of many MidCOM services.

It essentially wraps the calls to midcom_helper__dbfactory::new_collector().

Normally you should never have to create an instance of this type directly, instead use the new_collector() method available in the MidCOM DBA API or the midcom_helper__dbfactory::new_collector() method which is still available.

If you have to do create the instance manually however, do not forget to call the \initialize() function after construction, or the creation callbacks will fail.

Summary

Methods
Properties
Constants
get_doctrine()
get_current_group()
add_constraint()
add_constraint_with_property()
begin_group()
end_group()
set_limit()
set_offset()
add_order()
get_classname()
execute()
count()
count_unchecked()
__construct()
list_keys_unchecked()
get_values()
get_rows()
list_keys()
get_subkey()
get()
destroy()
set_key_property()
add_value_property()
get_objects()
$hide_invisible
$denied
No constants found
_convert_class()
_add_visibility_checks()
_reset()
$_visibility_checks_added
$_limit
$_offset
$_orders
$_real_class
$count
$_query
N/A
_list_keys_and_check_privileges()
$_user_id
N/A

Properties

$hide_invisible

$hide_invisible : boolean

Set this element to true to hide all items which are currently invisible according to the approval/scheduling settings made using Metadata. This must be set before executing the query.

NOTE: Approval checks not implemented in collector yet

Be aware, that this setting will currently not use the QB to filter the objects accordingly, since there is no way yet to filter against parameters. This will mean some performance impact.

Type

boolean

$denied

$denied : integer

The number of objects for which access was denied.

Type

integer

$_visibility_checks_added

$_visibility_checks_added : boolean

Flag that tracks whether deleted visibility check have already been added

Type

boolean

$_limit

$_limit : integer

The number of records to return to the client at most.

Type

integer

$_offset

$_offset : integer

The offset of the first record the client wants to have available.

Type

integer

$_orders

$_orders : array

The ordering instructions used for this query

Type

array

$_real_class

$_real_class : string

Type that the application expects to retrieve from this instance.

Type

string

$count

$count : integer

The number of records found by the last execute() run. This is -1 as long as no query has been executed. This member is read-only.

Type

integer

$_query

$_query : \midgard\portable\query

The query backend, should be set in constructor. Currently collector or querybuilder

Type

\midgard\portable\query

$_user_id

$_user_id : string

User id for ACL checks. This is set when executing to avoid unnecessary overhead

Type

string

Methods

get_doctrine()

get_doctrine() : \Doctrine\ORM\QueryBuilder

Returns

\Doctrine\ORM\QueryBuilder

get_current_group()

get_current_group() : \Doctrine\ORM\Query\Expr:

Returns

\Doctrine\ORM\Query\Expr:

add_constraint()

add_constraint(string  $field, string  $operator, mixed  $value) : boolean

Add a constraint to the query.

Parameters

string $field

The name of the MgdSchema property to query against.

string $operator

The operator to use for the constraint, currently supported are <, <=, =, <>, >=, >, LIKE. LIKE uses the percent sign ('%') as a wildcard character.

mixed $value

The value to compare against. It should be of the same type as the queried property.

Returns

boolean —

Indicating success.

add_constraint_with_property()

add_constraint_with_property(string  $field, string  $operator, string  $compare_field) : boolean

Add a constraint against another DB column to the query.

Parameters

string $field

The name of the MgdSchema property to query against.

string $operator

The operator to use for the constraint, currently supported are <, <=, =, <>, >=, >, LIKE. LIKE uses the percent sign ('%') as a wildcard character.

string $compare_field

The field to compare against.

Returns

boolean —

Indicating success.

begin_group()

begin_group(string  $operator = 'OR') 

Creates a new logical group within the query. They are set in parentheses in the final SQL and will thus be evaluated with precedence over the normal out-of-group constraints.

While the call lets you decide whether all constraints within the group are AND'ed or OR'ed, only OR constraints make logically sense in this context, which is why this proxy function sets 'OR' as the default operator.

Parameters

string $operator

One of 'OR' or 'AND' denoting the logical operation with which all constraints in the group are concatenated.

end_group()

end_group() 

Ends a group previously started with begin_group().

set_limit()

set_limit(integer  $limit) 

Limits the resultset to contain at most the specified number of records.

Set the limit to zero to retrieve all available records.

Parameters

integer $limit

The maximum number of records in the resultset.

set_offset()

set_offset(integer  $offset) 

Sets the offset of the first record to retrieve. This is a zero based index, so if you want to retrieve from the very first record, the correct offset would be zero, not one.

Parameters

integer $offset

The record number to start with.

add_order()

add_order(string  $field, string  $direction = 'ASC') : boolean

Add an ordering constraint to the query builder.

Parameters

string $field

The name of the MgdSchema property to query against.

string $direction

One of 'ASC' or 'DESC' indicating ascending or descending ordering. The default is 'ASC'.

Returns

boolean —

Indicating success.

get_classname()

get_classname() 

Get the DBA class we're currently working on

execute()

execute() : boolean

Execute the Querybuilder and call the appropriate callbacks from the associated class. This way, class authors have full control over what is actually returned to the application.

The calling sequence of all event handlers of the associated class is like this:

  1. boolean _on_prepare_exec_collector(&$this) is called before the actual query execution. Return false to abort the operation.

Returns

boolean —

True if the query was executed, false otherwise (e.g. if it had been executed already)

count()

count() : integer

Returns the number of elements matching the current query.

Due to ACL checking we must first execute the full query

Returns

integer —

The number of records found by the last query.

count_unchecked()

count_unchecked() : integer

This is a mapping to the real count function of the Midgard Collector. It is mainly intended when speed is important over accuracy, as it bypasses access control to get a fast impression of how many objects are available in a given query. It should always be kept in mind that this is a preliminary number, not a final one.

Use this function with care. The information you obtain in general is negligible, but a creative mind might nevertheless be able to take advantage of it.

Returns

integer —

The number of records matching the constraints without taking access control or visibility into account.

__construct()

__construct(string  $classname,   $domain = null,   $value = null) 

The initialization routine executes the _on_prepare_new_collector callback on the class.

Parameters

string $classname

The classname which should be queried.

$domain
$value

list_keys_unchecked()

list_keys_unchecked() 

Runs a query where limit and offset is taken into account <i>prior</i> to execution in the core.

This is useful in cases where you can safely assume read privileges on all objects, and where you would otherwise have to deal with huge resultsets.

Be aware that this might lead to empty resultsets "in the middle" of the actual full resultset when read privileges are missing.

get_values()

get_values(string  $field) 

Convenience function to get all values of a specific column, indexed by GUID

Parameters

string $field

the column name

get_rows()

get_rows(array  $fields, string  $indexed_by = 'guid') : array

Convenience function to get all values of a number of columns They are indexed by GUID unless you specify something else

Parameters

array $fields

The fields to get

string $indexed_by

the column name to be used as index

Returns

array

list_keys()

list_keys() : array

implements midgard_collector::list_keys with ACL checking

Returns

array

get_subkey()

get_subkey(  $key,   $property) 

Parameters

$key
$property

get()

get(  $key) 

Parameters

$key

destroy()

destroy() 

set_key_property()

set_key_property(  $property,   $value = null) 

Parameters

$property
$value

add_value_property()

add_value_property(  $property) 

Parameters

$property

get_objects()

get_objects() 

_convert_class()

_convert_class(string  $classname) : string

Class resolution into the MidCOM DBA system.

Currently, Midgard requires the actual MgdSchema base classes to be used when dealing with the query, so we internally note the corresponding class information to be able to do correct typecasting later.

Parameters

string $classname

The classname which should be converted.

Returns

string —

MgdSchema class name

_add_visibility_checks()

_add_visibility_checks() 

_reset()

_reset() 

Resets some internal variables for re-execute

_list_keys_and_check_privileges()

_list_keys_and_check_privileges(  $apply_offset_limit = true) 

Parameters

$apply_offset_limit