Inheritance: extends Pimcore\Model\Element\AbstractElement
Example #1
0
 /**
  *
  * Checks if an object is an allowed relation
  * @param Model\Object\AbstractObject $object
  * @return boolean
  */
 protected function allowObjectRelation($object)
 {
     $allowedClasses = $this->getClasses();
     $allowed = true;
     if (!$this->getObjectsAllowed()) {
         $allowed = false;
     } elseif ($this->getObjectsAllowed() and is_array($allowedClasses) and count($allowedClasses) > 0) {
         //check for allowed classes
         if ($object instanceof Object\Concrete) {
             $classname = $object->getClassName();
             foreach ($allowedClasses as $c) {
                 $allowedClassnames[] = $c['classes'];
             }
             if (!in_array($classname, $allowedClassnames)) {
                 $allowed = false;
             }
         } else {
             $allowed = false;
         }
     } else {
         //don't check if no allowed classes set
     }
     if ($object instanceof Object\AbstractObject) {
         \Logger::debug("checked object relation to target object [" . $object->getId() . "] in field [" . $this->getName() . "], allowed:" . $allowed);
     } else {
         \Logger::debug("checked object relation to target in field [" . $this->getName() . "], not allowed, target ist not an object");
         \Logger::debug($object);
     }
     return $allowed;
 }
 /**
  * enables inheritance for field collections, if xxxInheritance field is available and set to string 'true'
  *
  * @param string $key
  * @return mixed|\Pimcore\Model\Object\Fieldcollection
  */
 public function preGetValue($key)
 {
     if ($this->getClass()->getAllowInherit() && \Pimcore\Model\Object\AbstractObject::doGetInheritedValues() && $this->getClass()->getFieldDefinition($key) instanceof \Pimcore\Model\Object\ClassDefinition\Data\Fieldcollections) {
         $checkInheritanceKey = $key . "Inheritance";
         if ($this->{'get' . $checkInheritanceKey}() == "true") {
             $parentValue = $this->getValueFromParent($key);
             $data = $this->{$key};
             if (!$data) {
                 $data = $this->getClass()->getFieldDefinition($key)->preGetData($this);
             }
             if (!$data) {
                 return $parentValue;
             } else {
                 if (!empty($parentValue)) {
                     $value = new \Pimcore\Model\Object\Fieldcollection($parentValue->getItems());
                     if (!empty($data)) {
                         foreach ($data as $entry) {
                             $value->add($entry);
                         }
                     }
                 } else {
                     $value = new \Pimcore\Model\Object\Fieldcollection($data->getItems());
                 }
                 return $value;
             }
         }
     }
     return parent::preGetValue($key);
 }
Example #3
0
 /**
  * @throws \Exception
  */
 public function delete()
 {
     if ($this->getId() == 1) {
         throw new \Exception("root-node cannot be deleted");
     }
     parent::delete();
 }
Example #4
0
 /**
  * @static
  * @param int $id
  * @return null|\Pimcore\Model\Object\AbstractObject
  */
 public static function getById($id)
 {
     $object = \Pimcore\Model\Object\AbstractObject::getById($id);
     if ($object instanceof OnlineShop_Framework_AbstractCategory) {
         return $object;
     }
     return null;
 }
Example #5
0
 /**
  * @return OnlineShop_Framework_ProductInterfaces_ICheckoutable
  */
 public function getProduct()
 {
     if ($this->product) {
         return $this->product;
     }
     $this->product = \Pimcore\Model\Object\AbstractObject::getById($this->productId);
     return $this->product;
 }
 /**
 * @return \Pimcore\Model\Object\Objectbrick\Data\CoreShopDimensionSize
 */
 public function getCoreShopDimensionSize()
 {
     if (!$this->CoreShopDimensionSize && \Pimcore\Model\Object\AbstractObject::doGetInheritedValues($this->getObject())) {
         $brick = $this->getObject()->getValueFromParent("dimensions");
         if (!empty($brick)) {
             return $this->getObject()->getValueFromParent("dimensions")->getCoreShopDimensionSize();
         }
     }
     return $this->CoreShopDimensionSize;
 }
Example #7
0
 /**
  * returns all possible group by values for given column group, product list and field combination
  *
  * @param $columnGroup
  * @param OnlineShop_Framework_IProductList $productList
  * @param string $field
  * @return array
  */
 public static function getGroupByValuesForFilterGroup($columnGroup, OnlineShop_Framework_IProductList $productList, $field)
 {
     $columnType = self::getColumnTypeForColumnGroup($columnGroup);
     $data = array();
     if ($columnType == "relation") {
         $productList->prepareGroupByRelationValues($field);
         $values = $productList->getGroupByRelationValues($field);
         foreach ($values as $v) {
             $obj = \Pimcore\Model\Object\AbstractObject::getById($v);
             if ($obj) {
                 $name = $obj->getKey();
                 if (method_exists($obj, "getName")) {
                     $name = $obj->getName();
                 }
                 $data[$v] = array("key" => $v, "value" => $name . " (" . $obj->getId() . ")");
             }
         }
     } else {
         if ($columnType == "multiselect") {
             $values = $productList->getGroupByValues($field);
             sort($values);
             foreach ($values as $v) {
                 $helper = explode(OnlineShop_Framework_IndexService_Tenant_IWorker::MULTISELECT_DELIMITER, $v);
                 foreach ($helper as $h) {
                     $data[$h] = array("key" => $h, "value" => $h);
                 }
             }
         } else {
             if ($columnType == "category") {
                 $values = $productList->getGroupByValues($field);
                 foreach ($values as $v) {
                     $helper = explode(",", $v);
                     foreach ($helper as $h) {
                         $obj = \Pimcore\Model\Object\AbstractObject::getById($h);
                         if ($obj) {
                             $name = $obj->getKey();
                             if (method_exists($obj, "getName")) {
                                 $name = $obj->getName();
                             }
                             $data[$h] = array("key" => $h, "value" => $name . " (" . $obj->getId() . ")");
                         }
                     }
                 }
             } else {
                 $values = $productList->getGroupByValues($field);
                 sort($values);
                 foreach ($values as $v) {
                     $data[] = array("key" => $v, "value" => $v);
                 }
             }
         }
     }
     return $data;
 }
Example #8
0
 /**
  * @param $method
  * @param $args
  *
  * @return mixed
  * @throws \Exception
  */
 public function __call($method, $args)
 {
     $field = substr($method, 3);
     if (substr($method, 0, 3) == 'get' && array_key_exists($field, $this->resultRow)) {
         return $this->resultRow[$field];
     }
     $object = \Pimcore\Model\Object\AbstractObject::getById($this->getId());
     if ($object) {
         return call_user_func_array(array($object, $method), $args);
     } else {
         throw new \Exception("Object with {$this->getId()} not found.");
     }
 }
