Merge pull request #9575 from jitendrapurohit/CRM-19761
[civicrm-core.git] / api / v3 / Cxn.php
index 199d091634195af929f0366ef56dff73bedcd83c..12b3914108d00019e39f222aebbc637d41da6022 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -222,13 +222,14 @@ function _civicrm_api3_cxn_getlink_spec(&$spec) {
   $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'),
   );
 }
 
@@ -245,13 +246,78 @@ function civicrm_api3_cxn_getlink($params) {
   $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'],
   ));
 }
+
+/**
+ *
+ * @param array $params
+ * @return array
+ * @throws Exception
+ */
+function civicrm_api3_cxn_getcfg($params) {
+  $result = array(
+    'CIVICRM_CXN_CA' => defined('CIVICRM_CXN_CA') ? CIVICRM_CXN_CA : NULL,
+    'CIVICRM_CXN_VIA' => defined('CIVICRM_CXN_VIA') ? CIVICRM_CXN_VIA : NULL,
+    'CIVICRM_CXN_APPS_URL' => defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL : NULL,
+    'siteCallbackUrl' => CRM_Cxn_BAO_Cxn::getSiteCallbackUrl(),
+  );
+  return civicrm_api3_create_success($result);
+}
+
+/**
+ * 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 = "";
+
+  try {
+    // get the ID
+    if (!empty($params['id'])) {
+      $cxnId = $params['id'];
+    }
+    else {
+      $cxnId = _civicrm_api3_cxn_parseCxnId($params);
+    }
+
+    // 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;
+  }
+}