AutorÃa | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Mapper;
use LeadersLinked\Model\UserNotificationSetting;
use LeadersLinked\Mapper\Common\MapperCommon;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
class UserNotificationSettingMapper extends MapperCommon
{
const _TABLE = 'tbl_user_notification_settings';
/**
*
* @var UserNotificationSettingMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @returnUserNotificationSettingMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new UserNotificationSettingMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $user_id
* @return UserNotificationSetting
*/
public function fetchOne($user_id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('user_id', $user_id);
$prototype = new UserNotificationSetting();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param UserNotificationSetting $userNotificationSetting
* @return boolean
*/
public function insert($userNotificationSetting)
{
$hydrator = new ObjectPropertyHydrator();
$values= $hydrator->extract($userNotificationSetting);
$insert = $this->sql->insert(self::_TABLE);
$insert->values($values);
return $this->executeInsert($insert);
}
/**
*
* @param UserNotificationSetting $userNotificationSetting
* @return boolean
*/
public function update($userNotificationSetting)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($userNotificationSetting);
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('user_id', $userNotificationSetting->user_id);
return $this->executeUpdate($update);
}
/**
*
* @return boolean
*/
public function truncate()
{
$sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);
return $this->executeSentenceWithParameters($sql);
}
}