setLocalizedKeyValue() public method

public setLocalizedKeyValue ( $groupId, $keyId, $value, null $language = null )
$groupId
$keyId
$value
$language null
Exemplo n.º 1
0
 /**
  * @see Model\Object\ClassDefinition\Data::getDataFromEditmode
  * @param string $containerData
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return string
  */
 public function getDataFromEditmode($containerData, $object = null, $params = [])
 {
     $classificationStore = $this->getDataFromObjectParam($object);
     if (!$classificationStore instanceof Object\Classificationstore) {
         $classificationStore = new Object\Classificationstore();
     }
     $data = $containerData["data"];
     $activeGroups = $containerData["activeGroups"];
     $groupCollectionMapping = $containerData["groupCollectionMapping"];
     $correctedMapping = [];
     foreach ($groupCollectionMapping as $groupId => $collectionId) {
         if ($activeGroups[$groupId]) {
             $correctedMapping[$groupId] = $collectionId;
         }
     }
     $classificationStore->setGroupCollectionMappings($correctedMapping);
     if (is_array($data)) {
         foreach ($data as $language => $groups) {
             foreach ($groups as $groupId => $keys) {
                 foreach ($keys as $keyId => $value) {
                     $keyConfig = $this->getKeyConfiguration($keyId);
                     $dataDefinition = Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
                     $dataFromEditMode = $dataDefinition->getDataFromEditmode($value);
                     $activeGroups[$groupId] = true;
                     $classificationStore->setLocalizedKeyValue($groupId, $keyId, $dataFromEditMode, $language);
                 }
             }
         }
     }
     $activeGroupIds = array_keys($activeGroups);
     $classificationStore->setActiveGroups($activeGroups);
     // cleanup
     $existingGroupIds = $classificationStore->getGroupIdsWithData();
     if (is_array($existingGroupIds)) {
         foreach ($existingGroupIds as $existingGroupId) {
             if (!in_array($existingGroupId, $activeGroupIds)) {
                 $classificationStore->removeGroupData($existingGroupId);
             }
         }
     }
     return $classificationStore;
 }
Exemplo n.º 2
0
 /**
  * @param mixed $value
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @param IdMapper $idMapper
  * @return mixed|null|Object\Classificationstore
  * @throws \Exception
  */
 public function getFromWebserviceImport($value, $object = null, $params = [], $idMapper = null)
 {
     if ($value) {
         $storeData = new Object\Classificationstore();
         $storeData->setFieldname($this->getName());
         $storeData->setObject($object);
         $activeGroupsLocal = [];
         $activeGroupsRemote = $value->activeGroups;
         if (is_array($activeGroupsRemote)) {
             foreach ($activeGroupsRemote as $data) {
                 $remoteId = $data->id;
                 $localId = $idMapper->getMappedId("csGroup", $remoteId);
                 $activeGroupsLocal[$localId] = $localId;
             }
         }
         $storeData->setActiveGroups($activeGroupsLocal);
         $groupsRemote = $value->groups;
         if (is_array($groupsRemote)) {
             foreach ($groupsRemote as $remoteGroupData) {
                 $remoteGroupId = $remoteGroupData->id;
                 $localGroupId = $idMapper->getMappedId("csGroup", $remoteGroupId);
                 $remoteKeys = $remoteGroupData->keys;
                 $remoteKeys = (array) $remoteKeys;
                 foreach ($remoteKeys as $language => $keyList) {
                     foreach ($keyList as $keyData) {
                         $remoteKeyId = $keyData->id;
                         $localKeyId = $idMapper->getMappedId("csKey", $remoteKeyId);
                         $keyConfig = Object\Classificationstore\KeyConfig::getById($localKeyId);
                         $keyDef = Object\Classificationstore\Service::getFieldDefinitionFromJson(json_decode($keyConfig->getDefinition()), $keyConfig->getType());
                         $value = $keyData->value;
                         $value = $keyDef->getFromWebserviceImport($value, $object, []);
                         $storeData->setLocalizedKeyValue($localGroupId, $localKeyId, $value, $language);
                     }
                 }
             }
         }
         return $storeData;
     }
 }