UserModel::updateVisit PHP Метод

updateVisit() публичный Метод

Updates visit level information such as date last active and the user's ip address.
public updateVisit ( integer $UserID, string | integer | float $ClientHour = false )
$UserID integer
$ClientHour string | integer | float
    public function updateVisit($UserID, $ClientHour = false)
    {
        $UserID = (int) $UserID;
        if (!$UserID) {
            throw new Exception('A valid User ID is required.');
        }
        $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY);
        $Fields = [];
        if (Gdn_Format::toTimestamp($User['DateLastActive']) < strtotime('5 minutes ago')) {
            // We only update the last active date once every 5 minutes to cut down on DB activity.
            $Fields['DateLastActive'] = Gdn_Format::toDateTime();
        }
        // Update session level information if necessary.
        if ($UserID == Gdn::session()->UserID) {
            $IP = Gdn::request()->ipAddress();
            $Fields['LastIPAddress'] = ipEncode($IP);
            $this->saveIP($UserID, $IP);
            if (Gdn::session()->newVisit()) {
                $Fields['CountVisits'] = val('CountVisits', $User, 0) + 1;
                $this->fireEvent('Visit');
            }
        }
        // Set the hour offset based on the client's clock.
        if (is_numeric($ClientHour) && $ClientHour >= 0 && $ClientHour < 24) {
            $HourOffset = $ClientHour - date('G', time());
            $Fields['HourOffset'] = $HourOffset;
        }
        // See if the fields have changed.
        $Set = [];
        foreach ($Fields as $Name => $Value) {
            if (val($Name, $User) != $Value) {
                $Set[$Name] = $Value;
            }
        }
        if (!empty($Set)) {
            $this->EventArguments['Fields'] =& $Set;
            $this->fireEvent('UpdateVisit');
            $this->setField($UserID, $Set);
        }
        if ($User['LastIPAddress'] != $Fields['LastIPAddress']) {
            $User = $this->getID($UserID, DATASET_TYPE_ARRAY);
            if (!BanModel::checkUser($User, null, true, $Bans)) {
                $BanModel = new BanModel();
                $Ban = array_pop($Bans);
                $BanModel->saveUser($User, true, $Ban);
                $BanModel->setCounts($Ban);
            }
        }
    }
UserModel