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


PHP CRM_Utils_Hook::contactListQuery方法代码示例

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


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

示例1: getContactList

 static function getContactList(&$config)
 {
     require_once 'CRM/Core/BAO/Preferences.php';
     $name = CRM_Utils_Type::escape($_GET['s'], 'String');
     $limit = '10';
     $list = array_keys(CRM_Core_BAO_Preferences::valueOptions('contact_autocomplete_options'), '1');
     $select = array('sort_name');
     $where = '';
     $from = array();
     foreach ($list as $value) {
         $suffix = substr($value, 0, 2) . substr($value, -1);
         switch ($value) {
             case 'street_address':
             case 'city':
                 $selectText = $value;
                 $value = "address";
                 $suffix = 'sts';
             case 'phone':
             case 'email':
                 $select[] = $value == 'address' ? $selectText : $value;
                 $from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) ";
                 break;
             case 'country':
             case 'state_province':
                 $select[] = "{$suffix}.name";
                 if (!in_array('address', $from)) {
                     $from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) ';
                 }
                 $from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id  ) ";
                 break;
         }
     }
     $select = implode(', ', $select);
     $from = implode(' ', $from);
     if (CRM_Utils_Array::value('limit', $_GET)) {
         $limit = CRM_Utils_Type::escape($_GET['limit'], 'Positive');
     }
     // add acl clause here
     require_once 'CRM/Contact/BAO/Contact/Permission.php';
     list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
     if ($aclWhere) {
         $where .= " AND {$aclWhere} ";
     }
     $query = "\nSELECT DISTINCT(cc.id) as id, CONCAT_WS( ' :: ', {$select} ) as data\nFROM civicrm_contact cc {$from}\n{$aclFrom}\nWHERE sort_name LIKE '%{$name}%' {$where} \nORDER BY sort_name\nLIMIT 0, {$limit}\n";
     // send query to hook to be modified if needed
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Array::value('context', $_GET), CRM_Utils_Array::value('id', $_GET));
     $dao = CRM_Core_DAO::executeQuery($query);
     $contactList = null;
     while ($dao->fetch()) {
         echo $contactList = "{$dao->data}|{$dao->id}\n";
     }
     exit;
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:54,代码来源:AJAX.php

示例2: getContactPhone

 public static function getContactPhone()
 {
     $queryString = NULL;
     //check for mobile type
     $phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
     $mobileType = CRM_Utils_Array::value('Mobile', $phoneTypes);
     $name = CRM_Utils_Array::value('name', $_GET);
     if ($name) {
         $name = CRM_Utils_Type::escape($name, 'String');
         $queryString = " ( cc.sort_name LIKE '%{$name}%' OR cp.phone LIKE '%{$name}%' ) ";
     } else {
         $cid = CRM_Utils_Array::value('cid', $_GET);
         if ($cid) {
             //check cid for integer
             $contIDS = explode(',', $cid);
             foreach ($contIDS as $contID) {
                 CRM_Utils_Type::escape($contID, 'Integer');
             }
             $queryString = " cc.id IN ( {$cid} )";
         }
     }
     if ($queryString) {
         $offset = CRM_Utils_Array::value('offset', $_GET, 0);
         $rowCount = CRM_Utils_Array::value('rowcount', $_GET, 20);
         $offset = CRM_Utils_Type::escape($offset, 'Int');
         $rowCount = CRM_Utils_Type::escape($rowCount, 'Int');
         // add acl clause here
         list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
         if ($aclWhere) {
             $aclWhere = " AND {$aclWhere}";
         }
         $query = "\nSELECT sort_name name, cp.phone, cc.id\nFROM   civicrm_phone cp INNER JOIN civicrm_contact cc ON cc.id = cp.contact_id\n       {$aclFrom}\nWHERE  cc.is_deceased = 0 AND cc.do_not_sms = 0 AND cp.phone_type_id = {$mobileType} AND {$queryString}\n       {$aclWhere}\nLIMIT {$offset}, {$rowCount}\n";
         // send query to hook to be modified if needed
         CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject));
         $dao = CRM_Core_DAO::executeQuery($query);
         while ($dao->fetch()) {
             $result[] = array('text' => '"' . $dao->name . '" (' . $dao->phone . ')', 'id' => CRM_Utils_Array::value('id', $_GET) ? "{$dao->id}::{$dao->phone}" : '"' . $dao->name . '" <' . $dao->phone . '>');
         }
     }
     if ($result) {
         CRM_Utils_JSON::output($result);
     }
     CRM_Utils_System::civiExit();
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:44,代码来源:AJAX.php

