Rev 1 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Mapper;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Db\ResultSet\HydratingResultSet;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Paginator\Paginator;use Laminas\Paginator\Adapter\DbSelect;use LeadersLinked\Model\PushTemplate;use LeadersLinked\Mapper\Common\MapperCommon;class PushTemplateMapper extends MapperCommon{const _TABLE = 'tbl_push_templates';/**** @var PushTemplateMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return \LeadersLinked\Mapper\PushTemplateMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new PushTemplateMapper($adapter);}return self::$_instance;}/**** @param int $id* @return PushTemplate*/public function fetchOne($id){$prototype = new PushTemplate();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->limit(1);return $this->executeFetchOneObject($select, $prototype);}/**** @param string $uuid* @return PushTemplate*/public function fetchOneByUuid($uuid){$prototype = new PushTemplate();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$select->limit(1);return $this->executeFetchOneObject($select, $prototype);}/**** @param string $type* @return PushTemplate[]*/public function fetchAllActiveByType($type){$prototype = new PushTemplate();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('status', PushTemplate::STATUS_ACTIVE);$select->where->equalTo('type', $type);$select->limit(1);return $this->executeFetchAllObject($select, $prototype);}/**** @return PushTemplate[]*/public function fetchAllDefault(){$prototype = new PushTemplate();$select = $this->sql->select(self::_TABLE);$select->where->isNull('push_template_default_id');$select->limit(1);return $this->executeFetchAllObject($select, $prototype);}/**** @param string $search* @param int $page* @param int $records_per_page* @param string $order_field* @param string $order_direction* @return Paginator*/public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC'){$prototype = new PushTemplate();$select = $this->sql->select(self::_TABLE);if($search) {$select->where->like('id', '%' . $search . '%')->or->like('title', '%' . $search . '%');}$select->order($order_field . ' ' . $order_direction);$hydrator = new ObjectPropertyHydrator();$resultset = new HydratingResultSet($hydrator, $prototype);$adapter = new DbSelect($select, $this->sql, $resultset);$paginator = new Paginator($adapter);$paginator->setItemCountPerPage($records_per_page);$paginator->setCurrentPageNumber($page);return $paginator;}/**** @param PushTemplate $pushTemplate* @return boolean*/public function update($pushTemplate){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($pushTemplate);$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $pushTemplate->id);return $this->executeUpdate($update);}/**** @return boolean*/public function truncate(){$sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);return $this->executeSentenceWithParameters($sql);}}