@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function baseDirectory() |
65 | 65 | { |
66 | - return __DIR__ . '/..'; |
|
66 | + return __DIR__.'/..'; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public function boot() |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | Route::prefix('/api/a/{activity_slug}/{module_instance_slug}/typeform') |
77 | 77 | ->middleware(['api']) |
78 | 78 | ->namespace($this->namespace()) |
79 | - ->group($this->baseDirectory() . '/routes/admin/webhook.php'); |
|
79 | + ->group($this->baseDirectory().'/routes/admin/webhook.php'); |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | |
@@ -100,20 +100,20 @@ discard block |
||
100 | 100 | )->withField( |
101 | 101 | Field::input('form_url')->inputType('text')->label('Form URL')->hint('The URL of the form. Make sure it\'s published first!') |
102 | 102 | )->withField( |
103 | - Field::switch('hide_headers')->label('Hide form headers?')->hint('Should we hide the form headers? This helps integrate the form into the page.') |
|
103 | + Field::switch ('hide_headers')->label('Hide form headers?')->hint('Should we hide the form headers? This helps integrate the form into the page.') |
|
104 | 104 | ->textOn('Hidden')->textOff('Shown')->default(true) |
105 | 105 | )->withField( |
106 | - Field::switch('hide_footer')->label('Hide form footer?')->hint('Should we hide the form footer? This helps integrate the form into the page.') |
|
106 | + Field::switch ('hide_footer')->label('Hide form footer?')->hint('Should we hide the form footer? This helps integrate the form into the page.') |
|
107 | 107 | ->textOn('Hidden')->textOff('Shown')->default(true) |
108 | 108 | ) |
109 | 109 | )->withGroup( |
110 | 110 | Group::make('Responses')->withField( |
111 | - Field::switch('collect_responses')->label('Save responses?')->hint('Do you want responses to be saved on the portal? You will always be able to see responses on typeform.') |
|
111 | + Field::switch ('collect_responses')->label('Save responses?')->hint('Do you want responses to be saved on the portal? You will always be able to see responses on typeform.') |
|
112 | 112 | ->textOn('Save')->textOff('Do not save')->default(false) |
113 | 113 | )->withField( |
114 | 114 | Field::input('form_id')->inputType('text')->label('Form ID')->hint('ID of the form so we can collect responses') |
115 | 115 | )->withField( |
116 | - Field::switch('use_webhook')->label('Use webhook?')->hint('Use a webhook for instant responses?') |
|
116 | + Field::switch ('use_webhook')->label('Use webhook?')->hint('Use a webhook for instant responses?') |
|
117 | 117 | ->textOn('Use')->textOff('Do not use')->default(true) |
118 | 118 | ) |
119 | 119 | )->getSchema(); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function handle(Payload $payload): ?Response |
20 | 20 | { |
21 | - if($payload->activityInstanceId() === null || $payload->moduleInstanceId() === null || $payload->submitterId() === null) { |
|
21 | + if ($payload->activityInstanceId() === null || $payload->moduleInstanceId() === null || $payload->submitterId() === null) { |
|
22 | 22 | return null; |
23 | 23 | } |
24 | 24 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | $answers = collect($payload->answers()); |
30 | 30 | foreach ($fields as $field) { |
31 | - $answer = $answers->first(function ($answer) use ($field) { |
|
31 | + $answer = $answers->first(function($answer) use ($field) { |
|
32 | 32 | return isset($answer['field']) && isset($answer['field']['id']) && $answer['field']['id'] === $field['id']; |
33 | 33 | }); |
34 | 34 | if ($answer !== null) { |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | public function webhookExists(Webhook $webhook) |
22 | 22 | { |
23 | 23 | try { |
24 | - $this->connector->request('GET', 'https://api.typeform.com/forms/'. $webhook->form_id .'/webhooks/' . $webhook->tag); |
|
24 | + $this->connector->request('GET', 'https://api.typeform.com/forms/'.$webhook->form_id.'/webhooks/'.$webhook->tag); |
|
25 | 25 | return true; |
26 | 26 | } catch (ClientException $e) { |
27 | - if($e->getCode() === 404){ |
|
27 | + if ($e->getCode() === 404) { |
|
28 | 28 | return false; |
29 | 29 | } |
30 | 30 | throw $e; |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | |
34 | 34 | public function webhookEnabled(Webhook $webhook) |
35 | 35 | { |
36 | - $response = $this->connector->request('GET', 'https://api.typeform.com/forms/'. $webhook->form_id .'/webhooks/' . $webhook->tag); |
|
36 | + $response = $this->connector->request('GET', 'https://api.typeform.com/forms/'.$webhook->form_id.'/webhooks/'.$webhook->tag); |
|
37 | 37 | $response = json_decode((string) $response->getBody(), true); |
38 | - return (isset($response['enabled'])?$response['enabled']:false); |
|
38 | + return (isset($response['enabled']) ? $response['enabled'] : false); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function webhookCreate(Webhook $webhook) |
42 | 42 | { |
43 | - $this->connector->request('PUT', 'https://api.typeform.com/forms/'. $webhook->form_id .'/webhooks/' . $webhook->tag, [ |
|
43 | + $this->connector->request('PUT', 'https://api.typeform.com/forms/'.$webhook->form_id.'/webhooks/'.$webhook->tag, [ |
|
44 | 44 | 'json' => [ |
45 | 45 | 'url' => $webhook->url(), |
46 | 46 | 'enabled' => true |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | |
51 | 51 | public function webhookDelete(Webhook $webhook) |
52 | 52 | { |
53 | - $this->connector->request('DELETE', 'https://api.typeform.com/forms/'. $webhook->form_id .'/webhooks/' . $webhook->tag); |
|
53 | + $this->connector->request('DELETE', 'https://api.typeform.com/forms/'.$webhook->form_id.'/webhooks/'.$webhook->tag); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public function webhookEnable(Webhook $webhook) |
57 | 57 | { |
58 | - $this->connector->request('PUT', 'https://api.typeform.com/forms/'. $webhook->form_id .'/webhooks/' . $webhook->tag, [ |
|
58 | + $this->connector->request('PUT', 'https://api.typeform.com/forms/'.$webhook->form_id.'/webhooks/'.$webhook->tag, [ |
|
59 | 59 | 'json' => [ |
60 | 60 | 'enabled' => true |
61 | 61 | ] |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | public function webhookDisable(Webhook $webhook) |
66 | 66 | { |
67 | - $this->connector->request('PUT', 'https://api.typeform.com/forms/'. $webhook->form_id .'/webhooks/' . $webhook->tag, [ |
|
67 | + $this->connector->request('PUT', 'https://api.typeform.com/forms/'.$webhook->form_id.'/webhooks/'.$webhook->tag, [ |
|
68 | 68 | 'json' => [ |
69 | 69 | 'enabled' => false |
70 | 70 | ] |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | public function allResponses(string $formId) |
75 | 75 | { |
76 | - $response = $this->connector->request('GET', 'https://api.typeform.com/forms/'. $formId .'/responses', [ |
|
76 | + $response = $this->connector->request('GET', 'https://api.typeform.com/forms/'.$formId.'/responses', [ |
|
77 | 77 | 'query' => [ |
78 | 78 | 'page_size' => 1000 |
79 | 79 | ] |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | public function allFields(string $formId) |
86 | 86 | { |
87 | - $response = $this->connector->request('GET', 'https://api.typeform.com/forms/'. $formId); |
|
87 | + $response = $this->connector->request('GET', 'https://api.typeform.com/forms/'.$formId); |
|
88 | 88 | return json_decode((string) $response->getBody(), true)['fields']; |
89 | 89 | } |
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public static function generatedTag(ModuleInstance $moduleInstance) |
41 | 41 | { |
42 | - return $moduleInstance->activity->slug . '-' . $moduleInstance->slug . '-' . $moduleInstance->setting('form_id'); |
|
42 | + return $moduleInstance->activity->slug.'-'.$moduleInstance->slug.'-'.$moduleInstance->setting('form_id'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function url() |
51 | 51 | { |
52 | - return url('/api/a/' . $this->moduleInstance()->activity->slug . '/' . $this->moduleInstance()->slug . '/typeform/webhook/responses'); |
|
52 | + return url('/api/a/'.$this->moduleInstance()->activity->slug.'/'.$this->moduleInstance()->slug.'/typeform/webhook/responses'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function setAnswerAttribute($answer) |
21 | 21 | { |
22 | - if(is_array($answer)) { |
|
22 | + if (is_array($answer)) { |
|
23 | 23 | $this->attributes['answer'] = json_encode($answer); |
24 | 24 | $this->attributes['encoded'] = true; |
25 | 25 | } else { |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | public function getAnswerAttribute() |
31 | 31 | { |
32 | - if(($this->attributes['encoded']??false)) { |
|
32 | + if (($this->attributes['encoded']??false)) { |
|
33 | 33 | return json_decode($this->attributes['answer'], true); |
34 | 34 | } |
35 | 35 | return $this->attributes['answer']; |
@@ -21,17 +21,17 @@ |
||
21 | 21 | */ |
22 | 22 | public function isComplete($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): bool |
23 | 23 | { |
24 | - return Response::forResource($activityInstance->id, $moduleInstance->id)->count() >= ( $settings['number_of_responses'] ?? 1); |
|
24 | + return Response::forResource($activityInstance->id, $moduleInstance->id)->count() >= ($settings['number_of_responses'] ?? 1); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function percentage($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): int |
28 | 28 | { |
29 | 29 | $count = Response::forResource($activityInstance->id, $moduleInstance->id)->count(); |
30 | - $needed = ( $settings['number_of_responses'] ?? 1); |
|
30 | + $needed = ($settings['number_of_responses'] ?? 1); |
|
31 | 31 | |
32 | - $percentage = (int) round(($count/$needed) * 100, 0); |
|
32 | + $percentage = (int) round(($count / $needed) * 100, 0); |
|
33 | 33 | |
34 | - if($percentage > 100) { |
|
34 | + if ($percentage > 100) { |
|
35 | 35 | return 100; |
36 | 36 | } |
37 | 37 | return $percentage; |
@@ -36,17 +36,17 @@ |
||
36 | 36 | } |
37 | 37 | |
38 | 38 | // If the module should use a webhook, ensure it exists and is enabled |
39 | - if($this->usesWebhook()) { |
|
39 | + if ($this->usesWebhook()) { |
|
40 | 40 | $webhook = $this->getWebhook(); |
41 | - if(! $client->webhookExists($webhook)) { |
|
41 | + if (!$client->webhookExists($webhook)) { |
|
42 | 42 | $client->webhookCreate($webhook); |
43 | 43 | } |
44 | - if(!$client->webhookEnabled($webhook)) { |
|
44 | + if (!$client->webhookEnabled($webhook)) { |
|
45 | 45 | $client->webhookEnable($webhook); |
46 | 46 | } |
47 | - } elseif(Webhook::fromModuleInstance($this->moduleInstance)->count() > 0){ |
|
47 | + } elseif (Webhook::fromModuleInstance($this->moduleInstance)->count() > 0) { |
|
48 | 48 | $webhook = $this->getWebhook(); |
49 | - if($client->webhookExists($webhook) && $client->webhookEnabled($webhook)) { |
|
49 | + if ($client->webhookExists($webhook) && $client->webhookEnabled($webhook)) { |
|
50 | 50 | $client->webhookDisable($webhook); |
51 | 51 | } |
52 | 52 | } |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | $formId = $this->moduleInstance->setting('form_id'); |
41 | - if($formId === null) { |
|
41 | + if ($formId === null) { |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $responses = collect($client->allResponses($formId))->filter(function($response) { |
46 | - if(isset($response['hidden']) && isset($response['hidden']['module_instance'])) { |
|
46 | + if (isset($response['hidden']) && isset($response['hidden']['module_instance'])) { |
|
47 | 47 | return Response::where('id', $response['token'])->count() === 0 |
48 | 48 | && $response['hidden']['module_instance'] == $this->moduleInstance->id(); |
49 | 49 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | })->values(); |
52 | 52 | |
53 | 53 | $fields = $client->allFields($formId); |
54 | - foreach($responses as $response) { |
|
54 | + foreach ($responses as $response) { |
|
55 | 55 | $payload = new ResponsePayload($response, $formId, $fields); |
56 | 56 | app(ResponseHandler::class)->handle($payload); |
57 | 57 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | public function handle() |
36 | 36 | { |
37 | - foreach($this->moduleInstances() as $moduleInstance) { |
|
37 | + foreach ($this->moduleInstances() as $moduleInstance) { |
|
38 | 38 | dispatch(new UpdateResponses($moduleInstance)); |
39 | 39 | } |
40 | 40 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function moduleInstances() |
43 | 43 | { |
44 | 44 | $id = $this->argument('moduleinstance'); |
45 | - if($id === null) { |
|
45 | + if ($id === null) { |
|
46 | 46 | return collect(app(ModuleInstanceRepository::class)->allWithAlias('typeform'))->filter(function(ModuleInstance $moduleInstance) { |
47 | 47 | return $moduleInstance->setting('collect_responses', false) |
48 | 48 | && !$moduleInstance->setting('use_webhook', true) |