Esempio n. 1
0
/**
 * Returns a percentage of user's status in the current lecke.
 * @param $userId
 * @param $timeWindowName
 * @return int (percentage) on success or FALSE on failure.
 */
function db_getStatusInLecke($userId = -1, $timeWindowName = "-1")
{
    $ret = db_getUserDataRaw($userId, null, null, null);
    if (empty($ret)) {
        return FALSE;
    } else {
        $userName = $ret['felh_nev'];
    }
    $tid = db_getTimeWindowIdFromName($timeWindowName);
    global $conn;
    $stmt = $conn->prepare("SELECT SUM(suly)\n                            FROM aktivitas\n                            WHERE idoablakId = :twid");
    $stmt->bindParam(':twid', $tid);
    $stmt->execute();
    $egesz = $stmt->fetchColumn();
    $stmt = $conn->prepare("SELECT SUM(suly)\n                            FROM aktivitas, aktivitas_ertekek\n                            WHERE aktivitas.id = aktivitas_ertekek.aktivitasId AND felhNev = :usern AND idoablakId = :twid");
    $stmt->bindParam(':usern', $userName);
    $stmt->bindParam(':twid', $tid);
    $stmt->execute();
    $resz = $stmt->fetchColumn();
    return round($resz * (100 / $egesz));
}
Esempio n. 2
0
/**
 * Check if a user's activity is inserted or not.
 * @param $timeWindowName
 * @param $actName
 * @param $userId
 * @param $userName
 * @param $email
 * @param $cardId
 * @return bool TRUE on success or FALSE on failure.
 */
function db_checkUserActivity($timeWindowName = "-1", $actName = "-1", $userId = -1, $userName = "******", $email = "-1", $cardId = -1)
{
    $tid = db_getTimeWindowIdFromName($timeWindowName);
    if ($userName == "-1" || empty($userName)) {
        $ret = db_getUserDataRaw($userId, null, $email, $cardId);
        if (empty($ret)) {
            return false;
        } else {
            $userName = $ret['felh_nev'];
        }
    }
    global $conn;
    $stmt = $conn->prepare("SELECT *\n                            FROM aktivitas_ertekek\n                            WHERE aktivitasId = (SELECT id\n                                                 FROM aktivitas\n                                                 WHERE idoablakId = :twid AND nev = :aname) AND felhNev = :uname");
    $stmt->bindParam(':twid', $tid);
    $stmt->bindParam(':aname', $actName);
    $stmt->bindParam(':uname', $userName);
    $stmt->execute();
    if ($stmt->rowCount()) {
        return true;
    } else {
        return false;
    }
}
Esempio n. 3
0
/**
 * Adds a new record in table lzaro_kitolt into the database.
 * @param $userId
 * @param $timeWindowName
 * @param $testName
 * @param $time
 * @return integer containing the last inserted id, or FALSE on failure.
 */
function db_addNewRecordInTableLzaro_kitolt($userId, $timeWindowName, $testName, $time)
{
    $ret = db_getUserDataRaw($userId, null, null, null);
    if (empty($ret)) {
        return FALSE;
    } else {
        $userName = $ret['felh_nev'];
    }
    $tid = db_getTimeWindowIdFromName($timeWindowName);
    $ret = db_getTestId($testName);
    if (empty($ret)) {
        return FALSE;
    } else {
        $testId = $ret;
    }
    global $conn;
    $stmt = $conn->prepare("INSERT INTO lzaro_kitolt\n                            VALUES (NULL, :uname, :tid, :testId, :secs, NOW())");
    $stmt->bindParam(':uname', $userName);
    $stmt->bindParam(':tid', $tid);
    $stmt->bindParam(':testId', $testId);
    $stmt->bindParam(':secs', $time);
    $stmt->execute();
    return $conn->lastInsertId();
}