Example #9
0
 /**
  * @param $id
  * @throws \Exception
  */
 public function getById($id)
 {
     $data = $this->db->fetchRow("SELECT * FROM notes WHERE id = ?", $id);
     if (!$data["id"]) {
         throw new \Exception("Note item with id " . $id . " not found");
     }
     $this->assignVariablesToModel($data);
     // get key-value data
     $keyValues = $this->db->fetchAll("SELECT * FROM notes_data WHERE id = ?", $id);
     $preparedData = array();
     foreach ($keyValues as $keyValue) {
         $data = $keyValue["data"];
         $type = $keyValue["type"];
         $name = $keyValue["name"];
         if ($type == "document") {
             if ($data) {
                 $data = Document::getById($data);
             }
         } else {
             if ($type == "asset") {
                 if ($data) {
                     $data = Asset::getById($data);
                 }
             } else {
                 if ($type == "object") {
                     if ($data) {
                         $data = Object\AbstractObject::getById($data);
                     }
                 } else {
                     if ($type == "date") {
                         if ($data > 0) {
                             $data = new \Zend_Date($data);
                         }
                     } else {
                         if ($type == "bool") {
                             $data = (bool) $data;
                         }
                     }
                 }
             }
         }
         $preparedData[$name] = array("data" => $data, "type" => $type);
     }
     $this->model->setData($preparedData);
 }
 /**
  * @return AbstractObject|\Pimcore\Model\Object\Participation
  * @throws \Exception
  */
 public function makeParticipation()
 {
     $objectFolderPath = Plugin::getConfig()->get(Plugin::CONFIG_OBJECTFOLDERPATH);
     $objectFolder = AbstractObject::getByPath($objectFolderPath);
     if (!$objectFolder instanceof Folder) {
         throw new \Exception("Error: objectFolderPath [{$objectFolderPath}] " . "is not a valid object folder.");
     }
     // create basic object stuff
     $key = $this->createParticipationKey();
     $participation = new Participation();
     $participation->setKey($key);
     $participation->setParent($objectFolder);
     $participation->setPublished(true);
     $participation->setCreationDate(time());
     $participation->SetIpCreated($_SERVER['REMOTE_ADDR']);
     $confirmation = $this->makeConfirmation();
     $participation->setConfirmationCode($confirmation->createCode());
     return $participation;
 }
Example #11
0
 public function getFilterFrontend(OnlineShop_Framework_AbstractFilterDefinitionType $filterDefinition, OnlineShop_Framework_IProductList $productList, $currentFilter)
 {
     $field = $this->getField($filterDefinition);
     $values = $productList->getGroupByRelationValues($field, true);
     $objects = array();
     Logger::log("Load Objects...", Zend_Log::INFO);
     $availableRelations = array();
     if ($filterDefinition->getAvailableRelations()) {
         $availableRelations = $this->loadAllAvailableRelations($filterDefinition->getAvailableRelations());
     }
     foreach ($values as $v) {
         if (empty($availableRelations) || $availableRelations[$v['value']] === true) {
             $objects[$v['value']] = \Pimcore\Model\Object\AbstractObject::getById($v['value']);
         }
     }
     Logger::log("done.", Zend_Log::INFO);
     if ($filterDefinition->getScriptPath()) {
         $script = $filterDefinition->getScriptPath();
     } else {
         $script = $this->script;
     }
     return $this->view->partial($script, array("hideFilter" => $filterDefinition->getRequiredFilterField() && empty($currentFilter[$filterDefinition->getRequiredFilterField()]), "label" => $filterDefinition->getLabel(), "currentValue" => $currentFilter[$field], "values" => $values, "objects" => $objects, "fieldname" => $field, "metaData" => $filterDefinition->getMetaData()));
 }
Example #12
0
 /**
  *
  */
 public function save()
 {
     $this->delete(false);
     $object = $this->model->getObject();
     $validLanguages = Tool::getValidLanguages();
     $context = $this->model->getContext();
     if ($context && $context["containerType"] == "fieldcollection") {
         $containerKey = $context["containerKey"];
         $container = Object\Fieldcollection\Definition::getByKey($containerKey);
     } else {
         $container = $this->model->getClass();
     }
     $fieldDefinitions = $container->getFielddefinition("localizedfields")->getFielddefinitions();
     foreach ($validLanguages as $language) {
         $inheritedValues = Object\AbstractObject::doGetInheritedValues();
         Object\AbstractObject::setGetInheritedValues(false);
         $insertData = ["ooo_id" => $this->model->getObject()->getId(), "language" => $language];
         if ($container instanceof Object\Fieldcollection\Definition) {
             $insertData["fieldname"] = $context["fieldname"];
             $insertData["index"] = $context["index"];
         }
         foreach ($fieldDefinitions as $fd) {
             if (method_exists($fd, "save")) {
                 // for fieldtypes which have their own save algorithm eg. objects, multihref, ...
                 $context = $this->model->getContext() ? $this->model->getContext() : [];
                 if ($context["containerType"] == "fieldcollection") {
                     $context["subContainerType"] = "localizedfield";
                 }
                 $childParams = ["context" => $context, "language" => $language];
                 $fd->save($this->model, $childParams);
             } else {
                 if (is_array($fd->getColumnType())) {
                     $insertDataArray = $fd->getDataForResource($this->model->getLocalizedValue($fd->getName(), $language, true), $object);
                     $insertData = array_merge($insertData, $insertDataArray);
                 } else {
                     $insertData[$fd->getName()] = $fd->getDataForResource($this->model->getLocalizedValue($fd->getName(), $language, true), $object);
                 }
             }
         }
         $storeTable = $this->getTableName();
         $queryTable = $this->getQueryTableName() . "_" . $language;
         $this->db->insertOrUpdate($storeTable, $insertData);
         if ($container instanceof Object\ClassDefinition) {
             // query table
             $data = [];
             $data["ooo_id"] = $this->model->getObject()->getId();
             $data["language"] = $language;
             $this->inheritanceHelper = new Object\Concrete\Dao\InheritanceHelper($object->getClassId(), "ooo_id", $storeTable, $queryTable);
             $this->inheritanceHelper->resetFieldsToCheck();
             $sql = "SELECT * FROM " . $queryTable . " WHERE ooo_id = " . $object->getId() . " AND language = '" . $language . "'";
             $oldData = [];
             try {
                 $oldData = $this->db->fetchRow($sql);
             } catch (\Exception $e) {
                 // if the table doesn't exist -> create it!
                 if (strpos($e->getMessage(), "exist")) {
                     // the following is to ensure consistent data and atomic transactions, while having the flexibility
                     // to add new languages on the fly without saving all classes having localized fields
                     // first we need to roll back all modifications, because otherwise they would be implicitly committed
                     // by the following DDL
                     $this->db->rollBack();
                     // this creates the missing table
                     $this->createUpdateTable();
                     // at this point we throw an exception so that the transaction gets repeated in Object::save()
                     throw new \Exception("missing table created, start next run ... ;-)");
                 }
             }
             // get fields which shouldn't be updated
             $untouchable = [];
             // @TODO: currently we do not support lazyloading in localized fields
             $inheritanceEnabled = $object->getClass()->getAllowInherit();
             $parentData = null;
             if ($inheritanceEnabled) {
                 // get the next suitable parent for inheritance
                 $parentForInheritance = $object->getNextParentForInheritance();
                 if ($parentForInheritance) {
                     // we don't use the getter (built in functionality to get inherited values) because we need to avoid race conditions
                     // we cannot Object\AbstractObject::setGetInheritedValues(true); and then $this->model->getLocalizedValue($key, $language)
                     // so we select the data from the parent object using FOR UPDATE, which causes a lock on this row
                     // so the data of the parent cannot be changed while this transaction is on progress
                     $parentData = $this->db->fetchRow("SELECT * FROM " . $queryTable . " WHERE ooo_id = ? AND language = ? FOR UPDATE", [$parentForInheritance->getId(), $language]);
                 }
             }
             foreach ($fieldDefinitions as $fd) {
                 if ($fd->getQueryColumnType()) {
                     $key = $fd->getName();
                     // exclude untouchables if value is not an array - this means data has not been loaded
                     if (!(in_array($key, $untouchable) and !is_array($this->model->{$key}))) {
                         $localizedValue = $this->model->getLocalizedValue($key, $language);
                         $insertData = $fd->getDataForQueryResource($localizedValue, $object);
                         $isEmpty = $fd->isEmpty($localizedValue);
                         if (is_array($insertData)) {
                             $columnNames = array_keys($insertData);
                             $data = array_merge($data, $insertData);
                         } else {
                             $columnNames = [$key];
                             $data[$key] = $insertData;
                         }
                         // if the current value is empty and we have data from the parent, we just use it
                         if ($isEmpty && $parentData) {
                             foreach ($columnNames as $columnName) {
                                 if (array_key_exists($columnName, $parentData)) {
                                     $data[$columnName] = $parentData[$columnName];
                                     if (is_array($insertData)) {
                                         $insertData[$columnName] = $parentData[$columnName];
                                     } else {
                                         $insertData = $parentData[$columnName];
                                     }
                                 }
                             }
                         }
                         if ($inheritanceEnabled && $fd->getFieldType() != "calculatedValue") {
                             //get changed fields for inheritance
                             if ($fd->isRelationType()) {
                                 if (is_array($insertData)) {
                                     $doInsert = false;
                                     foreach ($insertData as $insertDataKey => $insertDataValue) {
                                         if ($isEmpty && $oldData[$insertDataKey] == $parentData[$insertDataKey]) {
                                             // do nothing, ... value is still empty and parent data is equal to current data in query table
                                         } elseif ($oldData[$insertDataKey] != $insertDataValue) {
                                             $doInsert = true;
                                             break;
                                         }
                                     }
                                     if ($doInsert) {
                                         $this->inheritanceHelper->addRelationToCheck($key, $fd, array_keys($insertData));
                                     }
                                 } else {
                                     if ($isEmpty && $oldData[$key] == $parentData[$key]) {
                                         // do nothing, ... value is still empty and parent data is equal to current data in query table
                                     } elseif ($oldData[$key] != $insertData) {
                                         $this->inheritanceHelper->addRelationToCheck($key, $fd);
                                     }
                                 }
                             } else {
                                 if (is_array($insertData)) {
                                     foreach ($insertData as $insertDataKey => $insertDataValue) {
                                         if ($isEmpty && $oldData[$insertDataKey] == $parentData[$insertDataKey]) {
                                             // do nothing, ... value is still empty and parent data is equal to current data in query table
                                         } elseif ($oldData[$insertDataKey] != $insertDataValue) {
                                             $this->inheritanceHelper->addFieldToCheck($insertDataKey, $fd);
                                         }
                                     }
                                 } else {
                                     if ($isEmpty && $oldData[$key] == $parentData[$key]) {
                                         // do nothing, ... value is still empty and parent data is equal to current data in query table
                                     } elseif ($oldData[$key] != $insertData) {
                                         // data changed, do check and update
                                         $this->inheritanceHelper->addFieldToCheck($key, $fd);
                                     }
                                 }
                             }
                         }
                     } else {
                         Logger::debug("Excluding untouchable query value for object [ " . $this->model->getId() . " ]  key [ {$key} ] because it has not been loaded");
                     }
                 }
             }
             $queryTable = $this->getQueryTableName() . "_" . $language;
             $this->db->insertOrUpdate($queryTable, $data);
             if ($inheritanceEnabled) {
                 $this->inheritanceHelper->doUpdate($object->getId(), true);
             }
             $this->inheritanceHelper->resetFieldsToCheck();
         }
         Object\AbstractObject::setGetInheritedValues($inheritedValues);
     }
     // foreach language
 }
