Rev 2826 | Rev 3254 | 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 LeadersLinked\Hydrator\ObjectPropertyHydrator;use LeadersLinked\Model\Behavior;use LeadersLinked\Mapper\Common\MapperCommon;class BehaviorMapper extends MapperCommon {const _TABLE = 'tbl_behaviors';/**** @var BehaviorMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter) {parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return BehaviorMapper*/public static function getInstance($adapter) {if (self::$_instance == null) {self::$_instance = new BehaviorMapper($adapter);}return self::$_instance;}/**** @param int $id* @return Behavior*/public function fetchOne($id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->limit(1);$prototype = new Behavior();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @param int $behavior_type_id_default* @return Behavior*/public function fetchOneByCompanyId($company_id, $behavior_type_id_default) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->limit(1);$prototype = new Behavior();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @param int $behavior_type_id_default* @return Behavior[]*/public function fetchAllCompanyId($company_id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$prototype = new Behavior();return $this->executeFetchAllObject($select, $prototype);}/**** @return Behavior[]*/public function fetchAllByDefault() {$select = $this->sql->select(self::_TABLE);$select->where->isNull('company_id');$prototype = new Behavior();return $this->executeFetchAllObject($select, $prototype);}/**** @param string $uuid* @return Behavior*/public function fetchOneByUuid($uuid) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$select->limit(1);$prototype = new Behavior();return $this->executeFetchOneObject($select, $prototype);}/**** @param string $description* @param string $company_id* @return Behavior*/public function fetchOneByDescription($description, $company_id) {$select = $this->sql->select(self::_TABLE);$select->where->equalTo('description', $description);$company_id ?$select->where->equalTo('company_id', $company_id):$select->where->isNull('company_id');$select->limit(1);$prototype = new Behavior();return $this->executeFetchOneObject($select, $prototype);}/**** @param Behavior $behaviorType* @return boolean*/public function insert($behaviorType) {$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($behaviorType);$insert = $this->sql->insert(self::_TABLE);$insert->values($values);$result = $this->executeInsert($insert);if ($result) {$behaviorType->id = $this->lastInsertId;}return $result;}/**** @param Behavior $behaviorType* @return boolean*/public function update($behaviorType) {$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($behaviorType);$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $behaviorType->id);return $this->executeUpdate($update);}/**** @param Behavior $behaviorType* @return boolean*/public function delete($id) {$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('id', $id);return $this->executeDelete($delete);}/**** @return boolean*/public function truncate() {$sql = 'DELETE FROM ' . self::_TABLE;if ($this->executeSentenceWithParameters($sql)) {$sql = 'ALTER TABLE ' . self::_TABLE . ' AUTO_INCREMENT = 1 ';return $this->executeSentenceWithParameters($sql);}return false;}/**** @return Behavior[]*/public function fetchAllActives() {$prototype = new Behavior();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('status', Behavior::STATUS_ACTIVE);$select->order('name ASC');return $this->executeFetchAllObject($select, $prototype);}/**** @return Behavior[]*/public function fetchAllActivesByDefault() {$prototype = new Behavior();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('status', Behavior::STATUS_ACTIVE);$select->where->isNull('company_id');$select->order('name ASC');return $this->executeFetchAllObject($select, $prototype);}/**** @return Behavior[]*/public function fetchAllActivesByCompanyId($company_id) {$prototype = new Behavior();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('status', Behavior::STATUS_ACTIVE);$select->order('name ASC');return $this->executeFetchAllObject($select, $prototype);}/**** @return Behavior[]*/public function fetchAllByCompanyId($company_id) {$prototype = new Behavior();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->order('name ASC');return $this->executeFetchAllObject($select, $prototype);}/**** @param int $company_id* @param $behavior_id_default* @return Behavior*/public function fetchOneByCompanyIdAndCompetencyIdDefault($company_id, $behavior_id_default){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('behavior_id_default', $behavior_id_default);$select->limit(1);$prototype = new Behavior();return $this->executeFetchOneObject($select, $prototype);}}