Merge pull request #9662 from JMAConsulting/CRM-19792
[civicrm-core.git] / api / v3 / examples / GroupContact / Create.php
index 0e3ad3b7d77c2904929e66669b1ecd26f7cef53c..515848316a08d06c7661f22d2a63144fae919c8c 100644 (file)
@@ -1,52 +1,61 @@
 <?php
 /**
- * Test Generated example of using group_contact create API
- * *
+ * Test Generated example demonstrating the GroupContact.create API.
+ *
+ * @return array
+ *   API result array
  */
-function group_contact_create_example(){
-$params = array(
-  'contact_id' => 1,
-  'contact_id.2' => 2,
-  'group_id' => 1,
-);
+function group_contact_create_example() {
+  $params = array(
+    'contact_id' => 8,
+    'contact_id.2' => 9,
+    'group_id' => 11,
+  );
 
-try{
-  $result = civicrm_api3('group_contact', 'create', $params);
-}
-catch (CiviCRM_API3_Exception $e) {
-  // handle error here
-  $errorMessage = $e->getMessage();
-  $errorCode = $e->getErrorCode();
-  $errorData = $e->getExtraParams();
-  return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
-}
+  try{
+    $result = civicrm_api3('GroupContact', 'create', $params);
+  }
+  catch (CiviCRM_API3_Exception $e) {
+    // Handle error here.
+    $errorMessage = $e->getMessage();
+    $errorCode = $e->getErrorCode();
+    $errorData = $e->getExtraParams();
+    return array(
+      'is_error' => 1,
+      'error_message' => $errorMessage,
+      'error_code' => $errorCode,
+      'error_data' => $errorData,
+    );
+  }
 
-return $result;
+  return $result;
 }
 
 /**
- * Function returns array of result expected from previous function
+ * Function returns array of result expected from previous function.
+ *
+ * @return array
+ *   API result array
  */
-function group_contact_create_expectedresult(){
+function group_contact_create_expectedresult() {
 
   $expectedResult = array(
-  'is_error' => 0,
-  'version' => 3,
-  'count' => 1,
-  'values' => 1,
-  'total_count' => 2,
-  'added' => 1,
-  'not_added' => 1,
-);
+    'is_error' => 0,
+    'version' => 3,
+    'count' => 1,
+    'values' => 1,
+    'total_count' => 2,
+    'added' => 1,
+    'not_added' => 1,
+  );
 
   return $expectedResult;
 }
 
-
 /*
-* This example has been generated from the API test suite. The test that created it is called
-*
-* testCreate and can be found in
+* This example has been generated from the API test suite.
+* The test that created it is called "testCreate"
+* and can be found at:
 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GroupContactTest.php
 *
 * You can see the outcome of the API tests at
@@ -56,7 +65,7 @@ function group_contact_create_expectedresult(){
 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
 *
 * Browse the api on your own site with the api explorer
-* http://MYSITE.ORG/path/to/civicrm/api/explorer
+* http://MYSITE.ORG/path/to/civicrm/api
 *
 * Read more about testing here
 * http://wiki.civicrm.org/confluence/display/CRM/Testing