Example #13
0
 /**
  * @param $object
  * @param array $params
  * @return null|Object\Fieldcollection\Data\Object\Concrete|Object\Objectbrick\Data\
  */
 public function preGetData($object, $params = array())
 {
     $data = null;
     if ($object instanceof Object\Concrete) {
         $data = $object->{$this->getName()};
         if ($this->getLazyLoading() and !in_array($this->getName(), $object->getO__loadedLazyFields())) {
             $data = $this->load($object, array("force" => true));
             $setter = "set" . ucfirst($this->getName());
             if (method_exists($object, $setter)) {
                 $object->{$setter}($data);
             }
         }
     } else {
         if ($object instanceof Object\Localizedfield) {
             $data = $params["data"];
         } else {
             if ($object instanceof Object\Fieldcollection\Data\AbstractData) {
                 $data = $object->{$this->getName()};
             } else {
                 if ($object instanceof Object\Objectbrick\Data\AbstractData) {
                     $data = $object->{$this->getName()};
                 }
             }
         }
     }
     if (Object\AbstractObject::doHideUnpublished() and $data instanceof Element\ElementInterface) {
         if (!Element\Service::isPublished($data)) {
             return null;
         }
     }
     return $data;
 }
Example #14
0
 /**
  * @param Object\Concrete $object
  * @throws \Exception
  */
 public function save(Object\Concrete $object)
 {
     // HACK: set the pimcore admin mode to false to get the inherited values from parent if this source one is empty
     $inheritedValues = Object\AbstractObject::doGetInheritedValues();
     $storetable = $this->model->getDefinition()->getTableName($object->getClass(), false);
     $querytable = $this->model->getDefinition()->getTableName($object->getClass(), true);
     $this->inheritanceHelper = new Object\Concrete\Dao\InheritanceHelper($object->getClassId(), "o_id", $storetable, $querytable);
     Object\AbstractObject::setGetInheritedValues(false);
     $fieldDefinitions = $this->model->getDefinition()->getFieldDefinitions();
     $data = [];
     $data["o_id"] = $object->getId();
     $data["fieldname"] = $this->model->getFieldname();
     // remove all relations
     try {
         $this->db->delete("object_relations_" . $object->getClassId(), "src_id = " . $object->getId() . " AND ownertype = 'objectbrick' AND ownername = '" . $this->model->getFieldname() . "' AND (position = '" . $this->model->getType() . "' OR position IS NULL OR position = '')");
     } catch (\Exception $e) {
         Logger::warning("Error during removing old relations: " . $e);
     }
     foreach ($fieldDefinitions as $key => $fd) {
         $getter = "get" . ucfirst($fd->getName());
         if (method_exists($fd, "save")) {
             // for fieldtypes which have their own save algorithm eg. objects, multihref, ...
             $fd->save($this->model);
         } elseif ($fd->getColumnType()) {
             if (is_array($fd->getColumnType())) {
                 $insertDataArray = $fd->getDataForResource($this->model->{$getter}(), $object, ['context' => $this->model]);
                 $data = array_merge($data, $insertDataArray);
             } else {
                 $insertData = $fd->getDataForResource($this->model->{$getter}(), $object, ['context' => $this->model]);
                 $data[$key] = $insertData;
             }
         }
     }
     $this->db->insertOrUpdate($storetable, $data);
     // get data for query table
     // $tableName = $this->model->getDefinition()->getTableName($object->getClass(), true);
     // this is special because we have to call each getter to get the inherited values from a possible parent object
     $data = [];
     $data["o_id"] = $object->getId();
     $data["fieldname"] = $this->model->getFieldname();
     $this->inheritanceHelper->resetFieldsToCheck();
     $oldData = $this->db->fetchRow("SELECT * FROM " . $querytable . " WHERE o_id = ?", $object->getId());
     $inheritanceEnabled = $object->getClass()->getAllowInherit();
     $parentData = null;
     if ($inheritanceEnabled) {
         // get the next suitable parent for inheritance
         $parentForInheritance = $object->getNextParentForInheritance();
         if ($parentForInheritance) {
             // we don't use the getter (built in functionality to get inherited values) because we need to avoid race conditions
             // we cannot Object\AbstractObject::setGetInheritedValues(true); and then $this->model->$method();
             // so we select the data from the parent object using FOR UPDATE, which causes a lock on this row
             // so the data of the parent cannot be changed while this transaction is on progress
             $parentData = $this->db->fetchRow("SELECT * FROM " . $querytable . " WHERE o_id = ? FOR UPDATE", $parentForInheritance->getId());
         }
     }
     foreach ($fieldDefinitions as $key => $fd) {
         if ($fd->getQueryColumnType()) {
             //exclude untouchables if value is not an array - this means data has not been loaded
             $method = "get" . $key;
             $fieldValue = $this->model->{$method}();
             $insertData = $fd->getDataForQueryResource($fieldValue, $object);
             $isEmpty = $fd->isEmpty($fieldValue);
             if (is_array($insertData)) {
                 $columnNames = array_keys($insertData);
                 $data = array_merge($data, $insertData);
             } else {
                 $columnNames = [$key];
                 $data[$key] = $insertData;
             }
             // if the current value is empty and we have data from the parent, we just use it
             if ($isEmpty && $parentData) {
                 foreach ($columnNames as $columnName) {
                     if (array_key_exists($columnName, $parentData)) {
                         $data[$columnName] = $parentData[$columnName];
                         if (is_array($insertData)) {
                             $insertData[$columnName] = $parentData[$columnName];
                         } else {
                             $insertData = $parentData[$columnName];
                         }
                     }
                 }
             }
             if ($inheritanceEnabled) {
                 //get changed fields for inheritance
                 if ($fd instanceof Object\ClassDefinition\Data\CalculatedValue) {
                     // nothing to do, see https://github.com/pimcore/pimcore/issues/727
                     continue;
                 } elseif ($fd->isRelationType()) {
                     if (is_array($insertData)) {
                         $doInsert = false;
                         foreach ($insertData as $insertDataKey => $insertDataValue) {
                             if ($isEmpty && $oldData[$insertDataKey] == $parentData[$insertDataKey]) {
                                 // do nothing, ... value is still empty and parent data is equal to current data in query table
                             } elseif ($oldData[$insertDataKey] != $insertDataValue) {
                                 $doInsert = true;
                                 break;
                             }
                         }
                         if ($doInsert) {
                             $this->inheritanceHelper->addRelationToCheck($key, $fd, array_keys($insertData));
                         }
                     } else {
                         if ($isEmpty && $oldData[$key] == $parentData[$key]) {
                             // do nothing, ... value is still empty and parent data is equal to current data in query table
                         } elseif ($oldData[$key] != $insertData) {
                             $this->inheritanceHelper->addRelationToCheck($key, $fd);
                         }
                     }
                 } else {
                     if (is_array($insertData)) {
                         foreach ($insertData as $insertDataKey => $insertDataValue) {
                             if ($isEmpty && $oldData[$insertDataKey] == $parentData[$insertDataKey]) {
                                 // do nothing, ... value is still empty and parent data is equal to current data in query table
                             } elseif ($oldData[$insertDataKey] != $insertDataValue) {
                                 $this->inheritanceHelper->addFieldToCheck($insertDataKey, $fd);
                             }
                         }
                     } else {
                         if ($isEmpty && $oldData[$key] == $parentData[$key]) {
                             // do nothing, ... value is still empty and parent data is equal to current data in query table
                         } elseif ($oldData[$key] != $insertData) {
                             // data changed, do check and update
                             $this->inheritanceHelper->addFieldToCheck($key, $fd);
                         }
                     }
                 }
             }
         }
     }
     $this->db->insertOrUpdate($querytable, $data);
     if ($inheritanceEnabled) {
         $this->inheritanceHelper->doUpdate($object->getId(), true);
     }
     $this->inheritanceHelper->resetFieldsToCheck();
     // HACK: see a few lines above!
     Object\AbstractObject::setGetInheritedValues($inheritedValues);
 }
