本文整理匯總了PHP中CRM_Utils_JSON類的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Utils_JSON類的具體用法?PHP CRM_Utils_JSON怎麽用?PHP CRM_Utils_JSON使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CRM_Utils_JSON類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: selectUnselectRelationships
/**
* Used to store selected contacts across multiple pages in advanced search.
*/
public static function selectUnselectRelationships()
{
$name = CRM_Utils_Array::value('name', $_REQUEST);
$cacheKey = CRM_Utils_Array::value('qfKey', $_REQUEST);
$state = CRM_Utils_Array::value('state', $_REQUEST, 'checked');
$variableType = CRM_Utils_Array::value('variableType', $_REQUEST, 'single');
$actionToPerform = CRM_Utils_Array::value('action', $_REQUEST, 'select');
if ($variableType == 'multiple') {
// action post value only works with multiple type variable
if ($name) {
//multiple names like mark_x_1-mark_x_2 where 1,2 are cids
$elements = explode('-', $name);
foreach ($elements as $key => $element) {
$elements[$key] = self::_convertToId($element);
}
CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, $elements, 'civicrm_relationship');
} else {
CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, NULL, 'civicrm_relationship');
}
} elseif ($variableType == 'single') {
$cId = self::_convertToId($name);
$action = $state == 'checked' ? 'select' : 'unselect';
CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $action, $cId, 'civicrm_relationship');
}
$contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, 'get', 'civicrm_relationship');
$countSelectionCids = count($contactIds[$cacheKey]);
$arrRet = array('getCount' => $countSelectionCids);
CRM_Utils_JSON::output($arrRet);
}
示例3: checkIsMultiRecord
/**
* Function the check whether the field belongs.
* to multi-record custom set
*/
public function checkIsMultiRecord()
{
$customId = $_GET['customId'];
$isMultiple = CRM_Core_BAO_CustomField::isMultiRecordField($customId);
$isMultiple = array('is_multi' => $isMultiple);
CRM_Utils_JSON::output($isMultiple);
}
示例4: updateMode
public static function updateMode()
{
$finalResult = array();
if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)) {
$mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
$entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
$entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String');
if (!empty($_REQUEST['linkedEntityTable'])) {
$result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable);
}
$dao = new CRM_Core_DAO_RecurringEntity();
if (!empty($result)) {
$dao->entity_id = $result['entityId'];
$dao->entity_table = $result['entityTable'];
} else {
$dao->entity_id = $entityId;
$dao->entity_table = $entityTable;
}
if ($dao->find(TRUE)) {
$dao->mode = $mode;
$dao->save();
$finalResult['status'] = 'Done';
} else {
$finalResult['status'] = 'Error';
}
}
CRM_Utils_JSON::output($finalResult);
}
示例5: getBatchList
/**
* Retrieve records.
*/
public static function getBatchList()
{
$sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => '');
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
$sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
$sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
$context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
$params = $_REQUEST;
if ($sort && $sortOrder) {
$params['sortBy'] = $sort . ' ' . $sortOrder;
}
$params['page'] = $offset / $rowCount + 1;
$params['rp'] = $rowCount;
if ($context != 'financialBatch') {
// data entry status batches
$params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name');
}
$params['context'] = $context;
// get batch list
$batches = CRM_Batch_BAO_Batch::getBatchListSelector($params);
$iFilteredTotal = $iTotal = $params['total'];
if ($context == 'financialBatch') {
$selectorElements = array('check', 'batch_name', 'payment_instrument', 'item_count', 'total', 'status', 'created_by', 'links');
} else {
$selectorElements = array('batch_name', 'type', 'item_count', 'total', 'status', 'created_by', 'links');
}
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
示例6: getCaseActivity
static function getCaseActivity()
{
$caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
$contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
$userID = CRM_Utils_Type::escape($_GET['userID'], 'Integer');
$context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String');
$sortMapper = array(0 => 'display_date', 1 => 'ca.subject', 2 => 'ca.activity_type_id', 3 => 'acc.sort_name', 4 => 'cc.sort_name', 5 => 'ca.status_id');
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
$sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : null;
$sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
$params = $_POST;
if ($sort && $sortOrder) {
$params['sortname'] = $sort;
$params['sortorder'] = $sortOrder;
}
$params['page'] = $offset / $rowCount + 1;
$params['rp'] = $rowCount;
// get the activities related to given case
require_once "CRM/Case/BAO/Case.php";
$activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID, $context, $userID);
require_once "CRM/Utils/JSON.php";
$iFilteredTotal = $iTotal = $params['total'];
$selectorElements = array('display_date', 'subject', 'type', 'with_contacts', 'reporter', 'status', 'links', 'class');
echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
示例7: getGroupList
/**
* Get list of groups.
*/
public static function getGroupList()
{
$params = $_GET;
if (isset($params['parent_id'])) {
// requesting child groups for a given parent
$params['page'] = 1;
$params['rp'] = 0;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
CRM_Utils_JSON::output($groups);
} else {
$params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
$optionalParameters = array('parentsOnly' => 'Integer', 'showOrgInfo' => 'Boolean');
$params += CRM_Core_Page_AJAX::validateParams(array(), $optionalParameters);
// get group list
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
// if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case),
// go ahead with flat hierarchy, CRM-12225
if (empty($groups)) {
$groupsAccessible = CRM_Core_PseudoConstant::group();
$parentsOnly = CRM_Utils_Array::value('parentsOnly', $params);
if (!empty($groupsAccessible) && $parentsOnly) {
// recompute group list with flat hierarchy
$params['parentsOnly'] = 0;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
}
}
CRM_Utils_JSON::output($groups);
}
}
示例8: getContactMailings
/**
* Function to retrieve contact mailings
*/
public static function getContactMailings()
{
$contactID = CRM_Utils_Type::escape($_GET['contact_id'], 'Integer');
$sortMapper = array(0 => 'subject', 1 => 'creator_name', 2 => '', 3 => 'start_date', 4 => '', 5 => 'links');
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
$sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
$sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
$params = $_POST;
if ($sort && $sortOrder) {
$params['sortBy'] = $sort . ' ' . $sortOrder;
}
$params['page'] = $offset / $rowCount + 1;
$params['rp'] = $rowCount;
$params['contact_id'] = $contactID;
$params['context'] = $context;
// get the contact mailings
$mailings = CRM_Mailing_BAO_Mailing::getContactMailingSelector($params);
$iFilteredTotal = $iTotal = $params['total'];
$selectorElements = array('subject', 'mailing_creator', 'recipients', 'start_date', 'openstats', 'links');
header('Content-Type: application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($mailings, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
示例9: 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();
}
示例10: getContactMailings
/**
* Retrieve contact mailings.
*/
public static function getContactMailings()
{
$params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
$params += CRM_Core_Page_AJAX::validateParams(array('contact_id' => 'Integer'));
// get the contact mailings
$mailings = CRM_Mailing_BAO_Mailing::getContactMailingSelector($params);
CRM_Utils_JSON::output($mailings);
}
示例11: getTeamList
/**
* Get list of teams.
*
* @return array
*/
public static function getTeamList()
{
$params = $_REQUEST;
if (isset($params['parent_id'])) {
// requesting child groups for a given parent
$params['page'] = 1;
$params['rp'] = 0;
$groups = self::getTeamListSelector($params);
CRM_Utils_JSON::output($groups);
} else {
$sortMapper = array(0 => 'groups.title', 1 => 'count', 2 => 'createdBy.sort_name', 3 => '', 4 => 'groups.group_type', 5 => 'groups.visibility');
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
$sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
$sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
if ($sort && $sortOrder) {
$params['sortBy'] = $sort . ' ' . $sortOrder;
}
$params['page'] = $offset / $rowCount + 1;
$params['rp'] = $rowCount;
$params['group_type'] = teamGroupType();
// restrict to teams logged in user may access
$contact = billing_contact_get();
//@todo remove for admin
if (!CRM_Core_Permission::check('edit all contacts')) {
$params['created_by'] = $contact['sort_name'];
}
// get team list
$groups = self::getTeamListSelector($params);
// if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case),
// go ahead with flat hierarchy
if (empty($groups)) {
$groupsAccessible = CRM_Core_PseudoConstant::group();
$parentsOnly = CRM_Utils_Array::value('parentsOnly', $params);
if (!empty($groupsAccessible) && $parentsOnly) {
// recompute group list with flat hierarchy
$params['parentsOnly'] = 0;
$groups = self::getTeamListSelector($params);
}
}
$iFilteredTotal = $iTotal = count($groups);
//$params['total'];
$selectorElements = array('group_name', 'count', 'created_by', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class');
if (empty($params['showOrgInfo'])) {
unset($selectorElements[6]);
}
//add setting so this can be tested by unit test
//@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate
// from the one which deals with web inputs & outputs so we have a properly testable & re-usable function
if (!empty($params['is_unit_test'])) {
return array($groups, $iFilteredTotal);
}
header('Content-Type: application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
}
示例12: getPledgeDefaults
/**
* Function to setDefaults according to Pledge Id
* for batch entry pledges
*/
public function getPledgeDefaults()
{
$details = array();
if (!empty($_POST['pid'])) {
$pledgeID = CRM_Utils_Type::escape($_POST['pid'], 'Integer');
$details = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
}
CRM_Utils_JSON::output($details);
}
示例13: run
/**
* Provide the legislators for the given address.
*
* Echos JSON object of the names, photo URLs, and emails.
*/
public function run()
{
$addressValues = array('Postal_Code_Field' => CRM_Utils_Request::retrieve('zip', 'Int'), 'State_Province_Field' => CRM_Utils_Request::retrieve('state', 'Int'), 'City_Field' => CRM_Utils_Request::retrieve('city', 'String'), 'Street_Address_Field' => CRM_Utils_Request::retrieve('address', 'String'));
foreach ($addressValues as $val) {
if (empty($val)) {
return;
}
}
$recipients = CRM_Petitionemail_Interface_Statelegemail::findRecipients($addressValues);
CRM_Utils_JSON::output($recipients);
}
示例14: getSoftContributionRows
/**
* Get Soft credit to list in DT
*/
public static function getSoftContributionRows()
{
$requiredParameters = array('cid' => 'Integer', 'context' => 'String');
$optionalParameters = array('entityID' => 'Integer', 'isTest' => 'Integer');
$params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
$params += CRM_Core_Page_AJAX::validateParams($requiredParameters, $optionalParameters);
$softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionSelector($params);
if (!empty($_GET['is_unit_test'])) {
return $softCreditList;
}
CRM_Utils_JSON::output($softCreditList);
}
示例15: getCaseActivity
static function getCaseActivity()
{
$caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
$contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
$params = $_POST;
// get the activities related to given case
require_once "CRM/Case/BAO/Case.php";
$activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID);
$page = CRM_Utils_Array::value('page', $_POST);
$total = $params['total'];
require_once "CRM/Utils/JSON.php";
$selectorElements = array('display_date', 'subject', 'type', 'reporter', 'status', 'links', 'class');
echo CRM_Utils_JSON::encodeSelector($activities, $page, $total, $selectorElements);
exit;
}