本文整理汇总了PHP中CRM_Utils_Type::typeToString方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Type::typeToString方法的具体用法?PHP CRM_Utils_Type::typeToString怎么用?PHP CRM_Utils_Type::typeToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Type
的用法示例。
在下文中一共展示了CRM_Utils_Type::typeToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTypedValue
/**
* @param string $name
* @param $type
*
* @return mixed|null
*/
public static function getTypedValue($name, $type)
{
$value = CRM_Utils_Array::value($name, $_GET);
if ($value === NULL) {
return NULL;
}
return CRM_Utils_Type::escape($value, CRM_Utils_Type::typeToString($type), FALSE);
}
示例2: getTypedValue
static function getTypedValue($name, $type)
{
$value = CRM_Utils_Array::value($name, $_GET);
if ($value === null) {
return null;
}
return CRM_Utils_Type::escape($value, CRM_Utils_Type::typeToString($type), false);
}
示例3: restWhere
//.........这里部分代码省略.........
$this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
$this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
} elseif ($name === 'current_employer') {
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
$value = "%{$value}%";
$op = 'LIKE';
}
$wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
$ceWhereClause = self::buildClause($wc, $op, $value);
$ceWhereClause .= " AND contact_a.contact_type = 'Individual'";
$this->_where[$grouping][] = $ceWhereClause;
$this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
} elseif ($name === 'email_greeting') {
$filterCondition = array('greeting_type' => 'email_greeting');
$this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting'));
} elseif ($name === 'postal_greeting') {
$filterCondition = array('greeting_type' => 'postal_greeting');
$this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting'));
} elseif ($name === 'addressee') {
$filterCondition = array('greeting_type' => 'addressee');
$this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee'));
} elseif (substr($name, 0, 4) === 'url-') {
$tName = 'civicrm_website';
$this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
$value = "%{$value}%";
$op = 'LIKE';
}
$wc = 'civicrm_website.url';
$this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value);
$this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
} elseif ($name === 'contact_is_deleted') {
$this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(NULL, $name, $value, $op);
$this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['title'], 2 => $qillop, 3 => $qillVal));
} elseif (!empty($field['where'])) {
$type = NULL;
if (!empty($field['type'])) {
$type = CRM_Utils_Type::typeToString($field['type']);
}
list($tableName, $fieldName) = explode('.', $field['where'], 2);
if (isset($locType[1]) && is_numeric($locType[1])) {
$setTables = FALSE;
//get the location name
list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
$fieldName = "LOWER(`{$tName}`.{$fldName})";
// we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should
$this->_tables[$tName] = $this->_whereTables[$tName] = 1;
} else {
if ($tableName == 'civicrm_contact') {
$fieldName = "LOWER(contact_a.{$fieldName})";
} else {
if ($op != 'IN' && !is_numeric($value)) {
$fieldName = "LOWER({$field['where']})";
} else {
$fieldName = "{$field['where']}";
}
}
}
list($qillop, $qillVal) = self::buildQillForFieldValue(NULL, $field['title'], $value, $op);
$this->_qill[$grouping][] = ts("%1 %2 %3", array(1 => $field['title'], 2 => $qillop, 3 => strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE ? $qillVal : "'{$qillVal}'"));
if (is_array($value)) {
// traditionally an array being passed has been a fatal error. We can take advantage of this to add support
// for api style operators for functions that hit this point without worrying about regression
// (the previous comments indicated the condition for hitting this point were unknown
// per CRM-14743 we are adding modified_date & created_date operator support
$operations = array_keys($value);
foreach ($operations as $operator) {
if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) {
//Via Contact get api value is not in array(operator => array(values)) format ONLY for IN/NOT IN operators
//so this condition will satisfy the search for now
if (strpos($op, 'IN') !== FALSE) {
$value = array($op => $value);
} else {
CRM_Core_Error::fatal(ts("%1 is not a valid operator", array(1 => $operator)));
}
}
}
$this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($fieldName, $value, $type);
} else {
if (!strpos($op, 'IN')) {
$value = $strtolower($value);
}
if ($wildcard) {
$value = "%{$value}%";
$op = 'LIKE';
}
$this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
}
}
if ($setTables && isset($field['where'])) {
list($tableName, $fieldName) = explode('.', $field['where'], 2);
if (isset($tableName)) {
$this->_tables[$tableName] = 1;
$this->_whereTables[$tableName] = 1;
}
}
}
示例4: formRule
/**
* global validation rules for the form
*
* @param array $fields posted values of the form
*
* @return array list of errors to be posted back to the form
* @static
* @access public
*/
static function formRule($values, $files, $self)
{
if (CRM_Utils_Array::value('addMore', $values) || CRM_Utils_Array::value('addBlock', $values)) {
return TRUE;
}
$fields = self::fields();
$fld = CRM_Core_BAO_Mapping::formattedFields($values, TRUE);
$errorMsg = array();
foreach ($fld as $k => $v) {
if (!$v[1]) {
$errorMsg["operator[{$v['3']}][{$v['4']}]"] = ts("Please enter the operator.");
} else {
// CRM-10338
$v[2] = self::checkArrayKeyEmpty($v[2]);
if (in_array($v[1], array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY')) && !empty($v[2])) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts('Please clear your value if you want to use %1 operator.', array(1 => $v[1]));
} elseif (($v[0] == 'group' || $v[0] == 'tag') && !empty($v[2])) {
$grpId = array_keys($v[2]);
if (!key($v[2])) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter a value.");
}
if (count($grpId) > 1) {
if ($v[1] != 'IN' && $v[1] != 'NOT IN') {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter a valid value.");
}
foreach ($grpId as $val) {
$error = CRM_Utils_Type::validate($val, 'Integer', FALSE);
if ($error != $val) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter valid value.");
break;
}
}
} else {
$error = CRM_Utils_Type::validate($grpId[0], 'Integer', FALSE);
if ($error != $grpId[0]) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts('Please enter valid %1 id.', array(1 => $v[0]));
}
}
} elseif (substr($v[0], 0, 7) === 'do_not_' or substr($v[0], 0, 3) === 'is_') {
if (isset($v[2])) {
$v2 = array($v[2]);
if (!isset($v[2])) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter a value.");
}
$error = CRM_Utils_Type::validate($v2[0], 'Integer', FALSE);
if ($error != $v2[0]) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter a valid value.");
}
} else {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter a value.");
}
} else {
if (substr($v[0], 0, 7) == 'custom_') {
// Get rid of appended location type id
list($fieldKey) = explode('-', $v[0]);
$type = $fields[$fieldKey]['data_type'];
// hack to handle custom data of type state and country
if (in_array($type, array('Country', 'StateProvince'))) {
$type = "Integer";
}
} else {
$fldName = $v[0];
// FIXME: no idea at this point what to do with this,
// FIXME: but definitely needs fixing.
if (substr($v[0], 0, 13) == 'contribution_') {
$fldName = substr($v[0], 13);
}
$fldValue = CRM_Utils_Array::value($fldName, $fields);
$fldType = CRM_Utils_Array::value('type', $fldValue);
$type = CRM_Utils_Type::typeToString($fldType);
// Check Empty values for Integer Or Boolean Or Date type For operators other than IS NULL and IS NOT NULL.
if (!in_array($v[1], array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))) {
if (($type == 'Int' || $type == 'Boolean') && !trim($v[2]) && $v[2] != '0') {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter a value.");
} elseif ($type == 'Date' && !trim($v[2])) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter a value.");
}
}
}
if ($type && empty($errorMsg)) {
// check for valid format while using IN Operator
if ($v[1] == 'IN') {
$inVal = trim($v[2]);
//checking for format to avoid db errors
if ($type == 'Int') {
if (!preg_match('/^[(]([A-Za-z0-9\\,]+)[)]$/', $inVal)) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter correct Data (in valid format).");
}
} else {
if (!(substr($inVal, 0, 1) == '(' && substr($inVal, -1, 1) == ')') && !preg_match('/^[(]([A-Za-z0-9åäöÅÄÖüÜœŒæÆøØ\\,\\s]+)[)]$/', $inVal)) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter correct Data (in valid format).");
//.........这里部分代码省略.........
示例5: str_replace
/**
* Execute a weight-related query
*
* @param string $queryType SELECT, UPDATE, DELETE
* @param string $daoName full name of the DAO
* @param array $fieldValues field => value to be used in the WHERE
* @param string $queryData data to be used, dependent on the query type
* @param string $orderBy optional ORDER BY field
* @return Object CRM_Core_DAO objet that holds the results of the query
*/
static function &query($queryType, $daoName, $fieldValues = null, $queryData, $additionalWhere = null, $orderBy = null, $groupBy = null)
{
require_once 'CRM/Utils/Type.php';
require_once str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php";
$dao =& new $daoName();
$table = $dao->getTablename();
$fields =& $dao->fields();
$fieldlist = array_keys($fields);
$whereConditions = array();
if ($additionalWhere) {
$whereConditions[] = $additionalWhere;
}
$params = array();
$fieldNum = 0;
if (is_array($fieldValues)) {
foreach ($fieldValues as $fieldName => $value) {
if (!in_array($fieldName, $fieldlist)) {
// invalid field specified. abort.
return false;
}
$fieldNum++;
$whereConditions[] = "{$fieldName} = %{$fieldNum}";
$fieldType = $fields[$fieldName]['type'];
$params[$fieldNum] = array($value, CRM_Utils_Type::typeToString($fieldType));
}
}
$where = implode(' AND ', $whereConditions);
switch ($queryType) {
case 'SELECT':
$query = "SELECT {$queryData} FROM {$table}";
if ($where) {
$query .= " WHERE {$where}";
}
if ($groupBy) {
$query .= " GROUP BY {$groupBy}";
}
if ($orderBy) {
$query .= " ORDER BY {$orderBy}";
}
break;
case 'UPDATE':
$query = "UPDATE {$table} SET {$queryData}";
if ($where) {
$query .= " WHERE {$where}";
}
break;
case 'DELETE':
$query = "DELETE FROM {$table} WHERE {$where} AND {$queryData}";
break;
default:
return false;
}
$resultDAO = CRM_Core_DAO::executeQuery($query, $params);
return $resultDAO;
}
示例6: retrieve
/**
* Get a list of Assignments matching the params, where each param key is:
* 1. the key of a field in civicrm_activity
* except for activity_type_id and activity_duration
* 2. the key of a custom field on the activity
* (volunteer_need_id, time_scheduled, time_completed)
* 3. the key of a field in civicrm_contact
* 4. project_id
*
* @param array $params
* @return array of CRM_Volunteer_BAO_Project objects
*/
static function retrieve(array $params)
{
$activity_fields = CRM_Activity_DAO_Activity::fields();
$contact_fields = CRM_Contact_DAO_Contact::fields();
$custom_fields = self::getCustomFields();
$foreign_fields = array('project_id', 'target_contact_id');
// This is the "real" id
$activity_fields['id'] = $activity_fields['activity_id'];
unset($activity_fields['activity_id']);
// enforce restrictions on parameters
$allowed_params = array_flip(array_merge(array_keys($activity_fields), array_keys($contact_fields), array_keys($custom_fields), $foreign_fields));
unset($allowed_params['activity_type_id']);
unset($allowed_params['activity_duration']);
$filtered_params = array_intersect_key($params, $allowed_params);
$custom_group = self::getCustomGroup();
$customTableName = $custom_group['table_name'];
foreach ($custom_fields as $name => $field) {
$selectClause[] = "{$customTableName}.{$field['column_name']} AS {$name}";
}
$customSelect = implode(', ', $selectClause);
$activityContactTypes = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContactTypes);
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContactTypes);
$volunteerStatus = CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate');
$available = CRM_Utils_Array::key('Available', $volunteerStatus);
$scheduled = CRM_Utils_Array::key('Scheduled', $volunteerStatus);
$placeholders = array(1 => array($assigneeID, 'Integer'), 2 => array(self::volunteerActivityTypeId(), 'Integer'), 3 => array($scheduled, 'Integer'), 4 => array($available, 'Integer'), 5 => array($targetID, 'Integer'));
$i = count($placeholders) + 1;
$where = array();
$whereClause = NULL;
foreach ($filtered_params as $key => $value) {
if (CRM_Utils_Array::value($key, $activity_fields)) {
$dataType = CRM_Utils_Type::typeToString($activity_fields[$key]['type']);
$fieldName = $activity_fields[$key]['name'];
$tableName = CRM_Activity_DAO_Activity::$_tableName;
} elseif (CRM_Utils_Array::value($key, $contact_fields)) {
$dataType = CRM_Utils_Type::typeToString($contact_fields[$key]['type']);
$fieldName = $contact_fields[$key]['name'];
$tableName = CRM_Contact_DAO_Contact::$_tableName;
} elseif (CRM_Utils_Array::value($key, $custom_fields)) {
$dataType = $custom_fields[$key]['data_type'];
$fieldName = $custom_fields[$key]['column_name'];
$tableName = $customTableName;
} elseif ($key == 'project_id') {
$dataType = 'Int';
$fieldName = 'id';
$tableName = CRM_Volunteer_DAO_Project::$_tableName;
} elseif ($key == 'target_contact_id') {
$dataType = 'Int';
$fieldName = 'contact_id';
$tableName = 'tgt';
// this is an alias for civicrm_activity_contact
}
$where[] = "{$tableName}.{$fieldName} = %{$i}";
$placeholders[$i] = array($value, $dataType);
$i++;
}
if (count($where)) {
$whereClause = 'AND ' . implode("\nAND ", $where);
}
$query = "\n SELECT\n civicrm_activity.*,\n assignee.contact_id AS assignee_contact_id,\n {$customSelect},\n civicrm_volunteer_need.start_time,\n civicrm_volunteer_need.is_flexible,\n civicrm_volunteer_need.role_id,\n assignee_contact.sort_name AS assignee_sort_name,\n assignee_contact.display_name AS assignee_display_name,\n assignee_phone.phone AS assignee_phone,\n assignee_phone.phone_ext AS assignee_phone_ext,\n assignee_email.email AS assignee_email,\n -- begin target contact fields\n tgt.contact_id AS target_contact_id,\n tgt_contact.sort_name AS target_sort_name,\n tgt_contact.display_name AS target_display_name,\n tgt_phone.phone AS target_phone,\n tgt_phone.phone_ext AS target_phone_ext,\n tgt_email.email AS target_email\n -- end target contact fields\n FROM civicrm_activity\n INNER JOIN civicrm_activity_contact assignee\n ON (\n assignee.activity_id = civicrm_activity.id\n AND assignee.record_type_id = %1\n )\n INNER JOIN civicrm_contact assignee_contact\n ON assignee.contact_id = assignee_contact.id\n LEFT JOIN civicrm_email assignee_email\n ON assignee_email.contact_id = assignee_contact.id AND assignee_email.is_primary = 1\n LEFT JOIN civicrm_phone assignee_phone\n ON assignee_phone.contact_id = assignee_contact.id AND assignee_phone.is_primary = 1\n -- begin target contact joins\n LEFT JOIN civicrm_activity_contact tgt\n ON (\n tgt.activity_id = civicrm_activity.id\n AND tgt.record_type_id = %5\n )\n LEFT JOIN civicrm_contact tgt_contact\n ON tgt.contact_id = tgt_contact.id\n LEFT JOIN civicrm_email tgt_email\n ON tgt_email.contact_id = tgt_contact.id AND tgt_email.is_primary = 1\n LEFT JOIN civicrm_phone tgt_phone\n ON tgt_phone.contact_id = tgt_contact.id AND tgt_phone.is_primary = 1\n -- end target contact joins\n INNER JOIN {$customTableName}\n ON ({$customTableName}.entity_id = civicrm_activity.id)\n INNER JOIN civicrm_volunteer_need\n ON (civicrm_volunteer_need.id = {$customTableName}.{$custom_fields['volunteer_need_id']['column_name']})\n INNER JOIN civicrm_volunteer_project\n ON (civicrm_volunteer_project.id = civicrm_volunteer_need.project_id)\n WHERE civicrm_activity.activity_type_id = %2\n AND civicrm_activity.status_id IN (%3, %4 )\n {$whereClause}\n ";
$dao = CRM_Core_DAO::executeQuery($query, $placeholders);
$rows = array();
while ($dao->fetch()) {
$rows[$dao->id] = $dao->toArray();
}
/*
* For clarity we want the fields associated with each contact prefixed with
* the contact type (e.g., target_phone). For backwards compatibility,
* however, we want the fields associated with each assignee contact to be
* accessible sans prefix. Eventually we should deprecate the non-prefixed
* field names.
*/
foreach ($rows as $id => $fields) {
foreach ($fields as $key => $value) {
if (substr($key, 0, 9) == 'assignee_') {
$rows[$id][substr($key, 9)] = $value;
}
}
}
return $rows;
}
示例7: foreach
/**
* make a shallow copy of an object.
* and all the fields in the object
*
* @param string $daoName
* Name of the dao.
* @param array $criteria
* Array of all the fields & values.
* on which basis to copy
* @param array $newData
* Array of all the fields & values.
* to be copied besides the other fields
* @param string $fieldsFix
* Array of fields that you want to prefix/suffix/replace.
* @param string $blockCopyOfDependencies
* Fields that you want to block from.
* getting copied
*
*
* @return CRM_Core_DAO
* the newly created copy of the object
*/
public static function ©Generic($daoName, $criteria, $newData = NULL, $fieldsFix = NULL, $blockCopyOfDependencies = NULL)
{
$object = new $daoName();
if (!$newData) {
$object->id = $criteria['id'];
} else {
foreach ($criteria as $key => $value) {
$object->{$key} = $value;
}
}
$object->find();
while ($object->fetch()) {
// all the objects except with $blockCopyOfDependencies set
// be copied - addresses #CRM-1962
if ($blockCopyOfDependencies && $object->{$blockCopyOfDependencies}) {
break;
}
$newObject = new $daoName();
$fields =& $object->fields();
if (!is_array($fieldsFix)) {
$fieldsToPrefix = array();
$fieldsToSuffix = array();
$fieldsToReplace = array();
}
if (!empty($fieldsFix['prefix'])) {
$fieldsToPrefix = $fieldsFix['prefix'];
}
if (!empty($fieldsFix['suffix'])) {
$fieldsToSuffix = $fieldsFix['suffix'];
}
if (!empty($fieldsFix['replace'])) {
$fieldsToReplace = $fieldsFix['replace'];
}
foreach ($fields as $name => $value) {
if ($name == 'id' || $value['name'] == 'id') {
// copy everything but the id!
continue;
}
$dbName = $value['name'];
$type = CRM_Utils_Type::typeToString($value['type']);
$newObject->{$dbName} = $object->{$dbName};
if (isset($fieldsToPrefix[$dbName])) {
$newObject->{$dbName} = $fieldsToPrefix[$dbName] . $newObject->{$dbName};
}
if (isset($fieldsToSuffix[$dbName])) {
$newObject->{$dbName} .= $fieldsToSuffix[$dbName];
}
if (isset($fieldsToReplace[$dbName])) {
$newObject->{$dbName} = $fieldsToReplace[$dbName];
}
if ($type == 'Timestamp' || $type == 'Date') {
$newObject->{$dbName} = CRM_Utils_Date::isoToMysql($newObject->{$dbName});
}
if ($newData) {
foreach ($newData as $k => $v) {
$newObject->{$k} = $v;
}
}
}
$newObject->save();
}
return $newObject;
}
示例8: whereClauseSingle
//.........这里部分代码省略.........
}
if (!empty($allEventIds)) {
$op = "IN";
$value = "(" . implode(",", $allEventIds) . ")";
}
}
$query->_where[$grouping][] = "civicrm_event.id {$op} {$value}";
$query->_qill[$grouping][] = ts('Include Repeating Events');
$query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1;
return;
case 'participant_is_test':
$key = array_search('civicrm_participant.is_test = 0', $query->_where[$grouping]);
if (!empty($key)) {
unset($query->_where[$grouping][$key]);
}
case 'participant_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_participant.is_test", $op, $value, "Boolean");
if ($value) {
$query->_qill[$grouping][] = ts("Participant is a Test");
}
$query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
}
return;
case 'participant_fee_id':
$feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $value, 'label');
$feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel));
if ($value) {
$query->_where[$grouping][] = "civicrm_participant.fee_level LIKE '%{$feeLabel}%'";
$query->_qill[$grouping][] = ts("Fee level") . " contains {$feeLabel}";
}
$query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
return;
case 'participant_fee_amount_high':
case 'participant_fee_amount_low':
$query->numberRangeBuilder($values, 'civicrm_participant', 'participant_fee_amount', 'fee_amount', 'Fee Amount');
return;
case 'participant_status_id':
case 'participant_role_id':
if ($value && is_array($value) && strpos($op, 'IN') === FALSE) {
$op = 'IN';
}
case 'participant_status':
case 'participant_role':
case 'participant_source':
case 'participant_id':
case 'participant_contact_id':
case 'participant_is_pay_later':
case 'participant_fee_amount':
case 'participant_fee_level':
$qillName = $name;
if (in_array($name, array('participant_status_id', 'participant_role_id', 'participant_source', 'participant_id', 'participant_contact_id', 'participant_fee_amount', 'participant_fee_level', 'participant_is_pay_later'))) {
$name = str_replace('participant_', '', $name);
if ($name == 'is_pay_later') {
$qillName = $name;
}
if ($name == 'role_id') {
$qillName = 'participant_role';
$query->_where[$grouping][] = " civicrm_participant.{$name} REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', (array) $value) . "[[:>:]]' ";
}
}
$dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
if (in_array($name, array('participant_status', 'participant_role'))) {
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("{$name}.label", $op, $value, $dataType);
} elseif ($name != 'role_id') {
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.{$name}", $op, $value, $dataType);
}
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
return;
case 'participant_register_date':
$query->dateQueryBuilder($values, 'civicrm_participant', 'participant_register_date', 'register_date', 'Register Date');
return;
case 'event_id':
case 'participant_event_id':
$name = str_replace('participant_', '', $name);
case 'event_is_public':
case 'event_type_id':
case 'event_title':
$qillName = $name;
if (in_array($name, array('event_id', 'event_title', 'event_is_public'))) {
$name = str_replace('event_', '', $name);
}
$dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_event.{$name}", $op, $value, $dataType);
$query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1;
if (!array_key_exists($qillName, $fields)) {
break;
}
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
return;
case 'participant_campaign_id':
$campParams = array('op' => $op, 'campaign' => $value, 'grouping' => $grouping, 'tableName' => 'civicrm_participant');
CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query);
return;
}
}
示例9: whereClauseSingle
/**
* @param $values
* @param $query
*/
public static function whereClauseSingle(&$values, &$query)
{
list($name, $op, $value, $grouping, $wildcard) = $values;
$quoteValue = NULL;
$fields = array_merge(CRM_Contribute_BAO_Contribution::fields(), self::getFields());
if (!empty($value) && !is_array($value)) {
$quoteValue = "\"{$value}\"";
}
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
foreach (self::getRecurringFields() as $dateField => $dateFieldTitle) {
if (self::buildDateWhere($values, $query, $name, $dateField, $dateFieldTitle)) {
return;
}
}
switch ($name) {
case 'contribution_date':
case 'contribution_date_low':
case 'contribution_date_low_time':
case 'contribution_date_high':
case 'contribution_date_high_time':
// process to / from date
$query->dateQueryBuilder($values, 'civicrm_contribution', 'contribution_date', 'receive_date', 'Contribution Date');
return;
case 'contribution_amount':
case 'contribution_amount_low':
case 'contribution_amount_high':
// process min/max amount
$query->numberRangeBuilder($values, 'civicrm_contribution', 'contribution_amount', 'total_amount', 'Contribution Amount', NULL);
return;
case 'contribution_thankyou_date_is_not_null':
if ($value) {
$op = "IS NOT NULL";
$query->_qill[$grouping][] = ts('Contribution Thank-you Sent');
} else {
$op = "IS NULL";
$query->_qill[$grouping][] = ts('Contribution Thank-you Not Sent');
}
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.thankyou_date", $op);
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
case 'contribution_receipt_date_is_not_null':
if ($value) {
$op = "IS NOT NULL";
$query->_qill[$grouping][] = ts('Contribution Receipt Sent');
} else {
$op = "IS NULL";
$query->_qill[$grouping][] = ts('Contribution Receipt Not Sent');
}
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.receipt_date", $op);
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
case 'financial_type':
case 'contribution_page':
case 'payment_instrument':
case 'contribution_payment_instrument':
case 'contribution_status':
$name .= '_id';
case 'financial_type_id':
case 'payment_instrument_id':
case 'contribution_payment_instrument_id':
case 'contribution_page_id':
case 'contribution_status_id':
case 'contribution_id':
case 'contribution_currency_type':
case 'contribution_currency':
case 'contribution_source':
case 'contribution_trxn_id':
case 'contribution_check_number':
case 'contribution_contact_id':
case strpos($name, '_amount') !== FALSE:
case strpos($name, '_date') !== FALSE:
$qillName = $name;
$pseudoExtraParam = NULL;
if (strpos($name, '_amount') !== FALSE || strpos($name, '_date') !== FALSE || in_array($name, array('contribution_id', 'contribution_currency', 'contribution_source', 'contribution_trxn_id', 'contribution_check_number', 'contribution_payment_instrument_id', 'contribution_contact_id'))) {
$name = str_replace('contribution_', '', $name);
if (!in_array($name, array('source', 'id', 'contact_id'))) {
$qillName = str_replace('contribution_', '', $qillName);
}
}
if (in_array($name, array('contribution_currency', 'contribution_currency_type'))) {
$qillName = $name = 'currency';
$pseudoExtraParam = array('labelColumn' => 'name');
}
$dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.{$name}", $op, $value, $dataType);
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op, $pseudoExtraParam);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
case 'contribution_pcp_made_through_id':
case 'contribution_soft_credit_type_id':
$qillName = $name;
if ($name == 'contribution_pcp_made_through_id') {
$qillName = $name = 'pcp_id';
$fields[$name] = array('title' => ts('Personal Campaign Page'), 'type' => 2);
}
//.........这里部分代码省略.........
示例10: formRule
/**
* global validation rules for the form
*
* @param array $fields posted values of the form
*
* @return array list of errors to be posted back to the form
* @static
* @access public
*/
static function formRule(&$values)
{
//CRM_Core_Error::debug('s', $values);
if (CRM_Utils_Array::value('addMore', $values) || CRM_Utils_Array::value('addBlock', $values)) {
return true;
}
require_once 'CRM/Contact/BAO/Contact.php';
$fields = array();
$fields = CRM_Contact_BAO_Contact::exportableFields('All', false, true);
require_once 'CRM/Core/Component.php';
$compomentFields =& CRM_Core_Component::getQueryFields();
$fields = array_merge($fields, $compomentFields);
$fld = array();
$fld = CRM_Core_BAO_Mapping::formattedFields($values, true);
require_once 'CRM/Utils/Type.php';
$errorMsg = array();
foreach ($fld as $k => $v) {
if (!$v[1]) {
$errorMsg["operator[{$v['3']}][{$v['4']}]"] = ts("Please enter the operator.");
} else {
if (in_array($v[1], array('IS NULL', 'IS NOT NULL')) && $v[2]) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts('Please clear your value if you want to use %1 operator.', array(1 => $v[1]));
} else {
if ($v[0] == 'group' || $v[0] == 'tag') {
$grpId = array_keys($v[2]);
if (!key($v[2])) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
}
if (count($grpId) > 1) {
if ($v[1] != 'IN' && $v[1] != 'NOT IN') {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the valid value.");
}
foreach ($grpId as $val) {
$error = CRM_Utils_Type::validate($val, 'Integer', false);
if ($error != $val) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter valid value.");
break;
}
}
} else {
$error = CRM_Utils_Type::validate($grpId[0], 'Integer', false);
if ($error != $grpId[0]) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts('Please enter valid %1 id.', array(1 => $v[0]));
}
}
} else {
if (substr($v[0], 0, 7) === 'do_not_' or substr($v[0], 0, 3) === 'is_') {
if ($v[2]) {
$v2 = array($v[2]);
if (!isset($v[2])) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
}
$error = CRM_Utils_Type::validate($v2[0], 'Integer', false);
if ($error != $v2[0]) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter valid value.");
}
} else {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
}
} else {
if ($v[0] === 'sort_name' || $v[0] === 'display_name') {
$v2 = trim($v[2]);
if (empty($v2)) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
}
} else {
if (substr($v[0], 0, 7) == 'custom_') {
$type = $fields[$v[0]]['data_type'];
// hack to handle custom data of type state and country
if (in_array($type, array('Country', 'StateProvince'))) {
$type = "Integer";
}
} else {
$fldName = $v[0];
// FIXME: no idea at this point what to do with this,
// FIXME: but definitely needs fixing.
if (substr($v[0], 0, 13) == 'contribution_') {
$fldName = substr($v[0], 13);
}
$fldType = CRM_Utils_Array::value('type', $fields[$fldName]);
$type = CRM_Utils_Type::typeToString($fldType);
// Check Empty values for Integer Or Boolean Or Date type For operators other than IS NULL and IS NOT NULL.
if (!in_array($v[1], array('IS NULL', 'IS NOT NULL'))) {
if (($type == 'Int' || $type == 'Boolean') && !trim($v[2]) && $v[2] != '0') {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
} else {
if ($type == 'Date' && !trim($v[2])) {
$errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
}
}
}
//.........这里部分代码省略.........
示例11: retrieve
/**
* Get a list of Commendations matching the params, where each param key is:
* 1. the key of a field in civicrm_activity, except for activity_type_id
* 2. the key of a custom field on the activity (volunteer_project_id)
* 3. the key of a field in civicrm_contact
*
* @param array $params
* @return array of CRM_Volunteer_BAO_Project objects
*/
public static function retrieve(array $params)
{
$activity_fields = CRM_Activity_DAO_Activity::fields();
$contact_fields = CRM_Contact_DAO_Contact::fields();
$custom_fields = self::getCustomFields();
// This is the "real" id
$activity_fields['id'] = $activity_fields['activity_id'];
unset($activity_fields['activity_id']);
// enforce restrictions on parameters
$allowed_params = array_flip(array_merge(array_keys($activity_fields), array_keys($contact_fields), array_keys($custom_fields)));
unset($allowed_params['activity_type_id']);
$filtered_params = array_intersect_key($params, $allowed_params);
$custom_group = self::getCustomGroup();
$customTableName = $custom_group['table_name'];
foreach ($custom_fields as $name => $field) {
$selectClause[] = "{$customTableName}.{$field['column_name']} AS {$name}";
}
$customSelect = implode(', ', $selectClause);
$activityContactTypes = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContactTypes);
$placeholders = array(1 => array($targetID, 'Integer'), 2 => array(self::getActivityTypeId(), 'Integer'));
$i = count($placeholders) + 1;
$where = array();
$whereClause = NULL;
foreach ($filtered_params as $key => $value) {
if (CRM_Utils_Array::value($key, $activity_fields)) {
$dataType = CRM_Utils_Type::typeToString($activity_fields[$key]['type']);
$fieldName = $activity_fields[$key]['name'];
$tableName = CRM_Activity_DAO_Activity::$_tableName;
} elseif (CRM_Utils_Array::value($key, $contact_fields)) {
$dataType = CRM_Utils_Type::typeToString($contact_fields[$key]['type']);
$fieldName = $contact_fields[$key]['name'];
$tableName = CRM_Contact_DAO_Contact::$_tableName;
} elseif (CRM_Utils_Array::value($key, $custom_fields)) {
$dataType = $custom_fields[$key]['data_type'];
$fieldName = $custom_fields[$key]['column_name'];
$tableName = $customTableName;
}
$where[] = "{$tableName}.{$fieldName} = %{$i}";
$placeholders[$i] = array($value, $dataType);
$i++;
}
if (count($where)) {
$whereClause = 'AND ' . implode("\nAND ", $where);
}
$query = "\n SELECT\n civicrm_activity.*,\n {$customSelect},\n activityContact.contact_id AS volunteer_contact_id,\n volunteer_contact.sort_name AS volunteer_sort_name,\n volunteer_contact.display_name AS volunteer_display_name\n FROM civicrm_activity\n INNER JOIN civicrm_activity_contact activityContact\n ON (\n activityContact.activity_id = civicrm_activity.id\n AND activityContact.record_type_id = %1\n )\n INNER JOIN civicrm_contact volunteer_contact\n ON activityContact.contact_id = volunteer_contact.id\n INNER JOIN {$customTableName}\n ON ({$customTableName}.entity_id = civicrm_activity.id)\n WHERE civicrm_activity.activity_type_id = %2\n {$whereClause}\n ";
$dao = CRM_Core_DAO::executeQuery($query, $placeholders);
$rows = array();
while ($dao->fetch()) {
$rows[$dao->id] = $dao->toArray();
}
return $rows;
}
示例12: restWhere
//.........这里部分代码省略.........
}
$wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}";
$this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
$this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
} elseif ($name === 'current_employer') {
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
$value = "%{$value}%";
$op = 'LIKE';
}
$wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
$ceWhereClause = self::buildClause($wc, $op, $value);
$ceWhereClause .= " AND contact_a.contact_type = 'Individual'";
$this->_where[$grouping][] = $ceWhereClause;
$this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
} elseif ($name === 'email_greeting') {
$filterCondition = array('greeting_type' => 'email_greeting');
$this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting'));
} elseif ($name === 'postal_greeting') {
$filterCondition = array('greeting_type' => 'postal_greeting');
$this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting'));
} elseif ($name === 'addressee') {
$filterCondition = array('greeting_type' => 'addressee');
$this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee'));
} elseif (substr($name, 0, 4) === 'url-') {
$tName = 'civicrm_website';
$this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
$value = "%{$value}%";
$op = 'LIKE';
}
$wc = 'civicrm_website.url';
$this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value);
$this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
} elseif ($name === 'contact_is_deleted') {
$this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
$this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
} else {
if (is_array($value)) {
// traditionally an array being passed has been a fatal error. We can take advantage of this to add support
// for api style operators for functions that hit this point without worrying about regression
// (the previous comments indicated the condition for hitting this point were unknown
// per CRM-14743 we are adding modified_date & created_date operator support
$operations = array_keys($value);
foreach ($operations as $operator) {
if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) {
// we don't know when this might happen
CRM_Core_Error::fatal();
}
}
$this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($name, $value, NULL);
//since this is not currently being called by the form layer we can skip worrying about the 'qill' for now
return;
}
if (!empty($field['where'])) {
if ($op != 'IN') {
$value = $strtolower($value);
}
if ($wildcard) {
$value = "%{$value}%";
$op = 'LIKE';
}
if (isset($locType[1]) && is_numeric($locType[1])) {
$setTables = FALSE;
//get the location name
list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
$where = "`{$tName}`.{$fldName}";
$this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
// we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should
$this->_tables[$tName] = $this->_whereTables[$tName] = 1;
$this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
} else {
list($tableName, $fieldName) = explode('.', $field['where'], 2);
if ($tableName == 'civicrm_contact') {
$fieldName = "LOWER(contact_a.{$fieldName})";
} else {
if ($op != 'IN' && !is_numeric($value)) {
$fieldName = "LOWER({$field['where']})";
} else {
$fieldName = "{$field['where']}";
}
}
$type = NULL;
if (!empty($field['type'])) {
$type = CRM_Utils_Type::typeToString($field['type']);
}
$this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
$this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
}
}
}
if ($setTables && isset($field['where'])) {
list($tableName, $fieldName) = explode('.', $field['where'], 2);
if (isset($tableName)) {
$this->_tables[$tableName] = 1;
$this->_whereTables[$tableName] = 1;
}
}
}
示例13: whereClause
function whereClause(&$field, $op, $value, $min, $max)
{
$type = CRM_Utils_Type::typeToString(CRM_Utils_Array::value('type', $field));
$clause = null;
switch ($op) {
case 'bw':
case 'nbw':
if ($min !== null && strlen($min) > 0 || $max !== null && strlen($max) > 0) {
$min = CRM_Utils_Type::escape($min, $type);
$max = CRM_Utils_Type::escape($max, $type);
$clauses = array();
if ($min) {
if ($op == 'bw') {
$clauses[] = "( {$field['dbAlias']} >= {$min} )";
} else {
$clauses[] = "( {$field['dbAlias']} < {$min} )";
}
}
if ($max) {
if ($op == 'bw') {
$clauses[] = "( {$field['dbAlias']} <= {$max} )";
} else {
$clauses[] = "( {$field['dbAlias']} > {$max} )";
}
}
if (!empty($clauses)) {
if ($op == 'bw') {
$clause = implode(' AND ', $clauses);
} else {
$clause = implode(' OR ', $clauses);
}
}
}
break;
case 'has':
case 'nhas':
if ($value !== null && strlen($value) > 0) {
$value = CRM_Utils_Type::escape($value, $type);
if (strpos($value, '%') === false) {
$value = "'%{$value}%'";
} else {
$value = "'{$value}'";
}
$sqlOP = self::getSQLOperator($op);
$clause = "( {$field['dbAlias']} {$sqlOP} {$value} )";
}
break;
case 'in':
if ($value !== null && is_array($value) && count($value) > 0) {
$sqlOP = self::getSQLOperator($op);
if (CRM_Utils_Array::value('type', $field) == CRM_Utils_Type::T_STRING) {
$clause = "( {$field['dbAlias']} {$sqlOP} ( '" . implode("' , '", $value) . "') )";
} else {
// for numerical values
$clause = "( {$field['dbAlias']} {$sqlOP} (" . implode(', ', $value) . ") )";
}
}
break;
case 'mhas':
// mhas == multiple has
if ($value !== null && count($value) > 0) {
$sqlOP = self::getSQLOperator($op);
$clause = "{$field['dbAlias']} REGEXP '[[:<:]]" . implode('|', $value) . "[[:>:]]'";
}
break;
case 'sw':
case 'ew':
if ($value !== null && strlen($value) > 0) {
$value = CRM_Utils_Type::escape($value, $type);
if (strpos($value, '%') === false) {
if ($op == 'sw') {
$value = "'{$value}%'";
} else {
$value = "'%{$value}'";
}
} else {
$value = "'{$value}'";
}
$sqlOP = self::getSQLOperator($op);
$clause = "( {$field['dbAlias']} {$sqlOP} {$value} )";
}
break;
case 'nll':
case 'nnll':
$sqlOP = self::getSQLOperator($op);
$clause = "( {$field['dbAlias']} {$sqlOP} )";
break;
default:
if ($value !== null && strlen($value) > 0) {
if (isset($field['clause'])) {
// FIXME: we not doing escape here. Better solution is to use two
// different types - data-type and filter-type
eval("\$clause = \"{$field['clause']}\";");
} else {
$value = CRM_Utils_Type::escape($value, $type);
$sqlOP = self::getSQLOperator($op);
if ($field['type'] == CRM_Utils_Type::T_STRING) {
$value = "'{$value}'";
}
$clause = "( {$field['dbAlias']} {$sqlOP} {$value} )";
//.........这里部分代码省略.........
示例14: whereClause
static function whereClause(&$field, $op, $value, $min, $max)
{
$type = CRM_Utils_Type::typeToString(CRM_Utils_Array::value('type', $field));
$clause = null;
switch ($op) {
case 'bw':
case 'nbw':
if ($min !== null && strlen($min) > 0 || $max !== null && strlen($max) > 0) {
$min = CRM_Utils_Type::escape($min, $type);
$max = CRM_Utils_Type::escape($max, $type);
$clauses = array();
if ($min) {
if ($op == 'bw') {
$clauses[] = "( {$field['dbAlias']} >= {$min} )";
} else {
$clauses[] = "( {$field['dbAlias']} < {$min} )";
}
}
if ($max) {
if ($op == 'bw') {
$clauses[] = "( {$field['dbAlias']} <= {$max} )";
} else {
$clauses[] = "( {$field['dbAlias']} > {$max} )";
}
}
if (!empty($clauses)) {
if ($op == 'bw') {
$clause = implode(' AND ', $clauses);
} else {
$clause = implode(' OR ', $clauses);
}
}
}
break;
case 'has':
case 'nhas':
if ($value !== null && strlen($value) > 0) {
$value = CRM_Utils_Type::escape($value, $type);
if (strpos($value, '%') === false) {
$value = "'%{$value}%'";
} else {
$value = "'{$value}'";
}
$sqlOP = self::getSQLOperator($op);
$clause = "( {$field['dbAlias']} {$sqlOP} {$value} )";
}
break;
case 'in':
if ($value !== null && count($value) > 0) {
$sqlOP = self::getSQLOperator($op);
if (CRM_Utils_Array::value('type', $field) == CRM_Utils_Type::T_STRING) {
$clause = "( {$field['dbAlias']} {$sqlOP} ( '" . implode("' , '", $value) . "') )";
} else {
$clause = "( {$field['dbAlias']} {$sqlOP} (" . implode(', ', $value) . ") )";
}
}
break;
case 'sw':
case 'ew':
if ($value !== null && strlen($value) > 0) {
$value = CRM_Utils_Type::escape($value, $type);
if (strpos($value, '%') === false) {
if ($op == 'sw') {
$value = "'{$value}%'";
} else {
$value = "'%{$value}'";
}
} else {
$value = "'{$value}'";
}
$sqlOP = self::getSQLOperator($op);
$clause = "( {$field['dbAlias']} {$sqlOP} {$value} )";
}
break;
case 'nll':
$sqlOP = self::getSQLOperator($op);
$clause = "( {$field['dbAlias']} {$sqlOP} )";
break;
default:
if ($value !== null && strlen($value) > 0) {
if (isset($field['clause'])) {
// FIXME: we not doing escape here. Better solution is to use two
// different types - data-type and filter-type
eval("\$clause = \"{$field['clause']}\";");
} else {
$value = CRM_Utils_Type::escape($value, $type);
$sqlOP = self::getSQLOperator($op);
if ($field['type'] == CRM_Utils_Type::T_STRING) {
$value = "'{$value}'";
}
$clause = "( {$field['dbAlias']} {$sqlOP} {$value} )";
}
}
break;
}
return $clause;
}
示例15: whereClause
/**
* Generate where clause.
*
* This can be overridden in reports for special treatment of a field
*
* @param array $field Field specifications
* @param string $op Query operator (not an exact match to sql)
* @param mixed $value
* @param float $min
* @param float $max
*
* @return null|string
*/
public function whereClause(&$field, $op, $value, $min, $max)
{
$type = CRM_Utils_Type::typeToString(CRM_Utils_Array::value('type', $field));
$clause = NULL;
switch ($op) {
case 'bw':
case 'nbw':
if ($min !== NULL && strlen($min) > 0 || $max !== NULL && strlen($max) > 0) {
$min = CRM_Utils_Type::escape($min, $type);
$max = CRM_Utils_Type::escape($max, $type);
$clauses = array();
if ($min) {
if ($op == 'bw') {
$clauses[] = "( {$field['dbAlias']} >= {$min} )";
} else {
$clauses[] = "( {$field['dbAlias']} < {$min} )";
}
}
if ($max) {
if ($op == 'bw') {
$clauses[] = "( {$field['dbAlias']} <= {$max} )";
} else {
$clauses[] = "( {$field['dbAlias']} > {$max} )";
}
}
if (!empty($clauses)) {
if ($op == 'bw') {
$clause = implode(' AND ', $clauses);
} else {
$clause = implode(' OR ', $clauses);
}
}
}
break;
case 'has':
case 'nhas':
if ($value !== NULL && strlen($value) > 0) {
$value = CRM_Utils_Type::escape($value, $type);
if (strpos($value, '%') === FALSE) {
$value = "'%{$value}%'";
} else {
$value = "'{$value}'";
}
$sqlOP = $this->getSQLOperator($op);
$clause = "( {$field['dbAlias']} {$sqlOP} {$value} )";
}
break;
case 'in':
case 'notin':
if (is_string($value) && strlen($value)) {
$value = explode(',', $value);
}
if ($value !== NULL && is_array($value) && count($value) > 0) {
$sqlOP = $this->getSQLOperator($op);
if (CRM_Utils_Array::value('type', $field) == CRM_Utils_Type::T_STRING) {
//cycle through selections and escape values
foreach ($value as $key => $selection) {
$value[$key] = CRM_Utils_Type::escape($selection, $type);
}
$clause = "( {$field['dbAlias']} {$sqlOP} ( '" . implode("' , '", $value) . "') )";
} else {
// for numerical values
$clause = "{$field['dbAlias']} {$sqlOP} (" . implode(', ', $value) . ")";
}
if ($op == 'notin') {
$clause = "( " . $clause . " OR {$field['dbAlias']} IS NULL )";
} else {
$clause = "( " . $clause . " )";
}
}
break;
case 'mhas':
case 'mnot':
// multiple has or multiple not
if ($value !== NULL && count($value) > 0) {
$value = CRM_Utils_Type::escapeAll($value, $type);
$operator = $op == 'mnot' ? 'NOT' : '';
$regexp = "[[:cntrl:]]*" . implode('[[:>:]]*|[[:<:]]*', (array) $value) . "[[:cntrl:]]*";
$clause = "{$field['dbAlias']} {$operator} REGEXP '{$regexp}'";
}
break;
case 'sw':
case 'ew':
if ($value !== NULL && strlen($value) > 0) {
$value = CRM_Utils_Type::escape($value, $type);
if (strpos($value, '%') === FALSE) {
if ($op == 'sw') {
//.........这里部分代码省略.........