/**
  * Delete Relationship Types.
  *
  * @param int $relationshipTypeId
  *
  * @throws CRM_Core_Exception
  * @return mixed
  */
 public static function del($relationshipTypeId)
 {
     // make sure relationshipTypeId is an integer
     // @todo review this as most delete functions rely on the api & form layer for this
     // or do a find first & throw error if no find
     if (!CRM_Utils_Rule::positiveInteger($relationshipTypeId)) {
         throw new CRM_Core_Exception(ts('Invalid relationship type'));
     }
     //check dependencies
     // delete all relationships
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->relationship_type_id = $relationshipTypeId;
     $relationship->delete();
     // remove this relationship type from membership types
     $mems = civicrm_api3('MembershipType', 'get', array('relationship_type_id' => array('LIKE' => "%{$relationshipTypeId}%"), 'return' => array('id', 'relationship_type_id', 'relationship_direction')));
     foreach ($mems['values'] as $membershipTypeId => $membershipType) {
         $pos = array_search($relationshipTypeId, $membershipType['relationship_type_id']);
         // Api call may have returned false positives but currently the relationship_type_id uses
         // nonstandard serialization which makes anything more accurate impossible.
         if ($pos !== FALSE) {
             unset($membershipType['relationship_type_id'][$pos], $membershipType['relationship_direction'][$pos]);
             civicrm_api3('MembershipType', 'create', $membershipType);
         }
     }
     //fixed for CRM-3323
     $mappingField = new CRM_Core_DAO_MappingField();
     $mappingField->relationship_type_id = $relationshipTypeId;
     $mappingField->find();
     while ($mappingField->fetch()) {
         $mappingField->delete();
     }
     $relationshipType = new CRM_Contact_DAO_RelationshipType();
     $relationshipType->id = $relationshipTypeId;
     return $relationshipType->delete();
 }
