本文整理匯總了PHP中SqlParser::addCriteria方法的典型用法代碼示例。如果您正苦於以下問題:PHP SqlParser::addCriteria方法的具體用法?PHP SqlParser::addCriteria怎麽用?PHP SqlParser::addCriteria使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SqlParser
的用法示例。
在下文中一共展示了SqlParser::addCriteria方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parseCriteria
/**
* @see DbConnector::getDefaultValue
*/
protected function parseCriteria($sqlParser, $searchcriteria)
{
if (!$searchcriteria || !is_array($searchcriteria)) {
return;
}
foreach ($searchcriteria as $key => $value) {
switch ($key) {
case 'usr_id':
$sqlParser->addCriteria(new SqlCriteria('a.usr_id', $value));
break;
case 'no_id':
$sqlParser->addCriteria(new SqlCriteria('a.usr_id', $value, '<>'));
break;
case 'grp_id':
$sqlParser->addFrom('left join usergroup as b on b.usr_id = a.usr_id');
$sqlParser->addCriteria(new SqlCriteria('b.grp_id', $value, '='));
break;
case 'no_grp_id':
//$sqlParser->addFrom('left join usergroup as b on b.usr_id = a.usr_id');
//$sqlParser->addCriteria(new SqlCriteria('b.grp_id', $value, '<>'));
$parser = new SqlParser();
$parser->setSelect('select');
$parser->setTable('usergroup', 'b');
$parser->addField(new SqlField('b', 'grp_id', 'grp_id', 'grp_id', SqlParser::SEL_LIST, SqlField::TYPE_INTEGER));
$parser->parseCriteria(array('grp_id' => $value));
$parser->addCriteria(new SqlCriteria('b.usr_id', 'a.usr_id', '=', true));
$subquery = $parser->getSql(SqlParser::SEL_LIST);
$sqlParser->addCriteria(new SqlCriteria(NULL, "({$subquery})", 'not exists', true));
break;
case 'tree_access':
$sqlParser->addFrom('left join usergroup as b on b.usr_id = a.usr_id');
$search = new SqlCriteria('a.usr_role', self::ROLE_ADMIN, '=');
$searchGroup = new SqlCriteria('a.usr_role', self::ROLE_FRONTEND, '<>');
$searchGroup->addCriteria(new SqlCriteria('b.grp_id', $group, '='), SqlCriteria::REL_AND);
$search->addCriteria($searchGroup, SqlCriteria::REL_OR);
$sqlParser->addCriteria($search);
break;
case 'search':
//$search = new SqlCriteria('a.usr_name', $value, 'regexp');
$value = "%{$value}%";
$search = new SqlCriteria('a.usr_name', $value, 'like');
$search->addCriteria(new SqlCriteria('a.usr_firstname', $value, 'like'), SqlCriteria::REL_OR);
$search->addCriteria(new SqlCriteria('a.usr_username', $value, 'like'), SqlCriteria::REL_OR);
$search->addCriteria(new SqlCriteria('a.usr_email', $value, 'like'), SqlCriteria::REL_OR);
$search->addCriteria(new SqlCriteria('a.usr_city', $value, 'like'), SqlCriteria::REL_OR);
$search->addCriteria(new SqlCriteria('a.usr_country', $value, 'like'), SqlCriteria::REL_OR);
//$search->addCriteria(new SqlCriteria('c.grp_name', $value, 'like'), SqlCriteria::REL_OR);
$sqlParser->addCriteria($search);
/*
$key = "concat(a.usr_name, a.usr_firstname, a.usr_username, a.usr_email, a.usr_city, a.usr_country)";
$sqlParser->addCriteria(new SqlCriteria($key, $value, 'regexp'));
*/
break;
}
}
}