本文整理汇总了PHP中QueryBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder类的具体用法?PHP QueryBuilder怎么用?PHP QueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLastId
public function getLastId()
{
$qb = new QueryBuilder();
$qb->select($qb->expr()->max(new Field('id'), 'lastId'))->from(Tbl::get('TBL_CHAT_MESSAGES'));
$lastId = $this->query->exec($qb->getSQL())->fetchField('lastId');
return empty($lastId) ? 0 : $lastId;
}
示例2: checkCredentials
/**
* Check validity of username, password and other auth factors
*
* @param string $username
* @param string $password
* @param array $additionalCredentials
* @param boolean $writeCookie
* @throws UserAuthFailedException
* @return User
*/
public function checkCredentials($username, $password, $additionalCredentials = array(), $writeCookie = false)
{
$qb = new QueryBuilder();
$qb->select(new Field('id'), new Field('password'), new Field('salt'))->from(Tbl::get('TBL_USERS', 'UserManager'))->where($qb->expr()->equal(new Field('login'), $username));
$this->query->exec($qb->getSQL());
if ($this->query->countRecords() == 1) {
$userData = $this->query->fetchRecord();
$hashToCheck = static::getUserPasswordHash($password, $userData['salt']);
if ($userData['password'] === $hashToCheck) {
$usr = $this->doLogin($userData['id'], $additionalCredentials, $writeCookie);
try {
$hookParams = array("user" => $usr, "additionalCredentials" => $additionalCredentials);
HookManager::callHook("UserAuthSuccess", $hookParams);
} catch (UserAuthFailedException $e) {
$this->doLogout();
throw $e;
}
return $usr;
}
}
// Failed login nothing returned from above code
$hookParams = array("username" => $username, "password" => $password, "additionalCredentials" => $additionalCredentials);
HookManager::callHook("UserAuthFail", $hookParams);
throw new UserAuthFailedException("Incorrect login/password combination");
}
示例3: getEntities
protected function getEntities($key)
{
if (!isset($this->relationships[$key])) {
return false;
}
$relationship = $this->relationships[$key];
if (!isset($this->managers[$relationship['manager']])) {
$this->managers[$relationship['manager']] = $this->factory->get($key);
}
$manager = $this->managers[$relationship['manager']];
/* @var $manager ManagerAbstract */
$query = new QueryBuilder($manager->table(), $this->factory::connection(), $relationship['conditions']);
$original_params = $query->params();
$params = array();
foreach ($original_params as $param) {
if (stripos($param, 'entity.' === 0)) {
$param = $this->entity[substr($param, 7)];
}
$params[] = $param;
}
if ($relationship['relation'] == 'HasOne') {
$this->entities[$key] = $manager->fetch($query, $params);
} else {
$this->entities[$key] = $manager->fetchAll($query, $params);
}
return $this->entities[$key];
}
示例4: scopeIdOrUuid
/**
* Method for searching model by Id or Uuid
* @param QueryBuilder $query
* @param Int|Uuid $value
* @return Illuminate\Database\Eloquent\Builder
*/
public function scopeIdOrUuid($query, $value)
{
if (!Uuid::isValid($value) && !is_numeric($value)) {
throw (new ModelNotFoundException())->setModel(get_class($this));
}
return $query->where($this->primaryKey, '=', $value)->orWhere('uuid', '=', $value);
}
示例5: playerQuery
private function playerQuery(\QueryBuilder $query, Request $request)
{
if ($team = $request->query->get('team')) {
$query->where('team')->is($team);
}
return $query->getArray(array('name', 'outdated'));
}
示例6: load
function load($sh, $c_query = null)
{
$db = DB::Instance();
$qb = new QueryBuilder($db, $this->_doname);
if ($sh instanceof SearchHandler) {
if ($this->_templateobject->isAccessControlled()) {
if (isModuleAdmin()) {
$cc = new ConstraintChain();
$cc->add(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
$cc->add(new Constraint('id', '=', EGS_COMPANY_ID), 'OR');
$sh->addConstraintChain($cc);
$qb->setDistinct();
} else {
$cc = new ConstraintChain();
$cc->add(new Constraint('usernameaccess', '=', EGS_USERNAME));
$cc->add(new Constraint('owner', '=', EGS_USERNAME), 'OR');
$cc2 = new ConstraintChain();
$cc2->add(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
$sh->addConstraintChain($cc);
$sh->addConstraintChain($cc2);
$qb->setDistinct();
}
}
$this->sh = $sh;
}
$this->_load($sh, $qb, $c_query);
}
示例7: query
public function query($table = null)
{
if ($table === null) {
$table = $this->_table;
}
$req = new QueryBuilder($this->_class);
return $req->_from($table);
}
示例8: testClauses
public function testClauses()
{
$arguments = array();
$arguments[] = 'all';
$arguments[] = array('condition' => 'state=?', 'columns' => 'name', 'order by' => 'last_login asc');
$query = new QueryBuilder('author', $arguments);
$this->assertEqual('select name from authors where state=? order by last_login asc', $query->compile()->getQueryString());
}
示例9: __construct
public function __construct(Registry $doctrineRegistry)
{
$this->doctrineRegistry = $doctrineRegistry;
$this->qbOroUsers = $this->doctrineRegistry->getManager()->getRepository('OroUserBundle:User')->createQueryBuilder('u');
$this->qbOroUsers->select('u');
$this->qbDiamanteUsers = $this->doctrineRegistry->getManager()->getRepository('DiamanteUserBundle:DiamanteUser')->createQueryBuilder('u');
$this->qbDiamanteUsers->select('u');
}
示例10: __construct
public function __construct()
{
$this->bs = new DisciplineBS(null);
$qbuilder = new QueryBuilder('discipline');
$qbuilder->addOrder("dsc_name", QueryBuilder::$ASC);
$qbuilder->addOrder("dsc_code", QueryBuilder::$ASC);
$this->disciplines = $this->bs->findNotDeleted($qbuilder);
}
示例11: __construct
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->load->library('model/QueryBuilder');
$this->load->library('Enviroment');
$this->db = $this->getDb();
$this->_query = new QueryBuilder($this->db, false);
$this->_query->setTable($this->_tabla);
}
示例12: logCustom
public static function logCustom($name, $value)
{
$remoteIP = "";
if (isset($_SERVER['REMOTE_ADDR'])) {
$remoteIP = $_SERVER['REMOTE_ADDR'];
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_MIXED_LOG'))->values(array("session_id" => session_id(), "name" => $name, "value" => $value, "ip" => $remoteIP));
Reg::get('sql')->exec($qb->getSQL());
}
示例13: addCatchAllWhereClause
/**
* @param QueryBuilder $q
* @param $filter
* @return array
*/
protected function addCatchAllWhereClause(&$q, $filter)
{
$unique = $this->generateRandomParameterName();
//ensure that the string has a unique parameter identifier
$string = $filter->strict ? $filter->string : "%{$filter->string}%";
$expr = $q->expr()->orX($q->expr()->like('f.label', ':' . $unique), $q->expr()->like('f.alias', ':' . $unique));
if ($filter->not) {
$expr = $q->expr()->not($expr);
}
return array($expr, array("{$unique}" => $string));
}
示例14: scopeArchiveFiltered
/**
* Get latest posts filtered by year and month?
*
* @param QueryBuilder $query
* @param int $year
* @param int $month
*/
public function scopeArchiveFiltered($query, $year, $month)
{
return $query->where(function ($query) use($year, $month) {
if ($year) {
$query->where(DB::raw('YEAR(created_at)'), $year);
}
if ($month) {
$query->where(DB::raw('MONTH(created_at)'), $month);
}
})->orderBy('posts.created_at', 'DESC');
}
示例15: getDBCurrentDateTime
/**
* Get Mysql's current datetime by selecting NOW()
*
* @return string
*/
function getDBCurrentDateTime($isTimestamp = false)
{
$sql = MySqlDbManager::getQueryObject();
$qb = new QueryBuilder();
if ($isTimestamp) {
$qb->select(new Func("UNIX_TIMESTAMP", new Func("NOW"), 'now'));
} else {
$qb->select(new Func("NOW", null, 'now'));
}
return $sql->exec($qb->getSQL())->fetchField('now');
}