Beispiel #1
0
/**
 * Deletes an existing contact membership
 * 
 * This API is used for deleting a contact membership
 * 
 * @param  Int  $membershipID   Id of the contact membership to be deleted
 * 
 * @return null if successfull, object of CRM_Core_Error otherwise
 * @access public
 */
function civicrm_membership_delete(&$membershipID)
{
    _civicrm_initialize();
    if (empty($membershipID)) {
        return civicrm_create_error('Membership ID cannot be empty.');
    }
    require_once 'CRM/Member/BAO/Membership.php';
    CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipID);
    $membership = new CRM_Member_BAO_Membership();
    $result = $membership->deleteMembership($membershipID);
    return $result ? civicrm_create_success() : civicrm_create_error('Error while deleting Membership');
}
Beispiel #2
0
/**
 * Retrieve a set of activities, specific to given input params.
 *
 * @param  array  $params (reference ) input parameters.
 *
 * @return array (reference)  array of activities / error message.
 * @access public
 */
function civicrm_activity_contact_get($params)
{
    _civicrm_initialize();
    $contactId = CRM_Utils_Array::value('contact_id', $params);
    if (empty($contactId)) {
        return civicrm_create_error(ts("Required parameter not found"));
    }
    if (!is_numeric($contactId)) {
        return civicrm_create_error(ts("Invalid contact Id"));
    }
    $activities =& _civicrm_activities_get($contactId);
    if ($activities) {
        return civicrm_create_success($activities);
    } else {
        return civicrm_create_error(ts('Invalid Data'));
    }
}
/**
 * Retrieve a set of activities, specific to given input params.
 *
 * @param  array  $params (reference ) input parameters.
 *
 * @return array (reference)  array of activities / error message.
 * @access public
 */
function civicrm_activity_contact_get($params)
{
    _civicrm_initialize();
    $contactId = CRM_Utils_Array::value('contact_id', $params);
    if (empty($contactId)) {
        return civicrm_create_error(ts("Required parameter not found"));
    }
    //check if $contactId is valid
    if (!is_numeric($contactId) || !preg_match('/^\\d+$/', $contactId)) {
        return civicrm_create_error(ts("Invalid contact Id"));
    }
    $activities =& _civicrm_activities_get($contactId);
    //show success for empty $activities array
    if (empty($activities)) {
        return civicrm_create_success(ts("0 activity record matching input params"));
    }
    if ($activities) {
        return civicrm_create_success($activities);
    } else {
        return civicrm_create_error(ts('Invalid Data'));
    }
}
/**
 * Deletes an existing Tag
 *
 * @param  array  $params
 *
 * @return boolean | error  true if successfull, error otherwise
 * @access public
 */
function civicrm_tag_delete(&$params)
{
    _civicrm_initialize();
    $errorScope = CRM_Core_TemporaryErrorScope::useException();
    try {
        civicrm_verify_mandatory($params, NULL, array('tag_id'));
        $tagID = CRM_Utils_Array::value('tag_id', $params);
        require_once 'CRM/Core/BAO/Tag.php';
        return CRM_Core_BAO_Tag::del($tagID) ? civicrm_create_success() : civicrm_create_error(ts('Could not delete tag'));
    } catch (Exception $e) {
        if (CRM_Core_Error::$modeException) {
            throw $e;
        }
        return civicrm_create_error($e->getMessage());
    }
}
/**
 * Delete a pledge
 *
 * @param  array   $params           array included 'pledge_id' of pledge to delete
 *
 * @return boolean        true if success, else false
 * @static void
 * @access public
 */
