/**
  * Function to perform enable / disable actions on record.
  *
  */
 static function enableDisable()
 {
     $op = CRM_Utils_Type::escape($_POST['op'], 'String');
     $recordID = CRM_Utils_Type::escape($_POST['recordID'], 'Positive');
     $recordBAO = CRM_Utils_Type::escape($_POST['recordBAO'], 'String');
     $isActive = NULL;
     if ($op == 'disable-enable') {
         $isActive = TRUE;
     } elseif ($op == 'enable-disable') {
         $isActive = FALSE;
     }
     $status = array('status' => 'record-updated-fail');
     if (isset($isActive)) {
         // first munge and clean the recordBAO and get rid of any non alpha numeric characters
         $recordBAO = CRM_Utils_String::munge($recordBAO);
         $recordClass = explode('_', $recordBAO);
         // make sure recordClass is namespaced (we cant check CRM since extensions can also use this)
         // but it should be at least 3 levels deep
         if (count($recordClass) >= 3) {
             require_once str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . ".php";
             $method = 'setIsActive';
             if (method_exists($recordBAO, $method)) {
                 $updated = call_user_func_array(array($recordBAO, $method), array($recordID, $isActive));
                 if ($updated) {
                     $status = array('status' => 'record-updated-success');
                 }
                 // call hook enableDisable
                 CRM_Utils_Hook::enableDisable($recordBAO, $recordID, $isActive);
             }
         }
         echo json_encode($status);
         CRM_Utils_System::civiExit();
     }
 }
 /**
  * update the is_active flag in the db
  *
  * @param int      $id        id of the database record
  * @param boolean  $is_active value we want to set the is_active field
  *
  * @return Object             DAO object on success, null otherwise
  * @static
  */
 static function setIsActive($id, $is_active)
 {
     CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Relationship', $id, 'is_active', $is_active);
     // call hook
     CRM_Utils_Hook::enableDisable('CRM_Contact_BAO_Relationship', $id, $is_active);
     return TRUE;
 }
Example #3
0
 /**
  * update the is_active flag in the db
  *
  * @param int      $id        id of the database record
  * @param boolean  $is_active value we want to set the is_active field
  *
  * @return Object             DAO object on success, null otherwise
  * @static
  */
 static function setIsActive($id, $is_active)
 {
     // as both the create & add functions have a bunch of logic in them that
     // doesn't seem to cope with a normal update we will call the api which
     // has tested handling for this
     // however, a longer term solution would be to simplify the add, create & api functions
     // to be more standard. It is debatable @ that point whether it's better to call the BAO
     // direct as the api is more tested.
     $result = civicrm_api('relationship', 'create', array('id' => $id, 'is_active' => $is_active, 'version' => 3));
     if (is_array($result) && !empty($result['is_error']) && $result['error_message'] != 'Relationship already exists') {
         throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result);
     }
     // call (undocumented possibly deprecated) hook
     CRM_Utils_Hook::enableDisable('CRM_Contact_BAO_Relationship', $id, $is_active);
     return TRUE;
 }
 /**
  * update the is_active flag in the db
  *
  * @param int      $id        id of the database record
  * @param boolean  $is_active value we want to set the is_active field
  *
  * @return Object             DAO object on success, null otherwise
  * @static
  */
 static function setIsActive($id, $is_active)
 {
     // as both the create & add functions have a bunch of logic in them that
     // doesn't seem to cope with a normal update we will call the api which
     // has tested handling for this
     // however, a longer term solution would be to simplify the add, create & api functions
     // to be more standard. It is debatable @ that point whether it's better to call the BAO
     // direct as the api is more tested.
     civicrm_api3('relationship', 'create', array('id' => $id, 'is_active' => $is_active));
     // call (undocumented possibly deprecated) hook
     CRM_Utils_Hook::enableDisable('CRM_Contact_BAO_Relationship', $id, $is_active);
     return TRUE;
 }