当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Contact_BAO_RelationshipType类代码示例

本文整理汇总了PHP中CRM_Contact_BAO_RelationshipType的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_RelationshipType类的具体用法?PHP CRM_Contact_BAO_RelationshipType怎么用?PHP CRM_Contact_BAO_RelationshipType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CRM_Contact_BAO_RelationshipType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: civicrm_api3_relationship_type_create

/**
 * Create relationship type.
 *
 * @param array $params
 *   Array per getfields metadata.
 *
 * @return array
 */
function civicrm_api3_relationship_type_create($params)
{
    if (!isset($params['label_a_b'])) {
        $params['label_a_b'] = $params['name_a_b'];
    }
    if (!isset($params['label_b_a'])) {
        $params['label_b_a'] = $params['name_b_a'];
    }
    $ids = array();
    if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
        return civicrm_api3_create_error('Invalid value for relationship type ID');
    } else {
        $ids['relationshipType'] = CRM_Utils_Array::value('id', $params);
    }
    $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids);
    $relType = array();
    _civicrm_api3_object_to_array($relationType, $relType[$relationType->id]);
    return civicrm_api3_create_success($relType, $params, 'RelationshipType', 'create', $relationType);
}
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:27,代码来源:RelationshipType.php

示例2: civicrm_membership_contact_get

/**
 * Get contact membership record.
 * 
 * This api is used for finding an existing membership record.
 * This api will also return the mebership records for the contacts
 * having mebership based on the relationship with the direct members.
 * 
 * @param  Array $params key/value pairs for contact_id and some
 *          options affecting the desired results; has legacy support
 *          for just passing the contact_id itself as the argument
 *
 * @return  Array of all found membership property values.
 * @access public
 */
function civicrm_membership_contact_get(&$params)
{
    _civicrm_initialize();
    $activeOnly = false;
    if (is_array($params)) {
        $contactID = CRM_Utils_Array::value('contact_id', $params);
        $activeOnly = CRM_Utils_Array::value('active_only', $params, false);
        if ($activeOnly == 1) {
            $activeOnly = true;
        } else {
            $activeOnly = false;
        }
    } elseif (CRM_Utils_Rule::integer($params)) {
        $contactID = $params;
    } else {
        return civicrm_create_error('Paramers can be only of type array or integer');
    }
    if (empty($contactID)) {
        return civicrm_create_error('Invalid value for ContactID.');
    }
    // get the membership for the given contact ID
    require_once 'CRM/Member/BAO/Membership.php';
    $membership = array('contact_id' => $contactID);
    $membershipValues = array();
    CRM_Member_BAO_Membership::getValues($membership, $membershipValues, $activeOnly);
    $recordCount = 0;
    if (empty($membershipValues)) {
        # No results is NOT an error!
        # return civicrm_create_error('No memberships for this contact.');
        $membershipValues['record_count'] = $recordCount;
        return $membershipValues;
    }
    $members[$contactID] = array();
    $relationships = array();
    foreach ($membershipValues as $membershipId => $values) {
        // populate the membership type name for the membership type id
        require_once 'CRM/Member/BAO/MembershipType.php';
        $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
        $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
        if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
            $relationships[$membershipType['relationship_type_id']] = $membershipId;
        }
        // populating relationship type name.
        require_once 'CRM/Contact/BAO/RelationshipType.php';
        $relationshipType = new CRM_Contact_BAO_RelationshipType();
        $relationshipType->id = CRM_Utils_Array::value('relationship_type_id', $membershipType);
        if ($relationshipType->find(true)) {
            $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
        }
        require_once 'CRM/Core/BAO/CustomGroup.php';
        $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', CRM_Core_DAO::$_nullObject, $membershipId, false, $values['membership_type_id']);
        $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
        $defaults = array();
        CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
        if (!empty($defaults)) {
            foreach ($defaults as $key => $val) {
                $membershipValues[$membershipId][$key] = $val;
            }
        }
        $recordCount++;
    }
    $members[$contactID] = $membershipValues;
    // populating contacts in members array based on their relationship with direct members.
    require_once 'CRM/Contact/BAO/Relationship.php';
    if (!empty($relationships)) {
        foreach ($relationships as $relTypeId => $membershipId) {
            // As members are not direct members, there should not be
            // membership id in the result array.
            unset($membershipValues[$membershipId]['id']);
            $relationship = new CRM_Contact_BAO_Relationship();
            $relationship->contact_id_b = $contactID;
            $relationship->relationship_type_id = $relTypeId;
            if ($relationship->find()) {
                while ($relationship->fetch()) {
                    clone $relationship;
                    $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
                    $members[$contactID][$relationship->contact_id_a] = $membershipValues[$membershipId];
                }
            }
            $recordCount++;
        }
    }
    $members['record_count'] = $recordCount;
    return $members;
}
开发者ID:bhirsch,项目名称:voipdev,代码行数:99,代码来源:MembershipContact.php

