Exemplo n.º 1
0
 /**
  * @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;
         }
     }
 }