public static function getLastConnectionInfo($source, $communication_type = '') { $sql = "SELECT * FROM `" . Listener::tableName() . "` WHERE UPPER(`source`) = UPPER(?)"; if ($communication_type != '') { $sql .= "AND additional_param='" . $communication_type . "'"; } $sql .= " ORDER BY `created` DESC"; $res = Yii::app()->db->createCommand($sql)->queryRow(true, array($source)); if (!$res) { return null; } $res['started_show'] = date('M jS, H:i', $res['started']); if (!$res['stopped']) { $res['duration'] = time() - $res['started']; $res['stopped_show'] = ''; } else { $res['duration'] = $res['stopped'] - $res['started']; $res['stopped_show'] = date('M jS, H:i', $res['stopped']); } if ($res['duration']) { $hour = floor($res['duration'] / 3600); //PHP Error[8]: Undefined index: duration_formatted line 123 // i don't have idea about that if ($hour) { $res['duration_formatted'] = $hour . 'hr'; } $min = floor(($res['duration'] - $hour * 3600) / 60); if ($min) { $res['duration_formatted'] .= ($res['duration_formatted'] ? ' ' : '') . $min . 'min'; } $sec = $res['duration'] - $min * 60 - $hour * 3600; if ($sec) { $res['duration_formatted'] .= ($res['duration_formatted'] ? ' ' : '') . $sec . 'sec'; } } else { $res['duration_formatted'] = '0 sec'; } return $res; }