/** * @param int|null $id * @param string|null $username * @param string|null $email * @return User */ public function get($id = null, $username = null, $email = null, $option = null) { if (!$id && !$username && !$email) { return null; } $select = $this->getDbSql()->select(['u' => self::TABLE_NAME]); if ($id) { $select->where(array('u.id' => $id)); } if ($username) { $select->where(array('u.username' => $username)); } if ($email) { $select->where(array('u.email' => $email)); } $select->limit(1); $query = $this->getDbSql()->buildSqlString($select); $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); if ($results->count()) { /* @var $dtMapper \Address\Model\DistrictMapper */ $dtMapper = $this->getServiceLocator()->get('Address\\Model\\DistrictMapper'); /* @var $ctMapper \Address\Model\CityMapper */ $ctMapper = $this->getServiceLocator()->get('Address\\Model\\CityMapper'); $user = new User(); $row = (array) $results->current(); $user->exchangeArray($row); if ($option) { $user->addOption('departmentName', $row['name']); } $user->setCity($ctMapper->get($row['cityId'])); $user->setDistrict($dtMapper->get($row['districtId'])); return $user; } return null; }