Rev 550 | Rev 4113 | 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 Laminas\Db\Sql\Expression;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Log\LoggerInterface;use Laminas\Paginator\Paginator;use Laminas\Paginator\Adapter\DbSelect;use LeadersLinked\Model\JobDescription;use LeadersLinked\Mapper\Common\MapperCommon;use Laminas\Hydrator\ArraySerializableHydrator;class JobDescriptionMapper extends MapperCommon {const _TABLE = 'tbl_jobs_description';/**** @var JobDescriptionMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter) {parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return JobDescriptionMapper*/public static function getInstance($adapter) {if (self::$_instance == null) {self::$_instance = new JobDescriptionMapper($adapter);}return self::$_instance;}/**** @param int $id* @return JobDescription*/public function fetchOne($id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->limit(1);$prototype = new JobDescription();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $id* @return JobDescription*/public function fetchAll($id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->limit(1);$prototype = new JobDescription();return $this->executeFetchAllObject($select, $prototype);}/**** @return JobDescription[]*/public function fetchAllByDefault() {$select = $this->sql->select(self::_TABLE);$select->where->isNull('company_id');$prototype = new JobDescription();return $this->executeFetchAllObject($select, $prototype);}/**** @param string $uuid* @return JobDescription*/public function fetchOneByUuid($uuid) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$select->limit(1);$prototype = new JobDescription();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @return JobDescription*/public function fetchAllByCompanyId($company_id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->order('name');$prototype = new JobDescription();return $this->executeFetchAllObject($select, $prototype);}/**** @param int $company_id* @return JobDescription*/public function fetchAllActiveByCompanyId($company_id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('status', JobDescription::STATUS_ACTIVE);$select->order('name');$prototype = new JobDescription();return $this->executeFetchAllObject($select, $prototype);}/**** @param int $company_id* @param int $job_description_id_default* @return JobDescription*/public function fetchOneByCompanyId($company_id, $job_description_id_default) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('job_description_id_default', $job_description_id_default);$select->limit(1);$prototype = new JobDescription();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @param int $id* @return JobDescription*/public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->notEqualTo('id', $id);$select->order('name');$prototype = new JobDescription();return $this->executeFetchAllObject($select, $prototype);}/**** @param int $company_id* @param int $id* @return JobDescription*/public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->notEqualTo('id', $id);$select->where->equalTo('status', JobDescription::STATUS_ACTIVE);$select->order('name');$prototype = new JobDescription();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 = 'name', $order_direction = 'ASC') {$prototype = new JobDescription();$select = $this->sql->select(self::_TABLE);$select->where->isNull('company_id');if ($search) {$select->where->like('name', '%' . $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 int $companyId* @param string $search* @param int $page* @param int $records_per_page* @param string $order_field* @param string $order_direction* @return Paginator*/public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {$prototype = new JobDescription();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $companyId);if ($search) {$select->where->like('name', '%' . $search . '%');}$select->order($order_field . ' ' . $order_direction);//echo $select->getSqlString($this->adapter->platform); exit;$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 JobDescription $jobDescription* @return boolean*/public function insert($jobDescription) {$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($jobDescription);$values = $this->removeEmpty($values);$values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;$insert = $this->sql->insert(self::_TABLE);$insert->values($values);//echo $insert->getSqlString($this->adapter->platform); exit;$result = $this->executeInsert($insert);if ($result) {$jobDescription->id = $this->getLastInsertId();}return $result;}/**** @param JobDescription $jobDescription* @return boolean*/public function update($jobDescription) {$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($jobDescription);$values = $this->removeEmpty($values);$values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $jobDescription->id);return $this->executeUpdate($update);}/**** @param JobDescription $jobDescription* @return boolean*/public function delete($jobDescription) {$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('id', $jobDescription->id);return $this->executeDelete($delete);}/**** @return JobDescription[]*/public function fetchAllActivesByCompanyId($company_id) {$prototype = new JobDescription();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('status', JobDescription::STATUS_ACTIVE);$select->order('name ASC');return $this->executeFetchAllObject($select, $prototype);}}