AutorÃa | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Mapper;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Db\ResultSet\HydratingResultSet;use Laminas\Paginator\Adapter\DbSelect;use Laminas\Paginator\Paginator;use Laminas\Log\LoggerInterface;use Laminas\Hydrator\ArraySerializableHydrator;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use LeadersLinked\Model\CompanyRole;use LeadersLinked\Mapper\Common\MapperCommon;class CompanyRoleMapper extends MapperCommon{const _TABLE = 'tbl_company_roles';/**** @var CompanyRoleMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return CompanyRoleMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new CompanyRoleMapper($adapter);}return self::$_instance;}/**** @param int $id* @return CompanyRole*/public function fetchOne($id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->limit(1);$prototype = new CompanyRole();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @param int $role_id* @return CompanyRole*/public function fetchOneByCompanyIdAndRoleId($company_id, $role_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('role_id', $role_id);$select->limit(1);$prototype = new CompanyRole();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @return CompanyRole[]*/public function fetchAllByCompanyId($company_id){$prototype = new CompanyRole();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);return $this->executeFetchAllObject($select, $prototype);}/**** @param CompanyRole $companyRole* @return boolean*/public function insert($companyRole){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($companyRole);$values = $this->removeEmpty($values);$insert = $this->sql->insert(self::_TABLE);$insert->values($values);$result = $this->executeInsert($insert);if($result) {$companyRole->id = $this->lastInsertId;}return $result;}/**** @param int $id* @return boolean*/public function delete($id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('id', $id);return $this->executeDelete($delete);}/**** @param int $company_id* @param int $role_id* @return boolean*/public function deleteByCompanyIdAndRoleId($company_id, $role_id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('company_id', $company_id);$delete->where->equalTo('role_id', $company_id);return $this->executeDelete($delete);}}