Example #1
0
 /**
  * Get details about a local account.
  * @param Database $db The database from which to fetch details.
  * @param string $user The name of the user for which to fetch local details.
  * @param Wiki $wiki The wiki on which the account is being fetched.
  */
 public function getLocal($db, $userName, $isUnified, $wiki)
 {
     // fetch details
     $row = $db->Query('SELECT user_id, user_registration, DATE_FORMAT(user_registration, "%Y-%m-%d %H:%i") as registration, user_editcount, GROUP_CONCAT(ug_group SEPARATOR ", ") AS user_groups, ipb_by_text, ipb_reason, DATE_FORMAT(ipb_timestamp, "%Y-%m-%d %H:%i") AS ipb_timestamp, ipb_deleted, COALESCE(DATE_FORMAT(ipb_expiry, "%Y-%m-%d %H:%i"), ipb_expiry) AS ipb_expiry FROM user LEFT JOIN user_groups ON user_id = ug_user LEFT JOIN ipblocks ON user_id = ipb_user WHERE user_name = ? LIMIT 1', array($userName))->fetchAssoc();
     // build model
     $account = new Stalktoy\LocalAccount();
     $account->exists = isset($row['user_id']);
     $account->wiki = $wiki;
     if ($account->exists) {
         // account details
         $account->id = $row['user_id'];
         $account->registered = $row['registration'];
         $account->registeredRaw = $row['user_registration'];
         $account->editCount = $row['user_editcount'];
         $account->groups = $row['user_groups'];
         $account->isUnified = $isUnified;
         // handle edge cases with older accounts
         if (!$account->registeredRaw) {
             $date = $db->getRegistrationDate($account->id);
             $account->registered = $date['formatted'];
             $account->registeredRaw = $date['raw'];
         }
         // block details
         $account->isBlocked = isset($row['ipb_timestamp']);
         if ($account->isBlocked) {
             $account->block = new Stalktoy\Block();
             $account->block->by = $row['ipb_by_text'];
             $account->block->target = $userName;
             $account->block->reason = $row['ipb_reason'];
             $account->block->timestamp = $row['ipb_timestamp'];
             $account->block->isHidden = $row['ipb_deleted'];
             $account->block->expiry = $row['ipb_expiry'];
         }
     }
     return $account;
 }