Merge pull request #2714 from jitendrapurohit/CRMTestFix
[civicrm-core.git] / api / v3 / examples / Activity / GetTargetandAssignee.php
index aba8da82d0a3d9a41a6aa902b0d360ac5b8fca04..98d33e59144236db91b2ad997f640163e5f27d9c 100644 (file)
@@ -1,11 +1,11 @@
 <?php
-
-/*
- Example demonstrates setting & retrieving the target & source
+/**
+ * Test Generated example of using activity  API
+ * Example demonstrates setting & retrieving the target & source *
  */
 function activity__example(){
-$params = array( 
-  'source_contact_id' => 17,
+$params = array(
+  'source_contact_id' => 1,
   'subject' => 'Make-it-Happen Meeting',
   'activity_date_time' => '20110316',
   'duration' => 120,
@@ -13,29 +13,37 @@ $params = array(
   'details' => 'a test activity',
   'status_id' => 1,
   'activity_type_id' => 1,
-  'version' => 3,
   'priority_id' => 1,
-  'target_contact_id' => 17,
-  'assignee_contact_id' => 17,
+  'target_contact_id' => 1,
+  'assignee_contact_id' => 1,
 );
 
-  $result = civicrm_api( 'activity','',$params );
+try{
+  $result = civicrm_api3('activity', '', $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);
+}
 
-  return $result;
+return $result;
 }
 
-/*
+/**
  * Function returns array of result expected from previous function
  */
 function activity__expectedresult(){
 
-  $expectedResult = array( 
+  $expectedResult = array(
   'is_error' => 0,
   'version' => 3,
   'count' => 1,
   'id' => 1,
-  'values' => array( 
-      '1' => array( 
+  'values' => array(
+      '1' => array(
           'id' => '1',
           'source_record_id' => '',
           'activity_type_id' => '1',
@@ -64,7 +72,7 @@ function activity__expectedresult(){
     ),
 );
 
-  return $expectedResult  ;
+  return $expectedResult;
 }
 
 
@@ -72,20 +80,20 @@ function activity__expectedresult(){
 * This example has been generated from the API test suite. The test that created it is called
 *
 * testActivityReturnTargetAssignee and can be found in
-* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ActivityTest.php
+* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php
 *
 * You can see the outcome of the API tests at
-* http://tests.dev.civicrm.org/trunk/results-api_v3
+* https://test.civicrm.org/job/CiviCRM-master-git/
 *
 * To Learn about the API read
-* http://book.civicrm.org/developer/current/techniques/api/
+* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
 *
-* and review the wiki at
-* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
+* Browse the api on your own site with the api explorer
+* http://MYSITE.ORG/path/to/civicrm/api/explorer
 *
 * Read more about testing here
 * http://wiki.civicrm.org/confluence/display/CRM/Testing
 *
 * API Standards documentation:
 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
-*/
\ No newline at end of file
+*/