当前位置: 首页>>代码示例>>PHP>>正文


PHP SelectInterface::conditions方法代码示例

本文整理汇总了PHP中Drupal\Core\Database\Query\SelectInterface::conditions方法的典型用法代码示例。如果您正苦于以下问题:PHP SelectInterface::conditions方法的具体用法?PHP SelectInterface::conditions怎么用?PHP SelectInterface::conditions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Database\Query\SelectInterface的用法示例。


在下文中一共展示了SelectInterface::conditions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: entityQueryAlter

 /**
  * {@inheritdoc}
  */
 public function entityQueryAlter(SelectInterface $query)
 {
     if (\Drupal::currentUser()->hasPermission('administer users')) {
         // In addition, if the user is administrator, we need to make sure to
         // match the anonymous user, that doesn't actually have a name in the
         // database.
         $conditions =& $query->conditions();
         foreach ($conditions as $key => $condition) {
             if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'users_field_data.name') {
                 // Remove the condition.
                 unset($conditions[$key]);
                 // Re-add the condition and a condition on uid = 0 so that we end up
                 // with a query in the form:
                 // WHERE (name LIKE :name) OR (:anonymous_name LIKE :name AND uid = 0)
                 $or = db_or();
                 $or->condition($condition['field'], $condition['value'], $condition['operator']);
                 // Sadly, the Database layer doesn't allow us to build a condition
                 // in the form ':placeholder = :placeholder2', because the 'field'
                 // part of a condition is always escaped.
                 // As a (cheap) workaround, we separately build a condition with no
                 // field, and concatenate the field and the condition separately.
                 $value_part = db_and();
                 $value_part->condition('anonymous_name', $condition['value'], $condition['operator']);
                 $value_part->compile(Database::getConnection(), $query);
                 $or->condition(db_and()->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => user_format_name(user_load(0))))->condition('base_table.uid', 0));
                 $query->condition($or);
             }
         }
     }
     // Add the filter by role option.
     if (!empty($this->fieldDefinition->getSetting('handler_settings')['filter'])) {
         $filter_settings = $this->fieldDefinition->getSetting('handler_settings')['filter'];
         if ($filter_settings['type'] == 'role') {
             $tables = $query->getTables();
             $base_table = $tables['base_table']['alias'];
             $query->join('users_roles', 'ur', $base_table . '.uid = ur.uid');
             $query->condition('ur.rid', $filter_settings['role']);
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:43,代码来源:UserSelection.php

示例2: entityQueryAlter

 /**
  * {@inheritdoc}
  */
 public function entityQueryAlter(SelectInterface $query)
 {
     // Bail out early if we do not need to match the Anonymous user.
     $handler_settings = $this->configuration['handler_settings'];
     if (isset($handler_settings['include_anonymous']) && !$handler_settings['include_anonymous']) {
         return;
     }
     if ($this->currentUser->hasPermission('administer users')) {
         // In addition, if the user is administrator, we need to make sure to
         // match the anonymous user, that doesn't actually have a name in the
         // database.
         $conditions =& $query->conditions();
         foreach ($conditions as $key => $condition) {
             if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'users_field_data.name') {
                 // Remove the condition.
                 unset($conditions[$key]);
                 // Re-add the condition and a condition on uid = 0 so that we end up
                 // with a query in the form:
                 // WHERE (name LIKE :name) OR (:anonymous_name LIKE :name AND uid = 0)
                 $or = db_or();
                 $or->condition($condition['field'], $condition['value'], $condition['operator']);
                 // Sadly, the Database layer doesn't allow us to build a condition
                 // in the form ':placeholder = :placeholder2', because the 'field'
                 // part of a condition is always escaped.
                 // As a (cheap) workaround, we separately build a condition with no
                 // field, and concatenate the field and the condition separately.
                 $value_part = db_and();
                 $value_part->condition('anonymous_name', $condition['value'], $condition['operator']);
                 $value_part->compile($this->connection, $query);
                 $or->condition(db_and()->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => user_format_name($this->userStorage->load(0))))->condition('base_table.uid', 0));
                 $query->condition($or);
             }
         }
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:38,代码来源:UserSelection.php

示例3:

 public function &conditions()
 {
     return $this->query->conditions();
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:4,代码来源:SelectExtender.php


注:本文中的Drupal\Core\Database\Query\SelectInterface::conditions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。