示例3: getContactList

 static function getContactList(&$config)
 {
     require_once 'CRM/Core/BAO/Preferences.php';
     $name = CRM_Utils_Array::value('s', $_GET);
     $name = CRM_Utils_Type::escape($name, 'String');
     $limit = '10';
     $list = array_keys(CRM_Core_BAO_Preferences::valueOptions('contact_autocomplete_options'), '1');
     $select = array('sort_name');
     $where = '';
     $from = array();
     foreach ($list as $value) {
         $suffix = substr($value, 0, 2) . substr($value, -1);
         switch ($value) {
             case 'street_address':
             case 'city':
                 $selectText = $value;
                 $value = "address";
                 $suffix = 'sts';
             case 'phone':
             case 'email':
                 $select[] = $value == 'address' ? $selectText : $value;
                 $from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) ";
                 break;
             case 'country':
             case 'state_province':
                 $select[] = "{$suffix}.name";
                 if (!in_array('address', $from)) {
                     $from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) ';
                 }
                 $from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id  ) ";
                 break;
         }
     }
     $select = implode(', ', $select);
     $from = implode(' ', $from);
     if (CRM_Utils_Array::value('limit', $_GET)) {
         $limit = CRM_Utils_Type::escape($_GET['limit'], 'Positive');
     }
     // add acl clause here
     require_once 'CRM/Contact/BAO/Contact/Permission.php';
     list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
     if ($aclWhere) {
         $where .= " AND {$aclWhere} ";
     }
     if (CRM_Utils_Array::value('org', $_GET)) {
         $where .= " AND contact_type = \"Organization\"";
         //set default for current_employer
         if ($orgId = CRM_Utils_Array::value('id', $_GET)) {
             $where .= " AND cc.id = {$orgId}";
         }
     }
     //contact's based of relationhip type
     $relType = null;
     if (isset($_GET['rel'])) {
         $relation = explode('_', $_GET['rel']);
         $relType = CRM_Utils_Type::escape($relation[0], 'Integer');
         $rel = CRM_Utils_Type::escape($relation[2], 'String');
     }
     $config =& CRM_Core_Config::singleton();
     if ($config->includeWildCardInName) {
         $strSearch = "%{$name}%";
     } else {
         $strSearch = "{$name}%";
     }
     $whereClause = " WHERE sort_name LIKE '{$strSearch}' {$where} ";
     $additionalFrom = '';
     if ($relType) {
         $additionalFrom = "\n            INNER JOIN civicrm_relationship_type r ON ( \n                r.id = {$relType}\n                AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL )\n                AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL )\n            )";
     }
     $query = "\nSELECT DISTINCT(cc.id) as id, CONCAT_WS( ' :: ', {$select} ) as data\nFROM civicrm_contact cc {$from}\n{$aclFrom}\n{$additionalFrom}\n{$whereClause} \nORDER BY sort_name\nLIMIT 0, {$limit}\n";
     // send query to hook to be modified if needed
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Array::value('context', $_GET), CRM_Utils_Array::value('id', $_GET));
     $dao = CRM_Core_DAO::executeQuery($query);
     $contactList = null;
     while ($dao->fetch()) {
         echo $contactList = "{$dao->data}|{$dao->id}\n";
     }
     //return organization name if doesn't exist in db
     if (!$contactList) {
         if (CRM_Utils_Array::value('org', $_GET)) {
             echo CRM_Utils_Array::value('s', $_GET);
         } else {
             if (CRM_Utils_Array::value('context', $_GET) == 'customfield') {
                 echo "{$name}|{$name}\n";
             }
         }
     }
     exit;
 }