Example #15
0
 /**
  * @throws \Zend_Controller_Router_Exception
  */
 public function init()
 {
     // this is only executed once per request (first request)
     if (self::$isInitial) {
         \Pimcore::getEventManager()->trigger("frontend.controller.preInit", $this);
     }
     parent::init();
     // log exceptions if handled by error_handler
     $this->checkForErrors();
     // general definitions
     if (self::$isInitial) {
         \Pimcore::unsetAdminMode();
         Document::setHideUnpublished(true);
         Object\AbstractObject::setHideUnpublished(true);
         Object\AbstractObject::setGetInheritedValues(true);
         Object\Localizedfield::setGetFallbackValues(true);
     }
     // assign variables
     $this->view->controller = $this;
     // init website config
     $config = Config::getWebsiteConfig();
     $this->config = $config;
     $this->view->config = $config;
     $document = $this->getParam("document");
     if (!$document instanceof Document) {
         \Zend_Registry::set("pimcore_editmode", false);
         $this->editmode = false;
         $this->view->editmode = false;
         self::$isInitial = false;
         // check for a locale first, and set it if available
         if ($this->getParam("pimcore_parentDocument")) {
             // this is a special exception for renderlets in editmode (ajax request), because they depend on the locale of the parent document
             // otherwise there'll be notices like:  Notice: 'No translation for the language 'XX' available.'
             if ($parentDocument = Document::getById($this->getParam("pimcore_parentDocument"))) {
                 if ($parentDocument->getProperty("language")) {
                     $this->setLocaleFromDocument($parentDocument->getProperty("language"));
                 }
             }
         }
         // no document available, continue, ...
         return;
     } else {
         $this->setDocument($document);
         // register global locale if the document has the system property "language"
         if ($this->getDocument()->getProperty("language")) {
             $this->setLocaleFromDocument($this->getDocument()->getProperty("language"));
         }
         if (self::$isInitial) {
             // append meta-data to the headMeta() view helper,  if it is a document-request
             if (!Model\Staticroute::getCurrentRoute() && $this->getDocument() instanceof Document\Page) {
                 if (is_array($this->getDocument()->getMetaData())) {
                     foreach ($this->getDocument()->getMetaData() as $meta) {
                         // only name
                         if (!empty($meta["idName"]) && !empty($meta["idValue"]) && !empty($meta["contentValue"])) {
                             $method = "append" . ucfirst($meta["idName"]);
                             $this->view->headMeta()->{$method}($meta["idValue"], $meta["contentValue"]);
                         }
                     }
                 }
             }
         }
     }
     // this is only executed once per request (first request)
     if (self::$isInitial) {
         // contains the logged in user if necessary
         $user = null;
         // default is to set the editmode to false, is enabled later if necessary
         \Zend_Registry::set("pimcore_editmode", false);
         if (Tool::isFrontentRequestByAdmin()) {
             $this->disableBrowserCache();
             // start admin session & get logged in user
             $user = Authentication::authenticateSession();
         }
         if (\Pimcore::inDebugMode()) {
             $this->disableBrowserCache();
         }
         if (!$this->document->isPublished()) {
             if (Tool::isFrontentRequestByAdmin()) {
                 if (!$user) {
                     throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
                 }
             } else {
                 throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
             }
         }
         // logged in users only
         if ($user) {
             // set the user to registry so that it is available via \Pimcore\Tool\Admin::getCurrentUser();
             \Zend_Registry::set("pimcore_admin_user", $user);
             // document editmode
             if ($this->getParam("pimcore_editmode")) {
                 \Zend_Registry::set("pimcore_editmode", true);
                 // check if there is the document in the session
                 $docKey = "document_" . $this->getDocument()->getId();
                 $docSession = Session::getReadOnly("pimcore_documents");
                 if ($docSession->{$docKey}) {
                     // if there is a document in the session use it
                     $this->setDocument($docSession->{$docKey});
                 } else {
                     // set the latest available version for editmode if there is no doc in the session
                     $latestVersion = $this->getDocument()->getLatestVersion();
                     if ($latestVersion) {
                         $latestDoc = $latestVersion->loadData();
                         if ($latestDoc instanceof Document\PageSnippet) {
                             $this->setDocument($latestDoc);
                         }
                     }
                 }
                 // register editmode plugin
                 $front = \Zend_Controller_Front::getInstance();
                 $front->registerPlugin(new \Pimcore\Controller\Plugin\Frontend\Editmode($this), 1000);
             }
             // document preview
             if ($this->getParam("pimcore_preview")) {
                 // get document from session
                 $docKey = "document_" . $this->getParam("document")->getId();
                 $docSession = Session::getReadOnly("pimcore_documents");
                 if ($docSession->{$docKey}) {
                     $this->setDocument($docSession->{$docKey});
                 }
             }
             // object preview
             if ($this->getParam("pimcore_object_preview")) {
                 $key = "object_" . $this->getParam("pimcore_object_preview");
                 $session = Session::getReadOnly("pimcore_objects");
                 if ($session->{$key}) {
                     $object = $session->{$key};
                     // add the object to the registry so every call to Object::getById() will return this object instead of the real one
                     \Zend_Registry::set("object_" . $object->getId(), $object);
                 }
             }
             // for version preview
             if ($this->getParam("pimcore_version")) {
                 // only get version data at the first call || because of embedded Snippets ...
                 if (!\Zend_Registry::isRegistered("pimcore_version_active")) {
                     $version = Model\Version::getById($this->getParam("pimcore_version"));
                     $this->setDocument($version->getData());
                     \Zend_Registry::set("pimcore_version_active", true);
                 }
             }
         }
         // for public versions
         if ($this->getParam("v")) {
             try {
                 $version = Model\Version::getById($this->getParam("v"));
                 if ($version->getPublic()) {
                     $this->setDocument($version->getData());
                 }
             } catch (\Exception $e) {
             }
         }
         // check for persona
         if ($this->getDocument() instanceof Document\Page) {
             $this->getDocument()->setUsePersona(null);
             // reset because of preview and editmode (saved in session)
             if ($this->getParam("_ptp") && self::$isInitial) {
                 $this->getDocument()->setUsePersona($this->getParam("_ptp"));
             }
         }
         // check if document is a wrapped hardlink, if this is the case send a rel=canonical header to the source document
         if ($this->getDocument() instanceof Document\Hardlink\Wrapper\WrapperInterface) {
             // get the cononical (source) document
             $hardlinkCanonicalSourceDocument = Document::getById($this->getDocument()->getId());
             $request = $this->getRequest();
             if (\Pimcore\Tool\Frontend::isDocumentInCurrentSite($hardlinkCanonicalSourceDocument)) {
                 $this->getResponse()->setHeader("Link", '<' . $request->getScheme() . "://" . $request->getHttpHost() . $hardlinkCanonicalSourceDocument->getFullPath() . '>; rel="canonical"');
             }
         }
         \Pimcore::getEventManager()->trigger("frontend.controller.postInit", $this);
     }
     // set some parameters
     $this->editmode = \Zend_Registry::get("pimcore_editmode");
     $this->view->editmode = \Zend_Registry::get("pimcore_editmode");
     self::$isInitial = false;
 }
 /**
  * Flattens object data to an array with key=>value where
  * value is simply a string representation of the value (for objects, hrefs and assets the full path is used)
  *
  * @param Object\AbstractObject $object
  * @return array
  */
 protected function csvObjectData($object)
 {
     $o = array();
     foreach ($object->getClass()->getFieldDefinitions() as $key => $value) {
         //exclude remote owner fields
         if (!($value instanceof Object\ClassDefinition\Data\Relations\AbstractRelations and $value->isRemoteOwner())) {
             $o[$key] = $value->getForCsvExport($object);
         }
     }
     $o["id (system)"] = $object->getId();
     $o["key (system)"] = $object->getKey();
     $o["fullpath (system)"] = $object->getFullPath();
     $o["published (system)"] = $object->isPublished();
     $o["type (system)"] = $object->getType();
     return $o;
 }
