function testConfigVar() { // setup ConfigVariable::remove("test_config_var"); $this->assertEquals(ConfigVariable::get("test_config_var", "1234"), "1234"); // see if we can save a new value and serialize an array ConfigVariable::set("test_config_var", array(1, 2, 3)); $this->assertEquals(ConfigVariable::get("test_config_var", "1234"), array(1, 2, 3)); // see if we can change an existing value, and store a nasty // string full of punctuation $ridiculous_punctuation = "'&@^%\$*(&^@%#\"\$&*^%@#\$+_)}{}{{?><,./,"; ConfigVariable::set("test_config_var", $ridiculous_punctuation); $this->assertEquals(ConfigVariable::get("test_config_var", "1234"), $ridiculous_punctuation); // make sure we can remove the value ConfigVariable::remove("test_config_var"); $this->assertEquals(ConfigVariable::get("test_config_var", "1234"), "1234"); }
/** * Get array of all users who login after latest updates of ranking. * */ public function recent_login_users() { Logger::log("Enter: Ranking::recent_login_users()"); $last_cron_timestamp = ConfigVariable::get('last_cron_timestamp', 0); //ConfigVariable::set('last_cron_timestamp',time()); $sql = "SELECT \n u.user_id, \n u.login_name, \n u.picture, \n (select count(*) from {contentcollections} cc where cc.author_id = u.user_id AND cc.type =1 AND is_active=1) as group_created, \n (select count(*) from {contents} c where c.author_id = u.user_id AND c.type = 4 AND is_active=1) as image_uploaded,\n (select count(*) from {relations} r where r.user_id = u.user_id AND r.status = 'approved') as buddies\n FROM {users} u\n WHERE u.is_active = 1 AND u.last_login >= ?"; $users = array(); $res = Dal::query($sql, array($last_cron_timestamp)); while ($user = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $users[$user->user_id]["user_id"] = $user->user_id; $users[$user->user_id]["login_name"] = $user->login_name; $users[$user->user_id]["picture"] = $user->picture; $users[$user->user_id]["group_created"] = $user->group_created; $users[$user->user_id]["image_uploaded"] = $user->image_uploaded; $users[$user->user_id]["buddies"] = $user->buddies; $sql = "SELECT field_name, field_value FROM {user_profile_data} WHERE user_id = ? AND field_name IN('time_spent', 'profile_visitor_count')"; $result = Dal::query($sql, array($user->user_id)); while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT)) { $users[$user->user_id][$row->field_name] = $row->field_value; } } Logger::log("Exit: Ranking::recent_login_users()"); return $users; }
/** This function keeps track of online registered user * @param user_id of logged in user * make an entry in users_online table * @return true, if entry succeeded else return false */ public static function track_status($user_id) { // TODO: we can fetch recent entries as well by specifying time stamp $timeout = ConfigVariable::get('session_timeout', 1800); $time = strtotime('-' . $timeout . ' seconds'); $sql = "DELETE FROM {users_online} WHERE timestamp < " . $time; Dal::query($sql); $sql = 'SELECT * FROM {users_online} WHERE user_id = ?'; $data = array($user_id); $res = Dal::query($sql, $data); //if session for user exists then update that entry if ($res->numRows()) { $sql = 'UPDATE {users_online} SET timestamp = ? WHERE user_id = ?'; $data = array(time(), $user_id); } else { $sql = 'INSERT INTO {users_online}(timestamp, user_id) VALUES(?, ?)'; $data = array(time(), $user_id); } $res = Dal::query($sql, $data); }