function civicrm_pledge_delete(&$params)
{
    if (!empty($params['id'])) {
        //handle field name or unique db name
        $params['pledge_id'] = $params['id'];
    }
    $pledgeID = CRM_Utils_Array::value('pledge_id', $params);
    if (!$pledgeID) {
        return civicrm_create_error('Could not find pledge_id in input parameters');
    }
    require_once 'CRM/Pledge/BAO/Pledge.php';
    if (CRM_Pledge_BAO_Pledge::deletePledge($pledgeID)) {
        return civicrm_create_success();
    } else {
        return civicrm_create_error('Could not delete pledge');
    }
}
/**
 * Function to get the relationship
 *
 * @param array   $contact_a          (reference ) input parameters.
 * @param array   $contact_b          (reference ) input parameters.
 * @param array   $relationshipTypes  an array of Relationship Type Name.
 * @param string  $sort               sort all relationship by relationshipId (eg asc/desc)
 *
 * @return        Array of all relationship.
 *
 * @access  public
 */
function civicrm_contact_relationship_get($contact_a, $contact_b = NULL, $relationshipTypes = NULL, $sort = NULL)
{
    if (!is_array($contact_a)) {
        return civicrm_create_error(ts('Input parameter is not an array'));
    }
    if (!isset($contact_a['contact_id'])) {
        return civicrm_create_error(ts('Could not find contact_id in input parameters.'));
    }
    require_once 'CRM/Contact/BAO/Relationship.php';
    $contactID = $contact_a['contact_id'];
    $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactID);
    if (!empty($relationshipTypes)) {
        $result = array();
        foreach ($relationshipTypes as $relationshipName) {
            foreach ($relationships as $key => $relationship) {
                if ($relationship['relation'] == $relationshipName) {
                    $result[$key] = $relationship;
                }
            }
        }
        $relationships = $result;
    }
    if (isset($contact_b['contact_id'])) {
        $cid = $contact_b['contact_id'];
        $result = array();
        foreach ($relationships as $key => $relationship) {
            if ($relationship['cid'] == $cid) {
                $result[$key] = $relationship;
            }
        }
        $relationships = $result;
    }
    //sort by relationship id
    if ($sort) {
        if (strtolower($sort) == 'asc') {
            ksort($relationships);
        } elseif (strtolower($sort) == 'desc') {
            krsort($relationships);
        }
    }
    //handle custom data.
    require_once 'CRM/Core/BAO/CustomGroup.php';
    foreach ($relationships as $relationshipId => $values) {
        $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', CRM_Core_DAO::$_nullObject, $relationshipId, FALSE, $values['civicrm_relationship_type_id']);
        $formatTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
        $defaults = array();
        CRM_Core_BAO_CustomGroup::setDefaults($formatTree, $defaults);
        if (!empty($defaults)) {
            foreach ($defaults as $key => $val) {
                $relationships[$relationshipId][$key] = $val;
            }
        }
    }
    if ($relationships) {
        return civicrm_create_success($relationships);
    } else {
        return civicrm_create_error(ts('Invalid Data'));
    }
}
Beispiel #7
0
/**
 * Delete a specified case.
 *
 * @param  array( //REQUIRED:
 *                  'case_id'           => int
 *
 *                //OPTIONAL
 *                  'move_to_trash'     => bool (defaults to false)
 *
 * @return boolean: true if success, else false
 *
 * @access public
 */
function civicrm_case_delete(&$params)
{
    _civicrm_initialize();
    //check parameters
    $errors = _civicrm_case_check_params($params, 'delete');
    if ($errors) {
        return $errors;
    }
    if (CRM_Case_BAO_Case::deleteCase($params['case_id'], $params['move_to_trash'])) {
        return civicrm_create_success(ts('Case Deleted'));
    } else {
        return civicrm_create_error(ts('Could not delete case.'));
    }
}
Beispiel #8
0
/**
 *
 * @param <type> $params
 * @param <type> $locationArray
 * @return <type>
 */
