Rev 3213 | AutorÃa | Comparar con el anterior | 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\Topic;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
use Laminas\Paginator\Paginator;
use Laminas\Db\ResultSet\HydratingResultSet;
use Laminas\Paginator\Adapter\DbSelect;
class TopicMapper extends MapperCommon
{
const _TABLE = 'tbl_topics';
/**
*
* @var TopicMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @return TopicMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new TopicMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $id
* @return Topic
*/
public function fetchOne($id)
{
$prototype = new Topic();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('id', $id);
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $uuid
* @return Topic
*/
public function fetchOneByUuid($uuid)
{
$prototype = new Topic();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('uuid', $uuid);
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $uuid
* @return Topic
*/
public function fetchOneByUuidOrTitle($uuidOrTitle)
{
$prototype = new Topic();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('uuid', $uuidOrTitle)->or->equalTo('title', $uuidOrTitle);
return $this->executeFetchOneObject($select, $prototype);
}
public function fetchOneByUuidAndGroupId($uuid,$group_id)
{
$prototype = new Topic();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('uuid', $uuid);
$select->where->equalTo('high_performance_group_id', $group_id);
return $this->executeFetchOneObject($select, $prototype);
}
public function fetchAllMyTrainer()
{
$prototype = new Topic;
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('type', Topic::TYPE_MYT);
$select->order('id');
return $this->executeFetchAllObject($select, $prototype);
}
public function fetchAllDevelopment()
{
$prototype = new Topic;
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('type', Topic::TYPE_DC);
$select->where->notEqualTo('status', Topic::STATUS_DELETE);
$select->order('id');
return $this->executeFetchAllObject($select, $prototype);
}
public function fetchAllHighPerfromanceTeamsGroup($group_id)
{
$prototype = new Topic;
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('type', Topic::TYPE_HPTG);
$select->where->equalTo('high_performance_group_id', $group_id);
$select->where->notEqualTo('status', Topic::STATUS_DELETE);
$select->order('id');
return $this->executeFetchAllObject($select, $prototype);
}
public function fetchAllHighPerfromanceTeamsGroupForo($group_id)
{
$prototype = new Topic;
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('type', Topic::TYPE_HPTGF);
$select->where->equalTo('high_performance_group_id', $group_id);
$select->where->notEqualTo('status', Topic::STATUS_DELETE);
$select->order('id');
return $this->executeFetchAllObject($select, $prototype);
}
/**
*
* @param Topic $form
* @return boolean
*/
public function insert($datos)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($datos);
$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) {
$datos->id = $this->lastInsertId;
}
return $result;
}
/**
*
* @param Topic $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 delete($form_id)
{
// $delete = $this->sql->delete(self::_TABLE);
// $delete->where->equalTo('id', $form_id);
// return $this->executeDelete($delete);
$update = $this->sql->update(self::_TABLE);
$update->set([
'status' => Topic::STATUS_DELETE
]);
$update->where->equalTo('id', $form_id);
return $this->executeUpdate($update);
}
}