cleanup some methods in databox_status as only 32bit ints used.

This commit is contained in:
Benoît Burnichon
2015-03-09 14:59:25 +01:00
parent 109c93f243
commit d2c5ecf620

View File

@@ -151,10 +151,6 @@ class databox_status
public static function operation_and(Application $app, $stat1, $stat2)
{
$conn = $app['phraseanet.appbox']->get_connection();
$status = '0';
if (substr($stat1, 0, 2) === '0x') {
$stat1 = self::hex2bin($app, substr($stat1, 2));
}
@@ -162,18 +158,7 @@ class databox_status
$stat2 = self::hex2bin($app, substr($stat2, 2));
}
$sql = 'select bin(0b' . trim($stat1) . ' & 0b' . trim($stat2) . ') as result';
$stmt = $conn->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
$status = $row['result'];
}
return $status;
return dechex(hexdec($stat1) & hexdec($stat2));
}
/**
@@ -184,42 +169,20 @@ class databox_status
* @param $stat1 a binary mask "010x1xx0.." STRING
* @param $stat2 a binary mask "x100x1..." STRING
*
* @return binary string
* @return string
*/
public static function operation_mask(Application $app, $stat1, $stat2)
{
$conn = $app['phraseanet.appbox']->get_connection();
$stat1_or = bindec(trim(str_replace("x", "0", $stat1)));
$stat1_and = bindec(trim(str_replace("x", "1", $stat1)));
$stat2_or = bindec(trim(str_replace("x", "0", $stat2)));
$stat2_and = bindec(trim(str_replace("x", "1", $stat2)));
$status = '0';
$stat1_or = '0b' . trim(str_replace("x", "0", $stat1));
$stat1_and = '0b' . trim(str_replace("x", "1", $stat1));
$stat2_or = '0b' . trim(str_replace("x", "0", $stat2));
$stat2_and = '0b' . trim(str_replace("x", "1", $stat2));
// $sql = "SELECT BIN(((((0 | :o1) & :a1)) | :o2) & :a2) AS result";
// $stmt = $conn->prepare($sql);
// $stmt->execute(array(':o1'=>$stat1_or, ':a1'=>$stat1_and, ':o2'=>$stat2_or, ':a2'=>$stat2_and));
$sql = "SELECT BIN(((((0 | $stat1_or) & $stat1_and)) | $stat2_or) & $stat2_and) AS result";
$stmt = $conn->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
$status = $row['result'];
}
return $status;
return decbin((((0 | $stat1_or) & $stat1_and) | $stat2_or) & $stat2_and);
}
public static function operation_and_not(Application $app, $stat1, $stat2)
{
$conn = $app['phraseanet.appbox']->get_connection();
$status = '0';
if (substr($stat1, 0, 2) === '0x') {
$stat1 = self::hex2bin($app, substr($stat1, 2));
}
@@ -227,26 +190,11 @@ class databox_status
$stat2 = self::hex2bin($app, substr($stat2, 2));
}
$sql = 'select bin(0b' . trim($stat1) . ' & ~0b' . trim($stat2) . ') as result';
$stmt = $conn->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
$status = $row['result'];
}
return $status;
return decbin(bindec($stat1) & ~bindec($stat2));
}
public static function operation_or(Application $app, $stat1, $stat2)
{
$conn = $app['phraseanet.appbox']->get_connection();
$status = '0';
if (substr($stat1, 0, 2) === '0x') {
$stat1 = self::hex2bin($app, substr($stat1, 2));
}
@@ -254,18 +202,7 @@ class databox_status
$stat2 = self::hex2bin($app, substr($stat2, 2));
}
$sql = 'select bin(0b' . trim($stat1) . ' | 0b' . trim($stat2) . ') as result';
$stmt = $conn->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
$status = $row['result'];
}
return $status;
return decbin(hexdec($stat1) | hexdec($stat2));
}
public static function dec2bin(Application $app, $status)
@@ -276,22 +213,7 @@ class databox_status
throw new \Exception(sprintf('`%s`is non-decimal value', $status));
}
$conn = $app['phraseanet.appbox']->get_connection();
$sql = 'select bin(' . $status . ') as result';
$stmt = $conn->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$status = '0';
if ($row) {
$status = $row['result'];
}
return $status;
return decbin($status);
}
public static function hex2bin(Application $app, $status)
@@ -305,22 +227,7 @@ class databox_status
throw new \Exception('Non-hexadecimal value');
}
$conn = $app['phraseanet.appbox']->get_connection();
$sql = 'select BIN( CAST( 0x' . trim($status) . ' AS UNSIGNED ) ) as result';
$stmt = $conn->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$status = '0';
if ($row) {
$status = $row['result'];
}
return $status;
return hex2bin($status);
}
public static function bitIsSet($bitValue, $nthBit)