本文整理匯總了PHP中CRM_Utils_JSON::encode方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Utils_JSON::encode方法的具體用法?PHP CRM_Utils_JSON::encode怎麽用?PHP CRM_Utils_JSON::encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Utils_JSON
的用法示例。
在下文中一共展示了CRM_Utils_JSON::encode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: pledgeName
/**
* Function for building Pledge Name combo box
*/
function pledgeName(&$config)
{
$getRecords = FALSE;
if (isset($_GET['name']) && $_GET['name']) {
$name = CRM_Utils_Type::escape($_GET['name'], 'String');
$name = str_replace('*', '%', $name);
$whereClause = "p.creator_pledge_desc LIKE '%{$name}%' ";
$getRecords = TRUE;
}
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$pledgeId = CRM_Utils_Type::escape($_GET['id'], 'Integer');
$whereClause = "p.id = {$pledgeId} ";
$getRecords = TRUE;
}
if ($getRecords) {
$query = "\nSELECT p.creator_pledge_desc, p.id\nFROM civicrm_pb_pledge p\nWHERE {$whereClause}\n";
$dao = CRM_Core_DAO::executeQuery($query);
$elements = array();
while ($dao->fetch()) {
$elements[] = array('name' => $dao->creator_pledge_desc, 'value' => $dao->id);
}
}
if (empty($elements)) {
$name = $_GET['name'];
if (!$name && isset($_GET['id'])) {
$name = $_GET['id'];
}
$elements[] = array('name' => trim($name, '*'), 'value' => trim($name, '*'));
}
echo CRM_Utils_JSON::encode($elements, 'value');
CRM_Utils_System::civiExit();
}
示例2: caseSubject
/**
* Function for Case Subject combo box
*/
function caseSubject(&$config)
{
require_once 'CRM/Utils/Type.php';
$whereclause = $caseIdClause = null;
if (isset($_GET['name'])) {
$name = CRM_Utils_Type::escape($_GET['name'], 'String');
$name = str_replace('*', '%', $name);
$whereclause = "civicrm_case.subject LIKE '%{$name}'";
}
if (isset($_GET['id'])) {
$caseId = CRM_Utils_Type::escape($_GET['id'], 'Integer');
$caseIdClause = " AND civicrm_case.id = {$caseId}";
}
$elements = array();
if ($name || $caseIdClause) {
if (is_numeric($_GET['c'])) {
$contactID = CRM_Utils_Type::escape($_GET['c'], 'Integer');
if ($contactID) {
$clause = "civicrm_case_contact.contact_id = {$contactID}";
$whereclause = $whereclause ? $whereclause . " AND " . $clause : $clause;
}
}
$query = "\nSELECT distinct(civicrm_case.subject) as subject, civicrm_case.id as id\nFROM civicrm_case\nLEFT JOIN civicrm_case_contact ON civicrm_case_contact.case_id = civicrm_case.id\nWHERE {$whereclause} {$caseIdClause}\nORDER BY subject";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$elements[] = array('name' => $dao->subject, 'id' => $dao->id);
}
}
if (empty($elements)) {
$name = str_replace('%', '', $name);
$elements[] = array('name' => $name, 'id' => $name);
}
require_once "CRM/Utils/JSON.php";
echo CRM_Utils_JSON::encode($elements);
}
示例3: countries
/**
* Test Function used for new hs-widget.
*/
function countries(&$config)
{
//get the country limit and restrict the combo select options
$limitCodes = $config->countryLimit();
if (!is_array($limitCodes)) {
$limitCodes = array($config->countryLimit => 1);
}
$limitCodes = array_intersect(CRM_Core_PseudoConstant::countryIsoCode(), $limitCodes);
// added for testing purpose
//$limitCodes['1101'] = 'IN';
if (count($limitCodes)) {
$whereClause = " iso_code IN ('" . implode("', '", $limitCodes) . "')";
} else {
$whereClause = " 1";
}
$elements = array();
require_once 'CRM/Utils/Type.php';
$name = NULL;
if (isset($_GET['name'])) {
$name = CRM_Utils_Type::escape($_GET['name'], 'String');
}
$countryId = NULL;
if (isset($_GET['id'])) {
$countryId = CRM_Utils_Type::escape($_GET['id'], 'Positive', FALSE);
}
//temporary fix to handle locales other than default US,
// CRM-2653
if (!$countryId && $name && $config->lcMessages != 'en_US') {
$countries = CRM_Core_PseudoConstant::country();
// get the country name in en_US, since db has this locale
$countryName = array_search($name, $countries);
if ($countryName) {
$countryId = $countryName;
}
}
$validValue = TRUE;
if (!$name && !$countryId) {
$validValue = FALSE;
}
if ($validValue) {
if (!$countryId) {
$name = str_replace('*', '%', $name);
$countryClause = " civicrm_country.name LIKE LOWER('{$name}%') ";
} else {
$countryClause = " civicrm_country.id = {$countryId} ";
}
$query = "\nSELECT id, name\n FROM civicrm_country\n WHERE {$countryClause}\n AND {$whereClause} \nORDER BY name";
$nullArray = array();
$dao = CRM_Core_DAO::executeQuery($query, $nullArray);
$count = 0;
while ($dao->fetch() && $count < 5) {
$elements[] = array('name' => ts($dao->name), 'value' => $dao->id);
$count++;
}
}
if (empty($elements)) {
if (isset($_GET['id'])) {
$name = $_GET['id'];
}
$elements[] = array('name' => trim($name, "%"), 'value' => trim($name, "%"));
}
require_once "CRM/Utils/JSON.php";
echo CRM_Utils_JSON::encode($elements, 'value');
}