Beispiel #1
0
 /**
  * 
  * @param SJB_User $user
  */
 public static function createTemplateStructureForUser($user)
 {
     if (!$user) {
         return array();
     }
     $structure = $user->getUserInfo();
     if (SJB_MemoryCache::has('userGroupInfo' . $user->getUserGroupSID())) {
         $user_group_info = SJB_MemoryCache::get('userGroupInfo' . $user->getUserGroupSID());
     } else {
         $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user->getUserGroupSID());
         SJB_MemoryCache::set('userGroupInfo' . $user->getUserGroupSID(), $user_group_info);
     }
     foreach ($user->getProperties() as $property) {
         $value = $property->getValue();
         if ($property->getType() == 'list') {
             $listValues = isset($property->type->property_info['list_values']) ? $property->type->property_info['list_values'] : array();
             foreach ($listValues as $listValue) {
                 if ($listValue['id'] == $value) {
                     $structure[$property->getID()] = $listValue['caption'];
                 }
             }
         } elseif ($property->getType() == 'location') {
             foreach ($property->type->fields as $locationField) {
                 if (isset($structure[$property->getID()]) && array_key_exists($locationField['id'], $structure[$property->getID()])) {
                     if ($locationField['id'] == 'State') {
                         $displayAs = !empty($locationField['display_as']) ? $locationField['display_as'] : 'state_name';
                         $listValues = SJB_StatesManager::getStateNamesBySid($property->value['State'], $displayAs);
                     } else {
                         $listValues = isset($locationField['list_values']) ? $locationField['list_values'] : array();
                     }
                     foreach ($listValues as $listValue) {
                         if ($listValue['id'] == $value[$locationField['id']]) {
                             $structure[$property->getID()][$locationField['id']] = $listValue['caption'];
                             $structure[$property->getID()][$locationField['id'] . '_Code'] = $listValue['Code'];
                             $structure[$property->getID()][$locationField['id'] . '_Name'] = $listValue['Name'];
                         }
                     }
                 }
             }
         } else {
             $structure[$property->getID()] = $value;
         }
     }
     $structure['id'] = $user->getID();
     $structure['isJobg8'] = strpos($structure['username'], 'jobg8_') !== false;
     $structure['group'] = array('id' => $user_group_info['id'], 'caption' => $user_group_info['name']);
     $subuserInfo = $user->getSubuserInfo();
     if (!empty($subuserInfo)) {
         $structure['subuser'] = $subuserInfo;
     }
     $structure['METADATA'] = array('group' => array('caption' => array('type' => 'string', 'propertyID' => 'caption')), 'registration_date' => array('type' => 'date'));
     $structure['METADATA'] = array_merge($structure['METADATA'], parent::getObjectMetaData($user));
     return $structure;
 }