作者:solvera
项目:pimcor
/**
*
* 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;
}
作者:ascertai
项目:NGsho
/**
* 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);
}
作者:ascertai
项目:NGsho
/**
* @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;
}
作者:ascertai
项目:NGsho
/**
* @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;
}
作者:yonetic
项目:pimcore-coreshop-dem
/**
* @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;
}
作者:ascertai
项目:NGsho
/**
* 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;
}
作者:ascertai
项目:NGsho
/**
* @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.");
}
}
作者:ChristophWurs
项目:pimcor
/**
* @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);
}
作者:basilico
项目:pimcore-plugin-participatio
/**
* @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;
}
作者:ascertai
项目:NGsho
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()));
}
作者:pimcor
项目:pimcor
/**
*
*/
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;
//.........这里部分代码省略.........
作者:sfi
项目:pimcor
/**
* @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;
}
作者:pimcor
项目:pimcor
/**
* @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;
//.........这里部分代码省略.........
作者:todod
项目:pimcor
/**
* @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
//.........这里部分代码省略.........
作者:cannoner
项目:pimcor
/**
* 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;
}
作者:elavarasan
项目:pimcor
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;
}
作者:yonetic
项目:pimcore-coreshop-dem
/**
* @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);
}
}
}
}
}
作者:ChristophWurs
项目:pimcor
/**
* @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;
}
作者:solvera
项目:pimcor
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();
}
作者:sfi
项目:pimcor
/**
* @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;
}