mirror of
https://github.com/Mibew/mibew.git
synced 2024-11-15 08:34:11 +03:00
Extend by page statistics
This commit is contained in:
parent
734c68a022
commit
62a2176aaa
@ -202,7 +202,11 @@ $dbtables = array(
|
||||
"date" => "int NOT NULL DEFAULT 0",
|
||||
"address" => "varchar(1024)",
|
||||
"visits" => "int NOT NULL DEFAULT 0",
|
||||
"chats" => "int NOT NULL DEFAULT 0"
|
||||
"chats" => "int NOT NULL DEFAULT 0",
|
||||
"sentinvitations" => "int NOT NULL DEFAULT 0",
|
||||
"acceptedinvitations" => "int NOT NULL DEFAULT 0",
|
||||
"rejectedinvitations" => "int NOT NULL DEFAULT 0",
|
||||
"ignoredinvitations" => "int NOT NULL DEFAULT 0"
|
||||
),
|
||||
);
|
||||
|
||||
@ -254,7 +258,7 @@ $dbtables_can_update = array(
|
||||
"${mysqlprefix}chatsitevisitor" => array(),
|
||||
"${mysqlprefix}requestcallback" => array("callbackid", "token", "function", "arguments"),
|
||||
"${mysqlprefix}visitedpage" => array(),
|
||||
"${mysqlprefix}visitedpagestatistics" => array(),
|
||||
"${mysqlprefix}visitedpagestatistics" => array("sentinvitations", "acceptedinvitations", "rejectedinvitations", "ignoredinvitations"),
|
||||
);
|
||||
|
||||
function show_install_err($text)
|
||||
|
@ -240,6 +240,22 @@ if ($act == "silentcreateall") {
|
||||
runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vchosturl varchar(255) DEFAULT ''", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}visitedpagestatistics.sentinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD sentinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}visitedpagestatistics.acceptedinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD acceptedinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}visitedpagestatistics.rejectedinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD rejectedinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if (in_array("${mysqlprefix}visitedpagestatistics.ignoredinvitations", $absent_columns)) {
|
||||
runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD ignoredinvitations int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
// Add absent indexes
|
||||
$absent_indexes = array();
|
||||
foreach ($dbtables_indexes as $id => $indexes) {
|
||||
|
@ -427,30 +427,204 @@ function calculate_page_statistics() {
|
||||
$start = empty($result['start']) ? 0 : $result['start'];
|
||||
$today = floor(time() / (24*60*60)) * 24*60*60;
|
||||
|
||||
$statistics = array();
|
||||
|
||||
// Calculate statistics
|
||||
$db->query(
|
||||
"INSERT INTO {visitedpagestatistics} (" .
|
||||
"date, address, visits, chats" .
|
||||
") SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " .
|
||||
"p.address AS address, " .
|
||||
"COUNT(DISTINCT p.pageid) AS visittimes, " .
|
||||
"COUNT(DISTINCT t.threadid) AS chattimes " .
|
||||
"FROM {visitedpage} p " .
|
||||
"LEFT OUTER JOIN {chatthread} t ON (" .
|
||||
"p.address = t.referer " .
|
||||
"AND DATE(FROM_UNIXTIME(p.visittime)) = " .
|
||||
"DATE(FROM_UNIXTIME(t.dtmcreated))) " .
|
||||
"WHERE p.calculated = 0 " .
|
||||
"AND (p.visittime - :start) > 24*60*60 " .
|
||||
"AND (:today - p.visittime) > 24*60*60 " .
|
||||
"GROUP BY date, address " .
|
||||
"ORDER BY date",
|
||||
// Get main pages info
|
||||
$db_results = $db->query(
|
||||
"SELECT FLOOR(visittime / (24*60*60)) * 24*60*60 AS date, " .
|
||||
"address, " .
|
||||
"COUNT(DISTINCT pageid) AS visits " .
|
||||
"FROM {visitedpage} ".
|
||||
"WHERE calculated = 0 " .
|
||||
"AND (visittime - :start) > 24*60*60 " .
|
||||
"AND (:today - visittime) > 24*60*60 " .
|
||||
"GROUP BY date, address",
|
||||
array(
|
||||
':start' => $start,
|
||||
':today' => $today
|
||||
)
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
foreach($db_results as $result) {
|
||||
$statistics[$result['date'] . '_' . $result['address']] = $result;
|
||||
}
|
||||
|
||||
// Get total chats count
|
||||
$db_results = $db->query(
|
||||
"SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " .
|
||||
"p.address AS address, " .
|
||||
"COUNT(DISTINCT t.threadid) AS chats " .
|
||||
"FROM {visitedpage} p, {chatthread} t, " .
|
||||
"(SELECT " .
|
||||
"COUNT(*) AS msgs, " .
|
||||
"m.threadid " .
|
||||
"FROM {indexedchatmessage} m " .
|
||||
"WHERE m.ikind = :kind_user OR m.ikind = :kind_agent " .
|
||||
"GROUP BY m.threadid) tmp " .
|
||||
"WHERE t.referer = p.address " .
|
||||
"AND p.calculated = 0 " .
|
||||
"AND t.threadid = tmp.threadid " .
|
||||
"AND tmp.msgs > 0 " .
|
||||
"AND t.dtmchatstarted <> 0 " .
|
||||
"AND (p.visittime - :start) > 24*60*60 " .
|
||||
"AND (:today - p.visittime) > 24*60*60 " .
|
||||
"AND DATE(FROM_UNIXTIME(p.visittime)) " .
|
||||
"= DATE(FROM_UNIXTIME(t.dtmcreated)) " .
|
||||
"AND (t.invitationstate = :not_invited " .
|
||||
"OR t.invitationstate = :invitation_accepted) " .
|
||||
"GROUP BY date, address",
|
||||
array(
|
||||
':start' => $start,
|
||||
':today' => $today,
|
||||
':not_invited' => Thread::INVITATION_NOT_INVITED,
|
||||
':invitation_accepted' => Thread::INVITATION_ACCEPTED,
|
||||
':kind_agent' => Thread::KIND_AGENT,
|
||||
':kind_user' => Thread::KIND_USER
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
// Store info in statistics data
|
||||
foreach($db_results as $result) {
|
||||
$key = $result['date'] . '_' . $result['address'];
|
||||
if (empty($statistics[$key])) {
|
||||
$statistics[$key] = array();
|
||||
}
|
||||
$statistics[$key] += $result;
|
||||
}
|
||||
|
||||
// Get info about accepted invitations
|
||||
$db_results = $db->query(
|
||||
"SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " .
|
||||
"p.address AS address, " .
|
||||
"COUNT(DISTINCT t.threadid) AS invitations_accepted " .
|
||||
"FROM {visitedpage} p, {chatthread} t " .
|
||||
"WHERE t.referer = p.address " .
|
||||
"AND p.calculated = 0 " .
|
||||
"AND (p.visittime - :start) > 24*60*60 " .
|
||||
"AND (:today - p.visittime) > 24*60*60 " .
|
||||
"AND DATE(FROM_UNIXTIME(p.visittime)) " .
|
||||
"= DATE(FROM_UNIXTIME(t.dtmcreated)) " .
|
||||
"AND t.invitationstate = :invitation_accepted " .
|
||||
"GROUP BY date, address",
|
||||
array(
|
||||
':start' => $start,
|
||||
':today' => $today,
|
||||
':invitation_accepted' => Thread::INVITATION_ACCEPTED
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
// Store info in statistics data
|
||||
foreach($db_results as $result) {
|
||||
$key = $result['date'] . '_' . $result['address'];
|
||||
if (empty($statistics[$key])) {
|
||||
$statistics[$key] = array();
|
||||
}
|
||||
$statistics[$key] += $result;
|
||||
}
|
||||
|
||||
// Get info about rejected invitations
|
||||
$db_results = $db->query(
|
||||
"SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " .
|
||||
"p.address AS address, " .
|
||||
"COUNT(DISTINCT t.threadid) AS invitations_rejected " .
|
||||
"FROM {visitedpage} p, {chatthread} t " .
|
||||
"WHERE t.referer = p.address " .
|
||||
"AND p.calculated = 0 " .
|
||||
"AND (p.visittime - :start) > 24*60*60 " .
|
||||
"AND (:today - p.visittime) > 24*60*60 " .
|
||||
"AND DATE(FROM_UNIXTIME(p.visittime)) " .
|
||||
"= DATE(FROM_UNIXTIME(t.dtmcreated)) " .
|
||||
"AND t.invitationstate = :invitation_rejected " .
|
||||
"GROUP BY date, address",
|
||||
array(
|
||||
':start' => $start,
|
||||
':today' => $today,
|
||||
':invitation_rejected' => Thread::INVITATION_REJECTED
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
// Store info in statistics data
|
||||
foreach($db_results as $result) {
|
||||
$key = $result['date'] . '_' . $result['address'];
|
||||
if (empty($statistics[$key])) {
|
||||
$statistics[$key] = array();
|
||||
}
|
||||
$statistics[$key] += $result;
|
||||
}
|
||||
|
||||
// Get info about ignored invitations
|
||||
$db_results = $db->query(
|
||||
"SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " .
|
||||
"p.address AS address, " .
|
||||
"COUNT(DISTINCT t.threadid) AS invitations_ignored " .
|
||||
"FROM {visitedpage} p, {chatthread} t " .
|
||||
"WHERE t.referer = p.address " .
|
||||
"AND p.calculated = 0 " .
|
||||
"AND (p.visittime - :start) > 24*60*60 " .
|
||||
"AND (:today - p.visittime) > 24*60*60 " .
|
||||
"AND DATE(FROM_UNIXTIME(p.visittime)) " .
|
||||
"= DATE(FROM_UNIXTIME(t.dtmcreated)) " .
|
||||
"AND t.invitationstate = :invitation_ignored " .
|
||||
"GROUP BY date, address",
|
||||
array(
|
||||
':start' => $start,
|
||||
':today' => $today,
|
||||
':invitation_ignored' => Thread::INVITATION_IGNORED
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
// Store info in statistics data
|
||||
foreach($db_results as $result) {
|
||||
$key = $result['date'] . '_' . $result['address'];
|
||||
if (empty($statistics[$key])) {
|
||||
$statistics[$key] = array();
|
||||
}
|
||||
$statistics[$key] += $result;
|
||||
}
|
||||
|
||||
// Sort statistics by date before save it in the database
|
||||
ksort($statistics);
|
||||
|
||||
foreach($statistics as $row) {
|
||||
// Set default values
|
||||
$row += array(
|
||||
'visits' => 0,
|
||||
'chats' => 0,
|
||||
'invitations_accepted' => 0,
|
||||
'invitations_rejected' => 0,
|
||||
'invitations_ignored' => 0
|
||||
);
|
||||
|
||||
$row['invitations_sent'] = $row['invitations_accepted']
|
||||
+ $row['invitations_rejected']
|
||||
+ $row['invitations_ignored'];
|
||||
|
||||
// Prepare data for insert
|
||||
$insert_data = array();
|
||||
foreach($row as $field_name => $field_value) {
|
||||
$insert_data[':' . $field_name] = $field_value;
|
||||
}
|
||||
|
||||
$db->query(
|
||||
"INSERT INTO {visitedpagestatistics} (" .
|
||||
"date, address, visits, chats, " .
|
||||
"sentinvitations, acceptedinvitations, " .
|
||||
"rejectedinvitations, ignoredinvitations " .
|
||||
") VALUES (".
|
||||
":date, :address, :visits, :chats, :invitations_sent, " .
|
||||
":invitations_accepted, :invitations_rejected, " .
|
||||
":invitations_ignored " .
|
||||
")",
|
||||
$insert_data
|
||||
);
|
||||
}
|
||||
|
||||
// Mark all visited pages as 'calculated'
|
||||
$db->query(
|
||||
"UPDATE {visitedpage} SET calculated = 1 " .
|
||||
|
@ -470,6 +470,10 @@ report.byoperator.title=Threads by operator
|
||||
report.bypage.1=Page
|
||||
report.bypage.2=View times
|
||||
report.bypage.3=Chat threads
|
||||
report.bypage.4=Invitations sent
|
||||
report.bypage.5=Invitations accepted
|
||||
report.bypage.6=Invitations rejected
|
||||
report.bypage.7=Invitations ignored
|
||||
report.bypage.title=Chat threads by page
|
||||
report.no_items=Not enough data
|
||||
report.total=Total:
|
||||
|
@ -469,6 +469,10 @@ report.byoperator.title=
|
||||
report.bypage.1=Страница
|
||||
report.bypage.2=Просмотров
|
||||
report.bypage.3=Диалогов
|
||||
report.bypage.4=Приглашений отправлено
|
||||
report.bypage.5=Приглашений принято
|
||||
report.bypage.6=Приглашений отклонено
|
||||
report.bypage.7=Приглашений проигнорировано
|
||||
report.bypage.title=Статистика по страницам
|
||||
report.no_items=Мало данных
|
||||
report.total=Итого:
|
||||
|
@ -154,7 +154,11 @@ if ($statisticstype == 'bydate') {
|
||||
$page['reportByPage'] = $db->query(
|
||||
"SELECT SUM(visits) as visittimes, " .
|
||||
"address, " .
|
||||
"SUM(chats) as chattimes " .
|
||||
"SUM(chats) as chattimes, " .
|
||||
"SUM(sentinvitations) AS sentinvitations, " .
|
||||
"SUM(acceptedinvitations) AS acceptedinvitations, " .
|
||||
"SUM(rejectedinvitations) AS rejectedinvitations, " .
|
||||
"SUM(ignoredinvitations) AS ignoredinvitations " .
|
||||
"FROM {visitedpagestatistics} " .
|
||||
"WHERE date >= :start " .
|
||||
"AND date < :end " .
|
||||
|
@ -221,7 +221,19 @@ require_once('inc_errors.php');
|
||||
<?php echo getlocal("report.bypage.2") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.bypage.3") ?>
|
||||
</th></tr>
|
||||
</th>
|
||||
<?php if ($page['show_invitations_info']) { ?>
|
||||
<th>
|
||||
<?php echo getlocal("report.bypage.4") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.bypage.5") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.bypage.6") ?>
|
||||
</th><th>
|
||||
<?php echo getlocal("report.bypage.7") ?>
|
||||
</th>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if( $page['reportByPage'] ) { ?>
|
||||
@ -230,11 +242,17 @@ require_once('inc_errors.php');
|
||||
<td><a href="<?php echo htmlspecialchars($row['address']) ?>"><?php echo htmlspecialchars($row['address']) ?></a></td>
|
||||
<td><?php echo $row['visittimes'] ?></td>
|
||||
<td><?php echo $row['chattimes'] ?></td>
|
||||
<?php if ($page['show_invitations_info']) { ?>
|
||||
<td><?php echo $row['sentinvitations'] ?></td>
|
||||
<td><?php echo $row['acceptedinvitations'] ?></td>
|
||||
<td><?php echo $row['rejectedinvitations'] ?></td>
|
||||
<td><?php echo $row['ignoredinvitations'] ?></td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<td colspan="<?php echo($page['show_invitations_info'] ? 7 : 3); ?>">
|
||||
<?php echo getlocal("report.no_items") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user