This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Dao/EntityConverters/SnapshotEntityConverter.php
2014-10-18 18:48:29 +02:00

34 lines
1.1 KiB
PHP

<?php
namespace Szurubooru\Dao\EntityConverters;
class SnapshotEntityConverter extends AbstractEntityConverter implements IEntityConverter
{
public function toArray(\Szurubooru\Entities\Entity $entity)
{
return
[
'id' => $entity->getId(),
'time' => $this->entityTimeToDbTime($entity->getTime()),
'type' => $entity->getType(),
'primaryKey' => $entity->getPrimaryKey(),
'userId' => $entity->getUserId(),
'operation' => $entity->getOperation(),
'data' => json_encode($entity->getData()),
'dataDifference' => json_encode($entity->getDataDifference()),
];
}
public function toBasicEntity(array $array)
{
$entity = new \Szurubooru\Entities\Snapshot(intval($array['id']));
$entity->setTime($this->dbTimeToEntityTime($array['time']));
$entity->setType(intval($array['type']));
$entity->setPrimaryKey($array['primaryKey']);
$entity->setUserId($array['userId']);
$entity->setOperation($array['operation']);
$entity->setData(json_decode($array['data'], true));
$entity->setDataDifference(json_decode($array['dataDifference'], true));
return $entity;
}
}