Example #17
0
 public static function getCustomGridFieldDefinitions($classId, $objectId)
 {
     $object = AbstractObject::getById($objectId);
     $class = ClassDefinition::getById($classId);
     $masterFieldDefinition = $class->getFieldDefinitions();
     if (!$object) {
         return null;
     }
     $user = AdminTool::getCurrentUser();
     if ($user->isAdmin()) {
         return null;
     }
     $permissionList = array();
     $parentPermissionSet = $object->getPermissions(null, $user, true);
     if ($parentPermissionSet) {
         $permissionList[] = $parentPermissionSet;
     }
     $childPermissions = $object->getChildPermissions(null, $user);
     $permissionList = array_merge($permissionList, $childPermissions);
     $layoutDefinitions = array();
     foreach ($permissionList as $permissionSet) {
         $allowedLayoutIds = self::getLayoutPermissions($classId, $permissionSet);
         if (is_array($allowedLayoutIds)) {
             foreach ($allowedLayoutIds as $allowedLayoutId) {
                 if ($allowedLayoutId) {
                     if (!$layoutDefinitions[$allowedLayoutId]) {
                         $customLayout = ClassDefinition\CustomLayout::getById($allowedLayoutId);
                         if (!$customLayout) {
                             continue;
                         }
                         $layoutDefinitions[$allowedLayoutId] = $customLayout;
                     }
                 }
             }
         }
     }
     $mergedFieldDefinition = unserialize(serialize($masterFieldDefinition));
     if (count($layoutDefinitions)) {
         foreach ($mergedFieldDefinition as $key => $def) {
             if ($def instanceof ClassDefinition\Data\Localizedfields) {
                 $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions();
                 foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) {
                     $mergedLocalizedFieldDefinitions[$locKey]->setInvisible(false);
                     $mergedLocalizedFieldDefinitions[$locKey]->setNotEditable(false);
                 }
                 $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions);
             } else {
                 $mergedFieldDefinition[$key]->setInvisible(false);
                 $mergedFieldDefinition[$key]->setNotEditable(false);
             }
         }
     }
     foreach ($layoutDefinitions as $customLayoutDefinition) {
         $layoutName = $customLayoutDefinition->getName();
         $layoutDefinitions = $customLayoutDefinition->getLayoutDefinitions();
         $dummyClass = new ClassDefinition();
         $dummyClass->setLayoutDefinitions($layoutDefinitions);
         $customFieldDefinitions = $dummyClass->getFieldDefinitions();
         foreach ($mergedFieldDefinition as $key => $value) {
             if (!$customFieldDefinitions[$key]) {
                 unset($mergedFieldDefinition[$key]);
             }
         }
         foreach ($customFieldDefinitions as $key => $def) {
             if ($def instanceof ClassDefinition\Data\Localizedfields) {
                 if (!$mergedFieldDefinition[$key]) {
                     continue;
                 }
                 $customLocalizedFieldDefinitions = $def->getFieldDefinitions();
                 $mergedLocalizedFieldDefinitions = $mergedFieldDefinition[$key]->getFieldDefinitions();
                 foreach ($mergedLocalizedFieldDefinitions as $locKey => $locValue) {
                     self::mergeFieldDefinition($mergedLocalizedFieldDefinitions, $customLocalizedFieldDefinitions, $locKey);
                 }
                 $mergedFieldDefinition[$key]->setChilds($mergedLocalizedFieldDefinitions);
             } else {
                 self::mergeFieldDefinition($mergedFieldDefinition, $customFieldDefinitions, $key);
             }
         }
     }
     return $mergedFieldDefinition;
 }
 /**
  * @param Concrete $object
  * @return void
  */
 public function save($object)
 {
     // set the current object again, this is necessary because the related object in $this->object can change (eg. clone & copy & paste, etc.)
     $this->setObject($object);
     $getters = $this->getBrickGetters();
     foreach ($getters as $getter) {
         $brick = $this->{$getter}();
         if ($brick instanceof Objectbrick\Data\AbstractData) {
             if ($brick->getDoDelete()) {
                 $brick->delete($object);
                 $setter = "s" . substr($getter, 1);
                 $this->{$setter}(null);
                 //check if parent object has brick, and if so, create an empty brick to enable inheritance
                 $parentBrick = null;
                 $inheritanceModeBackup = AbstractObject::getGetInheritedValues();
                 AbstractObject::setGetInheritedValues(true);
                 if (AbstractObject::doGetInheritedValues($object)) {
                     $container = $object->getValueFromParent($this->fieldname);
                     if (!empty($container)) {
                         $parentBrick = $container->{$getter}();
                     }
                 }
                 AbstractObject::setGetInheritedValues($inheritanceModeBackup);
                 if (!empty($parentBrick)) {
                     $brickType = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($parentBrick->getType());
                     $brick = new $brickType($object);
                     $brick->setFieldname($this->getFieldname());
                     $brick->save($object);
                     $this->{$setter}($brick);
                 }
             } else {
                 $brick->setFieldname($this->getFieldname());
                 $brick->save($object);
             }
         } else {
             if ($brick == null) {
                 $parentBrick = null;
                 $inheritanceModeBackup = AbstractObject::getGetInheritedValues();
                 AbstractObject::setGetInheritedValues(true);
                 if (AbstractObject::doGetInheritedValues($object)) {
                     $container = $object->getValueFromParent($this->fieldname);
                     if (!empty($container)) {
                         $parentBrick = $container->{$getter}();
                     }
                 }
                 AbstractObject::setGetInheritedValues($inheritanceModeBackup);
                 if (!empty($parentBrick)) {
                     $brickType = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($parentBrick->getType());
                     $brick = new $brickType($object);
                     $brick->setFieldname($this->getFieldname());
                     $brick->save($object);
                 }
             }
         }
     }
 }
