Groups

Class \Lib\GroupsManager

Introduction

Groups are deviceuid lists stored in MongoDB, in a collection dedicated to your application.
This class provides methods for accessing and modifying your groups.
Its methods allows you to manage groups and deviceuids attached via CRUD methods.

📘

Note

The main utility of the groups concerns the sending of push notifications or polls.
You can create segments of devices according to several criteria of your choice (age range, device type, etc.) and from the backoffice or via the \Lib\Push class sent targeted notifications.

Basic usage

<?php
// add the current deviceuid to a new group.

$deviceuid = \Lib\Device::getInstance()->get('deviceuid');
$group = \Lib\GroupsManager::getInstance();
$group->create('first_group', $deviceuid);

Methods

getInstance

<?php public static function \Lib\GroupsManager::getInstance()

Description
Creates an instance of GroupsManager class.

fetchAll

<?php public function fetchAll(bool $asCursor = true)

Description
Fetches every group an application has.

Parameters

  • asCursor
    true to return groups as a \MongoCursor, false to get them as an array. Default is true.

Return
A MongoCursor or an array, depending on the selected asCursor parameter.

find

<?php public function find(array $criteria, bool $asCursor = true)

Description
Fetches matching groups.

Parameters

  • criteria
    The groups criteria
  • asCursor
    true to return groups as a \MongoCursor, false to get them as an array. Default is true.

Return
A MongoCursor or an array, depending on the selected asCursor parameter.

create

<?php public function create(string $name, string[] $deviceuidList = array(), string $type = 'perso', mixed $parameters = null)

Description
Creates a new group.

Parameters

  • name
    The group's name.
  • deviceuidList
    The group's members.
  • type
    The group's type.
  • parameters
    The group's additional parameters.

Return
\Lib\GroupsManager This groups manager.

delete

<?php public function delete(array $criteria)

Description
Deletes every matching groups.

Parameters

  • criteria
    The groups criteria.

Return
\Lib\GroupsManager This groups manager.

add

<?php public function add(array $criteria, string|string[] $deviceuid)

Description
Adds a deviceuid to existing groups.

Parameters

  • criteria
    The groups criteria.
  • deviceuid
    The deviceuid, or deviceuids, to add.

Return
\Lib\GroupsManager This groups manager.

has

<?php public function has(array $criteria, string\string[] $deviceuid)

Description
Tests whether at least one matching group has a specific deviceuid.

Parameters

  • criteria
    The groups criteria.
  • deviceuid
    The deviceuid, or deviceuids, to look for.

Return
bool true if at least one matching group has the deviceuid, false otherwise.

remove

<?php public function remove(array $criteria, string\string[] $deviceuid)

Description
Removes a deviceuid from matching groups.

Parameters

  • criteria
    The groups criteria.
  • deviceuid
    The deviceuid, or deviceuids, to remove.

Return
\Lib\GroupsManager This groups manager.

clear

<?php public function clear(array $criteria)

Description
Removes a deviceuid from matching groups.

Parameters

  • criteria
    The groups criteria.

Return
\Lib\GroupsManager This groups manager.


Examples