2014-06-08 15:32:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class MsHelper {
|
|
|
|
public static function getStringDBVar($name)
|
|
|
|
{
|
|
|
|
$connection = Yii::app()->db;
|
|
|
|
|
|
|
|
$command=$connection->createCommand("SELECT SValue FROM {{othervalues}} WHERE Name = '$name'");
|
|
|
|
$val = $command->queryScalar();
|
|
|
|
|
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
|
2017-01-07 15:47:50 +01:00
|
|
|
|
|
|
|
public static function setStringDBVar($name, $value)
|
|
|
|
{
|
|
|
|
$connection = Yii::app()->db;
|
|
|
|
|
|
|
|
$command=$connection->createCommand("REPLACE INTO {{othervalues}} (Name, SValue) VALUES ('$name', '$value')");
|
|
|
|
$command->query();
|
|
|
|
}
|
|
|
|
|
2014-06-08 15:32:00 +02:00
|
|
|
public static function getIntDBVar($name)
|
|
|
|
{
|
|
|
|
$connection = Yii::app()->db;
|
|
|
|
|
|
|
|
$command=$connection->createCommand("SELECT [Value] FROM {{othervalues}} WHERE Name = '$name'");
|
|
|
|
$val = $command->queryScalar();
|
|
|
|
|
|
|
|
return $val;
|
|
|
|
}
|
2014-07-05 21:15:24 +02:00
|
|
|
|
|
|
|
public static function startsWith($haystack, $needle)
|
|
|
|
{
|
|
|
|
$length = strlen($needle);
|
|
|
|
return (substr($haystack, 0, $length) === $needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function endsWith($haystack, $needle)
|
|
|
|
{
|
|
|
|
$length = strlen($needle);
|
|
|
|
if ($length == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (substr($haystack, -$length) === $needle);
|
|
|
|
}
|
2014-07-06 15:45:52 +02:00
|
|
|
|
|
|
|
public static function deleteDir($dirPath) {
|
|
|
|
if (! is_dir($dirPath)) {
|
|
|
|
throw new InvalidArgumentException("$dirPath must be a directory");
|
|
|
|
}
|
|
|
|
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
|
|
|
|
$dirPath .= '/';
|
|
|
|
}
|
|
|
|
$files = glob($dirPath . '*', GLOB_MARK);
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if (is_dir($file)) {
|
|
|
|
self::deleteDir($file);
|
|
|
|
} else {
|
|
|
|
unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmdir($dirPath);
|
|
|
|
}
|
2014-09-28 02:37:53 +02:00
|
|
|
|
|
|
|
public static function formatMilliseconds($millis)
|
|
|
|
{
|
|
|
|
if ($millis < 1000)
|
|
|
|
{
|
|
|
|
return $millis . 'ms';
|
|
|
|
}
|
|
|
|
else if ($millis < 10 * 1000)
|
|
|
|
{
|
|
|
|
return number_format($millis / (1000), 2) . 's';
|
|
|
|
}
|
|
|
|
else if ($millis < 60 * 1000)
|
|
|
|
{
|
|
|
|
return floor($millis / (1000)) . 's';
|
|
|
|
}
|
|
|
|
else if ($millis < 10 * 60 * 1000)
|
|
|
|
{
|
|
|
|
return floor($millis / (60 * 1000)) . 'min ' . floor(($millis % (60 * 1000)) / 1000) . 's';
|
|
|
|
}
|
|
|
|
else if ($millis < 60 * 60 * 1000)
|
|
|
|
{
|
|
|
|
return floor($millis / (60 * 1000)) . 'min';
|
|
|
|
}
|
|
|
|
else if ($millis < 10 * 60 * 60 * 1000)
|
|
|
|
{
|
|
|
|
return number_format($millis / (60 * 60 * 1000), 2) . ' hours';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return floor($millis / (60 * 60 * 1000)) . ' hours';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appends/Prepends $before/$after to every line in $input
|
|
|
|
*
|
|
|
|
* @param $input
|
|
|
|
* @param $before
|
|
|
|
* @param $after
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function encloseLines($input, $before, $after)
|
|
|
|
{
|
|
|
|
$array = preg_split("/\r\n|\n|\r/", $input);
|
|
|
|
|
|
|
|
for($i = 0; $i < count($array); $i++)
|
|
|
|
$array[$i] = $before . $array[$i] . $after;
|
|
|
|
|
|
|
|
return implode(PHP_EOL, $array);
|
|
|
|
}
|
2014-06-08 15:32:00 +02:00
|
|
|
}
|