本文整理汇总了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;
}
}
}