Example #19
0
 /**
  * @param $name
  * @param null $language
  * @return 
  */
 public function getLocalizedValue($name, $language = null, $ignoreFallbackLanguage = false)
 {
     $data = null;
     $language = $this->getLanguage($language);
     $fieldDefinition = $this->getObject()->getClass()->getFieldDefinition("localizedfields")->getFieldDefinition($name);
     if ($fieldDefinition instanceof Model\Object\ClassDefinition\Data\CalculatedValue) {
         $valueData = new Model\Object\Data\CalculatedValue($fieldDefinition->getName());
         $valueData->setContextualData("localizedfield", "localizedfields", null, $language);
         $data = Service::getCalculatedFieldValue($this->getObject(), $valueData);
         return $data;
     }
     if ($this->languageExists($language)) {
         if (array_key_exists($name, $this->items[$language])) {
             $data = $this->items[$language][$name];
         }
     }
     // 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)) {
                             $localizedFields = $parent->getLocalizedFields();
                             if ($localizedFields instanceof Localizedfield) {
                                 if ($localizedFields->object->getId() != $this->object->getId()) {
                                     $data = $localizedFields->getLocalizedValue($name, $language, true);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // check for fallback value
     if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) {
         foreach (Tool::getFallbackLanguagesFor($language) as $l) {
             if ($this->languageExists($l)) {
                 if (array_key_exists($name, $this->items[$l])) {
                     $data = $this->getLocalizedValue($name, $l);
                 }
             }
         }
     }
     if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) {
         $data = $fieldDefinition->preGetData($this, array("data" => $data, "language" => $language, "name" => $name));
     }
     return $data;
 }
Example #20
0
 private function getSubObjectIds(\Pimcore\Model\Object\AbstractObject $object)
 {
     $childsList = new Pimcore\Model\Object\Listing();
     $condition = "o_path LIKE ?";
     if (!$this->getUser()->isAdmin()) {
         $userIds = $this->getUser()->getRoles();
         $userIds[] = $this->getUser()->getId();
         $condition .= " AND (\n                (SELECT `view` FROM users_workspaces_object WHERE userId IN (" . implode(',', $userIds) . ") and LOCATE(CONCAT(o_path,o_key),cpath)=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n                    OR\n                (SELECT `view` FROM users_workspaces_object WHERE userId IN (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(o_path,o_key))=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n             )";
     }
     $childsList->setCondition($condition, $object->getRealFullPath() . '/%');
     return $childsList->loadIdList();
 }
Example #21
0
 /**
  * @param $element
  * @return $this
  */
 public function setDataFromElement($element)
 {
     $this->data = null;
     $this->id = new Data\Id($element);
     $this->fullPath = $element->getFullPath();
     $this->creationDate = $element->getCreationDate();
     $this->modificationDate = $element->getModificationDate();
     $this->userModification = $element->getUserModification();
     $this->userOwner = $element->getUserOwner();
     $this->type = $element->getType();
     if ($element instanceof Object\Concrete) {
         $this->subtype = $element->getClassName();
     } else {
         $this->subtype = $this->type;
     }
     $this->properties = "";
     $properties = $element->getProperties();
     if (is_array($properties)) {
         foreach ($properties as $nextProperty) {
             $pData = (string) $nextProperty->getData();
             if ($nextProperty->getName() == "bool") {
                 $pData = $pData ? "true" : "false";
             }
             $this->properties .= $nextProperty->getName() . ":" . $pData . " ";
         }
     }
     $this->data = "";
     if ($element instanceof Document) {
         if ($element instanceof Document\Folder) {
             $this->data = $element->getKey();
             $this->published = true;
         } else {
             if ($element instanceof Document\Link) {
                 $this->published = $element->isPublished();
                 $this->data = $element->getTitle() . " " . $element->getHref();
             } else {
                 if ($element instanceof Document\PageSnippet) {
                     $this->published = $element->isPublished();
                     $elements = $element->getElements();
                     if (is_array($elements) && !empty($elements)) {
                         foreach ($elements as $tag) {
                             if ($tag instanceof Document\Tag\TagInterface) {
                                 ob_start();
                                 $this->data .= strip_tags($tag->frontend()) . " ";
                                 $this->data .= ob_get_clean();
                             }
                         }
                     }
                     if ($element instanceof Document\Page) {
                         $this->published = $element->isPublished();
                         $this->data .= " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getKeywords() . " " . $element->getPrettyUrl();
                     }
                 }
             }
         }
     } else {
         if ($element instanceof Asset) {
             $this->data = $element->getFilename();
             foreach ($element->getMetadata() as $md) {
                 $this->data .= " " . $md["name"] . ":" . $md["data"];
             }
             if ($element instanceof Asset\Document && \Pimcore\Document::isAvailable()) {
                 if (\Pimcore\Document::isFileTypeSupported($element->getFilename())) {
                     $contentText = $element->getText();
                     $contentText = str_replace(["\r\n", "\r", "\n", "\t", "\f"], " ", $contentText);
                     $contentText = preg_replace("/[ ]+/", " ", $contentText);
                     $this->data .= " " . $contentText;
                 }
             }
             $this->published = true;
         } else {
             if ($element instanceof Object\AbstractObject) {
                 if ($element instanceof Object\Concrete) {
                     $getInheritedValues = Object\AbstractObject::doGetInheritedValues();
                     Object\AbstractObject::setGetInheritedValues(true);
                     $this->published = $element->isPublished();
                     foreach ($element->getClass()->getFieldDefinitions() as $key => $value) {
                         $this->data .= $value->getDataForSearchIndex($element) . " ";
                     }
                     Object\AbstractObject::setGetInheritedValues($getInheritedValues);
                 } else {
                     if ($element instanceof Object\Folder) {
                         $this->data = $element->getKey();
                         $this->published = true;
                     }
                 }
             } else {
                 \Logger::crit("Search\\Backend\\Data received an unknown element!");
             }
         }
     }
     if ($element instanceof Element\ElementInterface) {
         $this->data = "ID: " . $element->getId() . "  \nPath: " . $this->getFullPath() . "  \n" . $this->cleanupData($this->data);
     }
     return $this;
 }
