本文整理汇总了PHP中db_like函数的典型用法代码示例。如果您正苦于以下问题:PHP db_like函数的具体用法?PHP db_like怎么用?PHP db_like使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_like函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchResults
/**
* Implements LinkitSearchPluginInterface::fetchResults().
*/
public function fetchResults($search_string)
{
// If the $search_string is not a string, something is wrong and an empty
// array is returned.
$matches = array();
// Get the EntityFieldQuery instance.
$this->getQueryInstance();
$or = db_or();
$or->condition('n.title', '%' . db_like($search_string) . '%', 'LIKE');
$or->condition('bcd.name', '%' . db_like($search_string) . '%', 'LIKE');
$or->condition('b.biblio_secondary_title', '%' . db_like($search_string) . '%', 'LIKE');
$or->condition('bkd.word', '%' . db_like($search_string) . '%', 'LIKE');
$this->query->condition($or);
$this->query->orderBy('b.biblio_year', 'DESC');
//ORDER BY created
// Add the search condition to the query object.
/*$this->query->propertyCondition($this->entity_field_label,
'%' . db_like($search_string) . '%', 'LIKE')
->addTag('linkit_entity_autocomplete')
->addTag('linkit_' . $this->plugin['entity_type'] . '_autocomplete');*/
/*
$matches[] = array(
'title' => $this->entity_field_label,
'description' => '',
'path' => '',
'group' => '',
'addClass' => '',
);
return $matches;
*/
/* // Add access tag for the query.
// There is also a runtime access check that uses entity_access().
$this->query->addTag($this->plugin['entity_type'] . '_access');
// Bundle check.
if (isset($this->entity_key_bundle) && isset($this->conf['bundles']) ) {
$bundles = array_filter($this->conf['bundles']);
if ($bundles) {
$this->query->propertyCondition($this->entity_key_bundle, $bundles, 'IN');
}
}*/
// Execute the query.
$result = $this->query->execute()->fetchAllAssoc('nid');
/*if (!isset($result[$this->plugin['entity_type']])) {
return array();
}*/
$ids = array_keys($result);
// Load all the entities with all the ids we got.
$entities = entity_load('node', $ids);
foreach ($entities as $key => $entity) {
// Check the access againt the definded entity access callback.
if (entity_access('view', 'node', $entity) === FALSE) {
continue;
}
$matches[] = array('title' => biblio_remove_brace($this->createLabel($entity)), 'description' => $this->createDescription($entity) . ' <span class="name">' . $result[$key]->name . '</span> <span class="year">' . $result[$key]->biblio_year . '</span>', 'path' => $this->createPath($entity), 'group' => $this->createGroup($entity), 'addClass' => $this->createRowClass($entity));
}
return $matches;
}
示例2: next
/**
* Returns the next available member id.
*/
public function next($membership)
{
$settings = $this->settings + array('pattern' => '', 'suffix' => 1, 'length' => 5, 'advanced' => array());
$settings['advanced'] += array('separator' => '-', 'maxlength' => '', 'case' => 'none', 'ignore_words' => '');
// Build the member id.
$member_id = token_replace($settings['pattern'], array('membership_entity' => $membership), array('sanitize' => TRUE, 'clear' => TRUE, 'callback' => '_membership_entity_token_member_id_token_callback', 'settings' => $settings['advanced']));
// Empty member_ids do not need any cleaning.
if ($member_id !== '' && $member_id !== NULL) {
$member_id = _membership_entity_token_clean_separator($member_id, $settings['advanced']['separator']);
}
// Optionally add a unique suffix.
if (!empty($settings['suffix'])) {
$length = $settings['length'];
$suffix = 1;
// Find the most recent matching member id.
$query = db_select('membership_entity', 'm');
$query->addExpression('MAX(member_id)', 'member_id');
$id = $query->condition('member_id', db_like($member_id) . '%', 'LIKE')->execute()->fetchField();
// If a member id already exists increment suffix by 1.
if (!empty($id)) {
$id = (int) str_replace($member_id, '', $id);
$suffix = $id + 1;
}
$member_id .= str_pad($suffix, $length, '0', STR_PAD_LEFT);
}
return $member_id;
}
示例3: analyze
/**
* {@inheritdoc}
*/
public function analyze(TargetInterface $target)
{
$violations = [];
$indexer = $target->getIndexer('function');
if ($indexer->has('hook_form_alter')) {
$violations[] = $indexer->get('hook_form_alter');
}
$id = $target->id() . '_form_%_alter';
// Until kernel tests are run in PHPUnit, we need to check for
// the existence of db_like().
if (function_exists('db_like')) {
$id = db_like($id);
}
$alter_hooks = $target->getIndexer('function')->getQuery()->condition('id', $id, 'LIKE')->execute();
foreach ($alter_hooks as $alter_hook) {
$violations[] = $target->open($alter_hook->file)->find(Filter::isFunction($alter_hook->id));
}
$issues = [];
if ($violations) {
$issue = $this->buildIssue($target);
array_walk($violations, function (FunctionDeclarationNode $function) use($issue) {
$issue->addViolation($function, $this);
});
$issues[] = $issue;
}
return $issues;
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['customer_type'] = array('#type' => 'radios', '#options' => array('search' => t('Search for an existing customer.'), 'create' => t('Create a new customer account.'), 'none' => t('No customer account required.')), '#required' => TRUE, '#default_value' => 'search', '#ajax' => array('callback' => array($this, 'customerSelect'), 'wrapper' => 'uc-order-customer', 'progress' => array('type' => 'throbber')));
$form['customer'] = array('#prefix' => '<div id="uc-order-customer">', '#suffix' => '</div>', '#tree' => TRUE);
// Create form elements needed for customer search.
// Shown only when the 'Search for an existing customer.' radio is selected.
if (!$form_state->hasValue('customer_type') || $form_state->getValue('customer_type') == 'search') {
// Container for customer search fields.
$form['customer'] += array('#type' => 'fieldset', '#title' => t('Customer search'), '#description' => t('Enter full or partial information in one or more of the following fields, then press the "Search" button. Search results will match all the provided information.'));
// Customer first name.
$form['customer']['first_name'] = array('#type' => 'textfield', '#title' => t('First name'), '#size' => 24, '#maxlength' => 32);
// Customer last name.
$form['customer']['last_name'] = array('#type' => 'textfield', '#title' => t('Last name'), '#size' => 24, '#maxlength' => 32);
// Customer e-mail address.
$form['customer']['email'] = array('#type' => 'textfield', '#title' => t('E-mail'), '#size' => 24, '#maxlength' => 96);
// Customer username.
$form['customer']['username'] = array('#type' => 'textfield', '#title' => t('Username'), '#size' => 24, '#maxlength' => 96);
$form['customer']['search'] = array('#type' => 'button', '#value' => t('Search'), '#limit_validation_errors' => array(), '#submit' => array(), '#ajax' => array('callback' => array($this, 'customerSearch'), 'wrapper' => 'uc-order-customer-results', 'progress' => array('type' => 'throbber')));
$form['customer']['uid'] = array('#prefix' => '<div id="uc-order-customer-results">', '#suffix' => '</div>');
// Search for existing customer by e-mail address.
if ($form_state->getValue('customer')) {
$query = db_select('users_field_data', 'u')->distinct();
$query->leftJoin('uc_orders', 'o', 'u.uid = o.uid');
$query->fields('u', array('uid', 'name', 'mail'))->fields('o', array('billing_first_name', 'billing_last_name'))->condition('u.uid', 0, '>')->condition(db_or()->isNull('o.billing_first_name')->condition('o.billing_first_name', db_like(trim($form_state->getValue(['customer', 'first_name']))) . '%', 'LIKE'))->condition(db_or()->isNull('o.billing_last_name')->condition('o.billing_last_name', db_like(trim($form_state->getValue(['customer', 'last_name']))) . '%', 'LIKE'))->condition(db_or()->condition('o.primary_email', db_like(trim($form_state->getValue(['customer', 'email']))) . '%', 'LIKE')->condition('u.mail', db_like(trim($form_state->getValue(['customer', 'email']))) . '%', 'LIKE'))->condition('u.name', db_like(trim($form_state->getValue(['customer', 'username']))) . '%', 'LIKE')->orderBy('o.created', 'DESC')->range(0, $limit = 11);
$result = $query->execute();
$options = array();
foreach ($result as $user) {
$name = '';
if (!empty($user->billing_first_name) && !empty($user->billing_last_name)) {
$name = $user->billing_first_name . ' ' . $user->billing_last_name . ' ';
}
// Options formatted as "First Last <email@example.com> (username)".
$options[$user->uid] = $name . '<' . $user->mail . '>' . ' (' . $user->name . ')';
}
$max = FALSE;
if (count($options) == $limit) {
array_pop($options);
$max = TRUE;
}
if (!empty($options)) {
// Display search results.
$form['customer']['uid'] += array('#type' => 'radios', '#title' => t('Select customer'), '#description' => $max ? t('More than @limit results found. Refine your search to find other customers.', ['@limit' => $limit - 1]) : '', '#options' => $options, '#default_value' => key($options));
} else {
// No search results found.
$form['customer']['uid'] += array('#markup' => '<p>' . t('Search returned no results.') . '</p>');
}
}
} elseif ($form_state->getValue('customer_type') == 'create') {
// Container for new customer information.
$form['customer'] += array('#type' => 'fieldset', '#title' => t('New customer details'));
// Customer e-mail address.
$form['customer']['email'] = array('#type' => 'email', '#title' => t('Customer e-mail address'), '#size' => 24, '#maxlength' => 96);
// Option to notify customer.
$form['customer']['sendmail'] = array('#type' => 'checkbox', '#title' => t('E-mail account details to customer.'));
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Create order'));
return $form;
}
示例5: userAutocomplete
public function userAutocomplete($query = NULL)
{
$query = db_select('users_field_data', 'e')->fields('e', array('uid', 'name'))->condition('name', '%' . db_like($query) . '%', 'LIKE')->range(0, 10)->execute();
$result = array();
foreach ($query as $row) {
$result[] = array('id' => $row->uid, 'name' => $row->name);
}
return new JsonResponse($result);
}
示例6: autocomplete_callback
/**
* The autocomplete callback function for the Linkit Entity plugin.
*/
function autocomplete_callback()
{
$matches = array();
// Get page urls.
$results = db_select('page_manager_pages', 'pmp')->fields('pmp', array('admin_title', 'path'))->condition('pmp.name', '%' . db_like($this->serach_string) . '%', 'LIKE')->execute();
foreach ($results as $page) {
$matches[] = array('title' => $this->buildLabel($page->admin_title), 'path' => $this->buildPath($page->path), 'group' => $this->buildGroup('Pages'));
}
return $matches;
}
示例7: validate
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint)
{
if (!isset($items)) {
return;
}
$field_name = $items->getFieldDefinition()->getName();
$value_taken = (bool) \Drupal::entityQuery('user')->condition('uid', (int) $items->getEntity()->id(), '<>')->condition($field_name, db_like($items->first()->value), 'LIKE')->range(0, 1)->count()->execute();
if ($value_taken) {
$this->context->addViolation($constraint->message, array("%value" => $items->value));
}
}
示例8: testLikeBackslash
/**
* Tests a LIKE query containing a backslash.
*/
function testLikeBackslash()
{
db_insert('test')->fields(array('name'))->values(array('name' => 'abcde\\f'))->values(array('name' => 'abc%\\_'))->execute();
// Match both rows using a LIKE expression with two wildcards and a verbatim
// backslash.
$num_matches = db_select('test', 't')->condition('name', 'abc%\\\\_', 'LIKE')->countQuery()->execute()->fetchField();
$this->assertIdentical($num_matches, '2', 'Found 2 records.');
// Match only the former using a LIKE expression with no wildcards.
$num_matches = db_select('test', 't')->condition('name', db_like('abc%\\_'), 'LIKE')->countQuery()->execute()->fetchField();
$this->assertIdentical($num_matches, '1', 'Found 1 record.');
}
示例9: autocompLieu
public function autocompLieu(Request $request)
{
$string = $request->query->get('q');
$matches = array();
if ($string) {
$result = db_select('gbb_netab_dafor')->fields('gbb_netab_dafor', array('co_lieu', 'denom_comp', 'sigle'))->condition('denom_comp', '%' . db_like($string) . '%', 'LIKE')->range(0, 10)->execute();
foreach ($result as $res) {
$matches[] = array('value' => "{$res->sigle} {$res->denom_comp} ({$res->co_lieu})", 'label' => "{$res->sigle} {$res->denom_comp} ({$res->co_lieu})");
}
}
return new JsonResponse($matches);
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$match = 'i:' . $this->option->aid . ';s:' . strlen($this->option->oid) . ':"' . $this->option->oid . '";';
db_delete('uc_product_adjustments')->condition('combination', '%' . db_like($match) . '%', 'LIKE')->execute();
$select = db_select('uc_attribute_options', 'ao')->where('{uc_class_attribute_options}.oid = ao.oid')->condition('ao.oid', $this->option->oid);
$select->addExpression('1');
db_delete('uc_class_attribute_options')->condition('', $select, 'EXISTS')->execute();
$select = db_select('uc_attribute_options', 'ao')->where('{uc_product_options}.oid = ao.oid')->condition('ao.oid', $this->option->oid);
$select->addExpression('1');
db_delete('uc_product_options')->condition('', $select, 'EXISTS')->execute();
db_delete('uc_attribute_options')->condition('oid', $this->option->oid)->execute();
$form_state->setRedirect('uc_attribute.options', ['aid' => $this->option->aid]);
}
示例11: autocomplete_callback
/**
* The autocomplete callback function for the Linkit Entity plugin.
*/
function autocomplete_callback()
{
// Create the tmp table.
$this->create_tmp_table();
// Populate the tmp table.
$this->populate_tmp_table();
$matches = array();
$query = db_select($this->table_name, 'tmp')->fields('tmp', array('path', 'display_title', 'human_name'))->condition('tmp.display_title', '%' . db_like($this->serach_string) . '%', 'LIKE')->addTag('linkit_views_autocomplete')->execute();
foreach ($query as $view) {
$matches[] = array('title' => $view->display_title, 'path' => base_path() . $view->path, 'description' => t('View: %view', array('%view' => $view->human_name)), 'group' => t('View pages'));
}
return $matches;
}
示例12: autocompleteFilename
/**
* Returns autocompletion content for file name textfield.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request of the page.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* A JSON response.
*/
public function autocompleteFilename(Request $request)
{
$matches = array();
// Get the typed string from the URL, if it exists.
if ($input = $request->query->get('q')) {
$typed_string = Tags::explode($input);
$typed_string = Unicode::strtolower(array_pop($typed_string));
$filenames = db_select('uc_files', 'f')->fields('f', ['filename'])->condition('filename', '%' . db_like($typed_string) . '%', 'LIKE')->execute();
while ($name = $filenames->fetchField()) {
$matches[] = array('value' => $name);
}
}
return new JsonResponse($matches);
}
示例13: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if ($form_state->getValue(['delete', 'all_aliases'])) {
db_delete('url_alias')->execute();
drupal_set_message($this->t('All of your path aliases have been deleted.'));
}
foreach (array_keys(array_filter($form_state->getValue(['delete', 'plugins']))) as $id) {
/** @var \Drupal\pathauto\AliasTypeInterface $alias_type */
$alias_type = $this->aliasTypeManager->createInstance($id);
db_delete('url_alias')->condition('source', db_like($alias_type->getSourcePrefix()) . '%', 'LIKE')->execute();
drupal_set_message(t('All of your %label path aliases have been deleted.', array('%label' => $alias_type->getLabel())));
}
$form_state->setRedirect('pathauto.bulk.update.form');
}
示例14: find
/**
* {@inheritdoc}
*/
public function find($string, $prefix = true, $limit = 20)
{
if ($prefix) {
$escaped = db_like($string) . '%';
} else {
$escaped = '%' . db_like($string) . '%';
}
$map = $this->db->select('node', 'n')->fields('n', ['nid', 'title'])->condition('n.type', $this->bundle)->condition('n.title', $escaped, 'LIKE')->orderBy('n.title')->range(0, $limit)->execute()->fetchAllKeyed();
$ret = [];
foreach ($map as $id => $title) {
$ret[] = new EntityFinderResult('node', $id, $title, $this->getLabel());
}
return $ret;
}
示例15: convert
/**
* {@inheritdoc}
*/
public function convert(TargetInterface $target)
{
$indexer = $target->getIndexer('function');
// @FIXME This is not working (returns empty result set)...don't know why.
$alter_hooks = $indexer->getQuery()->condition(db_or()->condition('id', $target->id() . '_form_alter')->condition('id', db_like($target->id() . '_form_%_alter'), 'LIKE'))->execute();
foreach ($alter_hooks as $alter_hook) {
/** @var \Pharborist\Functions\FunctionDeclarationNode $function */
$function = $indexer->get($alter_hook->id);
$parameters = $function->getParameters();
if (sizeof($parameters) > 1) {
$parameters[1]->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
$target->save($function);
}
}
}