예제 #1
0
 /**
  * @param array $preferenceList
  * @param array $userIdList
  * @return array[userId][preferenceName]
  */
 public function getPreferenceValueListByUserIdList(array $preferenceList, array $userIdList)
 {
     $resultList = array();
     foreach ($userIdList as $userId) {
         $resultList[$userId] = array();
     }
     if ($userIdList === null || !is_array($userIdList) || count($userIdList) === 0) {
         return $resultList;
     }
     if ($preferenceList === null || !is_array($preferenceList) || count($preferenceList) === 0) {
         return $resultList;
     }
     $usersBol = BOL_UserService::getInstance()->findUserListByIdList($userIdList);
     if ($usersBol === null || count($usersBol) === 0) {
         return $resultList;
     }
     $issetUserList = array();
     foreach ($usersBol as $user) {
         $issetUserList[$user->id] = $user->id;
     }
     $cachedPreferenceList = array();
     $notCachedPreferenceList = array();
     foreach ($usersBol as $user) {
         if (!empty($this->preferenceData[$userId])) {
             foreach ($preferenceList as $key) {
                 if (isset($this->preferenceData[$userId][$key]) && !isset($notCachedPreferenceList[$key])) {
                     $cachedPreferenceList[$key] = $key;
                 } else {
                     $notCachedPreferenceList[$key] = $key;
                     if (isset($cachedPreferenceList[$key])) {
                         unset($cachedPreferenceList[$key]);
                     }
                 }
             }
         } else {
             $notCachedPreferenceList = $preferenceList;
             $cachedPreferenceList = array();
         }
     }
     $preferenceDtoList = array();
     $preferenceData = array();
     if (count($notCachedPreferenceList) > 0) {
         /* @var $this->preferenceDataDao BOL_PreferenceDataDao */
         $preferenceDtoList = $this->preferenceDao->findPreferenceList($preferenceList);
         $preferenceData = $this->preferenceDataDao->findByPreferenceListForUserList($notCachedPreferenceList, $issetUserList);
     }
     foreach ($userIdList as $userId) {
         foreach ($preferenceDtoList as $dto) {
             $key = $dto->key;
             if (isset($preferenceData[$userId][$key])) {
                 $dataDto = $preferenceData[$userId][$key];
                 /* @var $dto BOL_PreferenceData */
                 $this->preferenceData[$userId][$key] = json_decode($dataDto->value);
                 $resultList[$userId][$key] = $this->preferenceData[$userId][$key];
             } else {
                 $this->preferenceData[$userId][$key] = json_decode($dto->defaultValue);
                 $resultList[$userId][$key] = $this->preferenceData[$userId][$key];
             }
         }
         foreach ($cachedPreferenceList as $key) {
             $resultList[$userId][$key] = $this->preferenceData[$userId][$key];
         }
     }
     return $resultList;
 }