function _civicrm_location_update($params, $locations)
{
    // convert api params to 3.0 format.
    if ('3.0' != CRM_Utils_Array::value('version', $params)) {
        _civicrm_format_params_v2_to_v3($params);
    }
    $contact = array('contact_id' => $params['contact_id']);
    $primary = $billing = array();
    // copy params value in contact array.
    foreach (array('email', 'phone', 'im', 'openid') as $name) {
        if (CRM_Utils_Array::value($name, $params) && is_array($params[$name])) {
            $blockCount = 0;
            $contact[$name] = array();
            foreach ($params[$name] as $val) {
                $contact[$name][++$blockCount] = $val;
                // check for primary and billing.
                if (CRM_Utils_Array::value('is_primary', $val)) {
                    $primary[$name][$blockCount] = true;
                }
                if (CRM_Utils_Array::value('is_billing', $val)) {
                    $primary[$name][$blockCount] = true;
                }
            }
        } else {
            // get values from db blocks so we dont lose them.
            if (!CRM_Utils_Array::value($name, $locations) || !is_array($locations[$name])) {
                continue;
            }
            $contact[$name] = $locations[$name];
        }
    }
    $addressCount = 1;
    if (CRM_Utils_Array::value(1, $params['address']) && !empty($params['address'][1])) {
        $contact['address'][$addressCount] = $params['address'][1];
        // check for primary and billing address.
        if (CRM_Utils_Array::value('is_primary', $params['address'][1])) {
            $primary['address'][$addressCount] = true;
        }
        if (CRM_Utils_Array::value('is_billing', $params['address'][1])) {
            $billing['address'][$addressCount] = true;
        }
        // format state and country.
        foreach (array('state_province', 'country') as $field) {
            $fName = $field == 'state_province' ? 'stateProvinceAbbreviation' : 'countryIsoCode';
            if (CRM_Utils_Array::value($field, $contact['address'][$addressCount]) && is_numeric($contact['address'][$addressCount][$field])) {
                $fValue =& $contact['address'][$addressCount][$field];
                eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );');
                //kill the reference.
                unset($fValue);
            }
        }
    }
    //handle primary and billing reset.
    foreach (array('email', 'phone', 'im', 'address', 'openid') as $name) {
        if (!array_key_exists($name, $contact) || CRM_Utils_System::isNull($contact[$name])) {
            continue;
        }
        $errorMsg = null;
        $primaryBlockIndex = $billingBlockIndex = 0;
        if (array_key_exists($name, $primary)) {
            if (count($primary[$name]) > 1) {
                $errorMsg .= ts("<br />Multiple Primary %1.", array(1 => $name));
            } else {
                $primaryBlockIndex = key($primary[$name]);
            }
        }
        if (array_key_exists($name, $billing)) {
            if (count($billing[$name]) > 1) {
                $errorMsg .= ts("<br />Multiple Billing %1.", array(1 => $name));
            } else {
                $billingBlockIndex = key($billing[$name]);
            }
        }
        if ($errorMsg) {
            return civicrm_create_error($errorMsg);
        }
        foreach ($contact[$name] as $count => &$values) {
            if ($primaryBlockIndex && $count != $primaryBlockIndex) {
                $values['is_primary'] = false;
            }
            if ($billingBlockIndex && $count != $billingBlockIndex) {
                $values['is_billing'] = false;
            }
            // kill the reference.
            unset($values);
        }
    }
    // get all ids if not present.
    require_once 'CRM/Contact/BAO/Contact.php';
    CRM_Contact_BAO_Contact::resolveDefaults($contact, true);
    $location = CRM_Core_BAO_Location::create($contact);
    if (empty($location)) {
        return civicrm_create_error(ts("Location not created"));
    }
    $locArray = array();
    $blocks = array('address', 'phone', 'email', 'im', 'openid');
    $locationTypeId = null;
    foreach ($blocks as $block) {
        for ($i = 0; $i < count($location[$block]); $i++) {
            $locArray[$block][$i] = $location[$block][$i]->id;
            $locationTypeId = $location[$block][$i]->location_type_id;
        }
    }
    // CRM-4800
    if (3.0 != CRM_Utils_Array::value('version', $params)) {
        $locArray['location_type_id'] = $locationTypeId;
    }
    return civicrm_create_success($locArray);
}
Beispiel #9
0
/**
 * Deletes an existing Tag
 *
 * @param  array  $params
 * 
 * @return boolean | error  true if successfull, error otherwise
 * @access public
 */
