Rev 663 | 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 LeadersLinked\Model\Location;use LeadersLinked\Mapper\Common\MapperCommon;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Log\LoggerInterface;use LeadersLinked\Hydrator\ObjectPropertyHydrator;class LocationMapper extends MapperCommon{const _TABLE = 'tbl_locations';/**** @var LocationMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return LocationMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new LocationMapper($adapter);}return self::$_instance;}/**** @return Location[]*/public function fetchAll(){$prototype = new Location;$select = $this->sql->select(self::_TABLE);return $this->executeFetchAllObject($select, $prototype);}/**** @param int $id* @return Location*/public function fetchOne($id){$prototype = new Location;$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $uuid* @return Location*/public function fetchOneBuUuid($uuid){$prototype = new Location;$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);return $this->executeFetchOneObject($select, $prototype);}/**** @param Location $location* @return boolean*/public function insert($location){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($location);$values = $this->removeEmpty($values);$insert = $this->sql->insert(self::_TABLE);$insert->values($values);$response = $this->executeInsert($insert);if($response) {$location->id = $this->lastInsertId;}return $response;}/**** @param Location $location* @return location*/public function update($location){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($location);$values = $this->removeEmpty($values);$update= $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $location->id);//echo $update->getSqlString($this->adapter->platform); exit;return $this->executeUpdate($update);}/**** @param int $id* @return boolean*/public function delete($id){$delete= $this->sql->delete(self::_TABLE);$delete->where->equalTo('id', $id);return $this->executeDelete($delete);}}