Browse Source

- Fixing the sessionx start time with a new column in the database

- Use the set timezone to compute the correct dates
pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
f1dbc6a7bb
  1. 9
      app/helpers/DateHelper.php
  2. 3
      app/models/sessionx/Sessionx.php
  3. 5
      app/models/sessionx/SessionxDAO.php
  4. 5
      app/widgets/Statistics/Statistics.php
  5. 4
      app/widgets/Statistics/statistics.tpl
  6. 5
      system/Sessionx.php

9
app/helpers/DateHelper.php

@ -34,6 +34,11 @@ function getMonths() {
12 => t('December'));
}
function getTimezoneCorrection() {
$timezones = getTimezoneList();
return $timezones[date_default_timezone_get()];
}
/**
* Return a human-readable date
*
@ -46,6 +51,10 @@ function prepareDate($time, $hours = true) {
$moty = getMonths();
$today = strtotime(date('M j, Y'));
// We fix the timezone
$time = $time + 3600*(int)getTimezoneCorrection();
$reldays = ($time - $today)/86400;
if ($reldays >= 0 && $reldays < 1) {

3
app/models/sessionx/Sessionx.php

@ -16,6 +16,7 @@ class Sessionx extends Model {
public $domain;
public $config;
public $active;
public $start;
public $timestamp;
public function __construct() {
@ -47,6 +48,8 @@ class Sessionx extends Model {
{"type":"text" },
"active" :
{"type":"int", "size":4 },
"start" :
{"type":"date" },
"timestamp" :
{"type":"date" }
}';

5
app/models/sessionx/SessionxDAO.php

@ -18,6 +18,7 @@ class SessionxDAO extends SQL {
domain = :domain,
config = :config,
active = :active,
start = :start,
timestamp = :timestamp
where session = :session';
@ -37,6 +38,7 @@ class SessionxDAO extends SQL {
'domain' => $s->domain,
'config' => $s->config,
'active' => $s->active,
'start' => $s->start,
'timestamp' => $s->timestamp
)
);
@ -59,6 +61,7 @@ class SessionxDAO extends SQL {
domain,
config,
active,
start,
timestamp)
values
(:session,
@ -74,6 +77,7 @@ class SessionxDAO extends SQL {
:domain,
:config,
:active,
:start,
:timestamp)';
$this->prepare(
@ -92,6 +96,7 @@ class SessionxDAO extends SQL {
'domain' => $s->domain,
'config' => $s->config,
'active' => $s->active,
'start' => $s->start,
'timestamp' => $s->timestamp
)
);

5
app/widgets/Statistics/Statistics.php

@ -23,8 +23,7 @@ class Statistics extends WidgetBase {
$this->view->assign('sessions', $sd->getAll());
}
function getTime($rid) {
$seconds = $rid*30;
return prepareDate(time() - $seconds, true);
function getTime($date) {
return prepareDate(strtotime($date));
}
}

4
app/widgets/Statistics/statistics.tpl

@ -6,7 +6,9 @@
</li>
{loop="$sessions"}
<li>
<a class="action">{$c->getTime($value->rid)}</a>
{if="isset($value->start)"}
<a class="action">{$c->getTime($value->start)}</a>
{/if}
<a>{$value->username}@{$value->host}</a>
</li>
{/loop}

5
system/Sessionx.php

@ -35,6 +35,7 @@ class Sessionx {
private $_port;
private $_host;
private $_domain;
private $_start;
private $_active = false;
private $_config;
/*
@ -88,6 +89,7 @@ class Sessionx {
$s->domain = $this->_domain;
$s->config = serialize($this->_config);
$s->active = $this->_active;
$s->start = $this->_start;
$s->timestamp = $this->_timestamp;
return $s;
}
@ -102,6 +104,7 @@ class Sessionx {
$this->_user = $user;
$this->_password = $pass;
$this->_ressource = 'moxl'.\generateKey(6);
$this->_start = date(DATE_ISO8601);
$this->_rid = 0;
$this->_id = 0;
@ -128,6 +131,7 @@ class Sessionx {
$this->_domain = $session->domain;
$this->_config = unserialize($session->config);
$this->_active = $session->active;
$this->_start = $session->start;
$this->_timestamp = $session->timestamp;
}
@ -152,6 +156,7 @@ class Sessionx {
'user',
'config',
'password',
'start',
'ressource')
)
) {

Loading…
Cancel
Save