tasks_collection_search

Allows processing custom task filtering parameters.

Teamwork

Input (passed by reference)

$params['collection'] object Instance of the tasksCollection class corresponding to the current task collection.
$params['conditions'] array Task filtering conditions list passed into the collection class instance and not processed by the standard app logic. Each list item is an array with the following keys:
$params['conditions'][]['field'] string Task filtering parameter name. A plugin usually processes only the parameters whose names begin with the plugin’s identifier to avoid conflicts with other plugins.
$params['conditions'][]['op'] string The operator which must be applied to the specified parameter value.
$params['conditions'][]['value'] mixed The parameter value to which the operator must be applied.
$params['conditions'][]['expression'] string The task filtering expression composed of the operator and the parameter value; e.g., '>= 2001-01-01'.
… your plugin code …

Output

Teamwork

Plugin code example

PHP

public function tasksCollectionSearch($params)
{
    /** @var tasksCollection */
    $collection = $params['collection'];

    foreach ((array) $params['conditions'] as $condition) {
        // Process only filter parameter names that begin with this plugin's ID.
        if (strpos($condition['field'], $this->id . '_') === 0) {
            switch ($condition['field']) {
                // E.g.; filter tasks by the the create date specified in the 'myplugin_create_date' parameter
                // passed to the tasks collection.
                // #/tasks/myplugin_create_date>2023-12-25&hash=inbox/
                case $this->id . '_create_date':
                    if (
                        in_array($condition['op'], ['<', '<=', '=', '>', '>='])
                        && preg_match('~\d{4}-\d{2}-\d{2}~', $condition['value'])
                    ) {
                        $collection->addWhere(sprintf(
                            't.create_datetime %s "%s 00:00:00"',
                            $condition['op'],
                            $condition['value']
                        ));
                    }
                    break;
            }
        }
    }
}