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