Beispiel #1
0
 /**
  * @return array|null
  * @param \User\Model\User $user
  */
 public function getUser($user)
 {
     if (!$user->getId()) {
         return null;
     }
     $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME));
     if ($user->getId()) {
         $select->where(['u.id' => $user->getId()]);
     }
     if ($user->getRole()) {
         $select->where(['u.role' => $user->getRole()]);
     }
     $select->limit(1);
     $query = $this->getDbSql()->buildSqlString($select);
     $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE);
     if ($results->count()) {
         $data = $results->current();
         $user->exchangeArray((array) $results->current());
         $select1 = clone $select;
         if ($user->getCityId()) {
             $select1->join(array('c' => CityMapper::TABLE_NAME), 'u.cityId = c.id', ['cityName' => 'nativeName'], 'left');
         }
         if ($user->getDistrictId()) {
             $select1->join(array('d' => DistrictMapper::TABLE_NAME), 'u.districtId = d.id', ['districtName' => 'name'], 'left');
         }
         $query1 = $this->getDbSql()->buildSqlString($select1);
         $results1 = $this->getDbAdapter()->query($query1, Adapter::QUERY_MODE_EXECUTE);
         $data1 = $results1->current();
         if (isset($data1['cityName']) && $data1['cityName']) {
             $user->addOption('cityName', $data1['cityName']);
         }
         if (isset($data1['districtName']) && $data1['districtName']) {
             $user->addOption('districtName', $data1['districtName']);
         }
         return $user;
     }
     return null;
 }