/** * Test civicrm_contact_memberships_get with relationship. * get Memberships. */ function testGetWithRelationship() { $orgContact = $this->organizationCreate(); $relTypeParams = array('name_a_b' => 'Relation 1', 'name_b_a' => 'Relation 2', 'description' => 'Testing relationship type', 'contact_type_a' => 'Organization', 'contact_type_b' => 'Individual', 'is_reserved' => 1, 'is_active' => 1); $relTypeID = $this->relationshipTypeCreate($relTypeParams); $params = array('contact_id_a' => $orgContact, 'contact_id_b' => $this->_contactID, 'relationship_type_id' => $relTypeID, 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'), 'is_active' => 1); $result =& civicrm_relationship_create($params); $params = array('name' => 'test General', 'duration_unit' => 'year', 'duration_interval' => 1, 'period_type' => 'rolling', 'member_of_contact_id' => $this->_contactID, 'domain_id' => 1, 'contribution_type_id' => 1, 'relationship_type_id' => $relTypeID, 'relationship_direction' => 'b_a', 'is_active' => 1); $memType = civicrm_membership_type_create($params); $params = array('contact_id' => $this->_contactID, 'membership_type_id' => $memType['id'], 'join_date' => '2009-01-21', 'start_date' => '2009-01-21', 'end_date' => '2009-12-21', 'source' => 'Payment', 'is_override' => 1, 'status_id' => $this->_membershipStatusID); $membershipID = $this->contactMembershipCreate($params); $params = array('contact_id' => $this->_contactID, 'membership_type_id' => $memType['id']); $membership =& civicrm_membership_contact_get($params); $result = $membership[$this->_contactID][$membershipID]; $this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__); $this->assertEquals($result['contact_id'], $orgContact, "In line " . __LINE__); }
/** * check with valid data with relationshipTypes */ function testGetRelationshipWithRelTypes() { $relParams = array('contact_id_a' => $this->_cId_a, 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'), 'end_date' => array('d' => '10', 'M' => '1', 'Y' => '2009'), 'is_active' => 1); $relationship =& civicrm_relationship_create($relParams); $contact_a = array('contact_id' => $this->_cId_a); $relationshipTypes = array('Relation 1 for delete'); $result =& civicrm_get_relationships($contact_a, null, $relationshipTypes, 'desc'); $this->assertEquals($result['is_error'], 0); $params['id'] = $relationship['result']['id']; $result =& civicrm_relationship_delete($params); $this->relationshipTypeDelete($relTypeID); }
/** * Function to update relationship * * @param array $params Associative array of property name/value pairs to update the relationship * * @return array Array with relationship information * * @access public * */ function civicrm_relationship_update($params) { try { _civicrm_initialize(); $errorScope = CRM_Core_TemporaryErrorScope::useException(); /* * Erik Hommel, 5 Oct 2010 : fix for CRM-6895 * check if required field relationship_id is in the parms. As the * CRM_Contact_BAO_Relationship::getRelatonship throws up some issues * (CRM-6905) the relationship is retrieved with a direct query */ civicrm_verify_mandatory($params, 'CRM_Contact_DAO_Relationship', array('relationship_id')); $names = array('id', 'contact_id_a', 'contact_id_b', 'relationship_type_id', 'start_date', 'end_date', 'is_active', 'description', 'is_permission_a_b', 'is_permission_b_a', 'case_id'); $relationship_id = (int) $params['relationship_id']; $query = "SELECT * FROM civicrm_relationship WHERE id = {$relationship_id}"; $daoRelations = CRM_Core_DAO::executeQuery($query); while ($daoRelations->fetch()) { foreach ($names as $name) { $current_values[$name] = $daoRelations->{$name}; } } $params = array_merge($current_values, $params); $params['start_date'] = date("Ymd", strtotime($params['start_date'])); $params['end_date'] = date("Ymd", strtotime($params['end_date'])); return civicrm_relationship_create($params); } catch (PEAR_Exception $e) { return civicrm_create_error($e->getMessage()); } catch (Exception $e) { return civicrm_create_error($e->getMessage()); } }
/** * Function to update relationship * * @param array $params Associative array of property name/value pairs to update the relationship * * @return array Array with relationship information * * @access public * */ function civicrm_relationship_update($params) { return civicrm_relationship_create($params); }