AutorÃa | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Mapper;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
use LeadersLinked\Model\DailyPulse;
use LeadersLinked\Mapper\Common\MapperCommon;
class DailyPulseMapper extends MapperCommon
{
const _TABLE = 'tbl_daily_pulse';
/**
*
* @var DailyPulseMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @return DailyPulseMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new DailyPulseMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $id
* @return DailyPulse
*/
public function fetchOne($id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('id', $id);
$select->limit(1);
$prototype = new DailyPulse();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param string $uuid
* @return DailyPulse
*/
public function fetchOneByUuid($uuid)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('uuid', $uuid);
$select->limit(1);
$prototype = new DailyPulse();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $company_id
* @return DailyPulse
*/
public function fetchOneByCompanyId($company_id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('company_id', $company_id);
$prototype = new DailyPulse();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param DailyPulse $record
* @return boolean
*/
public function insert($record)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($record);
$values = $this->removeEmpty($values);
$insert = $this->sql->insert(self::_TABLE);
$insert->values($values);
$result = $this->executeInsert($insert);
if($result) {
$record->id = $this->lastInsertId;
}
return $result;
}
/**
*
* @param DailyPulse $record
* @return boolean
*/
public function update($record)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($record);
$values = $this->removeEmpty($values);
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('id', $record->id);
return $this->executeUpdate($update);
}
/**
*
* @param DailyPulse $record
* @return boolean
*/
public function delete($record)
{
$delete = $this->sql->delete(self::_TABLE);
$delete->where->equalTo('id', $record->id);
return $this->executeDelete($delete);
}
}