function civicrm_tag_delete(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error(ts('Input parameters is not an array'));
    }
    $tagID = CRM_Utils_Array::value('tag_id', $params);
    if (!$tagID) {
        return civicrm_create_error(ts('Could not find tag_id in input parameters'));
    }
    require_once 'CRM/Core/BAO/Tag.php';
    return CRM_Core_BAO_Tag::del($tagID) ? civicrm_create_success() : civicrm_create_error(ts('Could not delete tag'));
}
Beispiel #10
0
/**
 * Delete a specified Activity.
 * @param CRM_Activity $activity Activity object to be deleted
 *
 * @return void|CRM_Core_Error  An error if 'activityName or ID' is invalid,
 *                         permissions are insufficient, etc.
 *
 * @access public
 *
 */
function civicrm_activity_delete(&$params)
{
    _civicrm_initialize();
    $errors = array();
    //check for various error and required conditions
    $errors = _civicrm_activity_check_params($params);
    if (!empty($errors)) {
        return $errors;
    }
    if (CRM_Activity_BAO_Activity::deleteActivity($params)) {
        return civicrm_create_success();
    } else {
        return civicrm_create_error(ts('Could not delete activity'));
    }
}
Beispiel #11
0
/**
 * Validate a formatted contact parameter list.
 *
 * @param array $params  Structured parameter list (as in crm_format_params)
 *
 * @return bool|CRM_Core_Error
 * @access public
 */
function _civicrm_validate_formatted_contact(&$params)
{
    /* Look for offending email addresses */
    if (array_key_exists('email', $params)) {
        foreach ($params['email'] as $count => $values) {
            if (!is_array($values)) {
                continue;
            }
            if ($email = CRM_Utils_Array::value('email', $values)) {
                //validate each email
                if (!CRM_Utils_Rule::email($email)) {
                    return civicrm_create_error('No valid email address');
                }
                //check for loc type id.
                if (!CRM_Utils_Array::value('location_type_id', $values)) {
                    return civicrm_create_error('Location Type Id missing.');
                }
            }
        }
    }
    /* Validate custom data fields */
    if (is_array($params['custom'])) {
        foreach ($params['custom'] as $key => $custom) {
            if (is_array($custom)) {
                $valid = CRM_Core_BAO_CustomValue::typecheck($custom['type'], $custom['value']);
                if (!$valid) {
                    return civicrm_create_error('Invalid value for custom field \'' . $custom['name'] . '\'');
                }
                if ($custom['type'] == 'Date') {
                    $params['custom'][$key]['value'] = str_replace('-', '', $params['custom'][$key]['value']);
                }
            }
        }
    }
    return civicrm_create_success(true);
}
/**
 * Handle an open event
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_mailer_event_open($params)
{
    $errors = _civicrm_mailer_check_params($params, array('event_queue_id'));
    if (!empty($errors)) {
        return $errors;
    }
    $queue = $params['event_queue_id'];
    $success = CRM_Mailing_Event_BAO_Opened::open($queue);
    if (!$success) {
        return civicrm_create_error(ts('mailer open event failed'));
    }
    return civicrm_create_success();
}
Beispiel #13
0
/**
 * Deletes an existing note
 * 
 * This API is used for deleting a note
 * 
 * @param  Int  $noteID   Id of the note to be deleted
 * 
 * @return null
 * @access public
 */
function civicrm_note_delete(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        $error = civicrm_create_error('Params is not an array');
        return $error;
    }
    if (!CRM_Utils_Array::value('id', $params)) {
        $error = civicrm_create_error('Invalid or no value for Note ID');
        return $error;
    }
    $result = new CRM_Core_BAO_Note();
    return $result->del($params['id']) ? civicrm_create_success() : civicrm_create_error('Error while deleting Note');
}
/**
 * Use this API to delete an existing custom group field.
 *
 * @param $params     Array id of the field to be deleted
 *
 *       
 * @access public
 **/