示例3: testRelCreateWithinDiffTypeStudentSponsor

 public function testRelCreateWithinDiffTypeStudentSponsor()
 {
     //check for Student to Sponcer
     $relTypeParams = array('name_a_b' => 'StudentToSponsor', 'name_b_a' => 'SponsorToStudent', 'contact_type_a' => 'Individual', 'contact_sub_type_a' => $this->student, 'contact_type_b' => 'Organization', 'contact_sub_type_b' => $this->sponsor);
     $relTypeIds = array();
     $relType = CRM_Contact_BAO_RelationshipType::add($relTypeParams, $relTypeIds);
     $params = array('relationship_type_id' => $relType->id . '_a_b', 'is_active' => 1, 'contact_check' => array($this->organization_sponsor => 1));
     $ids = array('contact' => $this->indivi_student);
     list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::legacyCreateMultiple($params, $ids);
     $this->assertEquals($valid, 1);
     $this->assertEquals(empty($relationshipIds), FALSE);
     $this->relationshipTypeDelete($relType->id);
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:13,代码来源:RelationshipTest.php

示例4: relatedMemberships

 /**
  * Function to create / update / delete membership for related contacts.
  *
  * This function will create/update/delete membership for related
  * contact based on 1) contact have active membership 2) that
  * membership is is extedned by the same relationship type to that
  * of the existing relationship.
  *
  * @param $contactId  Int     contact id
  * @param $params     array   array of values submitted by POST
  * @param $ids        array   array of ids
  * @param $action             which action called this function
  *
  * @static
  *
  */
 static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = TRUE)
 {
     // Check the end date and set the status of the relationship
     // accrodingly.
     $status = self::CURRENT;
     if (!empty($params['end_date'])) {
         $endDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($params['end_date']), NULL, 'Ymd');
         $today = date('Ymd');
         if ($today > $endDate) {
             $status = self::PAST;
         }
     }
     if ($action & CRM_Core_Action::ADD && $status & self::PAST) {
         // if relationship is PAST and action is ADD, no qustion
         // of creating RELATED membership and return back to
         // calling method
         return;
     }
     $rel = explode('_', $params['relationship_type_id']);
     $relTypeId = $rel[0];
     $relDirection = "_{$rel[1]}_{$rel[2]}";
     $targetContact = array();
     if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) {
         $contact = $contactId;
         $targetContact = CRM_Utils_Array::value('contact_check', $params);
     } elseif ($action & CRM_Core_Action::UPDATE) {
         $contact = $ids['contact'];
         $targetContact = array($ids['contactTarget'] => 1);
     }
     // Build the 'values' array for
     // 1. ContactA
     // 2. ContactB
     // This will allow us to check if either of the contacts in
     // relationship have active memberships.
     $values = array();
     // 1. ContactA
     $values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection);
     // 2. ContactB
     if (!empty($targetContact)) {
         foreach ($targetContact as $cid => $donCare) {
             $values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId);
             $relTypeParams = array('id' => $relTypeId);
             $relTypeValues = array();
             CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues);
             if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) {
                 $values[$cid]['relationshipTypeDirection'] = '_a_b';
             } else {
                 $values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b';
             }
         }
     }
     // Now get the active memberships for all the contacts.
     // If contact have any valid membership(s), then add it to
     // 'values' array.
     foreach ($values as $cid => $subValues) {
         $memParams = array('contact_id' => $cid);
         $memberships = array();
         CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
         if (empty($memberships)) {
             continue;
         }
         $values[$cid]['memberships'] = $memberships;
     }
     $deceasedStatusId = array_search('Deceased', CRM_Member_PseudoConstant::membershipStatus());
     // done with 'values' array.
     // Finally add / edit / delete memberships for the related contacts
     foreach ($values as $cid => $details) {
         if (!array_key_exists('memberships', $details)) {
             continue;
         }
         $mainRelatedContactId = key(CRM_Utils_Array::value('relatedContacts', $details, array()));
         foreach ($details['memberships'] as $membershipId => $membershipValues) {
             $relTypeIds = array();
             if ($action & CRM_Core_Action::DELETE) {
                 // Delete memberships of the related contacts only if relationship type exists for membership type
                 $query = "\nSELECT relationship_type_id, relationship_direction\n  FROM civicrm_membership_type\n WHERE id = {$membershipValues['membership_type_id']}";
                 $dao = CRM_Core_DAO::executeQuery($query);
                 $relTypeDirs = array();
                 while ($dao->fetch()) {
                     $relTypeId = $dao->relationship_type_id;
                     $relDirection = $dao->relationship_direction;
                 }
                 $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $relTypeId);
                 if (in_array($values[$cid]['relationshipTypeId'], $relTypeIds)) {
//.........这里部分代码省略.........
开发者ID:hguru,项目名称:224Civi,代码行数:101,代码来源:Relationship.php

示例5: relatedMemberships

 /**
  * Function to create / update / delete membership for related contacts.
  * 
  * This function will create/update/delete membership for related
  * contact based on 1) contact have active membership 2) that
  * membership is is extedned by the same relationship type to that
  * of the existing relationship.
  * 
  * @param $contactId  Int     contact id
  * @param $params     array   array of values submitted by POST
  * @param $ids        array   array of ids
  * @param $action             which action called this function
  * 
  * @static
  *
  */
 static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = true)
 {
     // Check the end date and set the status of the relationship
     // accrodingly.
     $status = self::CURRENT;
     if (!empty($params['end_date'])) {
         $endDate = CRM_Utils_Date::setDateDefaults($params['end_date'], null, 'Ymd');
         $today = date('Ymd');
         if ($today > $endDate) {
             $status = self::PAST;
         }
     }
     if ($action & CRM_Core_Action::ADD && $status & self::PAST) {
         // if relationship is PAST and action is ADD, no qustion
         // of creating RELATED membership and return back to
         // calling method
         return;
     }
     $rel = explode("_", $params['relationship_type_id']);
     $relTypeId = $rel[0];
     $relDirection = "_{$rel[1]}_{$rel[2]}";
     $targetContact = array();
     if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) {
         $contact = $contactId;
         $targetContact = CRM_Utils_Array::value('contact_check', $params);
     } else {
         if ($action & CRM_Core_Action::UPDATE) {
             $contact = $ids['contact'];
             $targetContact = array($ids['contactTarget'] => 1);
         }
     }
     // Build the 'values' array for
     // 1. ContactA
     // 2. ContactB
     // This will allow us to check if either of the contacts in
     // relationship have active memberships.
     $values = array();
     // 1. ContactA
     $values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection);
     // 2. ContactB
     if (!empty($targetContact)) {
         foreach ($targetContact as $cid => $donCare) {
             $values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId);
             $relTypeParams = array('id' => $relTypeId);
             $relTypeValues = array();
             require_once 'CRM/Contact/BAO/RelationshipType.php';
             CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues);
             if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) {
                 $values[$cid]['relationshipTypeDirection'] = '_a_b';
             } else {
                 $values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b';
             }
         }
     }
     // Now get the active memberships for all the contacts.
     // If contact have any valid membership(s), then add it to
     // 'values' array.
     foreach ($values as $cid => $subValues) {
         $memParams = array('contact_id' => $cid);
         $memberships = array();
         require_once 'CRM/Member/BAO/Membership.php';
         CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active);
         if (empty($memberships)) {
             continue;
         }
         $values[$cid]['memberships'] = $memberships;
     }
     // done with 'values' array.
     // Finally add / edit / delete memberships for the related contacts
     foreach ($values as $cid => $details) {
         if (!array_key_exists('memberships', $details)) {
             continue;
         }
         require_once 'CRM/Member/BAO/MembershipType.php';
         foreach ($details['memberships'] as $membershipId => $membershipValues) {
             if ($action & CRM_Core_Action::DELETE) {
                 // delete memberships of the related contacts.
                 CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId);
                 continue;
             }
             if ($action & CRM_Core_Action::UPDATE && $status & self::PAST && $membershipValues['owner_membership_id']) {
                 // If relationship is PAST and action is UPDATE
                 // then delete the RELATED membership
                 CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']);
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:Relationship.php

示例6: relationship

 /**
  * where / qill clause for relationship
  *
  * @return void
  * @access public
  */
 function relationship(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     // also get values array for relation_target_name
     // for relatinship search we always do wildcard
     $targetName = $this->getWhereValues('relation_target_name', $grouping);
     $relStatus = $this->getWhereValues('relation_status', $grouping);
     $targetGroup = $this->getWhereValues('relation_target_group', $grouping);
     $nameClause = $name = NULL;
     if ($targetName) {
         $name = trim($targetName[2]);
         if (substr($name, 0, 1) == '"' && substr($name, -1, 1) == '"') {
             $name = substr($name, 1, -1);
             $name = strtolower(CRM_Core_DAO::escapeString($name));
             $nameClause = "= '{$name}'";
         } else {
             $name = strtolower(CRM_Core_DAO::escapeString($name));
             $nameClause = "LIKE '%{$name}%'";
         }
     }
     $rel = explode('_', $value);
     self::$_relType = $rel[1];
     $params = array('id' => $rel[0]);
     $rTypeValues = array();
     $rType = CRM_Contact_BAO_RelationshipType::retrieve($params, $rTypeValues);
     if (!$rType) {
         return;
     }
     if ($rTypeValues['name_a_b'] == $rTypeValues['name_b_a']) {
         self::$_relType = 'reciprocal';
     }
     if ($nameClause) {
         $this->_where[$grouping][] = "( contact_b.sort_name {$nameClause} AND contact_b.id != contact_a.id )";
     }
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     if ($nameClause || !$targetGroup) {
         $this->_qill[$grouping][] = "{$allRelationshipType[$value]}  {$name}";
     }
     //check to see if the target contact is in specified group
     if ($targetGroup) {
         //add contacts from static groups
         $this->_tables['civicrm_relationship_group_contact'] = $this->_whereTables['civicrm_relationship_group_contact'] = " LEFT JOIN civicrm_group_contact civicrm_relationship_group_contact ON civicrm_relationship_group_contact.contact_id = contact_b.id";
         $groupWhere[] = "( civicrm_relationship_group_contact.group_id IN  (" . implode(",", $targetGroup[2]) . ") )";
         //add contacts from saved searches
         $ssWhere = $this->addGroupContactCache($targetGroup[2], "civicrm_relationship_group_contact_cache", "contact_b");
         //set the group where clause
         if ($ssWhere) {
             $groupWhere[] = "( " . $ssWhere . " )";
         }
         $this->_where[$grouping][] = "( " . implode(" OR ", $groupWhere) . " )";
         //Get the names of the target groups for the qill
         $groupNames =& CRM_Core_PseudoConstant::group();
         $qillNames = array();
         foreach ($targetGroup[2] as $groupId) {
             if (array_key_exists($groupId, $groupNames)) {
                 $qillNames[] = $groupNames[$groupId];
             }
         }
         $this->_qill[$grouping][] = "{$allRelationshipType[$value]}  ( " . implode(", ", $qillNames) . " )";
     }
     //check for active, inactive and all relation status
     $today = date('Ymd');
     if ($relStatus[2] == 0) {
         $this->_where[$grouping][] = "(\ncivicrm_relationship.is_active = 1 AND\n( civicrm_relationship.end_date IS NULL OR civicrm_relationship.end_date >= {$today} ) AND\n( civicrm_relationship.start_date IS NULL OR civicrm_relationship.start_date <= {$today} )\n)";
         $this->_qill[$grouping][] = ts('Relationship - Active');
     } elseif ($relStatus[2] == 1) {
         $this->_where[$grouping][] = "(\ncivicrm_relationship.is_active = 0 OR\ncivicrm_relationship.end_date < {$today} OR\ncivicrm_relationship.start_date > {$today}\n)";
         $this->_qill[$grouping][] = ts('Relationship - Inactive');
     }
     $this->_where[$grouping][] = 'civicrm_relationship.relationship_type_id = ' . $rel[0];
     $this->_tables['civicrm_relationship'] = $this->_whereTables['civicrm_relationship'] = 1;
     $this->_useDistinct = TRUE;
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:84,代码来源:Query.php

示例7: crm_create_relationship_type

/**
 * Function to create relationship type
 *
 * @param  array $params   Associative array of property name/value pairs to insert in new relationship type.
 *
 * @return Newly created Relationship_type object
 *
 * @access public
 *
 */
function crm_create_relationship_type($params)
{
    if (!isset($params['name_a_b']) and !isset($params['name_b_a']) and !isset($params['contact_type_a']) and !isset($params['contact_type_b'])) {
        return _crm_error('Return array is not properly set');
    }
    require_once 'CRM/Contact/BAO/RelationshipType.php';
    $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids);
    return $relationType;
}
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:19,代码来源:Relationship.php

示例8: relationship

 /**
  * Where / qill clause for relationship.
  *
  * @param array $values
  */
 public function relationship(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if ($this->_relationshipValuesAdded) {
         return;
     }
     // also get values array for relation_target_name
     // for relationship search we always do wildcard
     $relationType = $this->getWhereValues('relation_type_id', $grouping);
     $targetName = $this->getWhereValues('relation_target_name', $grouping);
     $relStatus = $this->getWhereValues('relation_status', $grouping);
     $relPermission = $this->getWhereValues('relation_permission', $grouping);
     $targetGroup = $this->getWhereValues('relation_target_group', $grouping);
     $nameClause = $name = NULL;
     if ($targetName) {
         $name = trim($targetName[2]);
         if (substr($name, 0, 1) == '"' && substr($name, -1, 1) == '"') {
             $name = substr($name, 1, -1);
             $name = strtolower(CRM_Core_DAO::escapeString($name));
             $nameClause = "= '{$name}'";
         } else {
             $name = strtolower(CRM_Core_DAO::escapeString($name));
             $nameClause = "LIKE '%{$name}%'";
         }
     }
     $rTypeValues = array();
     if (!empty($relationType)) {
         $rel = explode('_', $relationType[2]);
         self::$_relType = $rel[1];
         $params = array('id' => $rel[0]);
         $rType = CRM_Contact_BAO_RelationshipType::retrieve($params, $rTypeValues);
     }
     if (!empty($rTypeValues) && $rTypeValues['name_a_b'] == $rTypeValues['name_b_a']) {
         // if we don't know which end of the relationship we are dealing with we'll create a temp table
         //@todo unless we are dealing with a target group
         self::$_relType = 'reciprocal';
     }
     // if we are creating a temp table we build our own where for the relationship table
     $relationshipTempTable = NULL;
     if (self::$_relType == 'reciprocal' && empty($targetGroup)) {
         $where = array();
         self::$_relationshipTempTable = $relationshipTempTable = CRM_Core_DAO::createTempTableName('civicrm_rel');
         if ($nameClause) {
             $where[$grouping][] = " sort_name {$nameClause} ";
         }
     } else {
         $where =& $this->_where;
         if ($nameClause) {
             $where[$grouping][] = "( contact_b.sort_name {$nameClause} AND contact_b.id != contact_a.id )";
         }
     }
     $allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE);
     if ($nameClause || !$targetGroup) {
         if (!empty($relationType)) {
             $this->_qill[$grouping][] = $allRelationshipType[$relationType[2]] . " {$name}";
         } else {
             $this->_qill[$grouping][] = $name;
         }
     }
     //check to see if the target contact is in specified group
     if ($targetGroup) {
         //add contacts from static groups
         $this->_tables['civicrm_relationship_group_contact'] = $this->_whereTables['civicrm_relationship_group_contact'] = " LEFT JOIN civicrm_group_contact civicrm_relationship_group_contact ON civicrm_relationship_group_contact.contact_id = contact_b.id AND civicrm_relationship_group_contact.status = 'Added'";
         $groupWhere[] = "( civicrm_relationship_group_contact.group_id IN  (" . implode(",", $targetGroup[2]) . ") ) ";
         //add contacts from saved searches
         $ssWhere = $this->addGroupContactCache($targetGroup[2], "civicrm_relationship_group_contact_cache", "contact_b", $op);
         //set the group where clause
         if ($ssWhere) {
             $groupWhere[] = "( " . $ssWhere . " )";
         }
         $this->_where[$grouping][] = "( " . implode(" OR ", $groupWhere) . " )";
         //Get the names of the target groups for the qill
         $groupNames = CRM_Core_PseudoConstant::group();
         $qillNames = array();
         foreach ($targetGroup[2] as $groupId) {
             if (array_key_exists($groupId, $groupNames)) {
                 $qillNames[] = $groupNames[$groupId];
             }
         }
         if (!empty($relationType)) {
             $this->_qill[$grouping][] = $allRelationshipType[$relationType[2]] . " ( " . implode(", ", $qillNames) . " )";
         } else {
             $this->_qill[$grouping][] = implode(", ", $qillNames);
         }
     }
     // Note we do not currently set mySql to handle timezones, so doing this the old-fashioned way
     $today = date('Ymd');
     //check for active, inactive and all relation status
     if ($relStatus[2] == 0) {
         $where[$grouping][] = "(\ncivicrm_relationship.is_active = 1 AND\n( civicrm_relationship.end_date IS NULL OR civicrm_relationship.end_date >= {$today} ) AND\n( civicrm_relationship.start_date IS NULL OR civicrm_relationship.start_date <= {$today} )\n)";
         $this->_qill[$grouping][] = ts('Relationship - Active and Current');
     } elseif ($relStatus[2] == 1) {
         $where[$grouping][] = "(\ncivicrm_relationship.is_active = 0 OR\ncivicrm_relationship.end_date < {$today} OR\ncivicrm_relationship.start_date > {$today}\n)";
         $this->_qill[$grouping][] = ts('Relationship - Inactive or not Current');
     }
//.........这里部分代码省略.........
开发者ID:hoegrammer,项目名称:civicrm-core,代码行数:101,代码来源:Query.php

示例9: crm_get_contact_memberships

/**
 * Get conatct membership record.
 * 
 * This api is used for finding an existing membership record.
 * This api will also return the mebership records for the contacts
 * having mebership based on the relationship with the direct members.
 * 
 * @param  Int  $contactID  ID of a contact
 *
 * @return  Array of all found membership property values.
 * @access public
 */
function crm_get_contact_memberships($contactID)
{
    _crm_initialize();
    if (empty($contactID)) {
        return _crm_error('Invalid value for ContactID.');
    }
    // get the membership for the given contact ID
    require_once 'CRM/Member/BAO/Membership.php';
    $membership = array('contact_id' => $contactID);
    $membershipValues = array();
    CRM_Member_BAO_Membership::getValues($membership, $membershipValues);
    if (empty($membershipValues)) {
        return _crm_error('No memberships for this contact.');
    }
    foreach ($membershipValues as $membershipId => $values) {
        // populate the membership type name for the membership type id
        require_once 'CRM/Member/BAO/MembershipType.php';
        $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
        $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
        $relationships[$membershipType['relationship_type_id']] = $membershipId;
        // populating relationship type name.
        require_once 'CRM/Contact/BAO/RelationshipType.php';
        $relationshipType = new CRM_Contact_BAO_RelationshipType();
        $relationshipType->id = $membershipType['relationship_type_id'];
        if ($relationshipType->find(true)) {
            $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
        }
    }
    $members[$contactID] = $membershipValues;
    // populating contacts in members array based on their relationship with direct members.
    require_once 'CRM/Contact/BAO/Relationship.php';
    foreach ($relationships as $relTypeId => $membershipId) {
        // As members are not direct members, there should not be
        // membership id in the result array.
        unset($membershipValues[$membershipId]['id']);
        $relationship = new CRM_Contact_BAO_Relationship();
        $relationship->contact_id_b = $contactID;
        $relationship->relationship_type_id = $relTypeId;
        if ($relationship->find()) {
            while ($relationship->fetch()) {
                clone $relationship;
                $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
                $members[$contactID][$relationship->contact_id_a] = $membershipValues[$membershipId];
            }
        }
    }
    return $members;
}
开发者ID:bhirsch,项目名称:voipdev,代码行数:60,代码来源:Membership.php

示例10: relationshipType

 /**
  * Where / qill clause for relationship_type
  *
  * @param $values
  *
  * @return void
  */
 public function relationshipType(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     $clause = array();
     foreach ($value as $k => $relationship_type_value) {
         // we gebruiken de key om relaties in 2 richtingen op te vangen.
         $relationship_type_id = substr_replace($relationship_type_value, "", -4);
         $relationship_type_params = array('id' => $relationship_type_id);
         CRM_Contact_BAO_RelationshipType::retrieve($relationship_type_params, $relationship_type);
         $clause[$relationship_type['label_a_b']] = $relationship_type_id;
     }
     $this->_where[$grouping][] = "relationship.relationship_type_id {$op} ('" . implode("', '", $clause) . "')";
     $this->_qill[$grouping][] = ts('Relationship Type') . " {$op} " . implode(' ' . ts('or') . ' ', array_keys($clause));
 }
开发者ID:Chirojeugd-Vlaanderen,项目名称:civicrm-relationship-entity,代码行数:21,代码来源:Query.php

示例11: relationship

 /**
  * where / qill clause for relationship
  *
  * @return void
  * @access public
  */
 function relationship(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     // also get values array for relation_target_name
     // for relatinship search we always do wildcard
     $targetName = $this->getWhereValues('relation_target_name', $grouping);
     $relStatus = $this->getWhereValues('relation_status', $grouping);
     $nameClause = null;
     if ($targetName) {
         $name = trim($targetName[2]);
         if (substr($name, 0, 1) == '"' && substr($name, -1, 1) == '"') {
             $name = substr($name, 1, -1);
             $name = strtolower(CRM_Core_DAO::escapeString($name));
             $nameClause = "= '{$name}'";
         } else {
             $name = strtolower(CRM_Core_DAO::escapeString($name));
             $nameClause = "LIKE '%{$name}%'";
         }
     }
     $rel = explode('_', $value);
     self::$_relType = $rel[1];
     if ($nameClause) {
         require_once 'CRM/Contact/BAO/RelationshipType.php';
         $params = array('id' => $rel[0]);
         $rTypeValues = array();
         require_once "CRM/Contact/BAO/RelationshipType.php";
         $rType =& CRM_Contact_BAO_RelationshipType::retrieve($params, $rTypeValues);
         if (!$rType) {
             return;
         }
         // for relatinship search we always do wildcard
         if ($rTypeValues['name_a_b'] == $rTypeValues['name_b_a']) {
             self::$_relType = 'reciprocal';
         }
         $this->_where[$grouping][] = "( contact_b.sort_name {$nameClause} AND contact_b.id != contact_a.id )";
     }
     require_once 'CRM/Contact/BAO/Relationship.php';
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Household');
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     $this->_qill[$grouping][] = "{$allRelationshipType[$value]}  {$name}";
     //check for active, inactive and all relation status
     $today = date('Ymd');
     if ($relStatus[2] == 0) {
         $this->_where[$grouping][] = "civicrm_relationship.is_active = 1 AND ( civicrm_relationship.end_date is NULL OR civicrm_relationship.end_date >= {$today} )";
         $this->_qill[$grouping][] = ts('Relationship - Active');
     } else {
         if ($relStatus[2] == 1) {
             $this->_where[$grouping][] = "(civicrm_relationship.is_active = 0 OR civicrm_relationship.end_date < {$today})";
             $this->_qill[$grouping][] = ts('Relationship - Inactive');
         }
     }
     $this->_where[$grouping][] = 'civicrm_relationship.relationship_type_id = ' . $rel[0];
     $this->_tables['civicrm_relationship'] = $this->_whereTables['civicrm_relationship'] = 1;
     $this->_useDistinct = true;
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:65,代码来源:Query.php

示例12: postProcess

 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         CRM_Contact_BAO_RelationshipType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Relationship type has been deleted.'));
     } else {
         $params = array();
         $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
         if ($this->_action & CRM_CORE_ACTION_UPDATE) {
             $ids['relationshipType'] = $this->_id;
         }
         CRM_Contact_BAO_RelationshipType::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The Relationship Type has been saved.'));
     }
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:24,代码来源:RelationshipType.php

示例13: exportComponents

 public static function exportComponents($selectAll, $ids, $params, $order = NULL, $fields = NULL, $moreReturnProperties = NULL, $exportMode = CRM_Export_Form_Select_Relationship::RELATIONSHIP_EXPORT, $componentClause = NULL, $componentTable = NULL, $mergeSameAddress = FALSE, $mergeSameHousehold = FALSE, $exportParams = array(), $queryOperator = 'AND')
 {
     $headerRows = $returnProperties = array();
     $queryMode = CRM_Relationship_BAO_Query::MODE_RELATIONSHIPS;
     //Welke velden exporteren, gezet bij een mapping, indien niet gezet, primary fields.
     if ($fields) {
         foreach ($fields as $key => $value) {
             $fieldName = CRM_Utils_Array::value(0, $value);
             if (!$fieldName) {
                 continue;
             }
             $returnProperties[$fieldName] = 1;
         }
     } else {
         // Copied from CRM_Relationship_BAO_QUERY should be refactored to seperate
         // method.
         $fields = CRM_Contact_BAO_Relationship::fields();
         // Add display_name for both contacts
         $contact_fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE, TRUE);
         $fields['contact_a'] = $contact_fields['display_name'];
         $fields['contact_a']['where'] = 'contact_a.display_name';
         $fields['contact_b'] = $contact_fields['display_name'];
         $fields['contact_b']['where'] = 'contact_b.display_name';
         // Add relationship type field
         $relationship_type_fields = CRM_Contact_BAO_RelationshipType::fields();
         $fields['relationship_type'] = $relationship_type_fields['label_a_b'];
         $fields['relationship_type']['where'] = 'relationship_type.label_a_b';
         // Add custom fields
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Relationship'));
         $returnProperties = CRM_Relationship_BAO_Query::defaultReturnProperties();
     }
     if ($moreReturnProperties) {
         $returnProperties = array_merge($returnProperties, $moreReturnProperties);
     }
     $query = new CRM_Relationship_BAO_Query($params, $returnProperties, NULL, FALSE, FALSE, FALSE, TRUE, $queryOperator);
     //sort by state
     //CRM-15301
     $query->_sort = $order;
     list($select, $from, $where, $having) = $query->query();
     $allRelContactArray = $relationQuery = array();
     if (!$selectAll && $componentTable) {
         // TODO For not select all
         //$from .= " INNER JOIN $componentTable ctTable ON ctTable.contact_id = contact_a.id ";
     } elseif ($componentClause) {
         if (empty($where)) {
             $where = "WHERE {$componentClause}";
         } else {
             $where .= " AND {$componentClause}";
         }
     }
     $queryString = "{$select} {$from} {$where} {$having}";
     $groupBy = "";
     if ($queryMode & CRM_Relationship_BAO_Query::MODE_RELATIONSHIPS && $query->_useGroupBy) {
         $groupBy = " GROUP BY relationship.id";
     }
     $queryString .= $groupBy;
     // always add relationship.id to the ORDER clause
     // so the order is deterministic
     if (strpos('relationship.id', $order) === FALSE) {
         $order .= ", relationship.id";
     }
     if ($order) {
         list($field, $dir) = explode(' ', $order, 2);
         $field = trim($field);
         if (!empty($returnProperties[$field])) {
             //CRM-15301
             $queryString .= " ORDER BY {$order}";
         }
     }
     $componentDetails = $headerRows = $sqlColumns = array();
     $setHeader = TRUE;
     $rowCount = self::EXPORT_ROW_COUNT;
     $offset = 0;
     // we write to temp table often to avoid using too much memory
     $tempRowCount = 100;
     $count = -1;
     // for CRM-3157 purposes
     $i18n = CRM_Core_I18n::singleton();
     $outputColumns = array();
     //@todo - it would be clearer to start defining output columns earlier in this function rather than stick with return properties until this point
     // as the array is not actually 'returnProperties' after the sql query is formed - making the alterations to it confusing
     foreach ($returnProperties as $key => $value) {
         $outputColumns[$key] = $value;
     }
     while (1) {
         $limitQuery = "{$queryString} LIMIT {$offset}, {$rowCount}";
         $dao = CRM_Core_DAO::executeQuery($limitQuery);
         if ($dao->N <= 0) {
             break;
         }
         while ($dao->fetch()) {
             $count++;
             $row = array();
             //convert the pseudo constants
             // CRM-14398 there is problem in this architecture that is not easily solved. For now we are using the cloned
             // temporary iterationDAO object to get around it.
             // the issue is that the convertToPseudoNames function is adding additional properties (e.g for campaign) to the DAO object
             // these additional properties are NOT reset when the $dao cycles through the while loop
             // nor are they overwritten as they are not in the loop
             // the convertToPseudoNames will not adequately over-write them either as it doesn't 'kick-in' unless the
//.........这里部分代码省略.........
开发者ID:Chirojeugd-Vlaanderen,项目名称:civicrm-relationship-entity,代码行数:101,代码来源:Relationship.php

示例14: civicrm_api3_relationship_type_delete

/**
 * Delete a relationship type delete
 *
 * @param  id of relationship type  $id
 *
 * @return array API Result Array
 * {@getfields RelationshipType_delete}
 * @static void
 * @access public
 */
function civicrm_api3_relationship_type_delete($params)
{
    require_once 'CRM/Utils/Rule.php';
    if ($params['id'] != NULL && !CRM_Utils_Rule::integer($params['id'])) {
        return civicrm_api3_create_error('Invalid value for relationship type ID');
    }
    $relationTypeBAO = new CRM_Contact_BAO_RelationshipType();
    $result = $relationTypeBAO->del($params['id']);
    if (!$result) {
        return civicrm_api3_create_error('Could not delete relationship type');
    }
    return civicrm_api3_create_success($result, $params, 'relationship_type', 'delete', $relationTypeBAO);
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:23,代码来源:RelationshipType.php

示例15: civicrm_relationship_type_delete

/**
 * 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'));
}
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:21,代码来源:RelationshipType.php


注:本文中的CRM_Contact_BAO_RelationshipType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。