开发者ID:bhirsch,项目名称:civicrm,代码行数:90,代码来源:AJAX.php

示例4: civicrm_api3_contact_getquick


//.........这里部分代码省略.........
            }
        }
    }
    if (!empty($params['contact_sub_type'])) {
        $contactSubType = CRM_Utils_Type::escape($params['contact_sub_type'], 'String');
        $where .= " AND cc.contact_sub_type = '{$contactSubType}'";
    }
    if (!empty($params['contact_type'])) {
        $contactType = CRM_Utils_Type::escape($params['contact_type'], 'String');
        $where .= " AND cc.contact_type LIKE '{$contactType}'";
    }
    // Set default for current_employer or return contact with particular id
    if (!empty($params['id'])) {
        $where .= " AND cc.id = " . (int) $params['id'];
    }
    if (!empty($params['cid'])) {
        $where .= " AND cc.id <> " . (int) $params['cid'];
    }
    // Contact's based of relationhip type
    $relType = NULL;
    if (!empty($params['rel'])) {
        $relation = explode('_', CRM_Utils_Array::value('rel', $params));
        $relType = CRM_Utils_Type::escape($relation[0], 'Integer');
        $rel = CRM_Utils_Type::escape($relation[2], 'String');
    }
    if ($config->includeWildCardInName) {
        $strSearch = "%{$name}%";
    } else {
        $strSearch = "{$name}%";
    }
    $includeEmailFrom = $includeNickName = $exactIncludeNickName = '';
    if ($config->includeNickNameInName) {
        $includeNickName = " OR nick_name LIKE '{$strSearch}'";
        $exactIncludeNickName = " OR nick_name LIKE '{$name}'";
    }
    //CRM-10687
    if (!empty($params['field_name']) && !empty($params['table_name'])) {
        $whereClause = " WHERE ( {$table_name}.{$field_name} LIKE '{$strSearch}') {$where}";
        $exactWhereClause = " WHERE ( {$table_name}.{$field_name} = '{$name}') {$where}";
        // Search by id should be exact
        if ($field_name == 'id' || $field_name == 'external_identifier') {
            $whereClause = $exactWhereClause;
        }
    } else {
        $whereClause = " WHERE ( sort_name LIKE '{$strSearch}' {$includeNickName} ) {$where} ";
        $exactWhereClause = " WHERE ( sort_name LIKE '{$name}' {$exactIncludeNickName} ) {$where} ";
        if ($config->includeEmailInName) {
            if (!in_array('email', $list)) {
                $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )";
            }
            $emailWhere = " WHERE email LIKE '{$strSearch}'";
        }
    }
    $additionalFrom = '';
    if ($relType) {
        $additionalFrom = "\n            INNER JOIN civicrm_relationship_type r ON (\n                r.id = {$relType}\n                AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL )\n                AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL )\n            )";
    }
    // check if only CMS users are requested
    if (!empty($params['cmsuser'])) {
        $additionalFrom = "\n      INNER JOIN civicrm_uf_match um ON (um.contact_id=cc.id)\n      ";
    }
    $orderByInner = $orderByOuter = "ORDER BY exactFirst";
    if ($config->includeOrderByClause) {
        $orderByInner = "ORDER BY exactFirst, sort_name";
        $orderByOuter .= ", sort_name";
    }
    //CRM-5954
    $query = "\n        SELECT DISTINCT(id), data, sort_name {$selectAliases}, exactFirst\n        FROM   (\n            ( SELECT IF({$table_name}.{$field_name} = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',\n            {$actualSelectElements} )\n             as data\n            {$select}\n            FROM   civicrm_contact cc {$from}\n    {$aclFrom}\n    {$additionalFrom}\n    {$whereClause}\n    {$orderByInner}\n    LIMIT 0, {$limit} )\n    ";
    if (!empty($emailWhere)) {
        $query .= "\n      UNION (\n        SELECT IF({$table_name}.{$field_name} = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',\n          {$actualSelectElements} )\n          as data\n          {$select}\n          FROM   civicrm_contact cc {$from}\n        {$aclFrom}\n        {$additionalFrom} {$includeEmailFrom}\n        {$emailWhere} AND cc.is_deleted = 0 " . ($aclWhere ? " AND {$aclWhere} " : '') . "\n        {$orderByInner}\n      LIMIT 0, {$limit}\n      )\n    ";
    }
    $query .= ") t\n    {$orderByOuter}\n    LIMIT    0, {$limit}\n  ";
    // send query to hook to be modified if needed
    CRM_Utils_Hook::contactListQuery($query, $name, empty($params['context']) ? NULL : CRM_Utils_Type::escape($params['context'], 'String'), empty($params['id']) ? NULL : $params['id']);
    $dao = CRM_Core_DAO::executeQuery($query);
    $contactList = array();
    $listCurrentEmployer = TRUE;
    while ($dao->fetch()) {
        $t = array('id' => $dao->id);
        foreach ($as as $k) {
            $t[$k] = isset($dao->{$k}) ? $dao->{$k} : '';
        }
        $t['data'] = $dao->data;
        $contactList[] = $t;
        if (!empty($params['org']) && !empty($currEmpDetails) && $dao->id == $currEmpDetails['id']) {
            $listCurrentEmployer = FALSE;
        }
    }
    //return organization name if doesn't exist in db
    if (empty($contactList)) {
        if (!empty($params['org'])) {
            if ($listCurrentEmployer && !empty($currEmpDetails)) {
                $contactList = array(array('data' => $currEmpDetails['data'], 'id' => $currEmpDetails['id']));
            } else {
                $contactList = array(array('data' => $name, 'id' => $name));
            }
        }
    }
    return civicrm_api3_create_success($contactList, $params, 'Contact', 'getquick');
}
开发者ID:nielosz,项目名称:civicrm-core,代码行数:101,代码来源:Contact.php