function civicrm_custom_field_delete($params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array');
    }
    if (!CRM_Utils_Array::value('customFieldId', $params['result'])) {
        return civicrm_create_error('Invalid or no value for Custom Field ID');
    }
    require_once 'CRM/Core/DAO/CustomField.php';
    $field = new CRM_Core_DAO_CustomField();
    $field->id = $params['result']['customFieldId'];
    $field->find(true);
    require_once 'CRM/Core/BAO/CustomField.php';
    $customFieldDelete = CRM_Core_BAO_CustomField::deleteField($field);
    return $customFieldDelete ? civicrm_create_error('Error while deleting custom field') : civicrm_create_success();
}
Beispiel #15
0
/**
 * Delete a contribution
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return boolean        true if success, else false
 * @static void
 * @access public
 */
function civicrm_contribution_delete(&$params)
{
    $contributionID = CRM_Utils_Array::value('contribution_id', $params);
    if (!$contributionID) {
        return civicrm_create_error(ts('Could not find contribution_id in input parameters'));
    }
    require_once 'CRM/Contribute/BAO/Contribution.php';
    if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionID)) {
        return civicrm_create_success();
    } else {
        return civicrm_create_error(ts('Could not delete contribution'));
    }
}
Beispiel #16
0
/**
 * Deletes an existing event
 * 
 * This API is used for deleting a event
 * 
 * @param  Array  $params    array containing event_id to be deleted
 * 
 * @return boolean        true if success, error otherwise
 * @access public
 */
function civicrm_event_delete(&$params)
{
    if (empty($params)) {
        return civicrm_create_error(ts('No input parameters present'));
    }
    $eventID = null;
    $eventID = CRM_Utils_Array::value('event_id', $params);
    if (!isset($eventID)) {
        return civicrm_create_error(ts('Invalid value for eventID'));
    }
    require_once 'CRM/Event/BAO/Event.php';
    return CRM_Event_BAO_Event::del($eventID) ? civicrm_create_success() : civicrm_create_error(ts('Error while deleting event'));
}
Beispiel #17
0
/**
 * Deletes an existing membership status
 * 
 * This API is used for deleting a membership status
 * 
 * @param  Int  $membershipStatusID   Id of the membership status to be deleted
 * 
 * @return null if successfull, object of CRM_Core_Error otherwise
 * @access public
 */
function civicrm_membership_status_delete(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array');
    }
    if (!CRM_Utils_Array::value('id', $params)) {
        return civicrm_create_error('Invalid or no value for membershipStatusID');
    }
    require_once 'CRM/Member/BAO/MembershipStatus.php';
    $memberStatusDelete = CRM_Member_BAO_MembershipStatus::del($params['id']);
    return $memberStatusDelete ? civicrm_create_error('Error while deleting membership type Status') : civicrm_create_success();
}
Beispiel #18
0
/**
 * Deletes an existing membership type
 * 
 * This API is used for deleting a membership type
 * Required parrmeters : id of a membership type
 * 
 * @param  Array   $params  an associative array of name/value property values of civicrm_membership_type
 * 
 * @return boolean        true if success, else false
 * @access public
 */
function civicrm_membership_type_delete(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error('Params need to be of type array!');
    }
    if (empty($params)) {
        return civicrm_create_error('No input parameters present');
    }
    if (!CRM_Utils_Array::value('id', $params)) {
        return civicrm_create_error('Invalid or no value for membershipTypeID');
    }
    require_once 'CRM/Member/BAO/MembershipType.php';
    $memberDelete = CRM_Member_BAO_MembershipType::del($params['id']);
    return $memberDelete ? civicrm_create_success("Given Membership Type have been deleted") : civicrm_create_error('Error while deleting membership type');
}
/**
 * @todo What does this do? If it's still useful, figure out where it should live and what it should be named.
 *
 * @deprecated deprecated since version 2.2.3
 */
function civicrm_replace_contact_formatted($contactId, &$params, &$fields)
{
    //$contact = civcrm_get_contact(array('contact_id' => $contactId));
    $delContact = array('contact_id' => $contactId);
    civicrm_contact_delete($delContact);
    $cid = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, NULL, NULL, NULL, $params['contact_type']);
    return civicrm_create_success($cid);
}
/**
 * Deletes an existing Participant Payment
 *
 * This API is used for deleting a Participant Payment
 *
 * @param  Int  $participantPaymentID   Id of the Participant Payment to be deleted
 *
 * @return null if successfull, array with is_error=1 otherwise
 * @access public
 */
