本文整理匯總了PHP中Drupal\Core\Database\Connection::escapeLike方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::escapeLike方法的具體用法?PHP Connection::escapeLike怎麽用?PHP Connection::escapeLike使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\Core\Database\Connection
的用法示例。
在下文中一共展示了Connection::escapeLike方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: find
/**
* {@inheritdoc}
*/
public function find($ip, $url, $limit, $method, $start = NULL, $end = NULL)
{
$select = $this->database->select('webprofiler', 'wp', ['fetch' => \PDO::FETCH_ASSOC]);
if (NULL === $start) {
$start = 0;
}
if (NULL === $end) {
$end = time();
}
if ($ip = preg_replace('/[^\\d\\.]/', '', $ip)) {
$select->condition('ip', '%' . $this->database->escapeLike($ip) . '%', 'LIKE');
}
if ($url) {
$select->condition('url', '%' . $this->database->escapeLike(addcslashes($url, '%_\\')) . '%', 'LIKE');
}
if ($method) {
$select->condition('method', $method);
}
if (!empty($start)) {
$select->condition('time', $start, '>=');
}
if (!empty($end)) {
$select->condition('time', $end, '<=');
}
$select->fields('wp', ['token', 'ip', 'method', 'url', 'time', 'parent']);
$select->orderBy('time', 'DESC');
$select->range(0, $limit);
return $select->execute()->fetchAllAssoc('token');
}
示例2: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$results = array();
if (!$this->isSearchExecutable()) {
return $results;
}
$keys = $this->keywords;
// Replace wildcards with MySQL/PostgreSQL wildcards.
$keys = preg_replace('!\\*+!', '%', $keys);
$query = $this->database->select('users')->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query->fields('users', array('uid'));
if ($this->currentUser->hasPermission('administer users')) {
// Administrators can also search in the otherwise private email field, and
// they don't need to be restricted to only active users.
$query->fields('users', array('mail'));
$query->condition($query->orConditionGroup()->condition('name', '%' . $this->database->escapeLike($keys) . '%', 'LIKE')->condition('mail', '%' . $this->database->escapeLike($keys) . '%', 'LIKE'));
} else {
// Regular users can only search via usernames, and we do not show them
// blocked accounts.
$query->condition('name', '%' . $this->database->escapeLike($keys) . '%', 'LIKE')->condition('status', 1);
}
$uids = $query->limit(15)->execute()->fetchCol();
$accounts = $this->entityManager->getStorage('user')->loadMultiple($uids);
foreach ($accounts as $account) {
$result = array('title' => $account->getUsername(), 'link' => url('user/' . $account->id(), array('absolute' => TRUE)));
if ($this->currentUser->hasPermission('administer users')) {
$result['title'] .= ' (' . $account->getEmail() . ')';
}
$results[] = $result;
}
return $results;
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$uid = $input->getArgument('uid');
$account = User::load($uid);
if (!$account) {
// Error loading User entity.
$io->error(sprintf($this->trans('commands.user.login.clear.attempts.errors.invalid-user'), $uid));
return 1;
}
// Define event name and identifier.
$event = 'user.failed_login_user';
// Identifier is created by uid and IP address,
// Then we defined a generic identifier.
$identifier = "{$account->id()}-";
// Retrieve current database connection.
$schema = $this->database->schema();
$flood = $schema->findTables('flood');
if (!$flood) {
$io->error($this->trans('commands.user.login.clear.attempts.errors.no-flood'));
return 1;
}
// Clear login attempts.
$this->database->delete('flood')->condition('event', $event)->condition('identifier', $this->database->escapeLike($identifier) . '%', 'LIKE')->execute();
// Command executed successful.
$io->success(sprintf($this->trans('commands.user.login.clear.attempts.messages.successful'), $uid));
}
示例4: buildEntityQuery
/**
* Builds an EntityQuery to get entities.
*
* @param $match
* Text to match the label against.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* The EntityQuery object with the basic conditions and sorting applied to
* it.
*/
protected function buildEntityQuery($match) {
$match = $this->database->escapeLike($match);
$entity_type = $this->entityManager->getDefinition($this->target_type);
$query = $this->entityManager->getStorage($this->target_type)->getQuery();
$label_key = $entity_type->getKey('label');
if ($label_key) {
$query->condition($label_key, '%' . $match . '%', 'LIKE');
$query->sort($label_key, 'ASC');
}
// Bundle check.
if (!empty($this->configuration['bundles']) && $bundle_key = $entity_type->getKey('bundle')) {
$query->condition($bundle_key, $this->configuration['bundles'], 'IN');
}
// Add tags to let other modules alter the query.
$query->addTag('linkit_entity_autocomplete');
$query->addTag('linkit_entity_' . $this->target_type . '_autocomplete');
// Add access tag for the query.
$query->addTag('entity_access');
$query->addTag($this->target_type . '_access');
return $query;
}
示例5: listAll
/**
* {@inheritdoc}
*/
public function listAll($prefix = '')
{
try {
return $this->connection->query('SELECT name FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name LIKE :name', array(':collection' => $this->collection, ':name' => $this->connection->escapeLike($prefix) . '%'), $this->options)->fetchCol();
} catch (\Exception $e) {
return array();
}
}
示例6: pathHasMatchingAlias
/**
* {@inheritdoc}
*/
public function pathHasMatchingAlias($initial_substring)
{
$query = $this->connection->select(static::TABLE, 'u');
$query->addExpression(1);
try {
return (bool) $query->condition('u.source', $this->connection->escapeLike($initial_substring) . '%', 'LIKE')->range(0, 1)->execute()->fetchField();
} catch (\Exception $e) {
$this->catchException($e);
return FALSE;
}
}
示例7: pathHasMatchingAlias
/**
* {@inheritdoc}
*/
public function pathHasMatchingAlias($initial_substring)
{
$query = $this->connection->select('url_alias', 'u');
$query->addExpression(1);
return (bool) $query->condition('u.source', $this->connection->escapeLike($initial_substring) . '%', 'LIKE')->range(0, 1)->execute()->fetchField();
}
示例8: getAutocompleteSuggestions
/**
* Implements SearchApiAutocompleteInterface::getAutocompleteSuggestions().
*/
public function getAutocompleteSuggestions(QueryInterface $query, SearchApiAutocompleteSearch $search, $incomplete_key, $user_input) {
$settings = isset($this->configuration['autocomplete']) ? $this->configuration['autocomplete'] : array();
$settings += array(
'suggest_suffix' => TRUE,
'suggest_words' => TRUE,
);
// If none of these options is checked, the user apparently chose a very
// roundabout way of telling us he doesn't want autocompletion.
if (!array_filter($settings)) {
return array();
}
$index = $query->getIndex();
$db_info = $this->getIndexDbInfo($index);
if (empty($db_info['field_tables'])) {
throw new SearchApiException(new FormattableMarkup('Unknown index @id.', array('@id' => $index->id())));
}
$fields = $this->getFieldInfo($index);
$suggestions = array();
$passes = array();
$incomplete_like = NULL;
// Make the input lowercase as the indexed data is (usually) also all
// lowercase.
$incomplete_key = Unicode::strtolower($incomplete_key);
$user_input = Unicode::strtolower($user_input);
// Decide which methods we want to use.
if ($incomplete_key && $settings['suggest_suffix']) {
$passes[] = 1;
$incomplete_like = $this->database->escapeLike($incomplete_key) . '%';
}
if ($settings['suggest_words'] && (!$incomplete_key || strlen($incomplete_key) >= $this->configuration['min_chars'])) {
$passes[] = 2;
}
if (!$passes) {
return array();
}
// We want about half of the suggestions from each enabled method.
$limit = $query->getOption('limit', 10);
$limit /= count($passes);
$limit = ceil($limit);
// Also collect all keywords already contained in the query so we don't
// suggest them.
$keys = preg_split('/[^\p{L}\p{N}]+/u', $user_input, -1, PREG_SPLIT_NO_EMPTY);
$keys = array_combine($keys, $keys);
if ($incomplete_key) {
$keys[$incomplete_key] = $incomplete_key;
}
foreach ($passes as $pass) {
if ($pass == 2 && $incomplete_key) {
$query->keys($user_input);
}
// To avoid suggesting incomplete words, we have to temporarily disable
// the "partial_matches" option. (There should be no way we'll save the
// server during the createDbQuery() call, so this should be safe.)
$options = $this->options;
$this->options['partial_matches'] = FALSE;
$db_query = $this->createDbQuery($query, $fields);
$this->options = $options;
// We need a list of all current results to match the suggestions against.
// However, since MySQL doesn't allow using a temporary table multiple
// times in one query, we regrettably have to do it this way.
$fulltext_fields = $this->getQueryFulltextFields($query);
if (count($fulltext_fields) > 1) {
$all_results = $db_query->execute()->fetchCol();
// Compute the total number of results so we can later sort out matches
// that occur too often.
$total = count($all_results);
}
else {
$table = $this->getTemporaryResultsTable($db_query);
if (!$table) {
return array();
}
$all_results = $this->database->select($table, 't')
->fields('t', array('item_id'));
$total = $this->database->query("SELECT COUNT(item_id) FROM {{$table}}")->fetchField();
}
$max_occurrences = $this->getConfigFactory()->get('search_api_db.settings')->get('autocomplete_max_occurrences');
$max_occurrences = max(1, floor($total * $max_occurrences));
if (!$total) {
if ($pass == 1) {
return NULL;
}
continue;
}
/** @var \Drupal\Core\Database\Query\SelectInterface|null $word_query */
$word_query = NULL;
//.........這裏部分代碼省略.........