Пример #1
0
 /**
  * Saves the key config
  */
 public function save()
 {
     DefinitionCache::clear($this);
     $isUpdate = false;
     $def = \Zend_Json::decode($this->definition);
     if ($def && isset($def["title"])) {
         $this->title = $def["title"];
     } else {
         $this->title = null;
     }
     if ($this->getId()) {
         unset(self::$cache[$this->getId()]);
         $isUpdate = true;
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.preUpdate", $this);
     } else {
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.preAdd", $this);
     }
     $model = parent::save();
     if ($isUpdate) {
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.postUpdate", $this);
     } else {
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.postAdd", $this);
     }
     return $model;
 }
Пример #2
0
 /**
  * @param $keyId
  * @return mixed
  */
 public function getKeyConfiguration($keyId)
 {
     /** @var $keyConfig Object\Classificationstore\KeyConfig */
     $keyConfig = Object\Classificationstore\DefinitionCache::get($keyId);
     return $keyConfig;
 }
Пример #3
0
 /**
  * @param $keyId
  * @param $groupId
  * @param string $language
  * @param bool|false $ignoreFallbackLanguage
  * @return null
  */
 public function getLocalizedKeyValue($groupId, $keyId, $language = "default", $ignoreFallbackLanguage = false, $ignoreDefaultLanguage = false)
 {
     $oid = $this->object->getId();
     \Logger::debug($oid);
     $keyConfig = Model\Object\Classificationstore\DefinitionCache::get($keyId);
     $fieldDefinition = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
     $language = $this->getLanguage($language);
     $data = null;
     if (array_key_exists($groupId, $this->items) && array_key_exists($keyId, $this->items[$groupId]) && array_key_exists($language, $this->items[$groupId][$keyId])) {
         $data = $this->items[$groupId][$keyId][$language];
     }
     // check for fallback value
     if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) {
         $data = $this->getFallbackValue($groupId, $keyId, $language, $fieldDefinition);
     }
     if ($fieldDefinition->isEmpty($data) && !$ignoreDefaultLanguage && $language != "default") {
         $data = $this->items[$groupId][$keyId]["default"];
     }
     // check for inherited value
     $doGetInheritedValues = AbstractObject::doGetInheritedValues();
     if ($fieldDefinition->isEmpty($data) && $doGetInheritedValues) {
         $object = $this->getObject();
         $class = $object->getClass();
         $allowInherit = $class->getAllowInherit();
         if ($allowInherit) {
             if ($object->getParent() instanceof AbstractObject) {
                 $parent = $object->getParent();
                 while ($parent && $parent->getType() == "folder") {
                     $parent = $parent->getParent();
                 }
                 if ($parent && ($parent->getType() == "object" || $parent->getType() == "variant")) {
                     if ($parent->getClassId() == $object->getClassId()) {
                         $method = "getLocalizedfields";
                         if (method_exists($parent, $method)) {
                             $getter = "get" . ucfirst($this->fieldname);
                             $classificationStore = $parent->{$getter}();
                             if ($classificationStore instanceof Classificationstore) {
                                 if ($classificationStore->object->getId() != $this->object->getId()) {
                                     $data = $classificationStore->getLocalizedKeyValue($groupId, $keyId, $language, false);
                                     \Logger::debug($data);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) {
         $data = $fieldDefinition->preGetData($this, array("data" => $data, "language" => $language, "name" => $groupId . "-" . $keyId));
     }
     return $data;
 }
Пример #4
0
 /**
  *
  */
 public function load()
 {
     /** @var  $classificationStore Object\Classificationstore */
     $classificationStore = $this->model;
     $object = $this->model->getObject();
     $dataTableName = $this->getDataTableName();
     $objectId = $object->getId();
     $fieldname = $this->model->getFieldname();
     $query = "SELECT * FROM " . $dataTableName . " WHERE o_id = " . $this->db->quote($objectId) . " AND fieldname = " . $this->db->quote($fieldname);
     $data = $this->db->fetchAll($query);
     $groupCollectionMapping = array();
     foreach ($data as $item) {
         $groupId = $item["groupId"];
         $keyId = $item["keyId"];
         $collectionId = $item["collectionId"];
         $groupCollectionMapping[$groupId] = $collectionId;
         $value = $item["value"];
         $keyConfig = DefinitionCache::get($keyId);
         $fd = Service::getFieldDefinitionFromKeyConfig($keyConfig);
         $value = $fd->getDataFromResource($value);
         $language = $item["language"];
         $classificationStore->setLocalizedKeyValue($groupId, $keyId, $value, $language);
     }
     $groupsTableName = $this->getGroupsTableName();
     $query = "SELECT * FROM " . $groupsTableName . " WHERE o_id = " . $this->db->quote($objectId) . " AND fieldname = " . $this->db->quote($fieldname);
     $data = $this->db->fetchAll($query);
     $list = array();
     foreach ($data as $item) {
         $list[$item["groupId"]] = true;
     }
     $classificationStore->setActiveGroups($list);
     $classificationStore->setGroupCollectionMappings($groupCollectionMapping);
 }
Пример #5
0
 /**
  * Saves the key config
  */
 public function save()
 {
     DefinitionCache::clear($this);
     $isUpdate = false;
     if ($this->getId()) {
         unset(self::$cache[$this->getId()]);
         $isUpdate = true;
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.preUpdate", $this);
     } else {
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.preAdd", $this);
     }
     $model = parent::save();
     if ($isUpdate) {
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.postUpdate", $this);
     } else {
         \Pimcore::getEventManager()->trigger("object.Classificationstore.keyConfig.postAdd", $this);
     }
     return $model;
 }