copyValues($params); if ($relationshipType->find(TRUE)) { CRM_Core_DAO::storeValues($relationshipType, $defaults); $relationshipType->free(); return $relationshipType; } return NULL; } /** * 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 sucess, null otherwise * @static */ static function setIsActive($id, $is_active) { return CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_RelationshipType', $id, 'is_active', $is_active); } /** * Function to add the relationship type in the db * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contact_DAO_RelationshipType * @access public * @static * */ static function add(&$params, &$ids) { //to change name, CRM-3336 if (empty($params['label_a_b']) && !empty($params['name_a_b'])) { $params['label_a_b'] = $params['name_a_b']; } if (empty($params['label_b_a']) && !empty($params['name_b_a'])) { $params['label_b_a'] = $params['name_b_a']; } // set label to name if it's not set - but *only* for // ADD action. CRM-3336 as part from (CRM-3522) if (empty($ids['relationshipType'])) { if (empty($params['name_a_b']) && !empty($params['label_a_b'])) { $params['name_a_b'] = $params['label_a_b']; } if (empty($params['name_b_a']) && !empty($params['label_b_a'])) { $params['name_b_a'] = $params['label_b_a']; } } // action is taken depending upon the mode $relationshipType = new CRM_Contact_DAO_RelationshipType(); $relationshipType->copyValues($params); // if label B to A is blank, insert the value label A to B for it if (!strlen(trim($strName = CRM_Utils_Array::value('name_b_a', $params)))) { $relationshipType->name_b_a = CRM_Utils_Array::value('name_a_b', $params); } if (!strlen(trim($strName = CRM_Utils_Array::value('label_b_a', $params)))) { $relationshipType->label_b_a = CRM_Utils_Array::value('label_a_b', $params); } $relationshipType->id = CRM_Utils_Array::value('relationshipType', $ids); return $relationshipType->save(); } /** * 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 = " UPDATE civicrm_membership_type SET relationship_type_id = NULL WHERE relationship_type_id = %1 "; $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(); } }