Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Move regexpToLike to AJXP_Utils
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne CHAMPETIER <etienne.champetier@fiducial.net>
  • Loading branch information
Etienne CHAMPETIER committed Apr 23, 2014
1 parent 05b2736 commit 17b7c0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
17 changes: 17 additions & 0 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -1852,4 +1852,21 @@ public static function glob_recursive($pattern, $flags = 0)
return $files;
}

public static function regexpToLike(&$regexp)
{
$left = "~";
$right = "~";
if ($regexp[0]=="^") {
$regexp = ltrim($regexp, "^");
$left = "";
}
if ($regexp[strlen($regexp)-1] == "$") {
$regexp = rtrim($regexp, "$");
$right = "";
}
if ($left == "" && $right == "") {
return "= %s";
}
return "LIKE %".$left."like".$right;
}
}
24 changes: 3 additions & 21 deletions core/src/plugins/auth.sql/class.sqlAuthDriver.php
Expand Up @@ -61,7 +61,7 @@ public function supportsUsersPagination()
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
{
if ($regexp != null) {
$like = self::regexpToLike($regexp);
$like = AJXP_Utils::regexpToLike($regexp);
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [login] ".$like." AND [groupPath] LIKE %like~ ORDER BY [login] ASC", $regexp, $baseGroup) ;
} else if ($offset != -1 || $limit != -1) {
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [groupPath] LIKE %like~ ORDER BY [login] ASC %lmt %ofs", $baseGroup, $limit, $offset);
Expand All @@ -84,7 +84,7 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =

$wheres = array();
if(!empty($regexp)){
$wheres[] = "[ajxp_users].[login] ". self::regexpToLike($regexp);
$wheres[] = "[ajxp_users].[login] ". AJXP_Utils::regexpToLike($regexp);
}
$wheres[] = "[ajxp_users].[groupPath] LIKE %like~";

Expand Down Expand Up @@ -120,7 +120,7 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =

if (!empty($regexp)) {
$res = dibi::query($q, $regexp, $baseGroup);
//$like = self::regexpToLike($regexp);
//$like = AJXP_Utils::regexpToLike($regexp);
//$res = dibi::query("SELECT COUNT(*) FROM [ajxp_users] WHERE [login] ".$like." AND [groupPath] LIKE %like~", $regexp, $baseGroup) ;
} else {
$res = dibi::query($q, $baseGroup);
Expand All @@ -129,24 +129,6 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =
return $res->fetchSingle();
}

private static function regexpToLike(&$regexp)
{
$left = "~";
$right = "~";
if ($regexp[0]=="^") {
$regexp = ltrim($regexp, "^");
$left = "";
}
if ($regexp[strlen($regexp)-1] == "$") {
$regexp = rtrim($regexp, "$");
$right = "";
}
if ($left == "" && $right == "") {
return "= %s";
}
return "LIKE %".$left."like".$right;
}

public function listUsers($baseGroup="/")
{
$pairs = array();
Expand Down

0 comments on commit 17b7c0b

Please sign in to comment.