Rev 1524 | 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\Model\Survey;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
use Laminas\Paginator\Paginator;
use Laminas\Db\ResultSet\HydratingResultSet;
use Laminas\Paginator\Adapter\DbSelect;
use LeadersLinked\Model\SurveySkill;
class SurveySkillMapper extends MapperCommon
{
const _TABLE = 'tbl_survey_skill';
/**
*
* @var SurveySkillMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @return SurveySkillMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new SurveySkillMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $id
* @return Survey
*/
public function fetchOne($id)
{
$prototype = new Survey();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('id', $id);
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $uuid
* @return Survey
*/
public function fetchOneByUuid($uuid)
{
$prototype = new Survey();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('uuid', $uuid);
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $survey_id
* @return Survey
*/
public function fetchAllBySurveyId($survey_id)
{
$prototype = new SurveySkill();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('survey_id', $survey_id);
$select->order('id');
return $this->executeFetchAllObject($select, $prototype);
}
/**
*
* @param $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);
//echo $insert->getSqlString($this->adapter->platform); exit;
$result = $this->executeInsert($insert);
if($result) {
$record->id = $this->lastInsertId;
}
return $result;
}
/**
*
* @param SurveyForm $form
* @return boolean
*/
public function update($form)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($form);
$values = $this->removeEmpty($values);
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('id', $form->id);
return $this->executeUpdate($update);
}
/**
*
* @param int $form_id
* @return boolean
*/
public function deleteBySurevy($survey_id)
{
$delete = $this->sql->delete(self::_TABLE);
$delete->where->equalTo('survey_id', $survey_id);
return $this->executeDelete($delete);
}
}