Completed
Push — master ( 2e5ec2...8a55f8 )
by Jignesh
01:13
created

Bbb::hooksCreate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
4
namespace JoisarJignesh\Bigbluebutton;
5
6
use BigBlueButton\BigBlueButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, JoisarJignesh\Bigbluebutton\BigBlueButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use BigBlueButton\Parameters\CreateMeetingParameters;
8
use BigBlueButton\Parameters\DeleteRecordingsParameters;
9
use BigBlueButton\Parameters\EndMeetingParameters;
10
use BigBlueButton\Parameters\GetMeetingInfoParameters;
11
use BigBlueButton\Parameters\GetRecordingsParameters;
12
use BigBlueButton\Parameters\HooksCreateParameters;
13
use BigBlueButton\Parameters\IsMeetingRunningParameters;
14
use BigBlueButton\Parameters\JoinMeetingParameters;
15
use BigBlueButton\Parameters\PublishRecordingsParameters;
16
use BigBlueButton\Parameters\SetConfigXMLParameters;
17
use JoisarJignesh\Bigbluebutton\Services\initMeeting;
18
19
class Bbb
20
{
21
    use initMeeting;
22
23
    /**
24
     * @var
25
     */
26
    private $response;
27
    /**
28
     * @var BigBlueButton
29
     */
30
    protected $bbb;
31
32
33
    /**
34
     * Bbb constructor.
35
     *
36
     * @param BigBlueButton $bbb
37
     */
38
    public function __construct(BigBlueButton $bbb)
39
    {
40
        $this->bbb = $bbb;
41
    }
42
43
    /**
44
     * @return BigBlueButton
45
     */
46
    public function make()
47
    {
48
        return $this->bbb;
49
    }
50
    /**
51
     *  Return a list of all meetings
52
     *
53
     * @return \Illuminate\Support\Collection
54
     */
55
    public function all()
56
    {
57
        $this->response = $this->bbb->getMeetings();
58 View Code Duplication
        if ($this->response->success()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
            if (count($this->response->getRawXml()->meetings->meeting) > 0) {
60
                $meetings = [];
61
                foreach ($this->response->getRawXml()->meetings->meeting as $meeting) {
62
                    $meetings[] = XmlToArray($meeting);
63
                }
64
65
                return collect(XmlToArray($meetings));
66
            }
67
        }
68
69
        return collect([]);
70
    }
71
72
73
    /**
74
     * $meeting
75
     *
76
     * @param $meeting
77
     *
78
     * required fields
79
     * meetingID
80
     * meetingName
81
     *
82
     * @return mixed
83
     */
84 View Code Duplication
    public function create($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        if (!$meeting instanceof CreateMeetingParameters) {
87
            $meeting = $this->initCreateMeeting($meeting);
88
        }
89
90
        $this->response = $this->bbb->createMeeting($meeting);
91
        if ($this->response->failed()) {
92
            return $this->response->getMessage();
93
        } else {
94
            return collect(XmlToArray($this->response->getRawXml()));
95
        }
96
    }
97
98
    /**
99
     * @param $meeting
100
     *
101
     * required fields:
102
     * meetingID
103
     *
104
     * @return bool
105
     */
106 View Code Duplication
    public function isMeetingRunning($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        if (!$meeting instanceof IsMeetingRunningParameters) {
109
            $meeting = $this->initIsMeetingRunning($meeting);
110
        }
111
112
        $this->response = $this->bbb->isMeetingRunning($meeting);
113
        if ($this->response->success()) {
114
            $response = XmlToArray($this->response->getRawXml());
115
            if (isset($response['running']) && $response['running'] == "true") {
116
                return true;
117
            }
118
        }
119
120
        return false;
121
    }
122
123
    /**
124
     *  Join meeting
125
     *
126
     * @param $meeting
127
     * required fields
128
     *
129
     *  meetingID
130
     *  userName join by name
131
     *  password which role want to join
132
     *
133
     * @return string
134
     */
135
    public function join($meeting)
136
    {
137
        if (!$meeting instanceof JoinMeetingParameters) {
138
            $meeting = $this->initJoinMeeting($meeting);
139
        }
140
141
        if ($meeting->isRedirect()) {
142
            return $this->bbb->getJoinMeetingURL($meeting);
143
        }
144
145
        return $this->bbb->joinMeeting($meeting)->getUrl();
146
    }
147
148
    /**
149
     *  Returns information about the meeting
150
     *
151
     * @param $meeting
152
     * required fields
153
     * meetingID
154
     * moderatorPW must be there moderator password
155
     *
156
     * @return \Illuminate\Support\Collection
157
     */
158 View Code Duplication
    public function getMeetingInfo($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
159
    {
160
        if (!$meeting instanceof GetMeetingInfoParameters) {
161
            $meeting = $this->initGetMeetingInfo($meeting);
162
        }
163
164
        $this->response = $this->bbb->getMeetingInfo($meeting);
165
        if ($this->response->success()) {
166
            return collect(XmlToArray($this->response->getRawXml()));
167
        }
168
169
        return collect([]);
170
    }
171
172
    /**
173
     * @param $parameters
174
     *
175
     *  required fields
176
     * meetingID
177
     * meetingName
178
     * userName
179
     * attendeePW
180
     * moderatorPW
181
     *
182
     * @return mixed
183
     */
184
    public function start($parameters)
185
    {
186
        return $this->initStart($parameters);
187
    }
188
189
    /**
190
     *  Close meeting
191
     *
192
     * @param  $meeting
193
     * required fields:
194
     * meetingID
195
     * moderatorPW close meeting must be there moderator password
196
     *
197
     * @return bool
198
     */
199
    public function close($meeting)
200
    {
201
        if (!$meeting instanceof EndMeetingParameters) {
202
            $meeting = $this->initCloseMeeting($meeting);
203
        }
204
205
        $this->response = $this->bbb->endMeeting($meeting);
206
        if ($this->response->success()) {
207
            return true;
208
        }
209
210
        return false;
211
    }
212
213
    /**
214
     *
215
     * @param $recording
216
     * required fields
217
     * meetingID
218
     *
219
     * optional fields
220
     * recordID
221
     * state
222
     * @return \Illuminate\Support\Collection
223
     */
224
    public function getRecordings($recording)
225
    {
226
        if (!$recording instanceof GetRecordingsParameters) {
227
            $recording = $this->initGetRecordings($recording);
228
        }
229
230
        $this->response = $this->bbb->getRecordings($recording);
231 View Code Duplication
        if (count($this->response->getRawXml()->recordings->recording) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
232
            $recordings = [];
233
            foreach ($this->response->getRawXml()->recordings->recording as $r) {
234
                $recordings[] = XmlToArray($r);
235
            }
236
237
            return collect($recordings);
238
        }
239
240
        return collect([]);
241
    }
242
243
    /**
244
     * @param $recording
245
     * recordID as string(sepeate by commma)
246
     * publish as bool
247
     *
248
     * @return bool
249
     */
250 View Code Duplication
    public function publishRecordings($recording)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
251
    {
252
        if (!$recording instanceof PublishRecordingsParameters) {
253
            $recording = $this->initPublishRecordings($recording);
254
        }
255
256
        $this->response = $this->bbb->publishRecordings($recording);
257
        if ($this->response->success()) {
258
            $response = XmlToArray($this->response->getRawXml());
259
            if (isset($response['published']) && $response['published'] == "true") {
260
                return true;
261
            }
262
        }
263
264
        return false;
265
    }
266
267
    /**
268
     * @param $recording
269
     *
270
     * required fields
271
     * recordingID
272
     *
273
     * @return \Illuminate\Support\Collection
274
     */
275
    public function deleteRecordings($recording)
276
    {
277
        if (!$recording instanceof DeleteRecordingsParameters) {
278
            $recording = $this->initDeleteRecordings($recording);
279
        }
280
281
        $this->response = $this->bbb->deleteRecordings($recording);
282
        return collect(XmlToArray($this->response->getRawXml()));
283
    }
284
285
    /**
286
     * @param $configXml
287
     *
288
     * @return \Illuminate\Support\Collection
289
     */
290
    public function setConfigXml($configXml)
291
    {
292
        if(!$configXml instanceof SetConfigXMLParameters){
293
            $configXml = $this->initSetConfigXml($configXml);
294
        }
295
296
        $this->response = $this->bbb->setConfigXML($configXml);
297
        return collect(XmlToArray($this->response->getRawXml()));
298
    }
299
300
    /**
301
     * @return \BigBlueButton\Responses\GetDefaultConfigXMLResponse
302
     */
303
    public function getDefaultConfigXml()
304
    {
305
        $this->response = $this->bbb->getDefaultConfigXML();
306
        return $this->response;
307
    }
308
309
    /**
310
     * @return \Illuminate\Support\Collection
311
     */
312
    public function getApiVersion()
313
    {
314
        $this->response = $this->bbb->getApiVersion();
315
        return collect(XmlToArray($this->response->getRawXml()));
316
    }
317
318
    /**
319
     * @param $hooks
320
     *
321
     * @return \Illuminate\Support\Collection
322
     */
323
    public function hooksCreate($hooks)
324
    {
325
        if(!$hooks instanceof HooksCreateParameters){
326
            $hooks = $this->initHooksCreate($hooks);
327
        }
328
329
        $this->response = $this->bbb->hooksCreate($hooks);
330
        return collect(XmlToArray($this->response->getRawXml()));
331
    }
332
333
334
}
335