Completed
Push — master ( 85e358...cf3219 )
by Rakesh
04:24 queued 10s
created

Zend_Gdata_Gapps::insertNickname()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
/**
4
 * Zend Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file LICENSE.txt.
10
 * It is also available through the world-wide-web at this URL:
11
 * http://framework.zend.com/license/new-bsd
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @category   Zend
17
 * @package    Zend_Gdata
18
 * @subpackage Gapps
19
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
20
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
21
 * @version    $Id$
22
 */
23
24
/**
25
 * @see Zend_Gdata
26
 */
27
require_once 'Zend/Gdata.php';
28
29
/**
30
 * @see Zend_Gdata_Gapps_UserFeed
31
 */
32
require_once 'Zend/Gdata/Gapps/UserFeed.php';
33
34
/**
35
 * @see Zend_Gdata_Gapps_NicknameFeed
36
 */
37
require_once 'Zend/Gdata/Gapps/NicknameFeed.php';
38
39
/**
40
 * @see Zend_Gdata_Gapps_GroupFeed
41
 */
42
require_once 'Zend/Gdata/Gapps/GroupFeed.php';
43
44
/**
45
 * @see Zend_Gdata_Gapps_MemberFeed
46
 */
47
require_once 'Zend/Gdata/Gapps/MemberFeed.php';
48
49
/**
50
 * @see Zend_Gdata_Gapps_OwnerFeed
51
 */
52
require_once 'Zend/Gdata/Gapps/OwnerFeed.php';
53
54
/**
55
 * @see Zend_Gdata_Gapps_EmailListFeed
56
 */
57
require_once 'Zend/Gdata/Gapps/EmailListFeed.php';
58
59
/**
60
 * @see Zend_Gdata_Gapps_EmailListRecipientFeed
61
 */
62
require_once 'Zend/Gdata/Gapps/EmailListRecipientFeed.php';
63
64
65
/**
66
 * Service class for interacting with the Google Apps Provisioning API.
67
 *
68
 * Like other service classes in this module, this class provides access via
69
 * an HTTP client to Google servers for working with entries and feeds.
70
 *
71
 * Because of the nature of this API, all access must occur over an
72
 * authenticated connection.
73
 *
74
 * @link http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html
75
 *
76
 * @category   Zend
77
 * @package    Zend_Gdata
78
 * @subpackage Gapps
79
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
80
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
81
 */
