профиль пользака
This commit is contained in:
1 parent
a2fe36227b
commit
0b31f06efb
5 files changed
+74
-50
No files matched your search
@@ -50,7 +50,7 @@
|
||||
public function __construct(?int $id = null)
|
||||
{
|
||||
$this->folder = $_SERVER['DOCUMENT_ROOT'] . self::FOLDER;
|
||||
$this->DB = DB::getInstance();
|
||||
$this->DB = DB::getInstance();
|
||||
if (!empty($id)) {
|
||||
$this->id = $id;
|
||||
$this->loadFileProps();
|
||||
@@ -135,13 +135,11 @@
|
||||
/**
|
||||
* Получение файла по идентификатору
|
||||
*
|
||||
* @param int $id Идентификатор
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getById(int $id): ?array
|
||||
public function getAllProps(): ?array
|
||||
{
|
||||
return $this->DB->query('SELECT * FROM ' . self::TABLE . ' WHERE id="' . $id . '"');
|
||||
return $this->DB->query('SELECT * FROM ' . self::TABLE . ' WHERE id="' . $this->id . '"')[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +152,6 @@
|
||||
{
|
||||
$this->DB->update(self::TABLE, ['id' => $this->id], ['name' => $this->name, 'path' => $this->path]);
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,14 +168,14 @@
|
||||
{
|
||||
$storageFileName = md5(time() . $fileName . rand(1, 9999));
|
||||
if (empty($fileName)) {
|
||||
$fileName = $storageFileName . '.' . static::getExt($filePath);
|
||||
$fileName = $storageFileName . '.' . static::getExt($filePath);
|
||||
$storageFileName .= '.' . static::getExt($filePath);
|
||||
} else {
|
||||
$storageFileName .= '.' . static::getExt($fileName);
|
||||
}
|
||||
$storageFullPath = $this->folder . '/' . $storageFileName;
|
||||
|
||||
if($useMove) {
|
||||
if ($useMove) {
|
||||
if (!move_uploaded_file($filePath, $storageFullPath)) {
|
||||
throw new CoreException('Не удалось скопировать загруженный файл', CoreException::ERROR_FILE_COPY);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,26 @@
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение аватара пользователя
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getImage(): ?array
|
||||
{
|
||||
$result = null;
|
||||
$imageId = $this->getAllUserData()['image_id'];
|
||||
|
||||
if (!empty($imageId)) {
|
||||
try {
|
||||
$result = (new File($imageId))->getAllProps();
|
||||
} catch (CoreException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение всех полей пользователя
|
||||
*
|
||||
@@ -109,16 +129,6 @@
|
||||
return $this->getAllUserData() ? $this->getAllUserData()['name'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение аватарки текущего пользователя
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getImage(): ?string
|
||||
{
|
||||
return $this->getAllUserData() ? $this->getAllUserData()['image'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение токена текущего пользователя
|
||||
*
|
||||
@@ -298,7 +308,7 @@
|
||||
Log::logToFile(__METHOD__, 'User.log', func_get_args());
|
||||
|
||||
/** @var $DB DB */
|
||||
$DB = DB::getInstance();
|
||||
$DB = DB::getInstance();
|
||||
$userId = $DB->addItem(self::USERS_TABLE, [
|
||||
'login' => $login,
|
||||
'password' => self::passwordEncryption($password),
|
||||
|
||||
Reference in new issue
Block a user