Ir a la última revisión | Autoría | Comparar con el anterior | 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\HabitGoalSkill;
use LeadersLinked\Mapper\Common\MapperCommon;
class HabitGoalSkillMapper extends MapperCommon
{
const _TABLE = 'tbl_habits_goal_skills';
/**
*
* @var HabitGoalSkillMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @return HabitGoalSkillMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new HabitGoalSkillMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $user_id
* @param int $goal_id
* @param int $skill_id
* @return HabitGoalSkill
*/
public function fetchOneByUserIdAndGoalIdAndSkillId($user_id, $goal_id, $skill_id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('user_id', $user_id);
$select->where->equalTo('goal_id', $goal_id);
$select->where->equalTo('skill_id', $skill_id);
$select->limit(1);
$prototype = new HabitGoalSkill();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $user_id
* @param int $goal_id
* @return HabitGoalSkill
*/
public function fetchAllByUserIdAndGoalId($user_id, $goal_id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('user_id', $user_id);
$select->where->equalTo('goal_id', $goal_id);
$select->limit(1);
$prototype = new HabitGoalSkill();
return $this->executeFetchAllObject($select, $prototype);
}
/**
*
* @param HabitGoalSkill $habitGoalSkill
* @return boolean
*/
public function insert($habitGoalSkill)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($habitGoalSkill);
$values = $this->removeEmpty($values);
$insert = $this->sql->insert(self::_TABLE);
$insert->values($values);
$result = $this->executeInsert($insert);
if($result) {
$habitGoalSkill->id = $this->lastInsertId;
}
return $result;
}
/**
*
* @param HabitGoalSkill $habitGoalSkill
* @return boolean
*/
public function delete($habitGoalSkill)
{
$delete = $this->sql->delete(self::_TABLE);
$delete->where->equalTo('user_id', $habitGoalSkill->user_id);
$delete->where->equalTo('goal_id', $habitGoalSkill->goal_id);
$delete->where->equalTo('skill_id', $habitGoalSkill->skill_id);
return $this->executeDelete($delete);
}
/**
*
* @param int $user_id
* @param int $goal_id
* @return boolean
*/
public function deleteAllByUserIdAndGoalId($user_id, $goal_id)
{
$delete = $this->sql->delete(self::_TABLE);
$delete->where->equalTo('user_id', $user_id);
$delete->where->equalTo('goal_id', $goal_id);
return $this->executeDelete($delete);
}
}