-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmrf_form_processor.cmrf.inc
115 lines (104 loc) · 3.97 KB
/
cmrf_form_processor.cmrf.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
function cmrf_form_processor_get_connector_name($profile=null) {
return 'cmrf_form_processor_connector:'.$profile;
}
function cmrf_form_processor_get_connector_id($profile=null) {
$connector_name = cmrf_form_processor_get_connector_name($profile);
$core = cmrf_core_get_core();
$connector_id = variable_get($connector_name);
if (empty($connector_id)) {
$connector_id = $core->registerConnector($connector_name, $profile);
variable_set($connector_name, $connector_id);
}
return $connector_id;
}
function cmrf_form_processor_send_call($entity, $action, $parameters, $options, $profile=null) {
$connector_id = cmrf_form_processor_get_connector_id($profile);
$core = cmrf_core_get_core();
$call = $core->createCall($connector_id, $entity, $action, $parameters, $options);
$core->executeCall($call);
return $call;
}
function cmrf_form_processor_queue_call($entity, $action, $parameters, $options, $profile=null) {
$connector_id = cmrf_form_processor_get_connector_id($profile);
$core = cmrf_core_get_core();
$call = $core->createCall($connector_id, $entity, $action, $parameters, $options);
$call->setScheduledDate(new \DateTime());
$core->queueCall($call);
return $call;
}
function cmrf_form_processor_get_processor_list($profile=null) {
$processors = array();
$parameters = array();
$options['cache'] = '180 minutes';
$call = cmrf_form_processor_send_call('FormProcessorInstance', 'list', $parameters, $options, $profile);
$result = $call->getReply();
foreach($result['values'] as $value) {
$processors[$value['name']] = $value['title'];
}
return $processors;
}
function cmrf_form_processor_get_fields($form_processor, $profile=null, $additional_params=array()) {
$fields = array();
if (!is_array($additional_params)) {
$additional_params = array();
}
$parameters = $additional_params + array('api_action' => $form_processor);
$options = array();
if (empty($additional_params)) {
$options['cache'] = '180 minutes';
}
$call = cmrf_form_processor_send_call('FormProcessor', 'getfields', $parameters, $options, $profile);
$result = $call->getReply();
foreach($result['values'] as $name => $field) {
$fields[$name] = $field;
}
return $fields;
}
function cmrf_form_processor_get_options($form_processor, $field_name, $profile=null, $additional_params=array()) {
if (!is_array($additional_params)) {
$additional_params = array();
}
$parameters = $additional_params + array('api_action' => $form_processor, 'field' => $field_name);
$options = array();
if (empty($additional_params)) {
$options['cache'] = '180 minutes';
}
$call = cmrf_form_processor_send_call('FormProcessor', 'getoptions', $parameters, $options, $profile);
$result = $call->getReply();
if (isset($result['values'])) {
return $result['values'];
}
return array();
}
function cmrf_form_processor_get_default_fields($form_processor, $profile=null) {
$fields = array();
$parameters = array('api_action' => $form_processor);
$options['cache'] = '180 minutes';
$call = cmrf_form_processor_send_call('FormProcessorDefaults', 'getfields', $parameters, $options, $profile);
$result = $call->getReply();
foreach($result['values'] as $name => $field) {
$fields[$name] = $field;
}
return $fields;
}
function cmrf_form_processor_get_default_data($form_processor, $params, $cache='1 minute', $profile=null) {
global $cmrf_form_processor_latest_default_data;
$cmrf_form_processor_latest_default_data = array();
$options = array();
if (!empty($cache)) {
$options['cache'] = $cache;
}
$call = cmrf_form_processor_send_call('FormProcessorDefaults', $form_processor, $params, $options, $profile);
if ($call->getStatus() == \CMRF\Core\Call::STATUS_DONE) {
$result = $call->getReply();
foreach ($result as $name => $value) {
if ($name == 'is_error') {
continue;
}
$cmrf_form_processor_latest_default_data[$name] = $value;
}
return $cmrf_form_processor_latest_default_data;
}
return false;
}