Example #22
0
 /**
  * Save changes to database, it's an good idea to use save() instead
  *
  * @return void
  */
 public function update()
 {
     parent::update();
     // get fields which shouldn't be updated
     $fd = $this->model->getClass()->getFieldDefinitions();
     $untouchable = array();
     foreach ($fd as $key => $value) {
         if (method_exists($value, "getLazyLoading") && $value->getLazyLoading()) {
             if (!in_array($key, $this->model->getLazyLoadedFields())) {
                 //this is a relation subject to lazy loading - it has not been loaded
                 $untouchable[] = $key;
             }
         }
     }
     // empty relation table except the untouchable fields (eg. lazy loading fields)
     if (count($untouchable) > 0) {
         $untouchables = "'" . implode("','", $untouchable) . "'";
         $this->db->delete("object_relations_" . $this->model->getClassId(), $this->db->quoteInto("src_id = ? AND fieldname not in (" . $untouchables . ") AND ownertype = 'object'", $this->model->getId()));
     } else {
         $this->db->delete("object_relations_" . $this->model->getClassId(), $this->db->quoteInto("src_id = ? AND ownertype = 'object'", $this->model->getId()));
     }
     $inheritedValues = Object\AbstractObject::doGetInheritedValues();
     Object\AbstractObject::setGetInheritedValues(false);
     $data = array();
     $data["oo_id"] = $this->model->getId();
     foreach ($fd as $key => $value) {
         $getter = "get" . ucfirst($key);
         if (method_exists($value, "save")) {
             // for fieldtypes which have their own save algorithm eg. fieldcollections, objects, multihref, ...
             $value->save($this->model);
         } else {
             if ($value->getColumnType()) {
                 // pimcore saves the values with getDataForResource
                 if (is_array($value->getColumnType())) {
                     $insertDataArray = $value->getDataForResource($this->model->{$getter}(), $this->model);
                     if (is_array($insertDataArray)) {
                         $data = array_merge($data, $insertDataArray);
                     }
                 } else {
                     $insertData = $value->getDataForResource($this->model->{$getter}(), $this->model);
                     $data[$key] = $insertData;
                 }
             }
         }
     }
     $this->db->insertOrUpdate("object_store_" . $this->model->getClassId(), $data);
     // get data for query table
     // this is special because we have to call each getter to get the inherited values from a possible parent object
     Object\AbstractObject::setGetInheritedValues(true);
     $object = get_object_vars($this->model);
     $data = array();
     $this->inheritanceHelper->resetFieldsToCheck();
     $oldData = $this->db->fetchRow("SELECT * FROM object_query_" . $this->model->getClassId() . " WHERE oo_id = ?", $this->model->getId());
     foreach ($object as $key => $value) {
         $fd = $this->model->getClass()->getFieldDefinition($key);
         if ($fd) {
             if ($fd->getQueryColumnType()) {
                 //exclude untouchables if value is not an array - this means data has not been loaded
                 if (!(in_array($key, $untouchable) and !is_array($this->model->{$key}))) {
                     $method = "get" . $key;
                     $insertData = $fd->getDataForQueryResource($this->model->{$method}(), $this->model);
                     if (is_array($insertData)) {
                         $data = array_merge($data, $insertData);
                     } else {
                         $data[$key] = $insertData;
                     }
                     //get changed fields for inheritance
                     if ($fd->isRelationType()) {
                         if (is_array($insertData)) {
                             $doInsert = false;
                             foreach ($insertData as $insertDataKey => $insertDataValue) {
                                 if ($oldData[$insertDataKey] != $insertDataValue) {
                                     $doInsert = true;
                                 }
                             }
                             if ($doInsert) {
                                 $this->inheritanceHelper->addRelationToCheck($key, $fd, array_keys($insertData));
                             }
                         } else {
                             if ($oldData[$key] != $insertData) {
                                 $this->inheritanceHelper->addRelationToCheck($key, $fd);
                             }
                         }
                     } else {
                         if (is_array($insertData)) {
                             foreach ($insertData as $insertDataKey => $insertDataValue) {
                                 if ($oldData[$insertDataKey] != $insertDataValue) {
                                     $this->inheritanceHelper->addFieldToCheck($insertDataKey, $fd);
                                 }
                             }
                         } else {
                             if ($oldData[$key] != $insertData) {
                                 $this->inheritanceHelper->addFieldToCheck($key, $fd);
                             }
                         }
                     }
                 } else {
                     \Logger::debug("Excluding untouchable query value for object [ " . $this->model->getId() . " ]  key [ {$key} ] because it has not been loaded");
                 }
             }
         }
     }
     $data["oo_id"] = $this->model->getId();
     $this->db->insertOrUpdate("object_query_" . $this->model->getClassId(), $data);
     Object\AbstractObject::setGetInheritedValues($inheritedValues);
 }
Example #23
0
 public function preGetData($object, $params = array())
 {
     $data = null;
     if ($object instanceof Object\Concrete) {
         $data = $object->{$this->getName()};
         if ($this->getLazyLoading() and !in_array($this->getName(), $object->getO__loadedLazyFields())) {
             //$data = $this->getDataFromResource($object->getRelationData($this->getName(),true,null));
             $data = $this->load($object, array("force" => true));
             $setter = "set" . ucfirst($this->getName());
             if (method_exists($object, $setter)) {
                 $object->{$setter}($data);
             }
         }
     } else {
         if ($object instanceof Object\Localizedfield) {
             $data = $params["data"];
         } else {
             if ($object instanceof Object\Fieldcollection\Data\AbstractData) {
                 $data = $object->{$this->getName()};
             } else {
                 if ($object instanceof Object\Objectbrick\Data\AbstractData) {
                     $data = $object->{$this->getName()};
                 }
             }
         }
     }
     if (Object\AbstractObject::doHideUnpublished() and is_array($data)) {
         $publishedList = array();
         foreach ($data as $listElement) {
             if (Element\Service::isPublished($listElement)) {
                 $publishedList[] = $listElement;
             }
         }
         return $publishedList;
     }
     return is_array($data) ? $data : array();
 }
