BanModel::setCounts PHP Method

setCounts() public method

Set number of banned users in $Data.
Since: 2.0.18
public setCounts ( array &$Data )
$Data array
    public function setCounts(&$Data)
    {
        // Protect against a lack of inet6_ntoa, which wasn't introduced until MySQL 5.6.3.
        try {
            $CountUsers = $this->SQL->select('UserID', 'count', 'CountUsers')->from('User u')->where($this->BanWhere($Data))->get()->value('CountUsers', 0);
        } catch (Exception $e) {
            Logger::log(Logger::ERROR, $e->getMessage());
            $CountUsers = 0;
        }
        $Data['CountUsers'] = $CountUsers;
    }

Usage Example

Beispiel #1
0
 /**
  * Updates visit level information such as date last active and the user's ip address.
  *
  * @param int $UserID
  * @param string|int|float $ClientHour
  */
 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);
         }
     }
 }
All Usage Examples Of BanModel::setCounts