2014-08-30 18:11:32 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Dao;
|
|
|
|
|
|
|
|
class UserDao extends AbstractDao implements ICrudDao
|
|
|
|
{
|
2014-09-26 19:14:34 +02:00
|
|
|
const ORDER_NAME = 'name';
|
|
|
|
const ORDER_REGISTRATION_TIME = 'registrationTime';
|
|
|
|
|
2014-09-20 12:45:56 +02:00
|
|
|
private $fileService;
|
|
|
|
private $thumbnailService;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
\Szurubooru\DatabaseConnection $databaseConnection,
|
|
|
|
\Szurubooru\Services\FileService $fileService,
|
|
|
|
\Szurubooru\Services\ThumbnailService $thumbnailService)
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
2014-09-15 09:25:11 +02:00
|
|
|
parent::__construct(
|
|
|
|
$databaseConnection,
|
|
|
|
'users',
|
|
|
|
new \Szurubooru\Dao\EntityConverters\UserEntityConverter());
|
2014-09-20 12:45:56 +02:00
|
|
|
|
|
|
|
$this->fileService = $fileService;
|
|
|
|
$this->thumbnailService = $thumbnailService;
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|
|
|
|
|
2014-09-13 23:58:13 +02:00
|
|
|
public function findByName($userName)
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
return $this->findOneBy('name', $userName);
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|
2014-09-01 19:43:49 +02:00
|
|
|
|
2014-09-13 23:58:13 +02:00
|
|
|
public function findByEmail($userEmail, $allowUnconfirmed = false)
|
2014-09-08 13:06:32 +02:00
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
$result = $this->findOneBy('email', $userEmail);
|
|
|
|
if (!$result and $allowUnconfirmed)
|
|
|
|
{
|
|
|
|
$result = $this->findOneBy('emailUnconfirmed', $userEmail);
|
|
|
|
}
|
|
|
|
return $result;
|
2014-09-08 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
2014-09-01 19:43:49 +02:00
|
|
|
public function hasAnyUsers()
|
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
return $this->hasAnyRecords();
|
2014-09-01 19:43:49 +02:00
|
|
|
}
|
2014-09-05 13:50:51 +02:00
|
|
|
|
|
|
|
public function deleteByName($userName)
|
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
$this->deleteBy('name', $userName);
|
|
|
|
$this->fpdo->deleteFrom('tokens')->where('additionalData', $userName);
|
2014-09-05 13:50:51 +02:00
|
|
|
}
|
2014-09-20 12:45:56 +02:00
|
|
|
|
|
|
|
protected function afterLoad(\Szurubooru\Entities\Entity $user)
|
|
|
|
{
|
|
|
|
$user->setLazyLoader(
|
|
|
|
\Szurubooru\Entities\User::LAZY_LOADER_CUSTOM_AVATAR_SOURCE_CONTENT,
|
|
|
|
function(\Szurubooru\Entities\User $user)
|
|
|
|
{
|
|
|
|
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
|
|
|
return $this->fileService->load($avatarSource);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function afterSave(\Szurubooru\Entities\Entity $user)
|
|
|
|
{
|
|
|
|
$targetPath = $user->getCustomAvatarSourceContentPath();
|
|
|
|
$content = $user->getCustomAvatarSourceContent();
|
|
|
|
if ($content)
|
|
|
|
$this->fileService->save($targetPath, $content);
|
|
|
|
else
|
|
|
|
$this->fileService->delete($targetPath);
|
|
|
|
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function afterDelete(\Szurubooru\Entities\Entity $user)
|
|
|
|
{
|
|
|
|
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
|
|
|
$this->fileService->delete($avatarSource);
|
|
|
|
$this->thumbnailService->deleteUsedThumbnails($avatarSource);
|
|
|
|
}
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|