+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
$daoFields = CRM_Cxn_DAO_Cxn::fields();
$spec['app_guid'] = $daoFields['app_guid'];
$spec['cxn_guid'] = $daoFields['cxn_guid'];
- $spec['page'] = array(
- 'name' => 'page',
+ $spec['page_name'] = array(
+ 'name' => 'page_name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Page Type'),
'description' => 'The type of page (eg "settings")',
'maxlength' => 63,
'size' => CRM_Utils_Type::HUGE,
+ 'api.aliases' => array('page'),
);
}
$cxnId = _civicrm_api3_cxn_parseCxnId($params);
$appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId);
- if (empty($params['page']) || !is_string($params['page'])) {
+ if (empty($params['page_name']) || !is_string($params['page_name'])) {
throw new API_Exception("Invalid page");
}
/** @var \Civi\Cxn\Rpc\RegistrationClient $client */
$client = \Civi::service('cxn_reg_client');
return $client->call($appMeta, 'Cxn', 'getlink', array(
- 'page' => $params['page'],
+ 'page' => $params['page_name'],
));
}
'siteCallbackUrl' => CRM_Cxn_BAO_Cxn::getSiteCallbackUrl(),
);
return civicrm_api3_create_success($result);
+}
- $cxnId = _civicrm_api3_cxn_parseCxnId($params);
- $appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId);
+/**
+ * Creates or modifies a Cxn row.
+ *
+ * @param array $params
+ * Array with keys:
+ * - id, cxn_guid OR app_guid: string.
+ * - is_active: boolean.
+ * - options: JSON
+ * @return page
+ * @throws Exception
+ */
+function civicrm_api3_cxn_create($params) {
+ $result = "";
- if (empty($params['page']) || !is_string($params['page'])) {
- throw new API_Exception("Invalid page");
- }
+ try {
+ // get the ID
+ if (!empty($params['id'])) {
+ $cxnId = $params['id'];
+ }
+ else {
+ $cxnId = _civicrm_api3_cxn_parseCxnId($params);
+ }
- /** @var \Civi\Cxn\Rpc\RegistrationClient $client */
- $client = \Civi\Core\Container::singleton()->get('cxn_reg_client');
- return $client->call($appMeta, 'Cxn', 'getlink', array(
- 'page' => $params['page'],
- ));
+ // see if it's sth to update
+ if (isset($params['options']) || isset($params['is_active'])) {
+
+ $dao = new CRM_Cxn_DAO_Cxn();
+ $dao->id = $cxnId;
+
+ if ($dao->find()) {
+ if (isset($params['is_active'])) {
+ $dao->is_active = (int) $params['is_active'];
+ }
+ if (isset($params['options'])) {
+ $dao->options = $params['options'];
+ }
+
+ $result = $dao->save();
+ }
+
+ }
+ return civicrm_api3_create_success($result, $params, 'Cxn', 'create');
+
+ }
+ catch(Exception $ex){
+ throw $ex;
+ }
}