The code works perfect, but since I'm repeating myself (which I like to avoid while programming), I was wondering if this could be written any shorter/better?
$start = getLocaleDate($item[0]['start_day']);
$start = $start['day_int'] . ' ' . $start['month_string'];
if ($item[0]['start_houre'] !== '00:00:00') {
$houre = stripLeadingZero(substr($item[0]['start_houre'], 0, 2));
$minute = substr($item[0]['start_houre'], 3, 2);
$start .= ' at' . $houre . 'u' . $minute;
}
$end = getLocaleDate($item[0]['end_day']);
$end = $end['day_int'] . ' ' . $end['month_string'];
if ($item[0]['end_houre'] !== '00:00:00') {
$houre = stripLeadingZero(substr($item[0]['end_houre'], 0, 2));
$minute = substr($item[0]['end_houre'], 3, 2);
$end .= ' at' . $houre . 'u' . $minute;
}
Without changing any of the functionality, you could make it into a function:
function getTime($item, $which) {
$time = getLocaleDate($item[0][$which . '_day']);
$time = $time['day_int'] . ' ' . $time['month_string'];
if ($item[0][$which . '_houre'] !== '00:00:00') {
$houre = stripLeadingZero(substr($item[0][$which . '_houre'], 0, 2));
$minute = substr($item[0][$which . '_houre'], 3, 2);
$time .= ' at' . $houre . 'u' . $minute;
}
return $time;
}
$start = getTime($item, 'start');
$end = getTime($item, 'end');
* It should be noted that this code doesn't do any error checking/prevention though, so if there is no index 0 in the $item, you will have an error (same goes for $item[0]['start_day'], $item[0]['end_day'], etc). To handle a simple-case, you could add if (!isset($item[0])) return ''; to the beginning of the function, if it's a concern.
sure could you can write a function where you pass in your item and the key to use
function your_function($item, $key) {
$h = $item[$key.'_houre'];
$time = getLocaleDate($item[$key. '_day']);
$time = $end['day_int'] . ' ' . $end['month_string'];
if ($h !== '00:00:00') {
$houre = stripLeadingZero(substr($h , 0, 2));
$minute = substr($h , 3, 2);
$time .= ' at' . $houre . 'u' . $minute;
return $time;
}
}
your_function($item[0], 'end');
your_function($item[0], 'start');
Related
So what i am trying to do is for the function to return a string like this
January 19-20, 2018
the variables all i have are the initial date and the number of nights. Too bad there's no way to getDate or getYear like js. Thanks for the help
You can use this custom function:
function showDates($startDate, $nights) {
$d1=new DateTime($startDate);
$d2 = new DateTime($startDate);
$d2->add(new DateInterval("P10D"));
if ($d2->format('Y') == $d1->format('Y')) {
$year = $d1->format('Y');
} else {
$year = $d1->format('Y') . '-' . $d2->format('Y');
}
if ($d2->format('m') == $d1->format('m')) {
$month = $d1->format('F');
} else {
$month = $d1->format('F') . '-' . $d2->format('F');
}
if ($d2->format('d') == $d1->format('d')) {
$day = $d1->format('d');
} else {
$day = $d1->format('d') . '-' . $d2->format('d');
}
return $month . ' ' . $day . ' ' . $year;
}
echo showDates("2017-10-05 12:00:00", 3);
I don't know what are the errors of this code because it's suddenly not accurate the showing value to the user like this:
$holidays = array();
$query_holiday = "SELECT * FROM holiday_tbl";
$result = mysqli_query($dbcon, $query_holiday);
while($row_holiday = mysqli_fetch_assoc($result))
{
array_push($row_holiday, $holidays);
}
if(strtotime(date("Y-m-d")) > strtotime($row['due_date']))
{
$currentDate = date("Y-m-d");
$days = (strtotime($currentDate) - strtotime($row['due_date'])) / 86400;
$daysTemp = $days;
for($i=1;$i<$days;$i++)
{
$currentDay = date("D", strtotime("+ ".$i." days"));
$date_loop = date("Y-m-d", strtotime("+ ".$i." days"));
if($currentDay == "Sun" || $currentDay == "Sat")
{
$daysTemp--;
}
else if(in_array($date_loop, $holidays))
{
$daysTemp--;
}
}
echo $daysTemp;
}
The current implementation is rather convoluted. In these cases I find it's always better to start over and try to simplify the logic as much as possible. Here is my take on your problem:
function calculate_days_late($due_date = '', $holidays = array(), $current_date = 'today') {
$days_late = 0;
// Get the timestamps for due date and current date
$current_date_ts = strtotime($current_date);
$due_date_ts = strtotime($due_date);
// If current date is not after due date then not late
if ($current_date_ts <= $due_date_ts) {
return $days_late;
}
$loop_date_ts = $current_date_ts;
while ($loop_date_ts > $due_date_ts) {
// If the looping date is not a weekend or holiday then count it
if ( ! in_array(date('D', $loop_date_ts), array('Sat','Sun'))
&& ! in_array(date('Y-m-d', $loop_date_ts), $holidays)) {
$days_late++;
}
$loop_date_ts = strtotime('-1 day', $loop_date_ts);
}
return $days_late;
}
// Test
echo '2017-09-05 = ' . calculate_days_late('2017-09-05', array(), '2017-09-05') . "\n";
echo '2017-09-06 = ' . calculate_days_late('2017-09-05', array(), '2017-09-06') . "\n";
echo '2017-09-07 = ' . calculate_days_late('2017-09-05', array(), '2017-09-07') . "\n";
echo '2017-09-08 = ' . calculate_days_late('2017-09-05', array(), '2017-09-08') . "\n";
echo '2017-09-09 = ' . calculate_days_late('2017-09-05', array(), '2017-09-09') . "\n";
echo '2017-09-10 = ' . calculate_days_late('2017-09-05', array(), '2017-09-10') . "\n";
echo '2017-09-11 = ' . calculate_days_late('2017-09-05', array(), '2017-09-11') . "\n";
echo '2017-09-12 = ' . calculate_days_late('2017-09-05', array(), '2017-09-12') . "\n";
echo '2017-09-13 = ' . calculate_days_late('2017-09-05', array(), '2017-09-13') . "\n";
Working example: https://eval.in/856018
I am trying to get my code to work when the url its sent to does not have the variables needed.
this is the error:
E_WARNING : type 2 -- file_get_contents(the link): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found -- at line 23
Ex my code goes to this users page and everything okay:
https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/24267598/ranked?season=SEASON2016&api_key=e9044828-20e3-46cc-9eb5-545949299803
But when it goes to this users page it gives a error:
https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/77828400/ranked?season=SEASON2016&api_key=e9044828-20e3-46cc-9eb5-545949299803
What im after doing if when there is no content in url for it not to show anything and when there is to show it. But for some reason I cant get it to work with both.
Here is my code:
<?php
$apiKey = 'APIKEY';
$summonerName = 'raget deathdex';
$new = rawurlencode($summonerName);
$news = str_replace(' ', '', $summonerName);
$str = strtolower($news);
$result = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/' . $new . '?api_key=' . $apiKey);
$summoner = json_decode($result)->$str;
$id = $summoner->id;
?>
<?php
$claw = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/' . $id . '/ranked?season=SEASON2016&api_key=' . $apiKey);
$gaza = json_decode($claw);
?>
<?php
$entriesz = $gaza->champions;
usort($entriesz, function($ac,$bc){
return $bc->stats->totalSessionsPlayed-$ac->stats->totalSessionsPlayed;
});
foreach($entriesz as $statSummaryz) if ($tmp++ < 11){
$getLeagueNamelistside = $statSummaryz->id;
$getsessionsplayedNamelistside = $statSummaryz->stats->totalSessionsPlayed;
$getMiniomskillsNamelistside = $statSummaryz->stats->totalMinionKills;
$getkillsNamelistside = $statSummaryz->stats->totalChampionKills;
$getassistssNamelistside = $statSummaryz->stats->totalAssists;
$getdeathsNamelistside = $statSummaryz->stats->totalDeathsPerSession;
$getlosseslistside = $statSummaryz->stats->totalSessionsLost;
$getwinslistside = $statSummaryz->stats->totalSessionsWon;
$Percentkillrateside = $getkillsNamelistside / $getsessionsplayedNamelistside;
$Percentassistrateside = $getassistssNamelistside / $getsessionsplayedNamelistside;
$Percentdeathrateside = $getdeathsNamelistside / $getsessionsplayedNamelistside;
$KDAside = ($getkillsNamelistside + $getassistssNamelistside) / $getdeathsNamelistside;
$KDAMinniomsSide = $getMiniomskillsNamelistside / $getsessionsplayedNamelistside;
$PercentWinRateSide = 100 / ($getlosseslistside + $getwinslistside) * $getwinslistside;
if ($getLeagueNamelistside >=1){
$resultz = file_get_contents('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion/'.$getLeagueNamelistside.'?api_key=' . $apiKey);
$summonerz = json_decode($resultz, true);
$getLeagueNamelistsidez = $summonerz['name'];
$getLeagueKeyNamelistsidez = $summonerz['key'];
echo '<p><img src="http://lolchecker.esy.es/LOLGGWP/img/champion/' .$getLeagueKeyNamelistsidez. '.png"></p>'.$getLeagueNamelistsidez. '<p> Kills '.number_format((float)$Percentkillrateside, 1, '.', '').'</p><p> Deaths '.number_format((float)$Percentdeathrateside, 1, '.', '').'</p><p> Assists '.number_format((float)$Percentassistrateside, 1, '.', '').'</p><p> KDA '.number_format((float)$KDAside, 2, '.', '').':1 KDA</p><p> CS '.number_format((float)$KDAMinniomsSide, 1, '.', '').' CS</p><p> Games Played '.$getsessionsplayedNamelistside.'</p><p> Win Rate '.number_format((float)$PercentWinRateSide, 0, '.', '').'%</p>';
}
elseif($getLeagueNamelistside =0){
return DO_NOTHING;
}
}
?>
Try this ;)
$news = str_replace(' ', '', $summonerName);
$str = strtolower($news);
$result = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/' . $new . '?api_key=' . $apiKey);
$summoner = json_decode($result)->$str;
$id = $summoner->id;
$claw = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/' . $id . '/ranked?season=SEASON2016&api_key=' . $apiKey);
$gaza = json_decode($claw);
if (isset($gaza->champions)) {
$entriesz = $gaza->champions;
usort($entriesz, function($ac, $bc) {
return $bc->stats->totalSessionsPlayed - $ac->stats->totalSessionsPlayed;
});
foreach ($entriesz as $statSummaryz) {
if ($tmp++ < 11) {
$getLeagueNamelistside = $statSummaryz->id;
$getsessionsplayedNamelistside = $statSummaryz->stats->totalSessionsPlayed;
$getMiniomskillsNamelistside = $statSummaryz->stats->totalMinionKills;
$getkillsNamelistside = $statSummaryz->stats->totalChampionKills;
$getassistssNamelistside = $statSummaryz->stats->totalAssists;
$getdeathsNamelistside = $statSummaryz->stats->totalDeathsPerSession;
$getlosseslistside = $statSummaryz->stats->totalSessionsLost;
$getwinslistside = $statSummaryz->stats->totalSessionsWon;
$Percentkillrateside = $getkillsNamelistside / $getsessionsplayedNamelistside;
$Percentassistrateside = $getassistssNamelistside / $getsessionsplayedNamelistside;
$Percentdeathrateside = $getdeathsNamelistside / $getsessionsplayedNamelistside;
$KDAside = ($getkillsNamelistside + $getassistssNamelistside) / $getdeathsNamelistside;
$KDAMinniomsSide = $getMiniomskillsNamelistside / $getsessionsplayedNamelistside;
$PercentWinRateSide = 100 / ($getlosseslistside + $getwinslistside) * $getwinslistside;
if ($getLeagueNamelistside >= 1) {
$resultz = file_get_contents('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion/' . $getLeagueNamelistside . '?api_key=' . $apiKey);
$summonerz = json_decode($resultz, true);
$getLeagueNamelistsidez = $summonerz['name'];
$getLeagueKeyNamelistsidez = $summonerz['key'];
echo '<p><img src="http://lolchecker.esy.es/LOLGGWP/img/champion/' . $getLeagueKeyNamelistsidez . '.png"></p>' . $getLeagueNamelistsidez . '<p> Kills ' . number_format((float) $Percentkillrateside, 1, '.', '') . '</p><p> Deaths ' . number_format((float) $Percentdeathrateside, 1, '.', '') . '</p><p> Assists ' . number_format((float) $Percentassistrateside, 1, '.', '') . '</p><p> KDA ' . number_format((float) $KDAside, 2, '.', '') . ':1 KDA</p><p> CS ' . number_format((float) $KDAMinniomsSide, 1, '.', '') . ' CS</p><p> Games Played ' . $getsessionsplayedNamelistside . '</p><p> Win Rate ' . number_format((float) $PercentWinRateSide, 0, '.', '') . '%</p>';
} elseif ($getLeagueNamelistside == 0) {
return DO_NOTHING;
}
}
}
}
You should be able to check the file contents in order to determine it has the required data.
<?php
$claw = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/' . $id . '/ranked?season=SEASON2016&api_key=' . $apiKey);
if(false === empty($claw)) {
$gaza = json_decode($claw);
if(true === empty($gaza->champion)) {
return 'Invalid data received';
}
} else {
return 'No data found';
}
?>
It also looks like you have a syntax error on your comparison condition which is using an assignment operator which will always evaluate to true. But unsure if that portion of your code is used or not.
elseif($getLeagueNamelistside =0){
Should just be
else {
which will function as if ($getLeagueNamelistside <= 0) return DO_NOTHING;
UPDATE
To prevent the file not found error, and others from being displayed, you can disable the display of error messages. Which should be the case in production code anyways.
ini_set('display_errors', 'off');
Or filter the display of only certain error messages.
ini_set('error_reporting', E_ERROR | E_PARSE);
You can also bypass error reporting of specific commands by prepending #
#file_get_contents('https://example.com/index.php');
Last but not least, and my preferred method, is to use output buffering to prevent undesired content from outputting to the client.
ob_start();
echo file_get_contents('https://example.com/index.php');
$content = ob_get_clean();
echo false === strpos($content, '404') ? $content : 'OOps';
Is this what you're trying to do?
PHP treats strings like a byte array. Instead of checking if a string is empty of if the strings length is greater than 0, I like to check to see if the first byte is set. Some people consider it less humanly readable, but thats just some people.
Use isset($mystring[0]) to see if a string is at least one character in length.
The # symbol before the file_get_contents is for error suppression. The # prevents an error from appearing in your browser if the file can't be found.
<?php
$apiKey = 'e9044828-20e3-46cc-9eb5-545949299803';
$summonerName = 'raget deathdex';
$new = rawurlencode($summonerName);
$news = str_replace(' ', '', $summonerName);
$str = strtolower($news);
$result = #file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/' . $new . '?api_key=' . $apiKey);
if(!isset($result[0])) {
die(); // die('Nothing found in \'result\' file.');
}
$summoner = json_decode($result)->$str;
if(!$summoner) {
die(); // die('Nothing found in \'result\' content.');
}
$id = $summoner->id;
?>
<?php
$claw = #file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/' . $id . '/ranked?season=SEASON2016&api_key=' . $apiKey);
if(!isset($claw[0])) {
die(); // die('Nothing found in \'claw\' file.');
}
$gaza = json_decode($claw);
if(!$gaza) {
die(); // die('Nothing found in \'claw\' content.');
}
?>
<?php
$entriesz = $gaza->champions;
usort($entriesz, function($ac,$bc){
return $bc->stats->totalSessionsPlayed-$ac->stats->totalSessionsPlayed;
});
foreach($entriesz as $statSummaryz) if ($tmp++ < 11){
$getLeagueNamelistside = $statSummaryz->id;
$getsessionsplayedNamelistside = $statSummaryz->stats->totalSessionsPlayed;
$getMiniomskillsNamelistside = $statSummaryz->stats->totalMinionKills;
$getkillsNamelistside = $statSummaryz->stats->totalChampionKills;
$getassistssNamelistside = $statSummaryz->stats->totalAssists;
$getdeathsNamelistside = $statSummaryz->stats->totalDeathsPerSession;
$getlosseslistside = $statSummaryz->stats->totalSessionsLost;
$getwinslistside = $statSummaryz->stats->totalSessionsWon;
$Percentkillrateside = $getkillsNamelistside / $getsessionsplayedNamelistside;
$Percentassistrateside = $getassistssNamelistside / $getsessionsplayedNamelistside;
$Percentdeathrateside = $getdeathsNamelistside / $getsessionsplayedNamelistside;
$KDAside = ($getkillsNamelistside + $getassistssNamelistside) / $getdeathsNamelistside;
$KDAMinniomsSide = $getMiniomskillsNamelistside / $getsessionsplayedNamelistside;
$PercentWinRateSide = 100 / ($getlosseslistside + $getwinslistside) * $getwinslistside;
if ($getLeagueNamelistside >=1){
$resultz = #file_get_contents('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion/'.$getLeagueNamelistside.'?api_key=' . $apiKey);
if(!isset($resultz[0])) {
die(); // die('Nothing found in league file:' . $getLeagueNamelistside);
}
$summonerz = json_decode($resultz, true);
if(!summonerz) {
die(); // die('Nothing found in league content:' . $getLeagueNamelistside);
}
$getLeagueNamelistsidez = $summonerz['name'];
$getLeagueKeyNamelistsidez = $summonerz['key'];
echo '<p><img src="http://lolchecker.esy.es/LOLGGWP/img/champion/' .$getLeagueKeyNamelistsidez. '.png"></p>'.$getLeagueNamelistsidez. '<p> Kills '.number_format((float)$Percentkillrateside, 1, '.', '').'</p><p> Deaths '.number_format((float)$Percentdeathrateside, 1, '.', '').'</p><p> Assists '.number_format((float)$Percentassistrateside, 1, '.', '').'</p><p> KDA '.number_format((float)$KDAside, 2, '.', '').':1 KDA</p><p> CS '.number_format((float)$KDAMinniomsSide, 1, '.', '').' CS</p><p> Games Played '.$getsessionsplayedNamelistside.'</p><p> Win Rate '.number_format((float)$PercentWinRateSide, 0, '.', '').'%</p>';
}
elseif($getLeagueNamelistside == 0){
die();
}
}
?>
<?php
$apiKey = 'e9044828-20e3-46cc-9eb5-545949299803';
$summonerName = 'raget deathdex';
// =====
$results = #file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/' . rawurlencode($summonerName) . '?api_key=' . $apiKey);
if(!isset($results[0]))
die();
$summoner = json_decode($results)->strtolower(str_replace(' ', '', $summonerName));
if(!$summoner)
die();
$results = #file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/' . $summoner->id . '/ranked?season=SEASON2016&api_key=' . $apiKey);
if(!isset($results[0]))
die();
$gaza = json_decode($results);
if(!$gaza)
die();
// =====
$entriesz = $gaza->champions;
usort($entriesz, function($ac, $bc){
return $bc->stats->totalSessionsPlayed-$ac->stats->totalSessionsPlayed;
});
// =====
foreach($entriesz as $statSummaryz) {
if($tmp++ < 11) {
$getLeagueNamelistside = $statSummaryz->id;
$getsessionsplayedNamelistside = $statSummaryz->stats->totalSessionsPlayed;
$getMiniomskillsNamelistside = $statSummaryz->stats->totalMinionKills;
$getkillsNamelistside = $statSummaryz->stats->totalChampionKills;
$getassistssNamelistside = $statSummaryz->stats->totalAssists;
$getdeathsNamelistside = $statSummaryz->stats->totalDeathsPerSession;
$getlosseslistside = $statSummaryz->stats->totalSessionsLost;
$getwinslistside = $statSummaryz->stats->totalSessionsWon;
$Percentkillrateside = $getkillsNamelistside / $getsessionsplayedNamelistside;
$Percentassistrateside = $getassistssNamelistside / $getsessionsplayedNamelistside;
$Percentdeathrateside = $getdeathsNamelistside / $getsessionsplayedNamelistside;
$KDAside = ($getkillsNamelistside + $getassistssNamelistside) / $getdeathsNamelistside;
$KDAMinniomsSide = $getMiniomskillsNamelistside / $getsessionsplayedNamelistside;
$PercentWinRateSide = 100 / ($getlosseslistside + $getwinslistside) * $getwinslistside;
if($getLeagueNamelistside >= 1) {
$results = #file_get_contents('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion/' . $getLeagueNamelistside . '?api_key=' . $apiKey);
if(!isset($results[0]))
die();
}
$summonerz = json_decode($results, true);
if(!$summonerz)
die();
$getLeagueNamelistsidez = $summonerz['name'];
$getLeagueKeyNamelistsidez = $summonerz['key'];
echo
'<p><img src="http://lolchecker.esy.es/LOLGGWP/img/champion/', $getLeagueKeyNamelistsidez, '.png"></p>',
$getLeagueNamelistsidez,
'<p> Kills ', number_format((float)$Percentkillrateside, 1, '.', ''),
'</p><p> Deaths ', number_format((float)$Percentdeathrateside, 1, '.', ''),
'</p><p> Assists ', number_format((float)$Percentassistrateside, 1, '.', ''),
'</p><p> KDA ', number_format((float)$KDAside, 2, '.', ''),
':1 KDA</p><p> CS ', number_format((float)$KDAMinniomsSide, 1, '.', ''),
' CS</p><p> Games Played ', $getsessionsplayedNamelistside,
'</p><p> Win Rate ', number_format((float)$PercentWinRateSide, 0, '.', ''),
'%</p>', "\n";
}
elseif($getLeagueNamelistside == 0)
die();
}
i have this variable: $this->{$prefix . '_total'} that can equal any number depending on the case but for the time being lets say $this->{$prefix . '_total'} = 4000.
So i use $this->{$prefix . '_total'} in order to get 4,000.
However, i dont know why but i get 4 instead.
Whats happening to the other zeros?? I tried with different values such as 1564.13 for example and in all cases the output its only the very first number. So i tried it like this:
number_format(($this->{$prefix . '_total'}*100000))
and it doesnt work either! I still get only the first digit. Why?? This blows my mind at so many levels. Please help.
Thank you.
Full function:
function render($indent = "", InvoicePayment $payment = null)
{
$prefix = (!is_null($payment) && !$payment->isFirst()) ? 'second' : 'first';
$tm_added = is_null($payment) ? $this->tm_added : $payment->dattm;
$newline = "\r\n";
$price_width = max(mb_strlen(Am_Currency::render($this->{$prefix . '_total'}, $this->currency)), 8);
$column_padding = 1;
$column_title_max = 60;
$column_title_min = 20;
$column_qty = 4 + $price_width;
$column_num = 3;
$column_amount = $price_width;
$space = str_repeat(' ', $column_padding);
$max_length = 0;
foreach ($this->getItems() as $item) {
$max_length = max(mb_strlen(___($item->item_title)), $max_length);
}
$column_title = max(min($max_length, $column_title_max), $column_title_min);
$row_width = $column_num + $column_padding +
$column_title + $column_padding +
$column_qty + $column_padding +
$column_amount + $column_padding;
$column_total = $column_title +
$column_qty + $column_padding;
$total_space = str_repeat(' ', $column_padding + $column_num + $column_padding);
$border = $indent . str_repeat('-', $row_width) . "$newline";
$out = $indent . ___("Invoice") . ' #' . $this->public_id . " / " . amDate($tm_added) . "$newline";
$out .= $border;
$num = 1;
foreach ($this->getItems() as $item) {
$title = explode("\n", $this->wordWrap(___($item->item_title), $column_title, "\n", true));
$out .= $indent . sprintf("{$space}%{$column_num}s{$space}%-{$column_title}s{$space}%{$column_qty}s{$space}%{$price_width}s$newline",
$num . '.', $title[0], $item->qty . 'x' . Am_Currency::render($item->{$prefix . '_price'}, $this->currency), Am_Currency::render($item->{$prefix . '_total'}, $this->currency));
for ($i=1; $i<count($title); $i++)
$out .= $indent . sprintf("{$space}%{$column_num}s{$space}%-{$column_title}s$newline", ' ', $title[$i]);
$num++;
}
$out .= $border;
if ($this->{$prefix . '_subtotal'} != $this->{$prefix . '_total'})
$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Subtotal'), Am_Currency::render($this->{$prefix . '_subtotal'}, $this->currency));
if ($this->{$prefix . '_discount'} > 0)
$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Discount'), Am_Currency::render($this->{$prefix . '_discount'}, $this->currency));
if ($this->{$prefix . '_shipping'} > 0)
$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Shipping'), Am_Currency::render($this->{$prefix . '_shipping'}, $this->currency));
if ($this->{$prefix . '_tax'} > 0)
$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Tax'), Am_Currency::render(number_format($this->{$prefix . '_tax'}), $this->currency));
$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Total'), Am_Currency::render($this->{$prefix . '_total'}, $this->currency));
$out .= $border;
if ($this->rebill_times) {
$terms = explode("\n", $this->wordWrap(___($this->getTerms()), $row_width, "\n", true));
foreach ($terms as $term_part)
$out .= $indent . $term_part . $newline;
$out .= $border;
}
return $out;
}
And this is the render function
static function render($value, $currency = null, $locale = null)
{
return (string)self::create($value, $currency, $locale);
}
public function __toString()
{
$format = array_key_exists($this->currency, $this->formats) ?
$this->formats[$this->currency] :
'%.2f %s';
return sprintf($format, $this->value, $this->currency);
}
Try this
<?php
echo number_format($number,0,'',',');
?>
Stabbing into the dark here to explain the phenomenon:
echo (int)number_format(1000);
This results in "1". Because number_format produces "1,000", and (int) tries to parse it back into an integer, and since "," is not a valid part of an integer specification that's where it stops and returns only "1". See http://php.net/manual/en/language.types.string.php#language.types.string.conversion.
Something like this must be happening in your Am_Currency::render.
Few days ago server crashed and was down for few hours, after server become available, my calendar started to display wrong data. It had to show me current month and 5 next(half a year in total). Server data is correct. Any ideas whats wrong with calendar? Does mysql server time can make my calendar show wrong data?
if (!isset($_MONTH))
$_MONTH = 6;
if (isset($_POST['subscribe_month']))
$_MONTH = $class->_dig($_POST['subscribe_month']);
$sql = mysql_query("SELECT d.header, d.id FROM " . $class->_cfg['pfx'] . "workshops as w
LEFT JOIN " . $class->_cfg['pfx'] . "workshops_date as wd ON wd.cid=w.id
LEFT JOIN " . $class->_cfg['pfx'] . "dictionary as d ON d.id=wd.city
WHERE w.public='1' and wd.public='1' and wd.date_end>='" . date("Y-m-d") . "' a
nd wd.predprosomtr='0' " . $where . " ORDER BY d.rang");
$CityList = array();
while ($_sql = mysql_fetch_assoc($sql)) {
$CityList[$_sql['id']] = $_sql['header'];
}
if ($Fcity && $Fcity != 0)
$where.=" and d.id=" . $Fcity . "";
elseif ($_POST['city'] && $class->_dig($_POST['city']) > 0)
$where.=" and d.id=" . $class->_dig($_POST['city']) . "";
if ($CitySearch != 0)
$where.=" and wd.city=" . $CitySearch . " ";
$sql = mysql_query("SELECT w.header, w.direction, w.subheader, wd.colsmonth, wd.is_new, wd.public_date_finish, wd.p_date_finish, w.aliaslink, wd.aliaslink as wd_aliaslink, w.direction, wd.city, wd.date_start, d.header as city_name, wd.date_end, wd.cid, wd.id as wd_id, w.id as w_id FROM " . $class->_cfg['pfx'] . "workshops as w
LEFT JOIN " . $class->_cfg['pfx'] . "workshops_date as wd ON wd.cid=w.id
LEFT JOIN " . $class->_cfg['pfx'] . "dictionary as d ON d.id=wd.city
WHERE w.public='1' and wd.public='1' and wd.date_end>='" . date("Y-m-d") . "' and w.direction<>'' and wd.predprosomtr='0' " . $where . " ORDER BY wd.date_start, wd.city");
//$output.=$where;
$month = 12;
$year = date("Y");
while ($_sql = mysql_fetch_assoc($sql)) {
$view = true;
if ($_sql['public_date_finish'] == '1' && $_sql['p_date_finish'] < date("Y-m-d"))
$view = false;
if ($view) {
$arWorkshops[$_sql['w_id']] = $_sql;
if (!isset($arWorkshopsCity[$_sql['cid']][$_sql['city']]) && $_sql['city'] > 0)
$arWorkshopsCity[$_sql['cid']][$_sql['city']] = $_sql['city'];
if (isset($arWorkshopsDate[$_sql['cid']]['count']))
$arWorkshopsDate[$_sql['cid']]['count'] = $arWorkshopsDate[$_sql['cid']]['count'] + 1;
else
$arWorkshopsDate[$_sql['cid']]['count'] = 1;
$direct = explode('#', $_sql['direction']);
for ($i = 0; $i < count($direct); $i++) {
if (trim($direct[$i]) != '') {
$arDirectionList[$direct[$i]] = $direct[$i];
}
}
//$arDirectionList[$_sql['direction']]=$_sql['direction'];
if (!isset($arWorkshopsDate[$_sql['cid']][ceil($class->convert_date($_sql['date_start'], '.', "month"))]))
$arWorkshopsDate[$_sql['cid']][ceil($class->convert_date($_sql['date_start'], '.', "month"))] = $_sql;
if ($class->convert_date($_sql['date_start'], '.', "month") < $month && $class->convert_date($_sql['date_start'], '.', "year") == $year) {
$month = $class->convert_date($_sql['date_start'], '.', "month");
$year = $class->convert_date($_sql['date_start'], '.', "year");
}
//if($class->convert_date($_sql['date_start'], '.', "year")==(date("Y")+1))$year=$class->convert_date($_sql['date_start'], '.', "year");
//$output.=$_sql['header']."-".$_sql['date_start']."-".$_sql['wd_id']."<br>";
}
}
//var_dump($arWorkshopsDate[185]);
$output.='<table class="table"><tr><th width="60"> </th><th class="first" style="width:auto">Название</th>';
if ($_MONTH == 12)
$w = "5%"; else
$w = "9%";
for ($i = $month; $i < ($month + $_MONTH); $i++) {
if ($year == date("Y"))
$m = $i;else
$m++;
if ($m <= 12 && $year == date("Y")) {
$output.='<th class="month" style="width:' . $w . '">' . $class->convert_date($m, '.', "myear") . ' <span>' . $year . '</span></th>';
} else {
if ($m > 12) {
$m = 1;
$year = $year + 1;
}
$output.='<th class="month" style="width:' . $w . '">' . $class->convert_date($m, '.', "myear") . ' <span>' . $year . '</span></th>';
}
}
$output.=' <th style="width:10%">';
if ($typeblock == 'webinars')
$output.='Формат';
else
$output.='Город';
$output.='</th></tr>';
if (isset($arWorkshops)) {
//foreach($arWorkshops as $LO=>$listOrd){
foreach ($arWorkshops as $k => $value) {
if (!$direction || $direction == 0)
$direction2 = $class->_direction($value['direction']);
else
$direction2 = $direction;
foreach ($arWorkshopsCity[$k] as $LO => $listOrd) {
$output2 = "";
$link_date = "";
$pt = 0;
$m_nth = ceil($month);
$is_new_class = '';
for ($i = ceil($month); $i < ($month + $_MONTH); $i++) {
if ($m_nth > 12)
$m_nth = 1;
if (isset($arWorkshopsDate[$k][$m_nth]) && $arWorkshopsDate[$k][$m_nth]['city'] == $LO) {
$pt++;
if ($pt == 1)
$city_name = $arWorkshopsDate[$k][$m_nth]['city_name'];
//if(isset($_TYPE) && $_TYPE!=0)$output.='<td class="date"><a href="/'.$typeblock.'/'.$value['aliaslink'].'/'.$arWorkshopsDate[$k][$i]['wd_aliaslink'].'/">';
//else
if (($arWorkshopsDate[$k][$m_nth]['is_new'] == '1') || ($arWorkshopsDate[$k][$m_nth + 1]['is_new'] == '1')) {
$is_new_class = " it_is_new";
} else {
$is_new_class = '';
}
$output2.='<td class="date"><a href="/' . $typeblock . '/' . $arDictionaryID[$direction2]['aliaslink'] . '/' . $value['aliaslink'] . '/' . $arWorkshopsDate[$k][$m_nth]['wd_aliaslink'] . '/">';
$link_date = '/' . $typeblock . '/' . $arDictionaryID[$direction2]['aliaslink'] . '/' . $value['aliaslink'] . '/' . $arWorkshopsDate[$k][$m_nth]['wd_aliaslink'] . '/';
if ($arWorkshopsDate[$k][$m_nth]['colsmonth'] > 0)
$output2.=$class->convert_date($arWorkshopsDate[$k][$m_nth]['date_start'], '.', "day_month") . "</a><br />" . $arWorkshopsDate[$k][$m_nth]['colsmonth'] . " мес.";
elseif ($arWorkshopsDate[$k][$m_nth]['date_start'] == $arWorkshopsDate[$k][$m_nth]['date_end'])
$output2.=$class->convert_date($arWorkshopsDate[$k][$m_nth]['date_start'], '.', "day_month") . "</a>";
else
$output2.=$class->convert_date($arWorkshopsDate[$k][$m_nth]['date_start'], '.', "day_month") . "<br />-" . $class->convert_date($arWorkshopsDate[$k][$m_nth]['date_end'], '.', "day_month") . "</a>";
$output2.='</td>';
}else {
$output2.='<td></td>';
}
$m_nth++;
}
if (($arWorkshopsDate[$k][$m_nth]['is_new'] == '1')) {
$is_new_class = " it_is_new";
}
$output.='<tr><td class="' . $is_new_class . '"> </td><td>';
//if(isset($_TYPE) && $_TYPE!=0)$output.='<strong>'.$value['header'].'</strong>';
//else
if ($pt == 1 && $arWorkshopsDate[$k]['count'] == 1)
$link = $link_date;
else
$link = '/' . $typeblock . '/' . $arDictionaryID[$direction2]['aliaslink'] . '/' . $value['aliaslink'] . '/';
$output.='<a href="' . $link . '"><strong>' . $value['header'] . '</strong>';
if (trim($value['subheader']) != '')
$output.=': ' . $value['subheader'] . '';
$output.='</a>';
$output.='</td>';
$output.=$output2;
$output.=' <td class="city">' . $city_name . '</td></tr>';
}
}
//}
}
$output.='</table>';
?>
Issue solved. By default some "good" coder made it show only from 12th month in $month = 12;
I just changed it to $month = date("m"); And this solved my issue