function civicrm_participant_payment_delete(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        $error = civicrm_create_error('Params is not an array');
        return $error;
    }
    if (!CRM_Utils_Array::value('id', $params)) {
        $error = civicrm_create_error('Invalid or no value for Participant payment ID');
        return $error;
    }
    require_once 'CRM/Event/BAO/ParticipantPayment.php';
    $participant = new CRM_Event_BAO_ParticipantPayment();
    return $participant->deleteParticipantPayment($params) ? civicrm_create_success() : civicrm_create_error('Error while deleting participantPayment');
}
/**
 * Delete a relationship type delete
 *
 * @param  id of relationship type  $id
 *
 * @return boolean  true if success, else false
 * @static void
 * @access public
 */
function civicrm_relationship_type_delete(&$params)
{
    if (!CRM_Utils_Array::value('id', $params)) {
        return civicrm_create_error('Missing required parameter');
    }
    require_once 'CRM/Utils/Rule.php';
    if ($params['id'] != null && !CRM_Utils_Rule::integer($params['id'])) {
        return civicrm_create_error('Invalid value for relationship type ID');
    }
    $relationTypeBAO = new CRM_Contact_BAO_RelationshipType();
    return $relationTypeBAO->del($params['id']) ? civicrm_create_success(ts('Deleted relationship type successfully')) : civicrm_create_error(ts('Could not delete relationship type'));
}
/**
 * delete an existing group
 *
 * This method is used to delete any existing group. id of the group
 * to be deleted is required field in $params array
 *
 * @param array $params  (referance) array containing id of the group
 *                       to be deleted
 *
 * @return array  (referance) returns flag true if successfull, error
 *                message otherwise
 *
 * @access public
 */
function civicrm_group_delete(&$params)
{
    _civicrm_initialize();
    if (is_null($params) || !is_array($params) || !CRM_Utils_Array::value('id', $params)) {
        return civicrm_create_error('Required parameter missing');
    }
    CRM_Contact_BAO_Group::discard($params['id']);
    return civicrm_create_success(TRUE);
}
Beispiel #23
0
/**
 * Deletes an existing Group Organization
 * 
 * This API is used for deleting a Group Organization
 * 
 * @param  Array  $params  ID of the Group Organization to be deleted
 * 
 * @return null if successfull, array with is_error = 1 otherwise
 * @access public
 */
function civicrm_group_organization_remove(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        $error = civicrm_create_error('Input parameter is not an array');
        return $error;
    }
    if (empty($params)) {
        return civicrm_create_error('No input parameter present');
    }
    if (!CRM_Utils_Array::value('id', $params)) {
        $error = civicrm_create_error('Invalid or no value for Group Organization ID');
        return $error;
    }
    require_once 'CRM/Contact/BAO/GroupOrganization.php';
    $result = CRM_Contact_BAO_GroupOrganization::delete($params);
    return $result ? civicrm_create_success(ts('Deleted Group Organization successfully')) : civicrm_create_error(ts('Could not delete Group Organization'));
}
/**
 * Deletes an existing contact participant
 *
 * This API is used for deleting a contact participant
 *
 * @param  Int  $participantID   Id of the contact participant to be deleted
 *
 * @return boolean        true if success, else false
 * @access public
 */
function &civicrm_participant_delete(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        $error = civicrm_create_error('Params is not an array');
        return $error;
    }
    if (!isset($params['id'])) {
        $error = civicrm_create_error('Required parameter missing');
        return $error;
    }
    require_once 'CRM/Event/BAO/Participant.php';
    $participant = new CRM_Event_BAO_Participant();
    $result = $participant->deleteParticipant($params['id']);
    if ($result) {
        $values = civicrm_create_success();
    } else {
        $values = civicrm_create_error('Error while deleting participant');
    }
    return $values;
}