コード例 #1
0
/**
 * Deletes a contact location.
 * 
 * @param object $contact        A valid Contact object (passed by reference).
 * @param string $location_id    A valid location ID.
 *
 * @return  null, if successful. CRM error object, if 'contact' or 'location_id' is invalid, permissions are insufficient, etc.
 *
 * @access public
 *
 */
function crm_delete_location(&$contact, $location_id)
{
    _crm_initialize();
    if (!isset($contact->id)) {
        return _crm_error('$contact is not valid contact datatype');
    }
    $locationId = (int) $location_id;
    if ($locationId == 0) {
        return _crm_error('missing or invalid $location_id');
    }
    $locationDAO =& new CRM_Core_DAO_Location();
    $locationDAO->entity_table = 'civicrm_contact';
    $locationDAO->entity_id = $contact->id;
    $locationDAO->id = $locationId;
    if (!$locationDAO->find()) {
        return _crm_error('invalid $location_id');
    }
    $locationDAO->fetch();
    CRM_Core_BAO_Location::deleteLocationBlocks($locationId);
    // if we're deleting primary, lets change another one to primary
    if ($locationDAO->is_primary) {
        $otherLocationDAO =& new CRM_Core_DAO_Location();
        $otherLocationDAO->entity_table = 'civicrm_contact';
        $otherLocationDAO->entity_id = $contact->id;
        $otherLocationDAO->whereAdd("id != {$locationId}");
        $otherLocationDAO->orderBy('id');
        if ($otherLocationDAO->find()) {
            $otherLocationDAO->fetch();
            $otherLocationDAO->is_primary = 1;
            $otherLocationDAO->save();
        }
    }
    $locationDAO->delete();
    return null;
}
コード例 #2
0
ファイル: Location.php プロジェクト: ksecor/civicrm
/**
 *
 * @param <type> $contact
 * @return <type>
 */
function _civicrm_location_delete(&$contact)
{
    require_once 'CRM/Core/DAO/LocationType.php';
    $locationTypeDAO =& new CRM_Core_DAO_LocationType();
    $locationTypeDAO->id = $contact['location_type'];
    if (!$locationTypeDAO->find()) {
        return civicrm_create_error(ts('invalid location type'));
    }
    require_once 'CRM/Core/BAO/Location.php';
    CRM_Core_BAO_Location::deleteLocationBlocks($contact['contact_id'], $contact['location_type']);
    return null;
}
コード例 #3
0
 /**
  * Delete the object records that are associated with this contact
  *
  * @param  int  $contactId id of the contact to delete
  *
  * @return void
  * @access public
  * @static
  */
 function deleteContact($contactId)
 {
     $location =& new CRM_Core_DAO_Location();
     $location->entity_id = $contactId;
     $location->entity_table = CRM_Contact_DAO_Contact::getTableName();
     $location->find();
     while ($location->fetch()) {
         CRM_Core_BAO_Location::deleteLocationBlocks($location->id);
         $location->delete();
     }
 }