summaryrefslogtreecommitdiff
path: root/app/helpers.php
blob: 7ac1fd6176cac15ddfdc8ffd11ebcfe019b4ed45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

function replaceSpecialChars($string) {
	$string = str_replace("&lt;i&gt;", "<i>", $string);
	$string = str_replace("&lt;/i&gt;", "</i>", $string);
	$string = str_replace("&lt;b&gt;", "<b>", $string);
	$string = str_replace("&lt;/b&gt;", "</b>", $string);
	$string = str_replace("&lt;br&gt;", "<br>", $string);
	$string = str_replace("%%br%%", "<br>", $string);

	return $string;
}

function _formatFloat($float, $size = 2) {
	#return number_format($float, $size, ",", ".");
	return number_format($float, $size);
}

function formatFloat($f) {
	if ( 0 == ($f - floor($f))) {
		$f = intval($f);
	} else {
		$f = _formatFloat($f);
	}

	return $f;
}

/**
 * Shorter alias to formatFloat().
 */
function fF($f) {
	return formatFloat($f);
}

function printScoreData($score_array) {
	$return = "[";

	foreach($score_array as $score) {
		try {
			$f_score = formatFloat($score);
		} catch( Exception $e ) {
			error_log("printScoreData: score data seems to be messed up: " . $e->getMessage());
			$f_score = 0;
		}

		if ( 0 != $f_score ) {
			$return .= $f_score;
		} else {
			$return .= "null";
		}
		$return .= ",";
	}

	rtrim($return, ",");

	$return .= "]";

	return $return;
}

function getAiringStatusCode($airing_status) {
	$status = DB::select("SELECT id FROM airing_status WHERE status = ?", array($airing_status));
	if ( empty($status) ) {
		return 4;
	}
	return $status[0]->id;
}