82
class Zend_Gdata_Gapps extends Zend_Gdata
83
{
84
85
    const APPS_BASE_FEED_URI = 'https://apps-apis.google.com/a/feeds';
86
    const AUTH_SERVICE_NAME = 'apps';
87
88
    /**
89
     * Path to user feeds on the Google Apps server.
90
     */
91
    const APPS_USER_PATH = '/user/2.0';
92
93
    /**
94
     * Path to nickname feeds on the Google Apps server.
95
     */
96
    const APPS_NICKNAME_PATH = '/nickname/2.0';
97
98
    /**
99
     * Path to group feeds on the Google Apps server.
100
     */
101
    const APPS_GROUP_PATH = '/group/2.0';
102
103
    /**
104
     * Path to email list feeds on the Google Apps server.
105
     */
106
    const APPS_EMAIL_LIST_PATH = '/emailList/2.0';
107
108
    /**
109
     * Path to email list recipient feeds on the Google Apps server.
110
     */
111
    const APPS_EMAIL_LIST_RECIPIENT_POSTFIX = '/recipient';
112
113
    /**
114
     * The domain which is being administered via the Provisioning API.
115
     *
116
     * @var string
117
     */
118
    protected $_domain = null;
119
120
    /**
121
     * Namespaces used for Zend_Gdata_Gapps
122
     *
123
     * @var array
124
     */
125
    public static $namespaces = array(
126
        array('apps', 'http://schemas.google.com/apps/2006', 1, 0)
127
    );
128
129
    /**
130
     * Create Gdata_Gapps object
131
     *
132
     * @param Zend_Http_Client $client (optional) The HTTP client to use when
133
     *          when communicating with the Google Apps servers.
134
     * @param string $domain (optional) The Google Apps domain which is to be
135
     *          accessed.
136
     * @param string $applicationId The identity of the app in the form of Company-AppName-Version
137
     */
138
    public function __construct($client = null, $domain = null, $applicationId = 'MyCompany-MyApp-1.0')
139
    {
140
        $this->registerPackage('Zend_Gdata_Gapps');
141
        $this->registerPackage('Zend_Gdata_Gapps_Extension');
142
        parent::__construct($client, $applicationId);
143
        $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
144
        $this->_domain = $domain;
145
    }
146
147
    /**
148
     * Convert an exception to an ServiceException if an AppsForYourDomain
149
     * XML document is contained within the original exception's HTTP
150
     * response. If conversion fails, throw the original error.
151
     *
152
     * @param Zend_Gdata_Exception $e The exception to convert.
0 ignored issues
show
Bug introduced by
The type Zend_Gdata_Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
153
     * @throws Zend_Gdata_Gapps_ServiceException
154
     * @throws mixed
155
     */
156
    public static function throwServiceExceptionIfDetected($e) {
157
        // Check to make sure that there actually response!
158
        // This can happen if the connection dies before the request
159
        // completes. (See ZF-5949)
160
        $response = $e->getResponse();
161
        if (!$response) {
162
          require_once('Zend/Gdata/App/IOException.php');
163
          throw new Zend_Gdata_App_IOException('No HTTP response received (possible connection failure)');
164
        }
165
166
        try {
167
            // Check to see if there is an AppsForYourDomainErrors
168
            // datastructure in the response. If so, convert it to
169
            // an exception and throw it.
170
            require_once 'Zend/Gdata/Gapps/ServiceException.php';
171
            $error = new Zend_Gdata_Gapps_ServiceException();
172
            $error->importFromString($response->getBody());
173
            throw $error;
174
        } catch (Zend_Gdata_App_Exception $e2) {
175
            // Unable to convert the response to a ServiceException,
176
            // most likely because the server didn't return an
177
            // AppsForYourDomainErrors document. Throw the original
178
            // exception.
179
            throw $e;
180
        }
181
    }
182
183
    /**
184
     * Imports a feed located at $uri.
185
     * This method overrides the default behavior of Zend_Gdata_App,
186
     * providing support for Zend_Gdata_Gapps_ServiceException.
187
     *
188
     * @param  string $uri
189
     * @param  Zend_Http_Client $client (optional) The client used for
190
     *          communication
191
     * @param  string $className (optional) The class which is used as the
192
     *          return type
193
     * @throws Zend_Gdata_App_Exception
194
     * @throws Zend_Gdata_App_HttpException
195
     * @throws Zend_Gdata_Gapps_ServiceException
196
     * @return Zend_Gdata_App_Feed
197
     */
198
    public static function import($uri, $client = null, $className='Zend_Gdata_App_Feed', $useObjectMapping = true)
199
    {
200
        try {
201
            return parent::import($uri, $client, $className, $useObjectMapping);
202
        } catch (Zend_Gdata_App_HttpException $e) {
203
            self::throwServiceExceptionIfDetected($e);
204
        }
205
    }
206
207
    /**
208
     * GET a URI using client object.
209
     * This method overrides the default behavior of Zend_Gdata_App,
210
     * providing support for Zend_Gdata_Gapps_ServiceException.
211
     *
212
     * @param string $uri GET URI
213
     * @param array $extraHeaders Extra headers to add to the request, as an
214
     *        array of string-based key/value pairs.
215
     * @throws Zend_Gdata_App_HttpException
216
     * @throws Zend_Gdata_Gapps_ServiceException
217
     * @return Zend_Http_Response
218
     */
219
    public function get($uri, $extraHeaders = array())
220
    {
221
        try {
222
            return parent::get($uri, $extraHeaders);
223
        } catch (Zend_Gdata_App_HttpException $e) {
224
            self::throwServiceExceptionIfDetected($e);
225
        }
226
    }
227
228
    /**
229
     * POST data with client object.
230
     * This method overrides the default behavior of Zend_Gdata_App,
231
     * providing support for Zend_Gdata_Gapps_ServiceException.
232
     *
233
     * @param mixed $data The Zend_Gdata_App_Entry or XML to post
234
     * @param string $uri (optional) POST URI
235
     * @param integer $remainingRedirects (optional)
236
     * @param string $contentType Content-type of the data
237
     * @param array $extraHaders Extra headers to add tot he request
238
     * @return Zend_Http_Response
239
     * @throws Zend_Gdata_App_HttpException
240
     * @throws Zend_Gdata_App_InvalidArgumentException
241
     * @throws Zend_Gdata_Gapps_ServiceException
242
     */
243
    public function post($data, $uri = null, $remainingRedirects = null,
244
            $contentType = null, $extraHeaders = null)
245
    {
246
        try {
247
            return parent::post($data, $uri, $remainingRedirects, $contentType, $extraHeaders);
248
        } catch (Zend_Gdata_App_HttpException $e) {
249
            self::throwServiceExceptionIfDetected($e);
250
        }
251
    }
252
253
    /**
254
     * PUT data with client object
255
     * This method overrides the default behavior of Zend_Gdata_App,
256
     * providing support for Zend_Gdata_Gapps_ServiceException.
257
     *
258
     * @param mixed $data The Zend_Gdata_App_Entry or XML to post
259
     * @param string $uri (optional) PUT URI
260
     * @param integer $remainingRedirects (optional)
261
     * @param string $contentType Content-type of the data
262
     * @param array $extraHaders Extra headers to add tot he request
263
     * @return Zend_Http_Response
264
     * @throws Zend_Gdata_App_HttpException
265
     * @throws Zend_Gdata_App_InvalidArgumentException
266
     * @throws Zend_Gdata_Gapps_ServiceException
267
     */
268
    public function put($data, $uri = null, $remainingRedirects = null,
269
            $contentType = null, $extraHeaders = null)
270
    {
271
        try {
272
            return parent::put($data, $uri, $remainingRedirects, $contentType, $extraHeaders);
273
        } catch (Zend_Gdata_App_HttpException $e) {
274
            self::throwServiceExceptionIfDetected($e);
275
        }
276
    }
277
278
    /**
279
     * DELETE entry with client object
280
     * This method overrides the default behavior of Zend_Gdata_App,
281
     * providing support for Zend_Gdata_Gapps_ServiceException.
282
     *
283
     * @param mixed $data The Zend_Gdata_App_Entry or URL to delete
284
     * @param integer $remainingRedirects (optional)
285
     * @return void
286
     * @throws Zend_Gdata_App_HttpException
287
     * @throws Zend_Gdata_App_InvalidArgumentException
288
     * @throws Zend_Gdata_Gapps_ServiceException
289
     */
290
    public function delete($data, $remainingRedirects = null)
291
    {
292
        try {
293
            return parent::delete($data, $remainingRedirects);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::delete($data, $remainingRedirects) targeting Zend_Gdata_App::delete() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
294
        } catch (Zend_Gdata_App_HttpException $e) {
295
            self::throwServiceExceptionIfDetected($e);
296
        }
297
    }
298
299
    /**
300
     * Set domain for this service instance. This should be a fully qualified
301
     * domain, such as 'foo.example.com'.
302
     *
303
     * This value is used when calculating URLs for retrieving and posting
304
     * entries. If no value is specified, a URL will have to be manually
305
     * constructed prior to using any methods which interact with the Google
306
     * Apps provisioning service.
307
     *
308
     * @param string $value The domain to be used for this session.
309
     */
310
    public function setDomain($value)
311
    {
312
        $this->_domain = $value;
313
    }
314
315
    /**
316
     * Get domain for this service instance. This should be a fully qualified
317
     * domain, such as 'foo.example.com'. If no domain is set, null will be
318
     * returned.
319
     *
320
     * @return string The domain to be used for this session, or null if not
321
     *          set.
322
     */
323
    public function getDomain()
324
    {
325
        return $this->_domain;
326
    }
327
328
    /**
329
     * Returns the base URL used to access the Google Apps service, based
330
     * on the current domain. The current domain can be temporarily
331
     * overridden by providing a fully qualified domain as $domain.
332
     *
333
     * @param string $domain (optional) A fully-qualified domain to use
334
     *          instead of the default domain for this service instance.
335
     * @throws Zend_Gdata_App_InvalidArgumentException
336
     */
337
     public function getBaseUrl($domain = null)
338
     {
339
         if ($domain !== null) {
340
             return self::APPS_BASE_FEED_URI . '/' . $domain;
341
         } else if ($this->_domain !== null) {
342
             return self::APPS_BASE_FEED_URI . '/' . $this->_domain;
343
         } else {
344
             require_once 'Zend/Gdata/App/InvalidArgumentException.php';
345
             throw new Zend_Gdata_App_InvalidArgumentException(
346
                     'Domain must be specified.');
347
         }
348
     }
349
350
    /**
351
     * Retrieve a UserFeed containing multiple UserEntry objects.
352
     *
353
     * @param mixed $location (optional) The location for the feed, as a URL
354
     *          or Query.
355
     * @return Zend_Gdata_Gapps_UserFeed
356
     * @throws Zend_Gdata_App_Exception
357
     * @throws Zend_Gdata_App_HttpException
358
     * @throws Zend_Gdata_Gapps_ServiceException
359
     */
360
    public function getUserFeed($location = null)
361
    {
362
        if ($location === null) {
363
            $uri = $this->getBaseUrl() . self::APPS_USER_PATH;
364
        } else if ($location instanceof Zend_Gdata_Query) {
365
            $uri = $location->getQueryUrl();
366
        } else {
367
            $uri = $location;
368
        }
369
        return parent::getFeed($uri, 'Zend_Gdata_Gapps_UserFeed');
370
    }
371
372
    /**
373
     * Retreive NicknameFeed object containing multiple NicknameEntry objects.
374
     *
375
     * @param mixed $location (optional) The location for the feed, as a URL
376
     *          or Query.
377
     * @return Zend_Gdata_Gapps_NicknameFeed
378
     * @throws Zend_Gdata_App_Exception
379
     * @throws Zend_Gdata_App_HttpException
380
     * @throws Zend_Gdata_Gapps_ServiceException
381
     */
382
    public function getNicknameFeed($location = null)
383
    {
384
        if ($location === null) {
385
            $uri = $this->getBaseUrl() . self::APPS_NICKNAME_PATH;
386
        } else if ($location instanceof Zend_Gdata_Query) {
387
            $uri = $location->getQueryUrl();
388
        } else {
389
            $uri = $location;
390
        }
391
        return parent::getFeed($uri, 'Zend_Gdata_Gapps_NicknameFeed');
392
    }
393
394
    /**
395
     * Retreive GroupFeed object containing multiple GroupEntry
396
     * objects.
397
     *
398
     * @param mixed $location (optional) The location for the feed, as a URL
399
     *          or Query.
400
     * @return Zend_Gdata_Gapps_GroupFeed
401
     * @throws Zend_Gdata_App_Exception
402
     * @throws Zend_Gdata_App_HttpException
403
     * @throws Zend_Gdata_Gapps_ServiceException
404
     */
405
    public function getGroupFeed($location = null)
406
    {
407
        if ($location === null) {
408
            $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
409
            $uri .= $this->getDomain();
410
        } else if ($location instanceof Zend_Gdata_Query) {
411
            $uri = $location->getQueryUrl();
412
        } else {
413
            $uri = $location;
414
        }
415
        return parent::getFeed($uri, 'Zend_Gdata_Gapps_GroupFeed');
416
    }
417
418
    /**
419
     * Retreive MemberFeed object containing multiple MemberEntry
420
     * objects.
421
     *
422
     * @param mixed $location (optional) The location for the feed, as a URL
423
     *          or Query.
424
     * @return Zend_Gdata_Gapps_MemberFeed
425
     * @throws Zend_Gdata_App_Exception
426
     * @throws Zend_Gdata_App_HttpException
427
     * @throws Zend_Gdata_Gapps_ServiceException
428
     */
429
    public function getMemberFeed($location = null)
430
    {
431
        if ($location === null) {
432
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
433
            throw new Zend_Gdata_App_InvalidArgumentException(
434
                    'Location must not be null');
435
        } else if ($location instanceof Zend_Gdata_Query) {
436
            $uri = $location->getQueryUrl();
437
        } else {
438
            $uri = $location;
439
        }
440
        return parent::getFeed($uri, 'Zend_Gdata_Gapps_MemberFeed');
441
    }
442
443
    /**
444
     * Retreive OwnerFeed object containing multiple OwnerEntry
445
     * objects.
446
     *
447
     * @param mixed $location (optional) The location for the feed, as a URL
448
     *          or Query.
449
     * @return Zend_Gdata_Gapps_OwnerFeed
450
     * @throws Zend_Gdata_App_Exception
451
     * @throws Zend_Gdata_App_HttpException
452
     * @throws Zend_Gdata_Gapps_ServiceException
453
     */
454
    public function getOwnerFeed($location = null)
455
    {
456
        if ($location === null) {
457
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
458
            throw new Zend_Gdata_App_InvalidArgumentException(
459
                    'Location must not be null');
460
        } else if ($location instanceof Zend_Gdata_Query) {
461
            $uri = $location->getQueryUrl();
462
        } else {
463
            $uri = $location;
464
        }
465
        return parent::getFeed($uri, 'Zend_Gdata_Gapps_OwnerFeed');
466
    }
467
468
    /**
469
     * Retreive EmailListFeed object containing multiple EmailListEntry
470
     * objects.
471
     *
472
     * @param mixed $location (optional) The location for the feed, as a URL
473
     *          or Query.
474
     * @return Zend_Gdata_Gapps_EmailListFeed
475
     * @throws Zend_Gdata_App_Exception
476
     * @throws Zend_Gdata_App_HttpException
477
     * @throws Zend_Gdata_Gapps_ServiceException
478
     */
479
    public function getEmailListFeed($location = null)
480
    {
481
        if ($location === null) {
482
            $uri = $this->getBaseUrl() . self::APPS_NICKNAME_PATH;
483
        } else if ($location instanceof Zend_Gdata_Query) {
484
            $uri = $location->getQueryUrl();
485
        } else {
486
            $uri = $location;
487
        }
488
        return parent::getFeed($uri, 'Zend_Gdata_Gapps_EmailListFeed');
489
    }
490
491
    /**
492
     * Retreive EmailListRecipientFeed object containing multiple
493
     * EmailListRecipientEntry objects.
494
     *
495
     * @param mixed $location The location for the feed, as a URL or Query.
496
     * @return Zend_Gdata_Gapps_EmailListRecipientFeed
497
     * @throws Zend_Gdata_App_Exception
498
     * @throws Zend_Gdata_App_HttpException
499
     * @throws Zend_Gdata_Gapps_ServiceException
500
     */
501
    public function getEmailListRecipientFeed($location)
502
    {
503
        if ($location === null) {
504
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
505
            throw new Zend_Gdata_App_InvalidArgumentException(
506
                    'Location must not be null');
507
        } else if ($location instanceof Zend_Gdata_Query) {
508
            $uri = $location->getQueryUrl();
509
        } else {
510
            $uri = $location;
511
        }
512
        return parent::getFeed($uri, 'Zend_Gdata_Gapps_EmailListRecipientFeed');
513
    }
514
515
    /**
516
     * Retreive a single UserEntry object.
517
     *
518
     * @param mixed $location The location for the feed, as a URL or Query.
519
     * @return Zend_Gdata_Gapps_UserEntry
520
     * @throws Zend_Gdata_App_Exception
521
     * @throws Zend_Gdata_App_HttpException
522
     * @throws Zend_Gdata_Gapps_ServiceException
523
     */
524
    public function getUserEntry($location)
525
    {
526
        if ($location === null) {
527
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
528
            throw new Zend_Gdata_App_InvalidArgumentException(
529
                    'Location must not be null');
530
        } else if ($location instanceof Zend_Gdata_Query) {
531
            $uri = $location->getQueryUrl();
532
        } else {
533
            $uri = $location;
534
        }
535
        return parent::getEntry($uri, 'Zend_Gdata_Gapps_UserEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...Gdata_Gapps_UserEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_Gapps_UserEntry.
Loading history...
536
    }
537
538
    /**
539
     * Retreive a single NicknameEntry object.
540
     *
541
     * @param mixed $location The location for the feed, as a URL or Query.
542
     * @return Zend_Gdata_Gapps_NicknameEntry
543
     * @throws Zend_Gdata_App_Exception
544
     * @throws Zend_Gdata_App_HttpException
545
     * @throws Zend_Gdata_Gapps_ServiceException
546
     */
547
    public function getNicknameEntry($location)
548
    {
549
        if ($location === null) {
550
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
551
            throw new Zend_Gdata_App_InvalidArgumentException(
552
                    'Location must not be null');
553
        } else if ($location instanceof Zend_Gdata_Query) {
554
            $uri = $location->getQueryUrl();
555
        } else {
556
            $uri = $location;
557
        }
558
        return parent::getEntry($uri, 'Zend_Gdata_Gapps_NicknameEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...a_Gapps_NicknameEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_Gapps_NicknameEntry.
Loading history...
559
    }
560
561
    /**
562
     * Retreive a single GroupEntry object.
563
     *
564
     * @param mixed $location The location for the feed, as a URL or Query.
565
     * @return Zend_Gdata_Gapps_GroupEntry
566
     * @throws Zend_Gdata_App_Exception
567
     * @throws Zend_Gdata_App_HttpException
568
     * @throws Zend_Gdata_Gapps_ServiceException
569
     */
570
    public function getGroupEntry($location = null)
571
    {
572
        if ($location === null) {
573
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
574
            throw new Zend_Gdata_App_InvalidArgumentException(
575
                    'Location must not be null');
576
        } else if ($location instanceof Zend_Gdata_Query) {
577
            $uri = $location->getQueryUrl();
578
        } else {
579
            $uri = $location;
580
        }
581
        return parent::getEntry($uri, 'Zend_Gdata_Gapps_GroupEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...data_Gapps_GroupEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_Gapps_GroupEntry.
Loading history...
582
    }
583
584
    /**
585
     * Retreive a single MemberEntry object.
586
     *
587
     * @param mixed $location The location for the feed, as a URL or Query.
588
     * @return Zend_Gdata_Gapps_MemberEntry
589
     * @throws Zend_Gdata_App_Exception
590
     * @throws Zend_Gdata_App_HttpException
591
     * @throws Zend_Gdata_Gapps_ServiceException
592
     */
593
    public function getMemberEntry($location = null)
594
    {
595
        if ($location === null) {
596
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
597
            throw new Zend_Gdata_App_InvalidArgumentException(
598
                    'Location must not be null');
599
        } else if ($location instanceof Zend_Gdata_Query) {
600
            $uri = $location->getQueryUrl();
601
        } else {
602
            $uri = $location;
603
        }
604
        return parent::getEntry($uri, 'Zend_Gdata_Gapps_MemberEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...ata_Gapps_MemberEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_Gapps_MemberEntry.
Loading history...
605
    }
606
607
    /**
608
     * Retreive a single OwnerEntry object.
609
     *
610
     * @param mixed $location The location for the feed, as a URL or Query.
611
     * @return Zend_Gdata_Gapps_OwnerEntry
612
     * @throws Zend_Gdata_App_Exception
613
     * @throws Zend_Gdata_App_HttpException
614
     * @throws Zend_Gdata_Gapps_ServiceException
615
     */
616
    public function getOwnerEntry($location = null)
617
    {
618
        if ($location === null) {
619
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
620
            throw new Zend_Gdata_App_InvalidArgumentException(
621
                    'Location must not be null');
622
        } else if ($location instanceof Zend_Gdata_Query) {
623
            $uri = $location->getQueryUrl();
624
        } else {
625
            $uri = $location;
626
        }
627
        return parent::getEntry($uri, 'Zend_Gdata_Gapps_OwnerEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...data_Gapps_OwnerEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_Gapps_OwnerEntry.
Loading history...
628
    }
629
630
    /**
631
     * Retreive a single EmailListEntry object.
632
     *
633
     * @param mixed $location The location for the feed, as a URL or Query.
634
     * @return Zend_Gdata_Gapps_EmailListEntry
635
     * @throws Zend_Gdata_App_Exception
636
     * @throws Zend_Gdata_App_HttpException
637
     * @throws Zend_Gdata_Gapps_ServiceException
638
     */
639
    public function getEmailListEntry($location)
640
    {
641
        if ($location === null) {
642
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
643
            throw new Zend_Gdata_App_InvalidArgumentException(
644
                    'Location must not be null');
645
        } else if ($location instanceof Zend_Gdata_Query) {
646
            $uri = $location->getQueryUrl();
647
        } else {
648
            $uri = $location;
649
        }
650
        return parent::getEntry($uri, 'Zend_Gdata_Gapps_EmailListEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(..._Gapps_EmailListEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_Gapps_EmailListEntry.
Loading history...
651
    }
652
653
    /**
654
     * Retreive a single EmailListRecipientEntry object.
655
     *
656
     * @param mixed $location The location for the feed, as a URL or Query.
657
     * @return Zend_Gdata_Gapps_EmailListRecipientEntry
658
     * @throws Zend_Gdata_App_Exception
659
     * @throws Zend_Gdata_App_HttpException
660
     * @throws Zend_Gdata_Gapps_ServiceException
661
     */
662
    public function getEmailListRecipientEntry($location)
663
    {
664
        if ($location === null) {
665
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
666
            throw new Zend_Gdata_App_InvalidArgumentException(
667
                    'Location must not be null');
668
        } else if ($location instanceof Zend_Gdata_Query) {
669
            $uri = $location->getQueryUrl();
670
        } else {
671
            $uri = $location;
672
        }
673
        return parent::getEntry($uri, 'Zend_Gdata_Gapps_EmailListRecipientEntry');
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getEntry(...ailListRecipientEntry') returns the type string which is incompatible with the documented return type Zend_Gdata_Gapps_EmailListRecipientEntry.
Loading history...
674
    }
675
676
    /**
677
     * Create a new user from a UserEntry.
678
     *
679
     * @param Zend_Gdata_Gapps_UserEntry $user The user entry to insert.
680
     * @param string $uri (optional) The URI where the user should be
681
     *          uploaded to. If null, the default user creation URI for
682
     *          this domain will be used.
683
     * @return Zend_Gdata_Gapps_UserEntry The inserted user entry as
684
     *          returned by the server.
685
     * @throws Zend_Gdata_App_Exception
686
     * @throws Zend_Gdata_App_HttpException
687
     * @throws Zend_Gdata_Gapps_ServiceException
688
     */
689
    public function insertUser($user, $uri = null)
690
    {
691
        if ($uri === null) {
692
            $uri = $this->getBaseUrl() . self::APPS_USER_PATH;
693
        }
694
        $newEntry = $this->insertEntry($user, $uri, 'Zend_Gdata_Gapps_UserEntry');
695
        return $newEntry;
696
    }
697
698
    /**
699
     * Create a new nickname from a NicknameEntry.
700
     *
701
     * @param Zend_Gdata_Gapps_NicknameEntry $nickname The nickname entry to
702
     *          insert.
703
     * @param string $uri (optional) The URI where the nickname should be
704
     *          uploaded to. If null, the default nickname creation URI for
705
     *          this domain will be used.
706
     * @return Zend_Gdata_Gapps_NicknameEntry The inserted nickname entry as
707
     *          returned by the server.
708
     * @throws Zend_Gdata_App_Exception
709
     * @throws Zend_Gdata_App_HttpException
710
     * @throws Zend_Gdata_Gapps_ServiceException
711
     */
712
    public function insertNickname($nickname, $uri = null)
713
    {
714
        if ($uri === null) {
715
            $uri = $this->getBaseUrl() . self::APPS_NICKNAME_PATH;
716
        }
717
        $newEntry = $this->insertEntry($nickname, $uri, 'Zend_Gdata_Gapps_NicknameEntry');
718
        return $newEntry;
719
    }
720
721
    /**
722
     * Create a new group from a GroupEntry.
723
     *
724
     * @param Zend_Gdata_Gapps_GroupEntry $group The group entry to insert.
725
     * @param string $uri (optional) The URI where the group should be
726
     *          uploaded to. If null, the default user creation URI for
727
     *          this domain will be used.
728
     * @return Zend_Gdata_Gapps_GroupEntry The inserted group entry as
729
     *          returned by the server.
730
     * @throws Zend_Gdata_App_Exception
731
     * @throws Zend_Gdata_App_HttpException
732
     * @throws Zend_Gdata_Gapps_ServiceException
733
     */
734
    public function insertGroup($group, $uri = null)
735
    {
736
        if ($uri === null) {
737
            $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
738
            $uri .= $this->getDomain();
739
        }
740
        $newEntry = $this->insertEntry($group, $uri, 'Zend_Gdata_Gapps_GroupEntry');
741
        return $newEntry;
742
    }
743
744
    /**
745
     * Create a new member from a MemberEntry.
746
     *
747
     * @param Zend_Gdata_Gapps_MemberEntry $member The member entry to insert.
748
     * @param string $uri (optional) The URI where the group should be
749
     *          uploaded to. If null, the default user creation URI for
750
     *          this domain will be used.
751
     * @return Zend_Gdata_Gapps_MemberEntry The inserted member entry as
752
     *          returned by the server.
753
     * @throws Zend_Gdata_App_Exception
754
     * @throws Zend_Gdata_App_HttpException
755
     * @throws Zend_Gdata_Gapps_ServiceException
756
     */
757
    public function insertMember($member, $uri = null)
758
    {
759
        if ($uri === null) {
760
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
761
            throw new Zend_Gdata_App_InvalidArgumentException(
762
                    'URI must not be null');
763
        }
764
        $newEntry = $this->insertEntry($member, $uri, 'Zend_Gdata_Gapps_MemberEntry');
765
        return $newEntry;
766
    }
767
768
    /**
769
     * Create a new group from a OwnerEntry.
770
     *
771
     * @param Zend_Gdata_Gapps_OwnerEntry $owner The owner entry to insert.
772
     * @param string $uri (optional) The URI where the owner should be
773
     *          uploaded to. If null, the default user creation URI for
774
     *          this domain will be used.
775
     * @return Zend_Gdata_Gapps_OwnerEntry The inserted owner entry as
776
     *          returned by the server.
777
     * @throws Zend_Gdata_App_Exception
778
     * @throws Zend_Gdata_App_HttpException
779
     * @throws Zend_Gdata_Gapps_ServiceException
780
     */
781
    public function insertOwner($owner, $uri = null)
782
    {
783
        if ($uri === null) {
784
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
785
            throw new Zend_Gdata_App_InvalidArgumentException(
786
                    'URI must not be null');
787
        }
788
        $newEntry = $this->insertEntry($owner, $uri, 'Zend_Gdata_Gapps_OwnerEntry');
789
        return $newEntry;
790
    }
791
792
    /**
793
     * Create a new email list from an EmailListEntry.
794
     *
795
     * @param Zend_Gdata_Gapps_EmailListEntry $emailList The email list entry
796
     *          to insert.
797
     * @param string $uri (optional) The URI where the email list should be
798
     *          uploaded to. If null, the default email list creation URI for
799
     *          this domain will be used.
800
     * @return Zend_Gdata_Gapps_EmailListEntry The inserted email list entry
801
     *          as returned by the server.
802
     * @throws Zend_Gdata_App_Exception
803
     * @throws Zend_Gdata_App_HttpException
804
     * @throws Zend_Gdata_Gapps_ServiceException
805
     */
806
    public function insertEmailList($emailList, $uri = null)
807
    {
808
        if ($uri === null) {
809
            $uri = $this->getBaseUrl() . self::APPS_EMAIL_LIST_PATH;
810
        }
811
        $newEntry = $this->insertEntry($emailList, $uri, 'Zend_Gdata_Gapps_EmailListEntry');
812
        return $newEntry;
813
    }
814
815
    /**
816
     * Create a new email list recipient from an EmailListRecipientEntry.
817
     *
818
     * @param Zend_Gdata_Gapps_EmailListRecipientEntry $recipient The recipient
819
     *          entry to insert.
820
     * @param string $uri (optional) The URI where the recipient should be
821
     *          uploaded to. If null, the default recipient creation URI for
822
     *          this domain will be used.
823
     * @return Zend_Gdata_Gapps_EmailListRecipientEntry The inserted
824
     *          recipient entry as returned by the server.
825
     * @throws Zend_Gdata_App_Exception
826
     * @throws Zend_Gdata_App_HttpException
827
     * @throws Zend_Gdata_Gapps_ServiceException
828
     */
829
    public function insertEmailListRecipient($recipient, $uri = null)
830
    {
831
        if ($uri === null) {
832
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
833
            throw new Zend_Gdata_App_InvalidArgumentException(
834
                    'URI must not be null');
835
        } elseif ($uri instanceof Zend_Gdata_Gapps_EmailListEntry) {
0 ignored issues
show
introduced by
$uri is never a sub-type of Zend_Gdata_Gapps_EmailListEntry.
Loading history...
836
            $uri = $uri->getLink('edit')->href;
837
        }
838
        $newEntry = $this->insertEntry($recipient, $uri, 'Zend_Gdata_Gapps_EmailListRecipientEntry');
839
        return $newEntry;
840
    }
841
842
    /**
843
     * Provides a magic factory method to instantiate new objects with
844
     * shorter syntax than would otherwise be required by the Zend Framework
845
     * naming conventions. For more information, see Zend_Gdata_App::__call().
846
     *
847
     * This overrides the default behavior of __call() so that query classes
848
     * do not need to have their domain manually set when created with
849
     * a magic factory method.
850
     *
851
     * @see Zend_Gdata_App::__call()
852
     * @param string $method The method name being called
853
     * @param array $args The arguments passed to the call
854
     * @throws Zend_Gdata_App_Exception
855
     */
856
    public function __call($method, $args) {
857
        if (preg_match('/^new(\w+Query)/', $method, $matches)) {
858
            $class = $matches[1];
859
            $foundClassName = null;
860
            foreach ($this->_registeredPackages as $name) {
861
                 try {
862
                     // Autoloading disabled on next line for compatibility
863
                     // with magic factories. See ZF-6660.
864
                     if (!class_exists($name . '_' . $class, false)) {
865
                        require_once 'Zend/Loader.php';
866
                        @Zend_Loader::loadClass($name . '_' . $class);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for loadClass(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

866
                        /** @scrutinizer ignore-unhandled */ @Zend_Loader::loadClass($name . '_' . $class);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
Are you sure the usage of Zend_Loader::loadClass($name . '_' . $class) targeting Zend_Loader::loadClass() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
867
                     }
868
                     $foundClassName = $name . '_' . $class;
869
                     break;
870
                 } catch (Zend_Exception $e) {
871
                     // package wasn't here- continue searching
872
                 }
873
            }
874
            if ($foundClassName != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $foundClassName of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
875
                $reflectionObj = new ReflectionClass($foundClassName);
876
                // Prepend the domain to the query
877
                $args = array_merge(array($this->getDomain()), $args);
878
                return $reflectionObj->newInstanceArgs($args);
879
            } else {
880
                require_once 'Zend/Gdata/App/Exception.php';
881
                throw new Zend_Gdata_App_Exception(
882
                        "Unable to find '${class}' in registered packages");
883
            }
884
        } else {
885
            return parent::__call($method, $args);
886
        }
887
888
    }
889
890
    // Convenience methods
891
    // Specified at http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_e
892
893
    /**
894
     * Create a new user entry and send it to the Google Apps servers.
895
     *
896
     * @param string $username The username for the new user.
897
     * @param string $givenName The given name for the new user.
898
     * @param string $familyName The family name for the new user.
899
     * @param string $password The password for the new user as a plaintext string
900
     *                 (if $passwordHashFunction is null) or a SHA-1 hashed
901
     *                 value (if $passwordHashFunction = 'SHA-1').
902
     * @param string $quotaLimitInMB (optional) The quota limit for the new user in MB.
903
     * @return Zend_Gdata_Gapps_UserEntry (optional) The new user entry as returned by
904
     *                 server.
905
     * @throws Zend_Gdata_App_Exception
906
     * @throws Zend_Gdata_App_HttpException
907
     * @throws Zend_Gdata_Gapps_ServiceException
908
     */
909
    public function createUser ($username, $givenName, $familyName, $password,
910
            $passwordHashFunction = null, $quotaLimitInMB = null) {
911
        $user = $this->newUserEntry();
0 ignored issues
show
Bug introduced by
The method newUserEntry() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

911
        /** @scrutinizer ignore-call */ 
912
        $user = $this->newUserEntry();
Loading history...
912
        $user->login = $this->newLogin();
0 ignored issues
show
Bug introduced by
The method newLogin() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

912
        /** @scrutinizer ignore-call */ 
913
        $user->login = $this->newLogin();
Loading history...
913
        $user->login->username = $username;
914
        $user->login->password = $password;
915
        $user->login->hashFunctionName = $passwordHashFunction;
916
        $user->name = $this->newName();
0 ignored issues
show
Bug introduced by
The method newName() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

916
        /** @scrutinizer ignore-call */ 
917
        $user->name = $this->newName();
Loading history...
917
        $user->name->givenName = $givenName;
918
        $user->name->familyName = $familyName;
919
        if ($quotaLimitInMB !== null) {
920
            $user->quota = $this->newQuota();
0 ignored issues
show
Bug introduced by
The method newQuota() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

920
            /** @scrutinizer ignore-call */ 
921
            $user->quota = $this->newQuota();
Loading history...
921
            $user->quota->limit = $quotaLimitInMB;
922
        }
923
        return $this->insertUser($user);
924
    }
925
926
    /**
927
     * Retrieve a user based on their username.
928
     *
929
     * @param string $username The username to search for.
930
     * @return Zend_Gdata_Gapps_UserEntry The username to search for, or null
931
     *              if no match found.
932
     * @throws Zend_Gdata_App_InvalidArgumentException
933
     * @throws Zend_Gdata_App_HttpException
934
     */
935
    public function retrieveUser ($username) {
936
        $query = $this->newUserQuery($username);
0 ignored issues
show
Bug introduced by
The method newUserQuery() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

936
        /** @scrutinizer ignore-call */ 
937
        $query = $this->newUserQuery($username);
Loading history...
937
        try {
938
            $user = $this->getUserEntry($query);
939
        } catch (Zend_Gdata_Gapps_ServiceException $e) {
940
            // Set the user to null if not found
941
            if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
942
                $user = null;
943
            } else {
944
                throw $e;
945
            }
946
        }
947
        return $user;
948
    }
949
950
    /**
951
     * Retrieve a page of users in alphabetical order, starting with the
952
     * provided username.
953
     *
954
     * @param string $startUsername (optional) The first username to retrieve.
955
     *          If null or not declared, the page will begin with the first
956
     *          user in the domain.
957
     * @return Zend_Gdata_Gapps_UserFeed Collection of Zend_Gdata_UserEntry
958
     *              objects representing all users in the domain.
959
     * @throws Zend_Gdata_App_Exception
960
     * @throws Zend_Gdata_App_HttpException
961
     * @throws Zend_Gdata_Gapps_ServiceException
962
     */
963
    public function retrievePageOfUsers ($startUsername = null) {
964
        $query = $this->newUserQuery();
965
        $query->setStartUsername($startUsername);
966
        return $this->getUserFeed($query);
967
    }
968
969
    /**
970
     * Retrieve all users in the current domain. Be aware that
971
     * calling this function on a domain with many users will take a
972
     * signifigant amount of time to complete. On larger domains this may
973
     * may cause execution to timeout without proper precautions in place.
974
     *
975
     * @return Zend_Gdata_Gapps_UserFeed Collection of Zend_Gdata_UserEntry
976
     *              objects representing all users in the domain.
977
     * @throws Zend_Gdata_App_Exception
978
     * @throws Zend_Gdata_App_HttpException
979
     * @throws Zend_Gdata_Gapps_ServiceException
980
     */
981
    public function retrieveAllUsers () {
982
        return $this->retrieveAllEntriesForFeed($this->retrievePageOfUsers());
983
    }
984
985
    /**
986
     * Overwrite a specified username with the provided UserEntry.  The
987
     * UserEntry does not need to contain an edit link.
988
     *
989
     * This method is provided for compliance with the Google Apps
990
     * Provisioning API specification. Normally users will instead want to
991
     * call UserEntry::save() instead.
992
     *
993
     * @see Zend_Gdata_App_Entry::save
994
     * @param string $username The username whose data will be overwritten.
995
     * @param Zend_Gdata_Gapps_UserEntry $userEntry The user entry which
996
     *          will be overwritten.
997
     * @return Zend_Gdata_Gapps_UserEntry The UserEntry returned by the
998
     *          server.
999
     * @throws Zend_Gdata_App_Exception
1000
     * @throws Zend_Gdata_App_HttpException
1001
     * @throws Zend_Gdata_Gapps_ServiceException
1002
     */
1003
    public function updateUser($username, $userEntry) {
1004
        return $this->updateEntry($userEntry, $this->getBaseUrl() .
1005
            self::APPS_USER_PATH . '/' . $username);
1006
    }
1007
1008
    /**
1009
     * Mark a given user as suspended.
1010
     *
1011
     * @param string $username The username associated with the user who
1012
     *          should be suspended.
1013
     * @return Zend_Gdata_Gapps_UserEntry The UserEntry for the modified
1014
     *          user.
1015
     * @throws Zend_Gdata_App_Exception
1016
     * @throws Zend_Gdata_App_HttpException
1017
     * @throws Zend_Gdata_Gapps_ServiceException
1018
     */
1019
    public function suspendUser($username) {
1020
        $user = $this->retrieveUser($username);
1021
        $user->login->suspended = true;
0 ignored issues
show
Bug Best Practice introduced by
The property login does not exist on Zend_Gdata_Gapps_UserEntry. Since you implemented __get, consider adding a @property annotation.
Loading history...
1022
        return $user->save();
1023
    }
1024
1025
    /**
1026
     * Mark a given user as not suspended.
1027
     *
1028
     * @param string $username The username associated with the user who
1029
     *          should be restored.
1030
     * @return Zend_Gdata_Gapps_UserEntry The UserEntry for the modified
1031
     *          user.
1032
     * @throws Zend_Gdata_App_Exception
1033
     * @throws Zend_Gdata_App_HttpException
1034
     * @throws Zend_Gdata_Gapps_ServiceException
1035
     */
1036
    public function restoreUser($username) {
1037
        $user = $this->retrieveUser($username);
1038
        $user->login->suspended = false;
0 ignored issues
show
Bug Best Practice introduced by
The property login does not exist on Zend_Gdata_Gapps_UserEntry. Since you implemented __get, consider adding a @property annotation.
Loading history...
1039
        return $user->save();
1040
    }
1041
1042
    /**
1043
     * Delete a user by username.
1044
     *
1045
     * @param string $username The username associated with the user who
1046
     *          should be deleted.
1047
     * @throws Zend_Gdata_App_Exception
1048
     * @throws Zend_Gdata_App_HttpException
1049
     * @throws Zend_Gdata_Gapps_ServiceException
1050
     */
1051
    public function deleteUser($username) {
1052
        $this->delete($this->getBaseUrl() . self::APPS_USER_PATH . '/' .
1053
            $username);
1054
    }
1055
1056
    /**
1057
     * Create a nickname for a given user.
1058
     *
1059
     * @param string $username The username to which the new nickname should
1060
     *          be associated.
1061
     * @param string $nickname The new nickname to be created.
1062
     * @return Zend_Gdata_Gapps_NicknameEntry The nickname entry which was
1063
     *          created by the server.
1064
     * @throws Zend_Gdata_App_Exception
1065
     * @throws Zend_Gdata_App_HttpException
1066
     * @throws Zend_Gdata_Gapps_ServiceException
1067
     */
1068
    public function createNickname($username, $nickname) {
1069
        $entry = $this->newNicknameEntry();
0 ignored issues
show
Bug introduced by
The method newNicknameEntry() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1069
        /** @scrutinizer ignore-call */ 
1070
        $entry = $this->newNicknameEntry();
Loading history...
1070
        $nickname = $this->newNickname($nickname);
0 ignored issues
show
Bug introduced by
The method newNickname() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1070
        /** @scrutinizer ignore-call */ 
1071
        $nickname = $this->newNickname($nickname);
Loading history...
1071
        $login = $this->newLogin($username);
1072
        $entry->nickname = $nickname;
1073
        $entry->login = $login;
1074
        return $this->insertNickname($entry);
1075
    }
1076
1077
    /**
1078
     * Retrieve the entry for a specified nickname.
1079
     *
1080
     * @param string $nickname The nickname to be retrieved.
1081
     * @return Zend_Gdata_Gapps_NicknameEntry The requested nickname entry.
1082
     * @throws Zend_Gdata_App_Exception
1083
     * @throws Zend_Gdata_App_HttpException
1084
     * @throws Zend_Gdata_Gapps_ServiceException
1085
     */
1086
    public function retrieveNickname($nickname) {
1087
        $query = $this->newNicknameQuery();
0 ignored issues
show
Bug introduced by
The method newNicknameQuery() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1087
        /** @scrutinizer ignore-call */ 
1088
        $query = $this->newNicknameQuery();
Loading history...
1088
        $query->setNickname($nickname);
1089
        try {
1090
            $nickname = $this->getNicknameEntry($query);
1091
        } catch (Zend_Gdata_Gapps_ServiceException $e) {
1092
            // Set the nickname to null if not found
1093
            if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
1094
                $nickname = null;
1095
            } else {
1096
                throw $e;
1097
            }
1098
        }
1099
        return $nickname;
1100
    }
1101
1102
    /**
1103
     * Retrieve all nicknames associated with a specific username.
1104
     *
1105
     * @param string $username The username whose nicknames should be
1106
     *          returned.
1107
     * @return Zend_Gdata_Gapps_NicknameFeed A feed containing all nicknames
1108
     *          for the given user, or null if
1109
     * @throws Zend_Gdata_App_Exception
1110
     * @throws Zend_Gdata_App_HttpException
1111
     * @throws Zend_Gdata_Gapps_ServiceException
1112
     */
1113
    public function retrieveNicknames($username) {
1114
        $query = $this->newNicknameQuery();
1115
        $query->setUsername($username);
1116
        $nicknameFeed = $this->retrieveAllEntriesForFeed(
1117
            $this->getNicknameFeed($query));
1118
        return $nicknameFeed;
1119
    }
1120
1121
    /**
1122
     * Retrieve a page of nicknames in alphabetical order, starting with the
1123
     * provided nickname.
1124
     *
1125
     * @param string $startNickname (optional) The first nickname to
1126
     *          retrieve. If null or not declared, the page will begin with
1127
     *          the first nickname in the domain.
1128
     * @return Zend_Gdata_Gapps_NicknameFeed Collection of Zend_Gdata_NicknameEntry
1129
     *              objects representing all nicknames in the domain.
1130
     * @throws Zend_Gdata_App_Exception
1131
     * @throws Zend_Gdata_App_HttpException
1132
     * @throws Zend_Gdata_Gapps_ServiceException
1133
     */
1134
    public function retrievePageOfNicknames ($startNickname = null) {
1135
        $query = $this->newNicknameQuery();
1136
        $query->setStartNickname($startNickname);
1137
        return $this->getNicknameFeed($query);
1138
    }
1139
1140
    /**
1141
     * Retrieve all nicknames in the current domain. Be aware that
1142
     * calling this function on a domain with many nicknames will take a
1143
     * signifigant amount of time to complete. On larger domains this may
1144
     * may cause execution to timeout without proper precautions in place.
1145
     *
1146
     * @return Zend_Gdata_Gapps_NicknameFeed Collection of Zend_Gdata_NicknameEntry
1147
     *              objects representing all nicknames in the domain.
1148
     * @throws Zend_Gdata_App_Exception
1149
     * @throws Zend_Gdata_App_HttpException
1150
     * @throws Zend_Gdata_Gapps_ServiceException
1151
     */
1152
    public function retrieveAllNicknames () {
1153
        return $this->retrieveAllEntriesForFeed($this->retrievePageOfNicknames());
1154
    }
1155
1156
    /**
1157
     * Delete a specified nickname.
1158
     *
1159
     * @param string $nickname The name of the nickname to be deleted.
1160
     * @throws Zend_Gdata_App_Exception
1161
     * @throws Zend_Gdata_App_HttpException
1162
     * @throws Zend_Gdata_Gapps_ServiceException
1163
     */
1164
    public function deleteNickname($nickname) {
1165
        $this->delete($this->getBaseUrl() . self::APPS_NICKNAME_PATH . '/' . $nickname);
1166
    }
1167
1168
    /**
1169
     * Create a new group.
1170
     *
1171
     * @param string $groupId A unique identifier for the group
1172
     * @param string $groupName The name of the group
1173
     * @param string $description A description of the group
1174
     * @param string $emailPermission The subscription permission of the group
1175
     * @return Zend_Gdata_Gapps_GroupEntry The group entry as created on the server.
1176
     */
1177
    public function createGroup($groupId, $groupName, $description = null, $emailPermission = null)
1178
    {
1179
        $i = 0;
1180
        $properties = array();
1181
        $group = $this->newGroupEntry();
0 ignored issues
show
Bug introduced by
The method newGroupEntry() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1181
        /** @scrutinizer ignore-call */ 
1182
        $group = $this->newGroupEntry();
Loading history...
1182
1183
        $properties[$i] = $this->newProperty();
0 ignored issues
show
Bug introduced by
The method newProperty() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1183
        /** @scrutinizer ignore-call */ 
1184
        $properties[$i] = $this->newProperty();
Loading history...
1184
        $properties[$i]->name = 'groupId';
1185
        $properties[$i]->value = $groupId;
1186
        $i++;
1187
        $properties[$i] = $this->newProperty();
1188
        $properties[$i]->name = 'groupName';
1189
        $properties[$i]->value = $groupName;
1190
        $i++;
1191
1192
        if($description != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $description of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
1193
            $properties[$i] = $this->newProperty();
1194
            $properties[$i]->name = 'description';
1195
            $properties[$i]->value = $description;
1196
            $i++;
1197
        }
1198
1199
        if($emailPermission != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $emailPermission of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
1200
            $properties[$i] = $this->newProperty();
1201
            $properties[$i]->name = 'emailPermission';
1202
            $properties[$i]->value = $emailPermission;
1203
            $i++;
1204
        }
1205
1206
        $group->property = $properties;
1207
1208
        return $this->insertGroup($group);
1209
    }
1210
1211
    /**
1212
     * Retrieves a group based on group id
1213
     *
1214
     * @param string $groupId The unique identifier for the group
1215
     * @return Zend_Gdata_Gapps_GroupEntry The group entry as returned by the server.
1216
     */
1217
    public function retrieveGroup($groupId)
1218
    {
1219
        $query = $this->newGroupQuery($groupId);
0 ignored issues
show
Bug introduced by
The method newGroupQuery() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1219
        /** @scrutinizer ignore-call */ 
1220
        $query = $this->newGroupQuery($groupId);
Loading history...
1220
        //$query->setGroupId($groupId);
1221
1222
        try {
1223
            $group = $this->getGroupEntry($query);
1224
        } catch (Zend_Gdata_Gapps_ServiceException $e) {
1225
            // Set the group to null if not found
1226
            if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
1227
                $group = null;
1228
            } else {
1229
                throw $e;
1230
            }
1231
        }
1232
        return $group;
1233
    }
1234
1235
    /**
1236
     * Retrieve all groups in the current domain. Be aware that
1237
     * calling this function on a domain with many groups will take a
1238
     * signifigant amount of time to complete. On larger domains this may
1239
     * may cause execution to timeout without proper precautions in place.
1240
     *
1241
     * @return Zend_Gdata_Gapps_GroupFeed Collection of Zend_Gdata_GroupEntry objects
1242
     *              representing all groups apart of the domain.
1243
     */
1244
    public function retrieveAllGroups()
1245
    {
1246
        return $this->retrieveAllEntriesForFeed($this->retrievePageOfGroups());
1247
    }
1248
1249
    /**
1250
     * Delete a group
1251
     *
1252
     * @param string $groupId The unique identifier for the group
1253
     */
1254
    public function deleteGroup($groupId)
1255
    {
1256
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1257
        $uri .= $this->getDomain() . '/' . $groupId;
1258
1259
        $this->delete($uri);
1260
    }
1261
1262
    /**
1263
     * Check to see if a member id or group id is a member of group
1264
     *
1265
     * @param string $memberId Member id or group group id
1266
     * @param string $groupId Group to be checked for
1267
     * @return bool True, if given entity is a member
1268
     */
1269
    public function isMember($memberId, $groupId)
1270
    {
1271
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1272
        $uri .= $this->getDomain() . '/' . $groupId . '/member/' . $memberId;
1273
1274
        //if the enitiy is not a member, an exception is thrown
1275
        try {
1276
            $results = $this->get($uri);
1277
        } catch (Exception $e) {
1278
            $results = false;
1279
        }
1280
1281
        if($results) {
1282
            return TRUE;
1283
        } else {
1284
            return FALSE;
1285
        }
1286
    }
1287
1288
    /**
1289
     * Add an email address to a group as a member
1290
     *
1291
     * @param string $recipientAddress Email address, member id, or group id
1292
     * @param string $groupId The unique id of the group
1293
     * @return Zend_Gdata_Gapps_MemberEntry The member entry returned by the server
1294
     */
1295
    public function addMemberToGroup($recipientAddress, $groupId)
1296
    {
1297
        $member = $this->newMemberEntry();
0 ignored issues
show
Bug introduced by
The method newMemberEntry() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1297
        /** @scrutinizer ignore-call */ 
1298
        $member = $this->newMemberEntry();
Loading history...
1298
        $properties = array();
1299
1300
        $properties[] = $this->newProperty();
1301
        $properties[0]->name = 'memberId';
1302
        $properties[0]->value = $recipientAddress;
1303
1304
        $member->property = $properties;
1305
1306
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1307
        $uri .= $this->getDomain() . '/' . $groupId . '/member';
1308
1309
        return $this->insertMember($member, $uri);
1310
    }
1311
1312
    /**
1313
     * Remove a member id from a group
1314
     *
1315
     * @param string $memberId Member id or group id
1316
     * @param string $groupId The unique id of the group
1317
     */
1318
    public function removeMemberFromGroup($memberId, $groupId)
1319
    {
1320
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1321
        $uri .= $this->getDomain() . '/' . $groupId . '/member/' . $memberId;
1322
1323
        return $this->delete($uri);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->delete($uri) targeting Zend_Gdata_Gapps::delete() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1324
    }
1325
1326
    /**
1327
     * Retrieves all the members of a group
1328
     *
1329
     * @param string $groupId The unique id of the group
1330
     * @return Zend_Gdata_Gapps_MemberFeed Collection of MemberEntry objects
1331
     *              representing all members apart of the group.
1332
     */
1333
    public function retrieveAllMembers($groupId)
1334
    {
1335
        return $this->retrieveAllEntriesForFeed(
1336
                $this->retrievePageOfMembers($groupId));
1337
    }
1338
1339
    /**
1340
     * Add an email as an owner of a group
1341
     *
1342
     * @param string $email Owner's email
1343
     * @param string $groupId Group ownership to be checked for
1344
     * @return Zend_Gdata_Gapps_OwnerEntry The OwnerEntry returned by the server
1345
     */
1346
    public function addOwnerToGroup($email, $groupId)
1347
    {
1348
        $owner = $this->newOwnerEntry();
0 ignored issues
show
Bug introduced by
The method newOwnerEntry() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1348
        /** @scrutinizer ignore-call */ 
1349
        $owner = $this->newOwnerEntry();
Loading history...
1349
        $properties = array();
1350
1351
        $properties[] = $this->newProperty();
1352
        $properties[0]->name = 'email';
1353
        $properties[0]->value = $email;
1354
1355
        $owner->property = $properties;
1356
1357
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1358
        $uri .= $this->getDomain() . '/' . $groupId . '/owner';
1359
1360
        return $this->insertOwner($owner, $uri);
1361
    }
1362
1363
    /**
1364
     * Retrieves all the owners of a group
1365
     *
1366
     * @param string $groupId The unique identifier for the group
1367
     * @return Zend_Gdata_Gapps_OwnerFeed Collection of Zend_Gdata_OwnerEntry
1368
     *              objects representing all owners apart of the group.
1369
     */
1370
    public function retrieveGroupOwners($groupId)
1371
    {
1372
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1373
        $uri .= $this->getDomain() . '/' . $groupId . '/owner';
1374
1375
        return $this->getOwnerFeed($uri);
1376
    }
1377
1378
    /**
1379
     * Checks to see if an email is an owner of a group
1380
     *
1381
     * @param string $email Owner's email
1382
     * @param string $groupId Group ownership to be checked for
1383
     * @return bool True, if given entity is an owner
1384
     */
1385
    public function isOwner($email, $groupId)
1386
    {
1387
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1388
        $uri .= $this->getDomain() . '/' . $groupId . '/owner/' . $email;
1389
1390
        //if the enitiy is not an owner of the group, an exception is thrown
1391
        try {
1392
            $results = $this->get($uri);
1393
        } catch (Exception $e) {
1394
            $results = false;
1395
        }
1396
1397
        if($results) {
1398
            return TRUE;
1399
        } else {
1400
            return FALSE;
1401
        }
1402
    }
1403
1404
    /**
1405
     * Remove email as an owner of a group
1406
     *
1407
     * @param string $email Owner's email
1408
     * @param string $groupId The unique identifier for the group
1409
     */
1410
    public function removeOwnerFromGroup($email, $groupId)
1411
    {
1412
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1413
        $uri .= $this->getDomain() . '/' . $groupId . '/owner/' . $email;
1414
1415
        return $this->delete($uri);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->delete($uri) targeting Zend_Gdata_Gapps::delete() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1416
    }
1417
1418
    /**
1419
     * Update group properties with new values. any property not defined will not
1420
     * be updated
1421
     *
1422
     * @param string $groupId A unique identifier for the group
1423
     * @param string $groupName The name of the group
1424
     * @param string $description A description of the group
1425
     * @param string $emailPermission The subscription permission of the group
1426
     * @return Zend_Gdata_Gapps_GroupEntry The group entry as updated on the server.
1427
     */
1428
    public function updateGroup($groupId, $groupName = null, $description = null,
1429
            $emailPermission = null)
1430
    {
1431
        $i = 0;
1432
        $properties = array();
1433
        $group = $this->newGroupEntry();
1434
1435
        $properties[$i] = $this->newProperty();
1436
        $properties[$i]->name = 'groupId';
1437
        $properties[$i]->value = $groupId;
1438
        $i++;
1439
1440
        if($groupName != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $groupName of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
1441
            $properties[$i] = $this->newProperty();
1442
            $properties[$i]->name = 'groupName';
1443
            $properties[$i]->value = $groupName;
1444
            $i++;
1445
        }
1446
1447
        if($description != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $description of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
1448
            $properties[$i] = $this->newProperty();
1449
            $properties[$i]->name = 'description';
1450
            $properties[$i]->value = $description;
1451
            $i++;
1452
        }
1453
1454
        if($emailPermission != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $emailPermission of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
1455
            $properties[$i] = $this->newProperty();
1456
            $properties[$i]->name = 'emailPermission';
1457
            $properties[$i]->value = $emailPermission;
1458
            $i++;
1459
        }
1460
1461
        $group->property = $properties;
1462
1463
        $uri  = self::APPS_BASE_FEED_URI . self::APPS_GROUP_PATH . '/';
1464
        $uri .= $this->getDomain() . '/' . $groupId;
1465
1466
        return $this->updateEntry($group, $uri, 'Zend_Gdata_Gapps_GroupEntry');
1467
    }
1468
1469
    /**
1470
     * Retrieve all of the groups that a user is a member of
1471
     *
1472
     * @param string $memberId Member username
1473
     * @param bool $directOnly (Optional) If true, members with direct association
1474
     *             only will be considered
1475
     * @return Zend_Gdata_Gapps_GroupFeed Collection of Zend_Gdata_GroupEntry
1476
     *              objects representing all groups member is apart of in the domain.
1477
     */
1478
    public function retrieveGroups($memberId, $directOnly = null)
1479
    {
1480
        $query = $this->newGroupQuery();
1481
        $query->setMember($memberId);
1482
        if($directOnly != null) {
1483
            $query->setDirectOnly($directOnly);
1484
        }
1485
        return $this->getGroupFeed($query);
1486
    }
1487
1488
    /**
1489
     * Retrieve a page of groups in alphabetical order, starting with the
1490
     * provided group.
1491
     *
1492
     * @param string $startGroup (optional) The first group to
1493
     *              retrieve. If null or not defined, the page will begin
1494
     *              with the first group in the domain.
1495
     * @return Zend_Gdata_Gapps_GroupFeed Collection of Zend_Gdata_GroupEntry
1496
     *              objects representing the groups in the domain.
1497
     * @throws Zend_Gdata_App_Exception
1498
     * @throws Zend_Gdata_App_HttpException
1499
     * @throws Zend_Gdata_Gapps_ServiceException
1500
     */
1501
    public function retrievePageOfGroups ($startGroup = null)
1502
    {
1503
        $query = $this->newGroupQuery();
1504
        $query->setStartGroupId($startGroup);
1505
        return $this->getGroupFeed($query);
1506
    }
1507
1508
    /**
1509
     * Gets page of Members
1510
     *
1511
     * @param string $groupId The group id which should be searched.
1512
     * @param string $startMember (optinal) The address of the first member,
1513
     *              or null to start with the first member in the list.
1514
     * @return Zend_Gdata_Gapps_MemberFeed Collection of Zend_Gdata_MemberEntry
1515
     *              objects
1516
     */
1517
    public function retrievePageOfMembers($groupId, $startMember = null)
1518
    {
1519
        $query = $this->newMemberQuery($groupId);
0 ignored issues
show
Bug introduced by
The method newMemberQuery() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1519
        /** @scrutinizer ignore-call */ 
1520
        $query = $this->newMemberQuery($groupId);
Loading history...
1520
        $query->setStartMemberId($startMember);
1521
        return $this->getMemberFeed($query);
1522
    }
1523
1524
    /**
1525
     * Create a new email list.
1526
     *
1527
     * @param string $emailList The name of the email list to be created.
1528
     * @return Zend_Gdata_Gapps_EmailListEntry The email list entry
1529
     *          as created on the server.
1530
     * @throws Zend_Gdata_App_Exception
1531
     * @throws Zend_Gdata_App_HttpException
1532
     * @throws Zend_Gdata_Gapps_ServiceException
1533
     */
1534
    public function createEmailList($emailList) {
1535
        $entry = $this->newEmailListEntry();
0 ignored issues
show
Bug introduced by
The method newEmailListEntry() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1535
        /** @scrutinizer ignore-call */ 
1536
        $entry = $this->newEmailListEntry();
Loading history...
1536
        $list = $this->newEmailList();
0 ignored issues
show
Bug introduced by
The method newEmailList() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1536
        /** @scrutinizer ignore-call */ 
1537
        $list = $this->newEmailList();
Loading history...
1537
        $list->name = $emailList;
1538
        $entry->emailList = $list;
1539
        return $this->insertEmailList($entry);
1540
    }
1541
1542
    /**
1543
     * Retrieve all email lists associated with a recipient.
1544
     *
1545
     * @param string $username The recipient whose associated email lists
1546
     *          should be returned.
1547
     * @return Zend_Gdata_Gapps_EmailListFeed The list of email lists found as
1548
     *          Zend_Gdata_EmailListEntry objects.
1549
     * @throws Zend_Gdata_App_Exception
1550
     * @throws Zend_Gdata_App_HttpException
1551
     * @throws Zend_Gdata_Gapps_ServiceException
1552
     */
1553
    public function retrieveEmailLists($recipient) {
1554
        $query = $this->newEmailListQuery();
0 ignored issues
show
Bug introduced by
The method newEmailListQuery() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1554
        /** @scrutinizer ignore-call */ 
1555
        $query = $this->newEmailListQuery();
Loading history...
1555
        $query->recipient = $recipient;
1556
        return $this->getEmailListFeed($query);
1557
    }
1558
1559
    /**
1560
     * Retrieve a page of email lists in alphabetical order, starting with the
1561
     * provided email list.
1562
     *
1563
     * @param string $startEmailListName (optional) The first list to
1564
     *              retrieve. If null or not defined, the page will begin
1565
     *              with the first email list in the domain.
1566
     * @return Zend_Gdata_Gapps_EmailListFeed Collection of Zend_Gdata_EmailListEntry
1567
     *              objects representing all nicknames in the domain.
1568
     * @throws Zend_Gdata_App_Exception
1569
     * @throws Zend_Gdata_App_HttpException
1570
     * @throws Zend_Gdata_Gapps_ServiceException
1571
     */
1572
    public function retrievePageOfEmailLists ($startNickname = null) {
1573
        $query = $this->newEmailListQuery();
1574
        $query->setStartEmailListName($startNickname);
1575
        return $this->getEmailListFeed($query);
1576
    }
1577
1578
    /**
1579
     * Retrieve all email lists associated with the curent domain. Be aware that
1580
     * calling this function on a domain with many email lists will take a
1581
     * signifigant amount of time to complete. On larger domains this may
1582
     * may cause execution to timeout without proper precautions in place.
1583
     *
1584
     * @return Zend_Gdata_Gapps_EmailListFeed The list of email lists found
1585
     *              as Zend_Gdata_Gapps_EmailListEntry objects.
1586
     * @throws Zend_Gdata_App_Exception
1587
     * @throws Zend_Gdata_App_HttpException
1588
     * @throws Zend_Gdata_Gapps_ServiceException
1589
     */
1590
    public function retrieveAllEmailLists() {
1591
        return $this->retrieveAllEntriesForFeed($this->retrievePageOfEmailLists());
1592
    }
1593
1594
    /**
1595
     * Delete a specified email list.
1596
     *
1597
     * @param string $emailList The name of the emailList to be deleted.
1598
     * @throws Zend_Gdata_App_Exception
1599
     * @throws Zend_Gdata_App_HttpException
1600
     * @throws Zend_Gdata_Gapps_ServiceException
1601
     */
1602
    public function deleteEmailList($emailList) {
1603
        $this->delete($this->getBaseUrl() . self::APPS_EMAIL_LIST_PATH . '/'
1604
            . $emailList);
1605
    }
1606
1607
    /**
1608
     * Add a specified recipient to an existing emailList.
1609
     *
1610
     * @param string $recipientAddress The address of the recipient to be
1611
     *              added to the email list.
1612
     * @param string $emailList The name of the email address to which the
1613
     *              recipient should be added.
1614
     * @return Zend_Gdata_Gapps_EmailListRecipientEntry The recipient entry
1615
     *              created by the server.
1616
     * @throws Zend_Gdata_App_Exception
1617
     * @throws Zend_Gdata_App_HttpException
1618
     * @throws Zend_Gdata_Gapps_ServiceException
1619
     */
1620
    public function addRecipientToEmailList($recipientAddress, $emailList) {
1621
        $entry = $this->newEmailListRecipientEntry();
0 ignored issues
show
Bug introduced by
The method newEmailListRecipientEntry() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1621
        /** @scrutinizer ignore-call */ 
1622
        $entry = $this->newEmailListRecipientEntry();
Loading history...
1622
        $who = $this->newWho();
0 ignored issues
show
Bug introduced by
The method newWho() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1622
        /** @scrutinizer ignore-call */ 
1623
        $who = $this->newWho();
Loading history...
1623
        $who->email = $recipientAddress;
1624
        $entry->who = $who;
1625
        $address = $this->getBaseUrl() .  self::APPS_EMAIL_LIST_PATH . '/' .
1626
            $emailList . self::APPS_EMAIL_LIST_RECIPIENT_POSTFIX . '/';
1627
        return $this->insertEmailListRecipient($entry, $address);
1628
    }
1629
1630
    /**
1631
     * Retrieve a page of email list recipients in alphabetical order,
1632
     * starting with the provided email list recipient.
1633
     *
1634
     * @param string $emaiList The email list which should be searched.
1635
     * @param string $startRecipient (optinal) The address of the first
1636
     *              recipient, or null to start with the first recipient in
1637
     *              the list.
1638
     * @return Zend_Gdata_Gapps_EmailListRecipientFeed Collection of
1639
     *              Zend_Gdata_EmailListRecipientEntry objects representing all
1640
     *              recpients in the specified list.
1641
     * @throws Zend_Gdata_App_Exception
1642
     * @throws Zend_Gdata_App_HttpException
1643
     * @throws Zend_Gdata_Gapps_ServiceException
1644
     */
1645
    public function retrievePageOfRecipients ($emailList,
1646
            $startRecipient = null) {
1647
        $query = $this->newEmailListRecipientQuery();
0 ignored issues
show
Bug introduced by
The method newEmailListRecipientQuery() does not exist on Zend_Gdata_Gapps. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1647
        /** @scrutinizer ignore-call */ 
1648
        $query = $this->newEmailListRecipientQuery();
Loading history...
1648
        $query->setEmailListName($emailList);
1649
        $query->setStartRecipient($startRecipient);
1650
        return $this->getEmailListRecipientFeed($query);
1651
    }
1652
1653
    /**
1654
     * Retrieve all recipients associated with an email list. Be aware that
1655
     * calling this function on a domain with many email lists will take a
1656
     * signifigant amount of time to complete. On larger domains this may
1657
     * may cause execution to timeout without proper precautions in place.
1658
     *
1659
     * @param string $emaiList The email list which should be searched.
1660
     * @return Zend_Gdata_Gapps_EmailListRecipientFeed The list of email lists
1661
     *              found as Zend_Gdata_Gapps_EmailListRecipientEntry objects.
1662
     * @throws Zend_Gdata_App_Exception
1663
     * @throws Zend_Gdata_App_HttpException
1664
     * @throws Zend_Gdata_Gapps_ServiceException
1665
     */
1666
    public function retrieveAllRecipients($emailList) {
1667
        return $this->retrieveAllEntriesForFeed(
1668
                $this->retrievePageOfRecipients($emailList));
1669
    }
1670
1671
    /**
1672
     * Remove a specified recipient from an email list.
1673
     *
1674
     * @param string $recipientAddress The recipient to be removed.
1675
     * @param string $emailList The list from which the recipient should
1676
     *              be removed.
1677
     * @throws Zend_Gdata_App_Exception
1678
     * @throws Zend_Gdata_App_HttpException
1679
     * @throws Zend_Gdata_Gapps_ServiceException
1680
     */
1681
    public function removeRecipientFromEmailList($recipientAddress, $emailList) {
1682
        $this->delete($this->getBaseUrl() . self::APPS_EMAIL_LIST_PATH . '/'
1683
            . $emailList . self::APPS_EMAIL_LIST_RECIPIENT_POSTFIX . '/'
1684
            . $recipientAddress);
1685
    }
1686
1687
}
1688