-// Get timestamp for given stats type and data
-function getTimestampFromUserStats ($type, $data, $userid = '0') {
- // Default timestamp is zero
- $stamp = '0';
-
- // User id set?
- if ((isMemberIdSet()) && ($userid == '0')) {
- $userid = getMemberId();
- } // END - if
-
- // Is the extension installed and updated?
- if ((!isExtensionActive('sql_patches')) || (isExtensionOlder('sql_patches', '0.5.6'))) {
- // Return zero here
- return $stamp;
- } // END - if
-
- // Try to find the entry
- $result = SQL_QUERY_ESC("SELECT
- UNIX_TIMESTAMP(`inserted`) AS stamp
-FROM
- `{?_MYSQL_PREFIX?}_user_stats_data`
-WHERE
- `userid`=%s AND `stats_type`='%s' AND `stats_data`='%s'
-LIMIT 1",
- array(
- bigintval($userid),
- $type,
- $data
- ), __FUNCTION__, __LINE__);
-
- // Is the entry there?
- if (SQL_NUMROWS($result) == 1) {
- // Get this stamp
- list($stamp) = SQL_FETCHROW($result);
- } // END - if
-
- // Free result
- SQL_FREERESULT($result);
-
- // Return stamp
- return $stamp;
-}
-
-// Inserts user stats
-function insertUserStatsRecord ($userid, $type, $data) {
- // Is the extension installed and updated?
- if ((!isExtensionActive('sql_patches')) || (isExtensionOlder('sql_patches', '0.5.6'))) {
- // Return zero here
- return false;
- } // END - if
-
- // Does it exist?
- if ((!getTimestampFromUserStats($type, $data, $userid)) && (!is_array($data))) {
- // Then insert it!
- SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_stats_data` (`userid`,`stats_type`,`stats_data`) VALUES (%s,'%s','%s')",
- array(bigintval($userid), $type, $data), __FUNCTION__, __LINE__);
- } elseif (is_array($data)) {
- // Invalid data!
- logDebugMessage(__FUNCTION__, __LINE__, "userid={$userid},type={$type},data={".gettype($data).": Invalid statistics data type!");
- }
-}
-