Example #24
0
 /**
  * @param self $o_parent
  * @return $this
  */
 public function setParent($o_parent)
 {
     $this->o_parent = $o_parent;
     if ($o_parent instanceof self) {
         $this->o_parentId = $o_parent->getId();
     }
     return $this;
 }
 public function filterLocalizedFields(Object\AbstractObject $object, $objectData)
 {
     if (!$object instanceof Object\Concrete) {
         return $objectData;
     }
     $user = Tool\Admin::getCurrentUser();
     if ($user->getAdmin()) {
         return $objectData;
     }
     $fieldDefinitions = $object->getClass()->getFieldDefinitions();
     if ($fieldDefinitions) {
         $languageAllowedView = Object\Service::getLanguagePermissions($object, $user, "lView");
         $languageAllowedEdit = Object\Service::getLanguagePermissions($object, $user, "lEdit");
         foreach ($fieldDefinitions as $key => $fd) {
             if ($fd->getFieldtype() == "localizedfields") {
                 foreach ($objectData["data"][$key]["data"] as $language => $languageData) {
                     if (!is_null($languageAllowedView) && !$languageAllowedView[$language]) {
                         unset($objectData["data"][$key]["data"][$language]);
                     }
                 }
             }
         }
         $this->setLayoutPermission($objectData["layout"], $languageAllowedView, $languageAllowedEdit);
     }
     return $objectData;
 }
Example #26
0
 /**
  *
  */
 public function __wakeup()
 {
     if (isset($this->_fulldump) && !self::$doNotRestoreKeyAndPath) {
         // set current key and path this is necessary because the serialized data can have a different path than the original element ( element was renamed or moved )
         $originalElement = AbstractObject::getById($this->getId());
         if ($originalElement) {
             $this->setKey($originalElement->getKey());
             $this->setPath($originalElement->getPath());
         }
     }
     if (isset($this->_fulldump) && $this->o_properties !== null) {
         $this->renewInheritedProperties();
     }
     if (isset($this->_fulldump)) {
         unset($this->_fulldump);
     }
 }
Example #27
0
 /**
  * @param $wsDocument
  * @throws \Exception
  */
 protected function updateObject($wsDocument)
 {
     $object = Object\AbstractObject::getById($wsDocument->id);
     if ($object === NULL) {
         throw new \Exception("Object with given ID (" . $wsDocument->id . ") does not exist.");
     }
     $this->setModificationParams($object, false);
     if ($object instanceof Object\Concrete and $object->getClassName() == $wsDocument->className) {
         $wsDocument->reverseMap($object);
         $object->save();
         return true;
     } else {
         if ($object instanceof Object\Folder and $object->getType() == strtolower($wsDocument->type)) {
             $wsDocument->reverseMap($object);
             $object->save();
             return true;
         } else {
             throw new \Exception("Type/Class mismatch for given object with ID [" . $wsDocument->id . "] and existing object with id [" . $object->getId() . "]");
         }
     }
 }
Example #28
0
File: Dao.php Project: sfie/pimcore
 /**
  * @param \Zend_DB_Select $select
  *
  * @return $this
  */
 protected function addConditions(\Zend_DB_Select $select)
 {
     $condition = $this->model->getCondition();
     $objectTypes = $this->model->getObjectTypes();
     if (!empty($objectTypes)) {
         if (!empty($condition)) {
             $condition .= " AND ";
         }
         $condition .= " o_type IN ('" . implode("','", $objectTypes) . "')";
     }
     if ($condition) {
         if (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) {
             $condition = "(" . $condition . ") AND o_published = 1";
         }
     } else {
         if (Object\AbstractObject::doHideUnpublished() && !$this->model->getUnpublished()) {
             $condition = "o_published = 1";
         }
     }
     if ($condition) {
         $select->where($condition);
     }
     return $this;
 }
Example #29
0
 /**
  * Check if Object $object in array $objectList
  *
  * @param AbstractObject $object
  * @param array $objectList
  * @return bool
  */
 public static function objectInList(AbstractObject $object, array $objectList)
 {
     foreach ($objectList as $o) {
         if ($o->getId() == $object->getId()) {
             return true;
         }
     }
     return false;
 }
Example #30
0
 /**
  * @throws \Zend_Exception
  */
 public function init()
 {
     parent::init();
     // set language
     if (\Zend_Registry::isRegistered("Zend_Locale")) {
         $locale = (string) \Zend_Registry::get("Zend_Locale");
         $this->setLanguage($locale);
     } else {
         if ($this->getParam("language")) {
             $this->setLanguage($this->getParam("language"));
         } else {
             $config = Config::getSystemConfig();
             $this->setLanguage($config->general->language);
             // try to set browser-language (validation if installed is in $this->setLanguage() )
             $this->setLanguage(new \Zend_Locale());
         }
     }
     if (self::$adminInitialized) {
         // this will be executed on every call to this init() method
         try {
             $this->setUser(\Zend_Registry::get("pimcore_admin_user"));
         } catch (\Exception $e) {
             \Logger::emerg("adminInitialized was set to true although there was no user set in the registry -> to be save the process was killed");
             exit;
         }
     } else {
         // the following code is only called once, even when there are some subcalls (eg. with $this->action, ... )
         \Pimcore::getEventManager()->trigger("admin.controller.preInit", $this);
         $this->disableBrowserCache();
         // general definitions
         Model\Document::setHideUnpublished(false);
         Model\Object\AbstractObject::setHideUnpublished(false);
         Model\Object\AbstractObject::setGetInheritedValues(false);
         Model\Object\Localizedfield::setGetFallbackValues(false);
         \Pimcore::setAdminMode();
         // init translations
         self::initTranslations($this);
         // init zend action helpers, we need to leave the prefixed class name here as the plugin loader isn't able to handle namespaces
         \Zend_Controller_Action_HelperBroker::addPrefix('Pimcore_Controller_Action_Helper');
         // this is to make it possible to use the session id as a part of the route (ZF default route) used for external editors, etc.
         if ($this->getParam("pimcore_admin_sid")) {
             $_REQUEST["pimcore_admin_sid"] = $this->getParam("pimcore_admin_sid");
         }
         // authenticate user, first try to authenticate with session information
         $user = Authentication::authenticateSession();
         if ($user instanceof Model\User) {
             $this->setUser($user);
             if ($this->getUser()->getLanguage()) {
                 $this->setLanguage($this->getUser()->getLanguage());
             }
         } else {
             // try to authenticate with http basic auth, but this is only allowed for WebDAV
             if ($this->getParam("module") == "admin" && $this->getParam("controller") == "asset" && $this->getParam("action") == "webdav") {
                 $user = Authentication::authenticateHttpBasic();
                 if ($user instanceof Model\User) {
                     $this->setUser($user);
                     \Zend_Registry::set("pimcore_admin_user", $this->getUser());
                     self::$adminInitialized = true;
                     return;
                 }
             }
         }
         // redirect to the login-page if the user isn't authenticated
         if (!$this->getUser() instanceof Model\User && !($this->getParam("module") == "admin" && $this->getParam("controller") == "login")) {
             // put a detailed message into the debug.log
             \Logger::error("Prevented access to " . $_SERVER["REQUEST_URI"] . " because there is no user in the session!", ["server" => $_SERVER, "get" => $_GET, "post" => $_POST, "session" => $_SESSION, "cookie" => $_COOKIE]);
             // send a auth header for the client (is covered by the ajax object in javascript)
             $this->getResponse()->setHeader("X-Pimcore-Auth", "required");
             // redirect to login page
             $this->redirect("/admin/login");
             // exit the execution -> just to be sure
             exit;
         }
         // we're now authenticated so we can remove the default error handler so that we get just the normal PHP errors
         if ($this->getParam("controller") != "login") {
             $front = \Zend_Controller_Front::getInstance();
             $front->unregisterPlugin("Pimcore\\Controller\\Plugin\\ErrorHandler");
             $front->throwExceptions(true);
             @ini_set("display_errors", "On");
             @ini_set("display_startup_errors", "On");
         }
         \Zend_Registry::set("pimcore_admin_user", $this->getUser());
         self::$adminInitialized = true;
         // usage statistics
         $this->logUsageStatistics();
         \Pimcore::getEventManager()->trigger("admin.controller.postInit", $this);
     }
 }