1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SaaS Link plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Craft Field Types for linking Entries to Harvest, Trello, and Capsule. |
6
|
|
|
* |
7
|
|
|
* @link https://workingconcept.com |
8
|
|
|
* @copyright Copyright (c) 2018 Working Concept Inc. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace workingconcept\saaslink\controllers; |
12
|
|
|
|
13
|
|
|
use workingconcept\saaslink\SaasLink; |
14
|
|
|
|
15
|
|
|
use Craft; |
16
|
|
|
use craft\web\Controller; |
17
|
|
|
use yii\web\Response; |
18
|
|
|
|
19
|
|
|
class DefaultController extends Controller |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
public function actionFetchRelationshipTypes(): Response |
23
|
|
|
{ |
24
|
|
|
$this->requirePostRequest(); |
25
|
|
|
|
26
|
|
|
$request = Craft::$app->getRequest(); |
27
|
|
|
$serviceName = $request->getBodyParam('selectedService'); |
28
|
|
|
|
29
|
|
|
foreach (SaasLink::$plugin->getEnabledServices() as $service) |
30
|
|
|
{ |
31
|
|
|
if ($serviceName === $service->serviceSlug) |
32
|
|
|
{ |
33
|
|
|
return $this->asJson($service->getAvailableRelationshipTypes()); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return $this->asJson([]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function actionFetchTrelloOrganizationOptions(): Response |
41
|
|
|
{ |
42
|
|
|
$this->requirePostRequest(); |
43
|
|
|
|
44
|
|
|
$options = []; |
45
|
|
|
$request = Craft::$app->getRequest(); |
46
|
|
|
$trelloKey = $request->getBodyParam('trelloKey'); |
47
|
|
|
$trelloToken = $request->getBodyParam('trelloToken'); |
48
|
|
|
|
49
|
|
|
SaasLink::$plugin->getSettings()->trelloApiKey = $trelloKey; |
50
|
|
|
SaasLink::$plugin->getSettings()->trelloApiToken = $trelloToken; |
51
|
|
|
SaasLink::$plugin->getSettings()->trelloOrganizationId = '¯\_(ツ)_/¯'; |
52
|
|
|
|
53
|
|
|
$organizations = SaasLink::$plugin->trello->getMemberOrganizations(); |
54
|
|
|
|
55
|
|
|
foreach ($organizations as $organization) |
56
|
|
|
{ |
57
|
|
|
$options[] = [ |
58
|
|
|
'label' => $organization->displayName, |
59
|
|
|
'value' => $organization->id, |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $this->asJson($options); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|