Skip to content

Commit b892b7e

Browse files
authored
Merge pull request #9 from codeccoop/feat/suitecrm
feat: suitecrm addon
2 parents b1b8389 + 401cf7c commit b892b7e

File tree

19 files changed

+3223
-33
lines changed

19 files changed

+3223
-33
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,22 @@ to work with specific APIs, new workflow jobs and bridge templates.
3636

3737
Forms Bridge has the following addons:
3838

39-
- [REST API](https://en.wikipedia.org/wiki/REST)
40-
- [Bigin](https://www.bigin.com/developer/docs/apis/v2/?source=developer)
41-
- [Brevo](https://developers.brevo.com/)
42-
- [Dolibarr](<https://wiki.dolibarr.org/index.php/Module_Web_Services_API_REST_(developer)>)
43-
- [FinanCoop](https://somit.coop/financoop/)
44-
- [Google Sheets](https://workspace.google.com/products/sheets/)
45-
- [Holded](https://developers.holded.com/reference/api-key)
46-
- [Listmonk](https://listmonk.app/docs/apis/apis/)
47-
- [Nextcloud](https://docs.nextcloud.com/server/20/user_manual/en/files/access_webdav.html)
48-
- [Mailchimp](https://mailchimp.com/developer/)
49-
- [Odoo](https://www.odoo.com/)
50-
- [Rocket.Chat](https://developer.rocket.chat/apidocs)
51-
- [Slack](https://docs.slack.dev/reference/)
52-
- [Zoho CRM](https://www.zoho.com/developer/rest-api.html)
53-
- [Zulip](https://zulip.com/api/rest)
39+
- [REST API](https://formsbridge.codeccoop.org/documentation/#backends)
40+
- [Bigin](https://formsbridge.codeccoop.org/documentation/bigin/)
41+
- [Brevo](https://formsbridge.codeccoop.org/documentation/brevo/)
42+
- [Dolibarr](https://formsbridge.codeccoop.org/documentation/dolibarr/)
43+
- [FinanCoop](https://formsbridge.codeccoop.org/documentation/financoop/)
44+
- [Google Sheets](https://formsbridge.codeccoop.org/documentation/google-sheets/)
45+
- [Holded](https://formsbridge.codeccoop.org/documentation/holded/)
46+
- [Listmonk](https://formsbridge.codeccoop.org/documentation/listmonk/)
47+
- [Nextcloud](https://formsbridge.codeccoop.org/documentation/nextcloud/)
48+
- [Mailchimp](https://formsbridge.codeccoop.org/documentation/mailchimp/)
49+
- [Odoo](https://formsbridge.codeccoop.org/documentation/odoo/)
50+
- [Rocket.Chat](https://formsbridge.codeccoop.org/documentation/rocket-chat/)
51+
- [Slack](https://formsbridge.codeccoop.org/documentation/slack/)
52+
- [SuiteCRM](https://formsbridge.codeccoop.org/documentation/suitecrm/)
53+
- [Zoho CRM](https://formsbridge.codeccoop.org/documentation/zoho-crm/)
54+
- [Zulip](https://formsbridge.codeccoop.org/documentation/zulip/)
5455

5556
## Backends
5657

forms-bridge/addons/dolibarr/jobs/appointment-dates.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php
2+
/**
3+
* Dolibarr appointment dates job
4+
*
5+
* @package formsbridge
6+
*/
27

38
if ( ! defined( 'ABSPATH' ) ) {
49
exit();
510
}
611

712
function forms_bridge_dolibarr_appointment_dates( $payload ) {
813
$datetime = DateTime::createFromFormat( 'Y-m-d H:i:s', $payload['date'] );
9-
if ( $datetime === false ) {
14+
if ( false === $datetime ) {
1015
return new WP_Error(
1116
'invalid-date',
1217
__( 'Invalid date time value', 'forms-bridge' )
7.19 KB
Loading
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<?php
2+
/**
3+
* Class SuiteCRM_Addon
4+
*
5+
* @package formsbridge
6+
*/
7+
8+
namespace FORMS_BRIDGE;
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit();
12+
}
13+
14+
require_once 'class-suitecrm-form-bridge.php';
15+
require_once 'hooks.php';
16+
17+
/**
18+
* SuiteCRM Addon class.
19+
*
20+
* Provides integration with SuiteCRM v4_1 REST API.
21+
*/
22+
class SuiteCRM_Addon extends Addon {
23+
24+
/**
25+
* Holds the addon's title.
26+
*
27+
* @var string
28+
*/
29+
public const TITLE = 'SuiteCRM';
30+
31+
/**
32+
* Holds the addon's name.
33+
*
34+
* @var string
35+
*/
36+
public const NAME = 'suitecrm';
37+
38+
/**
39+
* Holds the addon's custom bridge class.
40+
*
41+
* @var string
42+
*/
43+
public const BRIDGE = '\FORMS_BRIDGE\SuiteCRM_Form_Bridge';
44+
45+
/**
46+
* Performs a request against the backend to check the connexion status.
47+
*
48+
* @param string $backend Target backend name.
49+
*
50+
* @return boolean
51+
*/
52+
public function ping( $backend ) {
53+
$bridge = new SuiteCRM_Form_Bridge(
54+
array(
55+
'name' => '__suitecrm-' . time(),
56+
'method' => 'get_user_id',
57+
'endpoint' => '',
58+
'backend' => $backend,
59+
)
60+
);
61+
62+
$response = $bridge->submit();
63+
64+
if ( is_wp_error( $response ) ) {
65+
Logger::log( 'SuiteCRM backend ping error response', Logger::ERROR );
66+
Logger::log( $response, Logger::ERROR );
67+
return false;
68+
}
69+
70+
return true;
71+
}
72+
73+
/**
74+
* Performs a GET request against the backend module and retrieve the response data.
75+
*
76+
* @param string $endpoint Target module name.
77+
* @param string $backend Target backend name.
78+
*
79+
* @return array|WP_Error
80+
*/
81+
public function fetch( $endpoint, $backend ) {
82+
$bridge = new SuiteCRM_Form_Bridge(
83+
array(
84+
'name' => '__suitecrm-' . time(),
85+
'method' => 'get_entry_list',
86+
'endpoint' => $endpoint,
87+
'backend' => $backend,
88+
)
89+
);
90+
91+
return $bridge->submit(
92+
array(
93+
'select_fields' => array( 'id', 'name' ),
94+
'max_results' => 100,
95+
)
96+
);
97+
}
98+
99+
/**
100+
* Fetch available modules from the backend.
101+
*
102+
* @param Backend $backend HTTP backend object.
103+
*
104+
* @return array
105+
*/
106+
public function get_endpoints( $backend ) {
107+
$bridge = new SuiteCRM_Form_Bridge(
108+
array(
109+
'name' => '__suitecrm-' . time(),
110+
'method' => 'get_available_modules',
111+
'endpoint' => '',
112+
'backend' => $backend,
113+
)
114+
);
115+
116+
$response = $bridge->submit();
117+
118+
if ( is_wp_error( $response ) ) {
119+
return array();
120+
}
121+
122+
if ( ! isset( $response['data']['modules'] ) ) {
123+
return array();
124+
}
125+
126+
return array_map(
127+
function ( $module ) {
128+
return $module['module_key'];
129+
},
130+
$response['data']['modules']
131+
);
132+
}
133+
134+
/**
135+
* Performs an introspection of the backend module and returns API fields
136+
* and accepted content type.
137+
*
138+
* @param string $module Target module name.
139+
* @param string $backend Target backend name.
140+
* @param string|null $method API method.
141+
*
142+
* @return array List of fields and content type of the module.
143+
*/
144+
public function get_endpoint_schema( $module, $backend, $method = null ) {
145+
if ( 'set_entry' !== $method ) {
146+
return array();
147+
}
148+
149+
$bridge = new SuiteCRM_Form_Bridge(
150+
array(
151+
'name' => '__suitecrm-' . time(),
152+
'method' => 'get_module_fields',
153+
'endpoint' => $module,
154+
'backend' => $backend,
155+
)
156+
);
157+
158+
$response = $bridge->submit();
159+
160+
if ( is_wp_error( $response ) ) {
161+
return array();
162+
}
163+
164+
if ( ! isset( $response['data']['module_fields'] ) ) {
165+
return array();
166+
}
167+
168+
$fields = array();
169+
foreach ( $response['data']['module_fields'] as $name => $spec ) {
170+
$type = 'string';
171+
172+
if ( in_array( $spec['type'], array( 'int', 'integer' ), true ) ) {
173+
$type = 'integer';
174+
} elseif ( in_array( $spec['type'], array( 'decimal', 'float', 'currency' ), true ) ) {
175+
$type = 'number';
176+
} elseif ( 'bool' === $spec['type'] ) {
177+
$type = 'boolean';
178+
}
179+
180+
$schema = array(
181+
'type' => $type,
182+
'required' => ! empty( $spec['required'] ),
183+
);
184+
185+
$fields[] = array(
186+
'name' => $name,
187+
'schema' => $schema,
188+
);
189+
}
190+
191+
return $fields;
192+
}
193+
}
194+
195+
SuiteCRM_Addon::setup();

0 commit comments

Comments
 (0)