prepare("SELECT * FROM `sys_accounts` WHERE `$sField` = ? LIMIT 1", $sValue); return $this->getRow($sSql); } /** * Get account info by id * @param int $iID account id * @return array with account info */ public function getInfoById( $iID ) { return $this->_getDataByField('id', (int)$iID); } /** * get account id by emial */ public function getIdByEmail($sEmail) { return (int)$this->_getFieldByField('id', 'email', $sEmail); } /** * get account id by id */ public function getIdById($iId) { return (int)$this->_getFieldByField('id', 'id', $iId); } /** * Get account email by id * @param string $s search account by this id * @return account email */ public function getEmail($iID) { return $this->_getFieldByField('email', 'id', (int)$iID); } /** * Get account password by id * @param string $s search account by this id * @return account password */ public function getPassword($iID) { return $this->_getFieldByField('password', 'id', (int)$iID); } /** * Update last logged in time * @param $sPasswordHash - password hash * @param $sSalt - pasword salt * @param $iAccountId - account id to update password for * @return number of affected rows */ public function updatePassword($sPasswordHash, $sSalt, $iAccountId) { $sQuery = $this->prepare("UPDATE `sys_accounts` SET `password` = ?, `salt` = ? WHERE `id`= ?", $sPasswordHash, $sSalt, $iAccountId); return $this->query($sQuery); } /** * Update last logged in time * @param int $iID account id * @return number of affected rows */ public function updateLoggedIn($iID) { return $this->_updateField ($iID, 'logged', time()); } /** * Update language * @param int $iID account id * @return number of affected rows */ public function updateLanguage($iID, $iLangId) { return $this->_updateField ($iID, 'lang_id', $iLangId); } /** * Update current profile id associated with account * @param int $iID account id * @param int $iProfileId set current profile id to this value * @return number of affected rows */ public function updateCurrentProfile($iID, $iProfileId) { return $this->_updateField ($iID, 'profile_id', $iProfileId); } /** * Update 'email_confirmed' field. * @param int $isConfirmed - 0: mark email as unconfirmed, 1: as confirmed * @param int $iID - account id * @return number of affected rows */ public function updateEmailConfirmed($isConfirmed, $iID) { return $this->_updateField ($iID, 'email_confirmed', $isConfirmed ? 1 : 0); } /** * Get account field by specified field name and value. * In most cases it is for internal usage only. * Use other funtions to get account info, like getIdByEmail, etc. * @param string $sFieldRequested database field name to return * @param string $sFieldSearch database field name to search for * @param mixed $sValue database field value * @return specified account field value */ protected function _getFieldByField ($sFieldRequested, $sFieldSearch, $sValue) { $sSql = $this->prepare("SELECT `$sFieldRequested` FROM `sys_accounts` WHERE `$sFieldSearch` = ? LIMIT 1", $sValue); return $this->getOne($sSql); } /** * Update some field by account id * In most cases it is for internal usage only. * Use other funtions to get account info, like updateLogged, etc. * @param string $sFieldRequested database field name to return * @param string $sFieldSearch database field name to search for * @param mixed $sValue database field value * @return specified account field value */ protected function _updateField ($iId, $sFieldForUpdate, $sValue) { $sSql = $this->prepare("UPDATE `sys_accounts` SET `$sFieldForUpdate` = ? WHERE `id` = ? LIMIT 1", $sValue, $iId); return $this->query($sSql); } /** * Delete account info by id * @param int $iID profile id * @return affected rows */ public function delete($iID) { $sSql = $this->prepare("DELETE FROM `sys_accounts` WHERE `id` = ? LIMIT 1", $iID); return $this->query($sSql); } } /** @} */