本文整理汇总了PHP中CRM_Core_DAO::escapeString方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::escapeString方法的具体用法?PHP CRM_Core_DAO::escapeString怎么用?PHP CRM_Core_DAO::escapeString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_DAO
的用法示例。
在下文中一共展示了CRM_Core_DAO::escapeString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* Check to see if we have cache entries for this group
* if not, regenerate, else return
*
* @param int $groupID groupID of group that we are checking against
*
* @return boolean true if we did not regenerate, false if we did
*/
static function check($groupID)
{
if (empty($groupID)) {
return true;
}
if (!is_array($groupID)) {
$groupID = array($groupID);
}
// note escapeString is a must here and we can't send the imploded value as second arguement to
// the executeQuery(), since that would put single quote around the string and such a string
// of comma separated integers would not work.
$groupID = CRM_Core_DAO::escapeString(implode(', ', $groupID));
$config = CRM_Core_Config::singleton();
$smartGroupCacheTimeout = isset($config->smartGroupCacheTimeout) && is_numeric($config->smartGroupCacheTimeout) ? $config->smartGroupCacheTimeout : 0;
//make sure to give original timezone settings again.
$originalTimezone = date_default_timezone_get();
date_default_timezone_set('UTC');
$now = date('YmdHis');
date_default_timezone_set($originalTimezone);
$query = "\nSELECT g.id\nFROM civicrm_group g\nWHERE g.id IN ( {$groupID} ) AND ( g.saved_search_id IS NOT NULL OR g.children IS NOT NULL ) AND \n (g.cache_date IS NULL OR (TIMESTAMPDIFF(MINUTE, g.cache_date, {$now}) >= {$smartGroupCacheTimeout}))\n";
$dao =& CRM_Core_DAO::executeQuery($query);
$groupIDs = array();
while ($dao->fetch()) {
$groupIDs[] = $dao->id;
}
if (empty($groupIDs)) {
return true;
} else {
self::add($groupIDs);
return false;
}
}
示例2: record
/**
* @param $rg
*
* @return array
*/
public static function record($rg)
{
$civicrm_contact = CRM_Utils_Array::value('civicrm_contact', $rg->params);
$civicrm_address = CRM_Utils_Array::value('civicrm_address', $rg->params);
// Since definitely have first and last name, escape them upfront.
$first_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('first_name', $civicrm_contact, ''));
$last_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('last_name', $civicrm_contact, ''));
$street_address = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('street_address', $civicrm_address, ''));
$query = "\n SELECT contact1.id id1, {$rg->threshold} as weight\n FROM civicrm_contact AS contact1\n JOIN civicrm_address AS address1 ON contact1.id=address1.contact_id\n WHERE contact1.contact_type = 'Couple'\n AND contact1.first_name = '{$first_name}'\n AND contact1.last_name = '{$last_name}'\n AND address1.street_address = '{$street_address}'\n ";
if ($spouse_first_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('spouse_first_name', $civicrm_contact, ''))) {
$query .= " AND (AND contact1.spouse_first_name IS NULL or contact1.spouse_first_name = '{$spouse_first_name}')\n";
}
if ($spouse_last_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('spouse_last_name', $civicrm_contact, ''))) {
$query .= " AND (AND contact1.spouse_last_name IS NULL or contact1.spouse_last_name = '{$spouse_last_name}')\n";
}
if ($birth_date = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('birth_date', $civicrm_contact, ''))) {
$query .= " AND (contact1.birth_date IS NULL or contact1.birth_date = '{$birth_date}')\n";
}
if ($spouse_birth_date = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('spouse_birth_date', $civicrm_contact, ''))) {
$query .= " AND (contact1.spouse_birth_date IS NULL or contact1.spouse_birth_date = '{$spouse_birth_date}')\n";
}
if ($suffix_id = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('suffix_id', $civicrm_contact, ''))) {
$query .= " AND (contact1.suffix_id IS NULL or contact1.suffix_id = {$suffix_id})\n";
}
if ($spouse_suffix_id = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('spouse_suffix_id', $civicrm_contact, ''))) {
$query .= " AND (contact1.spouse_suffix_id IS NULL or contact1.spouse_suffix_id = {$spouse_suffix_id})\n";
}
if ($middle_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('middle_name', $civicrm_contact, ''))) {
$query .= " AND (contact1.middle_name IS NULL or contact1.middle_name = '{$middle_name}')\n";
}
if ($spouse_middle_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('spouse_middle_name', $civicrm_contact, ''))) {
$query .= " AND (contact1.spouse_middle_name IS NULL or contact1.spouse_middle_name = '{$spouse_middle_name}')\n";
}
return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query);
}
示例3: mailing_select
/**
* @return array
*/
public function mailing_select()
{
$data = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$query = "SELECT name FROM civicrm_mailing WHERE sms_provider_id IS NULL";
$mailing->query($query);
while ($mailing->fetch()) {
$data[CRM_Core_DAO::escapeString($mailing->name)] = $mailing->name;
}
return $data;
}
示例4: __construct
function __construct(&$formValues)
{
$this->_formValues =& $formValues;
$this->_text = CRM_Utils_Array::value('text', $formValues);
$this->_table = CRM_Utils_Array::value('table', $formValues);
if (!$this->_text) {
$this->_text = CRM_Utils_Request::retrieve('text', 'String', CRM_Core_DAO::$_nullObject);
if ($this->_text) {
$this->_text = trim($this->_text);
$formValues['text'] = $this->_text;
}
}
if (!$this->_table) {
$this->_table = CRM_Utils_Request::retrieve('table', 'String', CRM_Core_DAO::$_nullObject);
if ($this->_table) {
$formValues['table'] = $this->_table;
}
}
// fix text to include wild card characters at begining and end
if ($this->_text) {
if (is_numeric($this->_text)) {
$this->_textID = $this->_text;
}
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$this->_text = $strtolower(CRM_Core_DAO::escapeString($this->_text));
if (strpos($this->_text, '%') === false) {
$this->_text = "'%{$this->_text}%'";
} else {
$this->_text = "'{$this->_text}'";
}
} else {
$this->_text = "'%'";
}
if (!$this->_table) {
$this->_limitClause = " LIMIT {$this->_limitNumber}";
$this->_limitRowClause = $this->_limitClause;
} else {
// when there is table specified, we would like to use the pager. But since
// 1. this custom search has slightly different structure ,
// 2. we are in constructor right now,
// we 'll use a small hack -
$rowCount = CRM_Utils_Pager::ROWCOUNT;
$pageId = CRM_Utils_Array::value('crmPID', $_REQUEST);
$pageId = $pageId ? $pageId : 1;
$offset = ($pageId - 1) * $rowCount;
$this->_limitClause = " LIMIT {$offset}, {$rowCount}";
$this->_limitRowClause = " LIMIT {$rowCount}";
}
$this->buildTempTable();
$this->fillTable();
}
示例5: __construct
function __construct(&$formValues)
{
$this->_formValues =& $formValues;
$this->_text = CRM_Utils_Array::value('text', $formValues);
$this->_table = CRM_Utils_Array::value('table', $formValues);
if (!$this->_text) {
$this->_text = CRM_Utils_Request::retrieve('text', 'String', CRM_Core_DAO::$_nullObject);
if ($this->_text) {
$this->_text = trim($this->_text);
$formValues['text'] = $this->_text;
}
}
if (!$this->_table) {
$this->_table = CRM_Utils_Request::retrieve('table', 'String', CRM_Core_DAO::$_nullObject);
if ($this->_table) {
$formValues['table'] = $this->_table;
}
}
// fix text to include wild card characters at begining and end
if ($this->_text) {
if (is_numeric($this->_text)) {
$this->_textID = $this->_text;
}
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$this->_text = $strtolower(CRM_Core_DAO::escapeString($this->_text));
if (strpos($this->_text, '%') === false) {
$this->_text = "'%{$this->_text}%'";
} else {
$this->_text = "'{$this->_text}'";
}
} else {
$this->_text = "'%'";
}
if (!$this->_table) {
$this->_limitClause = " LIMIT {$this->_limitNumber}";
}
$this->buildTempTable();
$this->fillTable();
}
示例6: matchText
/**
* Create a SQL expression for matching against a list of
* text columns.
*
* @param string $table eg "civicrm_note" or "civicrm_note mynote"
* @param array|string $fullTextFields list of field names
* @param string $queryText
* @return string SQL, eg "MATCH (col1) AGAINST (queryText)" or "col1 LIKE '%queryText%'"
*/
public function matchText($table, $fullTextFields, $queryText)
{
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
if (strpos($table, ' ') === FALSE) {
$tableName = $tableAlias = $table;
} else {
list($tableName, $tableAlias) = explode(' ', $table);
}
if (is_scalar($fullTextFields)) {
$fullTextFields = array($fullTextFields);
}
$clauses = array();
if (CRM_Core_InnoDBIndexer::singleton()->hasDeclaredIndex($tableName, $fullTextFields)) {
$formattedQuery = CRM_Utils_QueryFormatter::singleton()->format($queryText, CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL);
$prefixedFieldNames = array();
foreach ($fullTextFields as $fieldName) {
$prefixedFieldNames[] = "{$tableAlias}.{$fieldName}";
}
$clauses[] = sprintf("MATCH (%s) AGAINST ('%s' IN BOOLEAN MODE)", implode(',', $prefixedFieldNames), $strtolower(CRM_Core_DAO::escapeString($formattedQuery)));
} else {
//CRM_Core_Session::setStatus(ts('Cannot use FTS for %1 (%2)', array(
// 1 => $table,
// 2 => implode(', ', $fullTextFields),
//)));
$formattedQuery = CRM_Utils_QueryFormatter::singleton()->format($queryText, CRM_Utils_QueryFormatter::LANG_SQL_LIKE);
$escapedText = $strtolower(CRM_Core_DAO::escapeString($formattedQuery));
foreach ($fullTextFields as $fieldName) {
$clauses[] = "{$tableAlias}.{$fieldName} LIKE '{$escapedText}'";
}
}
return implode(' OR ', $clauses);
}
示例7: getGroups
/**
* Returns array of group object(s) matching a set of one or Group properties.
*
*
* @param array $param Array of one or more valid property_name=>value pairs. Limits the set of groups returned.
* @param array $returnProperties Which properties should be included in the returned group objects. (member_count should be last element.)
*
* @return An array of group objects.
*
* @access public
*/
static function getGroups($params = null, $returnProperties = null)
{
$dao =& new CRM_Contact_DAO_Group();
$dao->is_active = 1;
if ($params) {
foreach ($params as $k => $v) {
if ($k == 'name' || $k == 'title') {
$dao->whereAdd($k . ' LIKE "' . CRM_Core_DAO::escapeString($v) . '"');
} else {
if (is_array($v)) {
$dao->whereAdd($k . ' IN (' . implode(',', $v) . ')');
} else {
$dao->{$k} = $v;
}
}
}
}
// return only specific fields if returnproperties are sent
if (!empty($returnProperties)) {
$dao->selectAdd();
$dao->selectAdd(implode(',', $returnProperties));
}
$dao->find();
$flag = $returnProperties && in_array('member_count', $returnProperties) ? 1 : 0;
$groups = array();
while ($dao->fetch()) {
$group =& new CRM_Contact_DAO_Group();
if ($flag) {
$dao->member_count = CRM_Contact_BAO_Group::memberCount($dao->id);
}
$groups[] = clone $dao;
}
return $groups;
}
示例8: writeDetailsToTable
/**
* @param string $tableName
* @param $details
* @param $sqlColumns
*/
public static function writeDetailsToTable($tableName, &$details, &$sqlColumns)
{
if (empty($details)) {
return;
}
$sql = "\nSELECT max(id)\nFROM {$tableName}\n";
$id = CRM_Core_DAO::singleValueQuery($sql);
if (!$id) {
$id = 0;
}
$sqlClause = array();
foreach ($details as $dontCare => $row) {
$id++;
$valueString = array($id);
foreach ($row as $dontCare => $value) {
if (empty($value)) {
$valueString[] = "''";
} else {
$valueString[] = "'" . CRM_Core_DAO::escapeString($value) . "'";
}
}
$sqlClause[] = '(' . implode(',', $valueString) . ')';
}
$sqlColumnString = '(id, ' . implode(',', array_keys($sqlColumns)) . ')';
$sqlValueString = implode(",\n", $sqlClause);
$sql = "\nINSERT INTO {$tableName} {$sqlColumnString}\nVALUES {$sqlValueString}\n";
CRM_Core_DAO::executeQuery($sql);
}
示例9: whereClauseSingle
/**
* where clause for a single field
*
* @return void
* @access public
*/
static function whereClauseSingle(&$values, &$query)
{
list($name, $op, $value, $grouping, $wildcard) = $values;
switch ($name) {
case 'case_subject':
$value = strtolower(CRM_Core_DAO::escapeString(trim($value)));
$query->_where[$grouping][] = "civicrm_case.subject {$op} '{$value}'";
$query->_qill[$grouping][] = ts('Case Subject %2 %1', array(1 => $value, 2 => $op));
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_status_id':
require_once 'CRM/Core/OptionGroup.php';
$caseStatus = CRM_Core_OptionGroup::values('case_status');
$query->_where[$grouping][] = "civicrm_case.status_id {$op} {$value} ";
$value = $caseStatus[$value];
$query->_qill[$grouping][] = ts('Case Status %2 %1', array(1 => $value, 2 => $op));
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_type_id':
require_once 'CRM/Core/OptionGroup.php';
$caseType = CRM_Core_OptionGroup::values('case_type');
$names = array();
foreach ($value as $id => $val) {
$names[] = $caseType[$val];
}
require_once 'CRM/Case/BAO/Case.php';
$value = CRM_Case_BAO_Case::VALUE_SEPERATOR . implode(CRM_Case_BAO_Case::VALUE_SEPERATOR . "%' OR civicrm_case.case_type_id LIKE '%" . CRM_Case_BAO_Case::VALUE_SEPERATOR, $value) . CRM_Case_BAO_Case::VALUE_SEPERATOR;
$query->_where[$grouping][] = "(civicrm_case.case_type_id LIKE '%{$value}%')";
$value = $caseType[$value];
$query->_qill[$grouping][] = ts('Case Type %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_casetag2_id':
require_once 'CRM/Core/OptionGroup.php';
$caseSubtype = CRM_Core_OptionGroup::values('f1_case_sub_type');
$names = array();
foreach ($value as $id => $val) {
$names[] = $caseSubtype[$val];
}
require_once 'CRM/Case/BAO/Case.php';
$value = CRM_Case_BAO_Case::VALUE_SEPERATOR . implode(CRM_Case_BAO_Case::VALUE_SEPERATOR . "%' OR civicrm_case.casetag2_id LIKE '%" . CRM_Case_BAO_Case::VALUE_SEPERATOR, $value) . CRM_Case_BAO_Case::VALUE_SEPERATOR;
$query->_where[$grouping][] = "(civicrm_case.casetag2_id LIKE '%{$value}%')";
$value = $caseSubtype[$value];
$query->_qill[$grouping][] = ts('Case SubType %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_casetag3_id':
require_once 'CRM/Core/OptionGroup.php';
$caseViolation = CRM_Core_OptionGroup::values('f1_case_violation');
$names = array();
foreach ($value as $id => $val) {
$names[] = $caseViolation[$val];
}
require_once 'CRM/Case/BAO/Case.php';
$value = CRM_Case_BAO_Case::VALUE_SEPERATOR . implode(CRM_Case_BAO_Case::VALUE_SEPERATOR . "%' OR civicrm_case.casetag3_id LIKE '%" . CRM_Case_BAO_Case::VALUE_SEPERATOR, $value) . CRM_Case_BAO_Case::VALUE_SEPERATOR;
$query->_where[$grouping][] = "(civicrm_case.casetag3_id LIKE '%{$value}%')";
$value = $caseViolation[$value];
$query->_qill[$grouping][] = ts('Case Voilation %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_start_date_low':
case 'case_start_date_high':
$query->dateQueryBuilder($values, 'civicrm_case', 'case_start_date', 'start_date', 'Start Date');
return;
}
}
示例10: whereClauseSingle
//.........这里部分代码省略.........
case 'contribution_test':
// We dont want to include all tests for sql OR CRM-7827
if (!$value || $query->getOperator() != 'OR') {
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.is_test", $op, $value, "Boolean");
if ($value) {
$query->_qill[$grouping][] = ts("Only Display Test Contributions");
}
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
}
return;
case 'contribution_is_pay_later':
case 'contribution_pay_later':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.is_pay_later", $op, $value, "Boolean");
if ($value) {
$query->_qill[$grouping][] = ts("Find Pay Later Contributions");
} else {
$query->_qill[$grouping][] = ts("Exclude Pay Later Contributions");
}
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
case 'contribution_recurring':
if ($value) {
$query->_where[$grouping][] = "civicrm_contribution.contribution_recur_id IS NOT NULL";
$query->_qill[$grouping][] = ts("Find Recurring Contributions");
$query->_tables['civicrm_contribution_recur'] = $query->_whereTables['civicrm_contribution_recur'] = 1;
} else {
$query->_where[$grouping][] = "civicrm_contribution.contribution_recur_id IS NULL";
$query->_qill[$grouping][] = ts("Exclude Recurring Contributions");
}
return;
case 'contribution_recur_id':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.contribution_recur_id", $op, $value, "Integer");
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
case 'contribution_note':
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
$value = "%{$value}%";
$op = 'LIKE';
}
$wc = $op != 'LIKE' ? "LOWER(civicrm_note.note)" : "civicrm_note.note";
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($wc, $op, $value, "String");
$query->_qill[$grouping][] = ts('Contribution Note %1 %2', array(1 => $op, 2 => $quoteValue));
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = $query->_whereTables['contribution_note'] = 1;
return;
case 'contribution_membership_id':
$query->_where[$grouping][] = " civicrm_membership.id {$op} {$value}";
$query->_tables['contribution_membership'] = $query->_whereTables['contribution_membership'] = 1;
return;
case 'contribution_participant_id':
$query->_where[$grouping][] = " civicrm_participant.id {$op} {$value}";
$query->_tables['contribution_participant'] = $query->_whereTables['contribution_participant'] = 1;
return;
case 'contribution_pcp_display_in_roll':
$query->_where[$grouping][] = " civicrm_contribution_soft.pcp_display_in_roll {$op} '{$value}'";
if ($value) {
$query->_qill[$grouping][] = ts("Personal Campaign Page Honor Roll");
} else {
$query->_qill[$grouping][] = ts("NOT Personal Campaign Page Honor Roll");
}
$query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
return;
case 'contribution_campaign_id':
$campParams = array('op' => $op, 'campaign' => $value, 'grouping' => $grouping, 'tableName' => 'civicrm_contribution');
CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query);
return;
case 'contribution_batch_id':
$batches = CRM_Contribute_PseudoConstant::batch();
$query->_where[$grouping][] = " civicrm_entity_batch.batch_id {$op} {$value}";
$query->_qill[$grouping][] = ts('Batch Name %1 %2', array(1 => $op, 2 => $batches[$value]));
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
$query->_tables['contribution_batch'] = $query->_whereTables['contribution_batch'] = 1;
return;
default:
//all other elements are handle in this case
$fldName = substr($name, 13);
if (!isset($fields[$fldName])) {
// CRM-12597
CRM_Core_Session::setStatus(ts('We did not recognize the search field: %1. Please check and fix your contribution related smart groups.', array(1 => $fldName)));
return;
}
$whereTable = $fields[$fldName];
$value = trim($value);
$dataType = "String";
if (!empty($whereTable['type'])) {
$dataType = CRM_Utils_Type::typeToString($whereTable['type']);
}
$wc = $op != 'LIKE' && $dataType != 'Date' ? "LOWER({$whereTable['where']})" : "{$whereTable['where']}";
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($wc, $op, $value, $dataType);
$query->_qill[$grouping][] = "{$whereTable['title']} {$op} {$quoteValue}";
list($tableName, $fieldName) = explode('.', $whereTable['where'], 2);
$query->_tables[$tableName] = $query->_whereTables[$tableName] = 1;
if ($tableName == 'civicrm_contribution_product') {
$query->_tables['civicrm_product'] = $query->_whereTables['civicrm_product'] = 1;
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
} else {
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
}
}
}
示例11: updateGreeting
/**
* @param array $params
*
* @throws Exception
*/
public static function updateGreeting($params)
{
$contactType = $params['ct'];
$greeting = $params['gt'];
$valueID = $id = CRM_Utils_Array::value('id', $params);
$force = CRM_Utils_Array::value('force', $params);
$limit = CRM_Utils_Array::value('limit', $params);
// if valueID is not passed use default value
if (!$valueID) {
$valueID = $id = self::defaultGreeting($contactType, $greeting);
}
$filter = array('contact_type' => $contactType, 'greeting_type' => $greeting);
$allGreetings = CRM_Core_PseudoConstant::greeting($filter);
$originalGreetingString = $greetingString = CRM_Utils_Array::value($valueID, $allGreetings);
if (!$greetingString) {
CRM_Core_Error::fatal(ts('Incorrect greeting value id %1, or no default greeting for this contact type and greeting type.', array(1 => $valueID)));
}
// build return properties based on tokens
$greetingTokens = CRM_Utils_Token::getTokens($greetingString);
$tokens = CRM_Utils_Array::value('contact', $greetingTokens);
$greetingsReturnProperties = array();
if (is_array($tokens)) {
$greetingsReturnProperties = array_fill_keys(array_values($tokens), 1);
}
// Process ALL contacts only when force=1 or force=2 is passed. Else only contacts with NULL greeting or addressee value are updated.
$processAll = $processOnlyIdSet = FALSE;
if ($force == 1) {
$processAll = TRUE;
} elseif ($force == 2) {
$processOnlyIdSet = TRUE;
}
//FIXME : apiQuery should handle these clause.
$filterContactFldIds = $filterIds = array();
$idFldName = $displayFldName = NULL;
if (in_array($greeting, CRM_Contact_BAO_Contact::$_greetingTypes)) {
$idFldName = $greeting . '_id';
$displayFldName = $greeting . '_display';
}
if ($idFldName) {
$queryParams = array(1 => array($contactType, 'String'));
// if $force == 1 then update all contacts else only
// those with NULL greeting or addressee value CRM-9476
if ($processAll) {
$sql = "SELECT DISTINCT id, {$idFldName} FROM civicrm_contact WHERE contact_type = %1 ";
} else {
$sql = "\n SELECT DISTINCT id, {$idFldName}\n FROM civicrm_contact\n WHERE contact_type = %1\n AND ({$idFldName} IS NULL\n OR ( {$idFldName} IS NOT NULL AND ({$displayFldName} IS NULL OR {$displayFldName} = '')) )";
}
if ($limit) {
$sql .= " LIMIT 0, %2";
$queryParams += array(2 => array($limit, 'Integer'));
}
$dao = CRM_Core_DAO::executeQuery($sql, $queryParams);
while ($dao->fetch()) {
$filterContactFldIds[$dao->id] = $dao->{$idFldName};
if (!CRM_Utils_System::isNull($dao->{$idFldName})) {
$filterIds[$dao->id] = $dao->{$idFldName};
}
}
}
if (empty($filterContactFldIds)) {
$filterContactFldIds[] = 0;
}
// retrieve only required contact information
$extraParams[] = array('contact_type', '=', $contactType, 0, 0);
// we do token replacement in the replaceGreetingTokens hook
list($greetingDetails) = CRM_Utils_Token::getTokenDetails(array_keys($filterContactFldIds), $greetingsReturnProperties, FALSE, FALSE, $extraParams);
// perform token replacement and build update SQL
$contactIds = array();
$cacheFieldQuery = "UPDATE civicrm_contact SET {$greeting}_display = CASE id ";
foreach ($greetingDetails as $contactID => $contactDetails) {
if (!$processAll && !array_key_exists($contactID, $filterContactFldIds)) {
continue;
}
if ($processOnlyIdSet && !array_key_exists($contactID, $filterIds)) {
continue;
}
if ($id) {
$greetingString = $originalGreetingString;
$contactIds[] = $contactID;
} else {
if ($greetingBuffer = CRM_Utils_Array::value($filterContactFldIds[$contactID], $allGreetings)) {
$greetingString = $greetingBuffer;
}
}
self::processGreetingTemplate($greetingString, $contactDetails, $contactID, 'CRM_UpdateGreeting');
$greetingString = CRM_Core_DAO::escapeString($greetingString);
$cacheFieldQuery .= " WHEN {$contactID} THEN '{$greetingString}' ";
$allContactIds[] = $contactID;
}
if (!empty($allContactIds)) {
$cacheFieldQuery .= " ELSE {$greeting}_display\n END;";
if (!empty($contactIds)) {
// need to update greeting _id field.
// reset greeting _custom
$resetCustomGreeting = '';
//.........这里部分代码省略.........
示例12: escape
/**
* Verify that a variable is of a given type, and apply a bit of processing.
*
* @param mixed $data
* The value to be verified/escaped.
* @param string $type
* The type to verify against.
* @param bool $abort
* If TRUE, the operation will CRM_Core_Error::fatal() on invalid data.
*
* @return mixed
* The data, escaped if necessary.
*/
public static function escape($data, $type, $abort = TRUE)
{
switch ($type) {
case 'Integer':
case 'Int':
if (CRM_Utils_Rule::integer($data)) {
return (int) $data;
}
break;
case 'Positive':
// CRM-8925 the 3 below are for custom fields of this type
// CRM-8925 the 3 below are for custom fields of this type
case 'Country':
case 'StateProvince':
// Checked for multi valued state/country value
if (is_array($data)) {
$returnData = TRUE;
// @todo Reuse of the $data variable = asking for trouble.
// @todo This code will always return the last item in the array. Intended?
foreach ($data as $data) {
if (CRM_Utils_Rule::positiveInteger($data) || CRM_Core_DAO::escapeString($data)) {
$returnData = TRUE;
} else {
$returnData = FALSE;
}
}
if ($returnData) {
return $data;
}
} elseif (!is_numeric($data) && CRM_Core_DAO::escapeString($data)) {
return $data;
} elseif (CRM_Utils_Rule::positiveInteger($data)) {
return $data;
}
break;
case 'File':
if (CRM_Utils_Rule::positiveInteger($data)) {
return $data;
}
break;
case 'Link':
if (CRM_Utils_Rule::url($data = trim($data))) {
return $data;
}
break;
case 'Boolean':
if (CRM_Utils_Rule::boolean($data)) {
return $data;
}
break;
case 'Float':
case 'Money':
if (CRM_Utils_Rule::numeric($data)) {
return $data;
}
break;
case 'String':
case 'Memo':
case 'Text':
return CRM_Core_DAO::escapeString($data);
case 'Date':
case 'Timestamp':
// a null date or timestamp is valid
if (strlen(trim($data)) == 0) {
return trim($data);
}
if ((preg_match('/^\\d{8}$/', $data) || preg_match('/^\\d{14}$/', $data)) && CRM_Utils_Rule::mysqlDate($data)) {
return $data;
}
break;
case 'ContactReference':
if (strlen(trim($data)) == 0) {
return trim($data);
}
if (CRM_Utils_Rule::validContact($data)) {
return $data;
}
break;
default:
CRM_Core_Error::fatal($type . " is not a recognised (camel cased) data type.");
break;
}
// @todo Use exceptions instead of CRM_Core_Error::fatal().
if ($abort) {
$data = htmlentities($data);
CRM_Core_Error::fatal("{$data} is not of the type {$type}");
}
//.........这里部分代码省略.........
示例13: getGroups
/**
* Returns array of group object(s) matching a set of one or Group properties.
*
* @param array $params
* Limits the set of groups returned.
* @param array $returnProperties
* Which properties should be included in the returned group objects.
* (member_count should be last element.)
* @param string $sort
* @param int $offset
* @param int $rowCount
*
* @return array
* Array of group objects.
*
*
* @todo other BAO functions that use returnProperties (e.g. Query Objects) receive the array flipped & filled with 1s and
* add in essential fields (e.g. id). This should follow a regular pattern like the others
*/
public static function getGroups($params = NULL, $returnProperties = NULL, $sort = NULL, $offset = NULL, $rowCount = NULL)
{
$dao = new CRM_Contact_DAO_Group();
if (!isset($params['is_active'])) {
$dao->is_active = 1;
}
if ($params) {
foreach ($params as $k => $v) {
if ($k == 'name' || $k == 'title') {
$dao->whereAdd($k . ' LIKE "' . CRM_Core_DAO::escapeString($v) . '"');
} elseif ($k == 'group_type') {
foreach ((array) $v as $type) {
$dao->whereAdd($k . " LIKE '%" . CRM_Core_DAO::VALUE_SEPARATOR . (int) $type . CRM_Core_DAO::VALUE_SEPARATOR . "%'");
}
} elseif (is_array($v)) {
foreach ($v as &$num) {
$num = (int) $num;
}
$dao->whereAdd($k . ' IN (' . implode(',', $v) . ')');
} else {
$dao->{$k} = $v;
}
}
}
if ($offset || $rowCount) {
$offset = $offset > 0 ? $offset : 0;
$rowCount = $rowCount > 0 ? $rowCount : 25;
$dao->limit($offset, $rowCount);
}
if ($sort) {
$dao->orderBy($sort);
}
// return only specific fields if returnproperties are sent
if (!empty($returnProperties)) {
$dao->selectAdd();
$dao->selectAdd(implode(',', $returnProperties));
}
$dao->find();
$flag = $returnProperties && in_array('member_count', $returnProperties) ? 1 : 0;
$groups = array();
while ($dao->fetch()) {
$group = new CRM_Contact_DAO_Group();
if ($flag) {
$dao->member_count = CRM_Contact_BAO_Group::memberCount($dao->id);
}
$groups[] = clone $dao;
}
return $groups;
}
示例14: hasCustomGroup
/**
* Determine if given entity (sub)type has any custom groups
*
* @param string $extends
* E.g. "Individual", "Activity".
* @param int $columnId
* E.g. custom-group matching mechanism (usu NULL for matching on sub type-id); see extends_entity_column_id.
* @param string $columnValue
* E.g. "Student" or "3" or "3\05"; see extends_entity_column_value.
*
* @return bool
*/
public static function hasCustomGroup($extends, $columnId, $columnValue)
{
$dao = new CRM_Core_DAO_CustomGroup();
$dao->extends = $extends;
$dao->extends_entity_column_id = $columnId;
$escapedValue = CRM_Core_DAO::VALUE_SEPARATOR . CRM_Core_DAO::escapeString($columnValue) . CRM_Core_DAO::VALUE_SEPARATOR;
$dao->whereAdd("extends_entity_column_value LIKE \"%{$escapedValue}%\"");
//$dao->extends_entity_column_value = $columnValue;
return $dao->find() ? TRUE : FALSE;
}
示例15: whereClauseSingle
static function whereClauseSingle(&$values, &$query)
{
list($name, $op, $value, $grouping, $wildcard) = $values;
switch ($name) {
case 'member_join_date_low':
case 'member_join_date_high':
$query->dateQueryBuilder($values, 'civicrm_membership', 'member_join_date', 'join_date', 'Join Date', false);
return;
case 'member_start_date_low':
case 'member_start_date_high':
$query->dateQueryBuilder($values, 'civicrm_membership', 'member_start_date', 'start_date', 'Start Date', false);
return;
case 'member_end_date_low':
case 'member_end_date_high':
$query->dateQueryBuilder($values, 'civicrm_membership', 'member_end_date', 'end_date', 'End Date', false);
return;
case 'member_join_date':
$op = '>=';
$date = CRM_Utils_Date::format($value);
if ($date) {
$query->_where[$grouping][] = "civicrm_membership.join_date {$op} {$date}";
$date = CRM_Utils_Date::customFormat($value);
$format = CRM_Utils_Date::customFormat(CRM_Utils_Date::format(array_reverse($value), '-'));
$query->_qill[$grouping][] = ts('Member Since %2 %1', array(1 => $format, 2 => $op));
}
return;
case 'member_source':
$value = strtolower(CRM_Core_DAO::escapeString(trim($value)));
$query->_where[$grouping][] = "civicrm_membership.source {$op} '{$value}'";
$query->_qill[$grouping][] = ts('Source %2 %1', array(1 => $value, 2 => $op));
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
case 'member_status_id':
require_once 'CRM/Member/PseudoConstant.php';
$status = implode(',', array_keys($value));
if (count($value) > 1) {
$op = 'IN';
$status = "({$status})";
}
$names = array();
$statusTypes = CRM_Member_PseudoConstant::membershipStatus();
foreach ($value as $id => $dontCare) {
$names[] = $statusTypes[$id];
}
$query->_qill[$grouping][] = ts('Membership Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
$query->_where[$grouping][] = "civicrm_membership.status_id {$op} {$status}";
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
case 'member_test':
$query->_where[$grouping][] = " civicrm_membership.is_test {$op} {$value}";
if ($value) {
$query->_qill[$grouping][] = "Find Test Memberships";
}
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
case 'member_pay_later':
$query->_where[$grouping][] = " civicrm_membership.is_pay_later {$op} {$value}";
if ($value) {
$query->_qill[$grouping][] = "Find Pay Later Memberships";
}
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
case 'member_membership_type_id':
require_once 'CRM/Member/PseudoConstant.php';
$mType = implode(',', array_keys($value));
if (count($value) > 1) {
$op = 'IN';
$mType = "({$mType})";
}
$names = array();
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
foreach ($value as $id => $dontCare) {
$names[] = $membershipTypes[$id];
}
$query->_qill[$grouping][] = ts('Membership Type %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
$query->_where[$grouping][] = "civicrm_membership.membership_type_id {$op} {$mType}";
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
case 'member_id':
$query->_where[$grouping][] = " civicrm_membership.id {$op} {$value}";
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
case 'member_is_primary':
switch ($value) {
case 1:
$query->_qill[$grouping][] = "Primary AND Related Members";
break;
case 2:
$query->_where[$grouping][] = " civicrm_membership.owner_membership_id IS NULL";
$query->_qill[$grouping][] = "Primary Members Only";
break;
case 3:
$query->_where[$grouping][] = " civicrm_membership.owner_membership_id IS NOT NULL";
$query->_qill[$grouping][] = "Related Members Only";
break;
}
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
return;
}
}