AutorÃa | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Mapper;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Model\SyncLog;
use LeadersLinked\Mapper\Common\MapperCommon;
class SyncLogMapper extends MapperCommon
{
const _TABLE = 'tbl_sync_logs';
/**
*
* @var SyncLogMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @return SyncLogMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new SyncLogMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $id
* @return SyncLog
*/
public function fetchOne($id)
{
$prototype = new SyncLog();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('id', $id);
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $device_uuid
* @return SyncLog[]
*/
public function fetchAllByDeviceUuid($device_uuid)
{
$prototype = new SyncLog();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('device_uuid', $device_uuid);
return $this->executeFetchAllObject($select, $prototype);
}
/**
*
* @param SyncLog $syncLog
* return true
*/
public function insert($syncLog)
{
$hydrator = new \Laminas\Hydrator\ObjectPropertyHydrator();
$values = $hydrator->extract($syncLog);
$values = $this->removeEmpty($values);
$insert = $this->sql->insert(self::_TABLE);
$insert->values($values);
$result = $this->executeInsert($insert);
if($result) {
$syncLog->id = $this->lastInsertId;
}
return $result;
}
}