Rev 2090 | Rev 5205 | 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\CompanyUser;use LeadersLinked\Mapper\Common\MapperCommon;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Log\LoggerInterface;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Db\Sql\Expression;use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;class CompanyUserMapper extends MapperCommon{const _TABLE = 'tbl_company_users';/**** @var CompanyUserMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @param LoggerInterface $logger* @param int $user_id* @return \LeadersLinked\Mapper\CompanyUserMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new CompanyUserMapper($adapter);}return self::$_instance;}/**** @param int $company_id* @return CompanyUser[]*/public function fetchAllByCompanyId($company_id){$prototype = new CompanyUser();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);return $this->executeFetchAllObject($select, $prototype);}/**** @param int $company_id* @return CompanyUser[]*/public function fetchAllByUserId($user_id){$prototype = new CompanyUser();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('user_id', $user_id);return $this->executeFetchAllObject($select, $prototype);}/**** @param int $id* @return CompanyUser*/public function fetchOne($id){$prototype = new CompanyUser();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @return CompanyUser*/public function fetchOwnerByCompanyId($company_id){$prototype = new CompanyUser();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('owner', CompanyUser::OWNER_YES);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @return CompanyUser*/public function fetchCreatorByCompanyId($company_id){$prototype = new CompanyUser();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('creator', CompanyUser::CREATOR_YES);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @param int $user_id* @return CompanyUser*/public function fetchOneByCompanyIdAndUserId($company_id, $user_id){$prototype = new CompanyUser();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('user_id', $user_id);// echo $select->getSqlString($this->adapter->platform); exit;return $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @param int $user_id* @return int*/public function fetchCountOtherCompaniesByCompanyIdAndUserId($company_id, $user_id){$prototype = new CompanyUser();$select = $this->sql->select();$select->columns(['total' => new Expression('COUNT(*)') ]);$select->from(self::_TABLE);$select->where->notEqualTo('company_id', $company_id);$select->where->equalTo('user_id', $user_id);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param CompanyUser $companyUser* @return boolean*/public function insert($companyUser){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($companyUser);$values = $this->removeEmpty($values);$insert = $this->sql->insert(self::_TABLE);$insert->values($values);$result = $this->executeInsert($insert);if($result) {$companyUser->id = $this->lastInsertId;}return $result;}/**** @param CompanyUser $companyUser* @return boolean*/public function update($companyUser){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($companyUser);$values = $this->removeEmpty($values);$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $companyUser->id);return $this->executeUpdate($update);}/**** @param int $id* @return boolean*/public function delete($id){$delete = $this->sql->select(self::_TABLE);$delete->where->equalTo('id', $id);return $this->executeDelete($delete);}}