PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Interacting with groups

Google Groups allows people to post messages like an email list. Google is depreciating the Email List API. Google Groups provides some neat features like nested groups and group owners. If you want to start a new email lst, it is advisable to use Google Groups instead. Google's Email List is not compatible with Google Groups. So if you create an email list, it will not show up as a group. The opposite is true as well.

Each group on a domain is represented as an instance of Zend_Gdata_Gapps_GroupEntry.

Creating a group

Groups can be created by calling the createGroup() convenience method:

<?php
$gdata
->createGroup('friends''The Friends Group');

Groups can also be created by instantiating GroupEntry, providing a group id and name for the group, then calling insertGroup() on a service object to upload the entry to the server.

<?php
$group 
$gdata->newGroupEntry();

$properties[0] = $this->newProperty();
$properties[0]->name 'groupId';
$properties[0]->value 'friends';
$properties[1] = $this->newProperty();
$properties[1]->name 'groupName';
$properties[1]->value 'The Friends Group';

$group->property $properties;

$group $gdata->insertGroup($group);

Retrieving an individual group

To retrieve an individual group, call the retrieveGroup() convenience method:

<?php
$entry 
$gdata->retrieveGroup('friends');

foreach (
$entry->property as $p) {
    echo 
"Property Name: " $p->name;
    echo 
"\nProperty Value: " $p->value "\n\n";
}

This will create a Zend_Gdata_Gapps_GroupEntry object which holds the properties about the group.

Alternatively, create a new Zend_Gdata_Gapps_GroupQuery, set its groupId property to the desired group id, and submit the query by calling getGroupEntry() on a service object.

<?php
$query 
$gdata->newGroupQuery();
$query->setGroupId('friends');
$entry $gdata->getGroupEntry($query);

foreach (
$entry->property as $p) {
    echo 
"Property Name: " $p->name;
    echo 
"\nProperty Value: " $p->value "\n\n";
}

Retrieving all groups in a domain

To retrieve all groups in a domain, call the convenience method retrieveAllGroups().

<?php
$feed 
$gdata->retrieveAllGroups();

foreach (
$feed->entry as $entry) {
    foreach (
$entry->property as $p) {
        echo 
"Property Name: " $p->name;
        echo 
"\nProperty Value: " $p->value "\n\n";
    }
    echo 
"\n\n";
}

This will create a Zend_Gdata_Gapps_GroupFeed object which holds each group on the domain.

Alternatively, call getGroupFeed() on a service object with no arguments.

<?php
$feed 
$gdata->getGroupFeed();

foreach (
$feed->entry as $entry) {
    foreach (
$entry->property as $p) {
        echo 
"Property Name: " $p->name;
        echo 
"\nProperty Value: " $p->value "\n\n";
    }
    echo 
"\n\n";
}

Deleting a group

To delete a group, call the deleteGroup() convenience method:

<?php
$gdata
->deleteGroup('friends');

Updating a group

Groups can be updated by calling the updateGroup() convenience method:

<?php
$gdata
->updateGroup('group-id-here''Group Name Here');

The first parameter is required. The second, third and fourth parameter, representing the group name, group descscription, and email permission, respectively are optional. Setting any of these optional parameters to null will not update that item.

Retrieving all groups to which a person is a member

To retrieve all groups to which a particular person is a member, call the retrieveGroups() convenience method:

<?php
$feed 
$gdata->retrieveGroups('baz@somewhere.com');

foreach (
$feed->entry as $entry) {
    foreach (
$entry->property as $p) {
        echo 
"Property Name: " $p->name;
        echo 
"\nProperty Value: " $p->value "\n\n";
    }
    echo 
"\n\n";
}

This will create a Zend_Gdata_Gapps_GroupFeed object which holds each group associated with the specified member.

Alternatively, create a new Zend_Gdata_Gapps_GroupQuery, set its member property to the desired email address, and submit the query by calling getGroupFeed() on a service object.

<?php
$query 
$gdata->newGroupQuery();
$query->setMember('baz@somewhere.com');
$feed $gdata->getGroupFeed($query);

foreach (
$feed->entry as $entry) {
    foreach (
$entry->property as $p) {
        echo 
"Property Name: " $p->name;
        echo 
"\nProperty Value: " $p->value "\n\n";
    }
    echo 
"\n\n";
}

Zend Framework