Completed
Pull Request — master (#277)
by
unknown
14:03
created

Page::getUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
/**
3
 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
25
namespace FacebookAds\Object;
26
27
use FacebookAds\Cursor;
28
use FacebookAds\Http\RequestInterface;
29
use FacebookAds\Object\SystemUser;
30
31
class Page extends AbstractCrudObject {
32
33
  /**
34
   * @return string
35
   */
36
  public function getEndpoint() {
37
    return 'pages';
38
  }
39
40
  /**
41
   * @param array $fields
42
   * @param array $params
43
   * @return Cursor
44
   */
45
  public function getLeadgenForms(
46
    array $fields = array(), array $params = array()) {
47
    return $this->getManyByConnection(
48
      LeadgenForm::className(), $fields, $params);
49
  }
50
51
  /**
52
   * @param array $fields
53
   * @param array $params
54
   * @return Cursor
55
   */
56
  public function getAgencies(
57
    array $fields = array(), array $params = array()) {
58
    return $this->getManyByConnection(
59
      Agency::className(), $fields, $params, 'agencies');
60
  }
61
62
  /**
63
   * @param int $business_id
64
   * @param int $user_id
65
   * @param array $fields
66
   * @return Cursor
67
   */
68
  public function getUsers($business_id, $user_id = null, $fields = array()) {
69
      $params = array(
70
          'business' => $business_id,
71
          'user' => $user_id
72
      );
73
74
      return $this->getManyByConnection(
75
          SystemUser::className(), $fields, $params, 'userpermissions');
76
  }
77
78
  /**
79
   * @param int $business_id
80
   * @param int $user_id
81
   * @param string $role
82
   */
83
  public function addUser($business_id, $user_id, $role) {
84
    $params = array(
85
      'business' => $business_id,
86
      'user' => $user_id,
87
      'role' => $role,
88
    );
89
90
    $this->getApi()->call(
91
      '/'.$this->assureId().'/userpermissions',
92
      RequestInterface::METHOD_POST,
93
      $params);
94
  }
95
96
  /**
97
   * @param int $business_id
98
   * @param int $user_id
99
   */
100
  public function deleteUser($business_id, $user_id) {
101
    $params = array(
102
      'business' => $business_id,
103
      'user' => $user_id,
104
    );
105
106
    $this->getApi()->call(
107
      '/'.$this->assureId().'/userpermissions',
108
      RequestInterface::METHOD_DELETE,
109
      $params);
110
  }
111
112
  /**
113
   * @param int $business_id
114
   * @param array $roles
115
   */
116
  public function grantBusinessAccess($business_id, $roles) {
117
    $params = array(
118
      'business' => $business_id,
119
      'permitted_roles' => $roles,
120
    );
121
122
    $this->getApi()->call(
123
      '/'.$this->assureId().'/agencies',
124
      RequestInterface::METHOD_POST,
125
      $params);
126
  }
127
128
  /**
129
   * @param int $business_id
130
   */
131
  public function revokeBusinessAccess($business_id) {
132
    $params = array(
133
      'business' => $business_id,
134
    );
135
136
    $this->getApi()->call(
137
      '/'.$this->assureId().'/agencies',
138
      RequestInterface::METHOD_DELETE,
139
      $params);
140
  }
141
}
142