2014-08-30 18:11:32 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Dao;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Dao\EntityConverters\TokenEntityConverter;
|
|
|
|
use Szurubooru\DatabaseConnection;
|
2014-08-30 18:11:32 +02:00
|
|
|
|
|
|
|
class TokenDao extends AbstractDao
|
|
|
|
{
|
2014-10-08 14:47:47 +02:00
|
|
|
public function __construct(DatabaseConnection $databaseConnection)
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
2014-09-15 09:25:11 +02:00
|
|
|
parent::__construct(
|
|
|
|
$databaseConnection,
|
|
|
|
'tokens',
|
2014-10-08 14:47:47 +02:00
|
|
|
new TokenEntityConverter());
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|
|
|
|
|
2014-09-13 23:58:13 +02:00
|
|
|
public function findByName($tokenName)
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
return $this->findOneBy('name', $tokenName);
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|
|
|
|
|
2014-09-30 10:35:55 +02:00
|
|
|
public function findByAdditionalDataAndPurpose($additionalData, $purpose)
|
|
|
|
{
|
|
|
|
$query = $this->fpdo->from($this->tableName)
|
|
|
|
->where('additionalData', $additionalData)
|
|
|
|
->where('purpose', $purpose);
|
|
|
|
$arrayEntities = iterator_to_array($query);
|
|
|
|
if (!$arrayEntities or !count($arrayEntities))
|
|
|
|
return null;
|
|
|
|
$arrayEntity = array_shift($arrayEntities);
|
|
|
|
return $this->entityConverter->toEntity($arrayEntity);
|
|
|
|
}
|
|
|
|
|
2014-08-30 18:11:32 +02:00
|
|
|
public function deleteByName($tokenName)
|
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
return $this->deleteBy('name', $tokenName);
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|
2014-09-05 09:37:53 +02:00
|
|
|
|
|
|
|
public function deleteByAdditionalData($additionalData)
|
|
|
|
{
|
2014-09-14 16:16:15 +02:00
|
|
|
return $this->deleteBy('additionalData', $additionalData);
|
2014-09-05 09:37:53 +02:00
|
|
|
}
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|