示例#2
0
 /**
  * Save the mapping field info for search builder / export given the formvalues
  *
  * @param array $params
  *   Asscociated array of formvalues.
  * @param int $mappingId
  *   Mapping id.
  *
  * @return NULL
  */
 public static function saveMappingFields(&$params, $mappingId)
 {
     //delete mapping fields records for exixting mapping
     $mappingFields = new CRM_Core_DAO_MappingField();
     $mappingFields->mapping_id = $mappingId;
     $mappingFields->delete();
     if (empty($params['mapper'])) {
         return NULL;
     }
     //save record in mapping field table
     foreach ($params['mapper'] as $key => $value) {
         $colCnt = 0;
         foreach ($value as $k => $v) {
             if (!empty($v['1'])) {
                 $saveMappingFields = new CRM_Core_DAO_MappingField();
                 $saveMappingFields->mapping_id = $mappingId;
                 $saveMappingFields->name = CRM_Utils_Array::value('1', $v);
                 $saveMappingFields->contact_type = CRM_Utils_Array::value('0', $v);
                 $locationId = CRM_Utils_Array::value('2', $v);
                 $saveMappingFields->location_type_id = is_numeric($locationId) ? $locationId : NULL;
                 if ($v[1] == 'phone') {
                     $saveMappingFields->phone_type_id = CRM_Utils_Array::value('3', $v);
                 } elseif ($v[1] == 'im') {
                     $saveMappingFields->im_provider_id = CRM_Utils_Array::value('3', $v);
                 }
                 if (!empty($params['operator'])) {
                     $saveMappingFields->operator = CRM_Utils_Array::value($k, $params['operator'][$key]);
                 }
                 if (!empty($params['value'])) {
                     $saveMappingFields->value = CRM_Utils_Array::value($k, $params['value'][$key]);
                 }
                 // Handle mapping for 'related contact' fields
                 if (count(explode('_', CRM_Utils_Array::value('1', $v))) > 2) {
                     list($id, $first, $second) = explode('_', CRM_Utils_Array::value('1', $v));
                     if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
                         if (!empty($v['2'])) {
                             $saveMappingFields->name = CRM_Utils_Array::value('2', $v);
                         } elseif (!empty($v['4'])) {
                             $saveMappingFields->name = CRM_Utils_Array::value('4', $v);
                         }
                         if (is_numeric(CRM_Utils_Array::value('3', $v))) {
                             $locationTypeid = CRM_Utils_Array::value('3', $v);
                         } elseif (is_numeric(CRM_Utils_Array::value('5', $v))) {
                             $locationTypeid = CRM_Utils_Array::value('5', $v);
                         }
                         if (is_numeric(CRM_Utils_Array::value('4', $v))) {
                             $phoneTypeid = CRM_Utils_Array::value('4', $v);
                         } elseif (is_numeric(CRM_Utils_Array::value('6', $v))) {
                             $phoneTypeid = CRM_Utils_Array::value('6', $v);
                         }
                         $saveMappingFields->location_type_id = is_numeric($locationTypeid) ? $locationTypeid : NULL;
                         $saveMappingFields->phone_type_id = is_numeric($phoneTypeid) ? $phoneTypeid : NULL;
                         $saveMappingFields->relationship_type_id = $id;
                         $saveMappingFields->relationship_direction = "{$first}_{$second}";
                     }
                 }
                 $saveMappingFields->grouping = $key;
                 $saveMappingFields->column_number = $colCnt;
                 $saveMappingFields->save();
                 $colCnt++;
                 $locationTypeid = $phoneTypeid = NULL;
             }
         }
     }
 }
 /**
  * Function to delete Relationship Types
  *
  * @param int $relationshipTypeId
  * @static
  */
 static function del($relationshipTypeId)
 {
     // make sure relationshipTypeId is an integer
     // @todo review this as most delete functions rely on the api & form layer for this
     // or do a find first & throw error if no find
     if (!CRM_Utils_Rule::positiveInteger($relationshipTypeId)) {
         throw new CRM_Core_Exception(ts('Invalid relationship type'));
     }
     //check dependencies
     // delete all relationships
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->relationship_type_id = $relationshipTypeId;
     $relationship->delete();
     // set all membership_type to null
     $query = "\nUPDATE civicrm_membership_type\n  SET  relationship_type_id = NULL\n WHERE relationship_type_id = %1\n";
     $params = array(1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $relationshipTypeId . CRM_Core_DAO::VALUE_SEPARATOR, 'String'));
     CRM_Core_DAO::executeQuery($query, $params);
     //fixed for CRM-3323
     $mappingField = new CRM_Core_DAO_MappingField();
     $mappingField->relationship_type_id = $relationshipTypeId;
     $mappingField->find();
     while ($mappingField->fetch()) {
         $mappingField->delete();
     }
     $relationshipType = new CRM_Contact_DAO_RelationshipType();
     $relationshipType->id = $relationshipTypeId;
     return $relationshipType->delete();
 }
 /**
  * Function to delete Relationship Types
  *
  * @param int $relationshipTypeId
  * @static
  */
 static function del($relationshipTypeId)
 {
     // make sure relationshipTypeId is an integer
     if (!CRM_Utils_Rule::positiveInteger($relationshipTypeId)) {
         CRM_Core_Error::fatal(ts('Invalid relationship type'));
     }
     //check dependencies
     // delete all relationships
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->relationship_type_id = $relationshipTypeId;
     $relationship->delete();
     // set all membership_type to null
     $query = "\nUPDATE civicrm_membership_type\n  SET  relationship_type_id = NULL\n WHERE relationship_type_id = %1\n";
     $params = array(1 => array($relationshipTypeId, 'Integer'));
     CRM_Core_DAO::executeQuery($query, $params);
     //fixed for CRM-3323
     $mappingField = new CRM_Core_DAO_MappingField();
     $mappingField->relationship_type_id = $relationshipTypeId;
     $mappingField->find();
     while ($mappingField->fetch()) {
         $mappingField->delete();
     }
     $relationshipType = new CRM_Contact_DAO_RelationshipType();
     $relationshipType->id = $relationshipTypeId;
     return $relationshipType->delete();
 }