本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder::setParameter方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::setParameter方法的具体用法?PHP QueryBuilder::setParameter怎么用?PHP QueryBuilder::setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Query\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::setParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
/**
* @return array
*/
public function fetch()
{
$data = $this->query->execute()->fetchAll(\PDO::FETCH_KEY_PAIR);
$keys = array_keys($data);
$this->query->setParameter(':lastId', array_pop($keys));
return array_values($data);
}
示例2: apply
/**
* {@inheritdoc}
*/
public function apply($fromAlias, $fromIdentifier, $resourcePrefix, array $requesterIdentifiers, $mask, array $orX = [])
{
$this->queryBuilder->leftJoin($fromAlias, $this->getAclSchema()->getPermissionsTableName(), 'acl_p', 'acl_p.resource = ' . $this->connection->getDatabasePlatform()->getConcatExpression(':acl_prefix', $fromAlias . '.' . $fromIdentifier));
$orX[] = 'acl_p.requester IN (:acl_identifiers) AND :acl_mask = (acl_p.mask & :acl_mask)';
$this->queryBuilder->andWhere(implode(' OR ', $orX));
$this->queryBuilder->setParameter('acl_prefix', $resourcePrefix, \PDO::PARAM_STR)->setParameter('acl_identifiers', $requesterIdentifiers, Connection::PARAM_STR_ARRAY)->setParameter('acl_mask', $mask, \PDO::PARAM_INT);
return $this->queryBuilder;
}
示例3: setParameter
/**
* paramTypes is private, we need to redefine setParameter
* to access it
*
* @param string $key
* @param string $value
* @param string $type
*
* @return $this
*/
public function setParameter($key, $value, $type = null)
{
if ($type !== null) {
$this->paramTypes[$key] = $type;
}
return parent::setParameter($key, $value, $type);
}
示例4: match
public function match(QueryBuilder $qb)
{
if ($this->has('username')) {
$qb->andWhere('u.username = :username');
$qb->setParameter('username', $this->get('username'));
}
}
示例5: finalizeQuery
public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
{
if (!$this->includeAllGroups) {
$query->andWhere('g.gID > :minGroupID');
$query->setParameter('minGroupID', REGISTERED_GROUP_ID);
}
return $query;
}
示例6: process
/**
* Applies operation to data source and returns modified data source.
*
* @param QueryBuilder $src
* @param OperationInterface|FilterOperation $operation
* @return QueryBuilder
*/
public function process($src, OperationInterface $operation)
{
$value = $operation->getValue();
$operator = $operation->getOperator();
$fieldName = $operation->getField();
$parameterName = 'p' . md5($fieldName . $operator);
$src->andWhere("{$fieldName} {$operator} :{$parameterName}");
$src->setParameter($parameterName, $value);
return $src;
}
示例7: match
/**
* @see \ComPHPPuebla\Doctrine\TableGateway\Specification\QueryBuilderSpecification::match()
*/
public function match(QueryBuilder $qb)
{
if ($this->has('latitude') && $this->has('longitude')) {
$qb->addSelect(<<<SELECT
(6371
* (2 * ATAN(SQRT(SIN(((:latitude - s.latitude) * (PI()/180))/2) * SIN(((:latitude - s.latitude) * (PI()/180))/2)
+ COS(:latitude * (PI()/180)) * COS(s.latitude * (PI()/180))
* SIN(((:longitude - s.longitude) * (PI()/180))/2) * SIN(((:longitude - s.longitude) * (PI()/180))/2)),
SQRT(1-(sin(((:latitude - s.latitude) * (PI()/180))/2) * SIN(((:latitude - s.latitude) * (PI()/180))/2)
+ COS(:latitude * (PI()/180) * COS(s.latitude * (PI()/180)
* SIN(((:longitude - s.longitude) * (PI()/180))/2) * SIN(((:longitude - s.longitude) * (PI()/180))/2))))))))
AS distance
SELECT
);
$qb->orderBy('distance');
$qb->setParameter('latitude', $this->get('latitude'));
$qb->setParameter('longitude', $this->get('longitude'));
}
}
示例8: finalizeQuery
public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
{
if (!$this->includeInactiveUsers) {
$query->andWhere('u.uIsActive = :uIsActive');
$query->setParameter('uIsActive', true);
}
if (!$this->includeUnvalidatedUsers) {
$query->andWhere('u.uIsValidated != 0');
}
return $query;
}
示例9: setValuesAndParameters
/**
* Sets the values and parameters of the upcoming given query according
* to the entity.
*
* @param Entity $entity
* the entity with its fields and values
* @param QueryBuilder $queryBuilder
* the upcoming query
* @param string $setMethod
* what method to use on the QueryBuilder: 'setValue' or 'set'
*/
protected function setValuesAndParameters(Entity $entity, QueryBuilder $queryBuilder, $setMethod)
{
$formFields = $this->getFormFields();
$count = count($formFields);
for ($i = 0; $i < $count; ++$i) {
$type = $this->definition->getType($formFields[$i]);
$value = $entity->get($formFields[$i]);
if ($type == 'boolean') {
$value = $value ? 1 : 0;
}
$queryBuilder->{$setMethod}('`' . $formFields[$i] . '`', '?');
$queryBuilder->setParameter($i, $value);
}
}
示例10: buildQuery
/**
* {@inheritdoc}
*/
public function buildQuery(QueryBuilder $queryBuilder, array $values = array())
{
if (!array_key_exists($this->getName(), $values) || 0 === count($values[$this->getName()])) {
return;
}
$codes = $values[$this->getName()];
if (in_array('all_but_paris', $codes)) {
$departements = new Departments();
$regions = new Regions();
unset($codes[array_search('all_but_paris', $codes)]);
$codes = array_merge($codes, array_diff(array_keys($departements->getArrayCopy()), $regions->get(self::ALL_BUT_PARIS_REGION_CODE)->getCodesDepartements()));
}
if (count($codes)) {
$queryBuilder->setParameter('department', $codes, Connection::PARAM_STR_ARRAY)->andWhere('response.companyDepartment IN(:department)');
}
}
示例11: setValuesAndParameters
/**
* Sets the values and parameters of the upcoming given query according
* to the entity.
*
* @param CRUDEntity $entity
* the entity with its fields and values
* @param QueryBuilder $queryBuilder
* the upcoming query
* @param boolean $setValue
* whether to use QueryBuilder::setValue (true) or QueryBuilder::set (false)
*/
protected function setValuesAndParameters(CRUDEntity $entity, QueryBuilder $queryBuilder, $setValue)
{
$formFields = $this->definition->getEditableFieldNames();
$count = count($formFields);
for ($i = 0; $i < $count; ++$i) {
$value = $entity->get($formFields[$i]);
$type = $this->definition->getType($formFields[$i]);
if ($type == 'bool') {
$value = $value ? 1 : 0;
}
if ($type == 'date' || $type == 'datetime' || $type == 'reference') {
$value = $value == '' ? null : $value;
}
if ($setValue) {
$queryBuilder->setValue('`' . $formFields[$i] . '`', '?');
} else {
$queryBuilder->set('`' . $formFields[$i] . '`', '?');
}
$queryBuilder->setParameter($i, $value);
}
}
示例12: applyFilters
/**
* @param array $filters
* @param QueryBuilder $queryBuilder
* @param array $filterDefinitions
*
* @return bool
*/
private function applyFilters(array $filters, QueryBuilder $queryBuilder, array $filterDefinitions)
{
$expr = $queryBuilder->expr();
$filterExpr = $expr->andX();
if (count($filters)) {
foreach ($filters as $filter) {
$exprFunction = isset($filter['expr']) ? $filter['expr'] : $filter['condition'];
$paramName = InputHelper::alphanum($filter['column']);
switch ($exprFunction) {
case 'notEmpty':
$filterExpr->add($expr->isNotNull($filter['column']));
$filterExpr->add($expr->neq($filter['column'], $expr->literal('')));
break;
case 'empty':
$filterExpr->add($expr->isNull($filter['column']));
$filterExpr->add($expr->eq($filter['column'], $expr->literal('')));
break;
default:
if (trim($filter['value']) == '') {
// Ignore empty
break;
}
$columnValue = ":{$paramName}";
switch ($filterDefinitions[$filter['column']]['type']) {
case 'bool':
case 'boolean':
if ((int) $filter['value'] > 1) {
// Ignore the "reset" value of "2"
break;
}
$queryBuilder->setParameter($paramName, $filter['value'], 'boolean');
break;
case 'float':
$columnValue = (double) $filter['value'];
break;
case 'int':
case 'integer':
$columnValue = (int) $filter['value'];
break;
default:
$queryBuilder->setParameter($paramName, $filter['value']);
}
$filterExpr->add($expr->{$exprFunction}($filter['column'], $columnValue));
}
}
}
if ($filterExpr->count()) {
$queryBuilder->andWhere($filterExpr);
return true;
}
return false;
}
示例13: prepareConditions
/**
* @param QueryBuilder $query
* @return QueryBuilder
*/
protected function prepareConditions($query)
{
$i = 0;
if (count($this->getConditions()) !== 0) {
foreach ($this->getConditions() as $condition) {
$conditionKey = 'NNXGridCondition_' . $i;
$query->andWhere($condition->getKey() . ' ' . $condition->getCriteria() . ' :' . $conditionKey);
$query->setParameter($conditionKey, $condition->getValue());
$i++;
}
}
return $query;
}
示例14: notEquals
/**
* {@inheritdoc}
*/
public function notEquals($field, $value)
{
$this->queryBuilder->setParameter($field, $value);
return $this->queryBuilder->expr()->neq($field, ':' . $field);
}
示例15: modifyCountDateDiffQuery
/**
* Modify the query to count how many rows is between a range of date diff in seconds
*
* @param QueryBuilder $query
* @param string $dateColumn1
* @param string $dateColumn2
* @param integer $startSecond
* @param integer $endSecond
* @param array $filters will be added to where claues
* @param string $tablePrefix
*/
public function modifyCountDateDiffQuery(QueryBuilder &$query, $dateColumn1, $dateColumn2, $startSecond = 0, $endSecond = 60, $tablePrefix = 't')
{
$query->select('COUNT(' . $tablePrefix . '.' . $dateColumn1 . ') AS count');
$query->where('TIMESTAMPDIFF(SECOND, ' . $tablePrefix . '.' . $dateColumn1 . ', ' . $tablePrefix . '.' . $dateColumn2 . ') >= :startSecond');
$query->andWhere('TIMESTAMPDIFF(SECOND, ' . $tablePrefix . '.' . $dateColumn1 . ', ' . $tablePrefix . '.' . $dateColumn2 . ') < :endSecond');
$query->setParameter('startSecond', $startSecond);
$query->setParameter('endSecond', $endSecond);
}