/** * Retrieves the score for the current user * * @return integer the score * */ static function GetMyScore($user_or_id = null) { $user = $user_or_id ? User::toObject($user_or_id) : User::findCurrent(); $cache = StudipCacheFactory::getCache(); if ($cache->read("user_score_of_".$user->id)) { return $cache->read("user_score_of_".$user->id); } //Behold! The all new mighty score algorithm! //Step 1: Select all activities as mkdate-timestamps. //Step 2: Group these activities to timeslots of halfhours // with COUNT(*) as a weigh of the timeslot. //Step 3: Calculate the measurement of the timeslot from the weigh of it. // This makes the first activity count fully, the second // almost half and so on. We use log_n to make huge amounts of // activities to not count so much. //Step 4: Calculate a single score for each timeslot depending on the // measurement and the mkdate-timestamp. Use arctan as the function // here so that older activities tend to zero. //Step 5: Sum all scores from all timeslots together. $sql = " SELECT round(SUM((-atan(measurement / " . round(31556926 / self::MEASURING_STEP) . ") / PI() + 0.5) * 200)) as score FROM ( SELECT ((unix_timestamp() / " . self::MEASURING_STEP . ") - timeslot) / (LN(weigh) + 1) AS measurement FROM ( SELECT (round(mkdate / " . self::MEASURING_STEP . ")) as timeslot, COUNT(*) AS weigh FROM ( " . self::createTimestampQuery() . " ) as mkdates GROUP BY timeslot ) as measurements ) as dates "; $stmt = DBManager::get()->prepare($sql); $stmt->execute(array(':user' => $user->id)); $score = $stmt->fetchColumn(); if ($user->score && $user->score != $score) { $user->score = $score; $user->store(); } $cache->write("user_score_of_".$user->id, $score, 60 * 5); return $score; }
/** * load user data from database into internal array * * @access private * @param string $user_id the user which should be retrieved */ function getFromDatabase($user_id) { $this->user = User::toObject($user_id); if (!$this->user) { $this->user = new User(); } $this->user_data = new UserDataAdapter($this->user); }
public static function sendSystemMessage($recipient, $message_title, $message_body) { $m = new messaging(); $user = User::toObject($recipient); return $m->insert_message($message_body, $user['username'], '____%system%____', FALSE, FALSE, '1', FALSE, $message_title); }
/** * @param $user */ function auth_set_user_settings($user) { $divided = explode("x", Request::get('resolution')); $this->auth["xres"] = $divided[0] != 0 ? (int) $divided[0] : 1024; //default $this->auth["yres"] = $divided[1] != 0 ? (int) $divided[1] : 768; //default // Change X-Resulotion on Multi-Screen Systems (as Matrox Graphic-Adapters are) if ($this->auth["xres"] / $this->auth["yres"] > 2) { $this->auth["xres"] = $this->auth["xres"] / 2; } $user = User::toObject($user); //restore user-specific language preference if ($user->preferred_language) { // we found a stored setting for preferred language $_SESSION['_language'] = $user->preferred_language; } }