示例5: civicrm_api3_contact_getquick


//.........这里部分代码省略.........
    if (!empty($selectAliases)) {
        $selectAliases = ", {$selectAliases}";
    }
    $from = implode(' ', $from);
    $limit = CRM_Utils_Array::value('limit', $params, 10);
    // add acl clause here
    require_once 'CRM/Contact/BAO/Contact/Permission.php';
    list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
    if ($aclWhere) {
        $where .= " AND {$aclWhere} ";
    }
    if (CRM_Utils_Array::value('org', $params)) {
        $where .= " AND contact_type = \"Organization\"";
        //set default for current_employer
        if ($orgId = CRM_Utils_Array::value('id', $params)) {
            $where .= " AND cc.id = {$orgId}";
        }
        // CRM-7157, hack: get current employer details when
        // employee_id is present.
        $currEmpDetails = array();
        if (CRM_Utils_Array::value('employee_id', $params)) {
            if ($currentEmployer = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', CRM_Utils_Array::value('employee_id', $params), 'employer_id')) {
                if ($config->includeWildCardInName) {
                    $strSearch = "%{$name}%";
                } else {
                    $strSearch = "{$name}%";
                }
                // get current employer details
                $dao = CRM_Core_DAO::executeQuery("SELECT cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data, sort_name\n                    FROM civicrm_contact cc {$from} WHERE cc.contact_type = \"Organization\" AND cc.id = {$currentEmployer} AND cc.sort_name LIKE '{$strSearch}'");
                if ($dao->fetch()) {
                    $currEmpDetails = array('id' => $dao->id, 'data' => $dao->data);
                }
            }
        }
    }
    if (CRM_Utils_Array::value('cid', $params)) {
        $where .= " AND cc.id <> {$params['cid']}";
    }
    //contact's based of relationhip type
    $relType = NULL;
    if (CRM_Utils_Array::value('rel', $params)) {
        $relation = explode('_', CRM_Utils_Array::value('rel', $params));
        $relType = CRM_Utils_Type::escape($relation[0], 'Integer');
        $rel = CRM_Utils_Type::escape($relation[2], 'String');
    }
    if ($config->includeWildCardInName) {
        $strSearch = "%{$name}%";
    } else {
        $strSearch = "{$name}%";
    }
    $includeEmailFrom = $includeNickName = $exactIncludeNickName = '';
    if ($config->includeNickNameInName) {
        $includeNickName = " OR nick_name LIKE '{$strSearch}'";
        $exactIncludeNickName = " OR nick_name LIKE '{$name}'";
    }
    if ($config->includeEmailInName) {
        if (!in_array('email', $list)) {
            $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )";
        }
        $whereClause = " WHERE ( email LIKE '{$strSearch}' OR sort_name LIKE '{$strSearch}' {$includeNickName} ) {$where} ";
        $exactWhereClause = " WHERE ( email LIKE '{$name}' OR sort_name LIKE '{$name}' {$exactIncludeNickName} ) {$where} ";
    } else {
        $whereClause = " WHERE ( sort_name LIKE '{$strSearch}' {$includeNickName} ) {$where} ";
        $exactWhereClause = " WHERE ( sort_name LIKE '{$name}' {$exactIncludeNickName} ) {$where} ";
    }
    $additionalFrom = '';
    if ($relType) {
        $additionalFrom = "\n            INNER JOIN civicrm_relationship_type r ON (\n                r.id = {$relType}\n                AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL )\n                AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL )\n            )";
    }
    //CRM-5954
    $query = "\n        SELECT DISTINCT(id), data, sort_name {$selectAliases}\n        FROM   (\n            ( SELECT 0 as exactFirst, cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data {$select}\n            FROM   civicrm_contact cc {$from}\n    {$aclFrom}\n    {$additionalFrom} {$includeEmailFrom}\n    {$exactWhereClause}\n    LIMIT 0, {$limit} )\n    UNION\n    ( SELECT 1 as exactFirst, cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data {$select}\n    FROM   civicrm_contact cc {$from}\n    {$aclFrom}\n    {$additionalFrom} {$includeEmailFrom}\n    {$whereClause}\n    ORDER BY sort_name\n    LIMIT 0, {$limit} )\n) t\nORDER BY exactFirst, sort_name\nLIMIT    0, {$limit}\n    ";
    // send query to hook to be modified if needed
    require_once 'CRM/Utils/Hook.php';
    CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Array::value('context', $params), CRM_Utils_Array::value('id', $params));
    $dao = CRM_Core_DAO::executeQuery($query);
    $contactList = array();
    $listCurrentEmployer = TRUE;
    while ($dao->fetch()) {
        $t = array('id' => $dao->id);
        foreach ($as as $k) {
            $t[$k] = $dao->{$k};
        }
        $t['data'] = $dao->data;
        $contactList[] = $t;
        if (CRM_Utils_Array::value('org', $params) && !empty($currEmpDetails) && $dao->id == $currEmpDetails['id']) {
            $listCurrentEmployer = FALSE;
        }
    }
    //return organization name if doesn't exist in db
    if (empty($contactList)) {
        if (CRM_Utils_Array::value('org', $params)) {
            if ($listCurrentEmployer && !empty($currEmpDetails)) {
                $contactList = array(array('data' => $currEmpDetails['data'], 'id' => $currEmpDetails['id']));
            } else {
                $contactList = array(array('data' => $name, 'id' => $name));
            }
        }
    }
    return civicrm_api3_create_success($contactList, $params);
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Contact.php


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