本文整理汇总了PHP中Pimcore\Model\Object\Service::gridObjectData方法的典型用法代码示例。如果您正苦于以下问题:PHP Service::gridObjectData方法的具体用法?PHP Service::gridObjectData怎么用?PHP Service::gridObjectData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Model\Object\Service
的用法示例。
在下文中一共展示了Service::gridObjectData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadObjectDataAction
public function loadObjectDataAction()
{
$object = Object::getById($this->getParam("id"));
$result = array();
if ($object) {
$result['success'] = true;
$fields = $this->getParam("fields");
$result['fields'] = Object\Service::gridObjectData($object, $fields);
} else {
$result['success'] = false;
}
$this->_helper->json($result);
}
示例2: gridProxyAction
public function gridProxyAction()
{
if ($this->getParam("language")) {
$this->setLanguage($this->getParam("language"), true);
}
if ($this->getParam("data")) {
if ($this->getParam("xaction") == "update") {
try {
$data = \Zend_Json::decode($this->getParam("data"));
// save
$object = Object::getById($data["id"]);
/** @var Object\ClassDefinition $class */
$class = $object->getClass();
if (!$object->isAllowed("publish")) {
throw new \Exception("Permission denied. You don't have the rights to save this object.");
}
$user = Tool\Admin::getCurrentUser();
if (!$user->isAdmin()) {
$languagePermissions = $object->getPermissions("lEdit", $user);
$languagePermissions = explode(",", $languagePermissions["lEdit"]);
}
$objectData = array();
foreach ($data as $key => $value) {
$parts = explode("~", $key);
if (substr($key, 0, 1) == "~") {
$type = $parts[1];
$field = $parts[2];
$keyid = $parts[3];
$getter = "get" . ucfirst($field);
$setter = "set" . ucfirst($field);
$keyValuePairs = $object->{$getter}();
if (!$keyValuePairs) {
$keyValuePairs = new Object\Data\KeyValue();
$keyValuePairs->setObjectId($object->getId());
$keyValuePairs->setClass($object->getClass());
}
$keyValuePairs->setPropertyWithId($keyid, $value, true);
$object->{$setter}($keyValuePairs);
} elseif (count($parts) > 1) {
$brickType = $parts[0];
$brickKey = $parts[1];
$brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
$fieldGetter = "get" . ucfirst($brickField);
$brickGetter = "get" . ucfirst($brickType);
$valueSetter = "set" . ucfirst($brickKey);
$brick = $object->{$fieldGetter}()->{$brickGetter}();
if (empty($brick)) {
$classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
$brickSetter = "set" . ucfirst($brickType);
$brick = new $classname($object);
$object->{$fieldGetter}()->{$brickSetter}($brick);
}
$brick->{$valueSetter}($value);
} else {
if (!$user->isAdmin() && $languagePermissions) {
$fd = $class->getFieldDefinition($key);
if (!$fd) {
// try to get via localized fields
$localized = $class->getFieldDefinition("localizedfields");
if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) {
$field = $localized->getFieldDefinition($key);
if ($field) {
$currentLocale = (string) \Zend_Registry::get("Zend_Locale");
if (!in_array($currentLocale, $languagePermissions)) {
continue;
}
}
}
}
}
$objectData[$key] = $value;
}
}
$object->setValues($objectData);
$object->save();
$this->_helper->json(array("data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true));
} catch (\Exception $e) {
$this->_helper->json(array("success" => false, "message" => $e->getMessage()));
}
}
} else {
// get list of objects
$folder = Object::getById($this->getParam("folderId"));
$class = Object\ClassDefinition::getById($this->getParam("classId"));
$className = $class->getName();
$colMappings = array("filename" => "o_key", "fullpath" => array("o_path", "o_key"), "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate");
$start = 0;
$limit = 20;
$orderKey = "o_id";
$order = "ASC";
$fields = array();
$bricks = array();
if ($this->getParam("fields")) {
$fields = $this->getParam("fields");
foreach ($fields as $f) {
$parts = explode("~", $f);
$sub = substr($f, 0, 1);
if (substr($f, 0, 1) == "~") {
// $type = $parts[1];
// $field = $parts[2];
//.........这里部分代码省略.........
示例3: getDataForEditmode
/**
* @see Object\ClassDefinition\Data::getDataForEditmode
* @param array $data
* @param null|Model\Object\AbstractObject $object
* @return array
*/
public function getDataForEditmode($data, $object = null)
{
$return = array();
$visibleFieldsArray = explode(",", $this->getVisibleFields());
$gridFields = (array) $visibleFieldsArray;
// add data
if (is_array($data) && count($data) > 0) {
foreach ($data as $metaObject) {
$object = $metaObject->getObject();
if ($object instanceof Object\Concrete) {
$columnData = Object\Service::gridObjectData($object, $gridFields);
foreach ($this->getColumns() as $c) {
$getter = "get" . ucfirst($c['key']);
$columnData[$c['key']] = $metaObject->{$getter}();
}
$return[] = $columnData;
}
}
}
return $return;
}
示例4: findAction
//.........这里部分代码省略.........
// $type = $parts[1];
// $field = $parts[2];
// $keyid = $parts[3];
// key value, ignore for now
} else {
if (count($parts) > 1) {
$bricks[$parts[0]] = $parts[0];
}
}
}
}
// filtering for objects
if ($this->getParam("filter") && $this->getParam("class")) {
$class = Object\ClassDefinition::getByName($this->getParam("class"));
$conditionFilters = Object\Service::getFilterCondition($this->getParam("filter"), $class);
$join = "";
foreach ($bricks as $ob) {
$join .= " LEFT JOIN object_brick_query_" . $ob . "_" . $class->getId();
$join .= " `" . $ob . "`";
$join .= " ON `" . $ob . "`.o_id = `object_" . $class->getId() . "`.o_id";
}
$conditionParts[] = "( id IN (SELECT `object_" . $class->getId() . "`.o_id FROM object_" . $class->getId() . $join . " WHERE " . $conditionFilters . ") )";
}
if (is_array($types) and !empty($types[0])) {
foreach ($types as $type) {
$conditionTypeParts[] = $db->quote($type);
}
if (in_array("folder", $subtypes)) {
$conditionTypeParts[] = $db->quote('folder');
}
$conditionParts[] = "( maintype IN (" . implode(",", $conditionTypeParts) . ") )";
}
if (is_array($subtypes) and !empty($subtypes[0])) {
foreach ($subtypes as $subtype) {
$conditionSubtypeParts[] = $db->quote($subtype);
}
$conditionParts[] = "( type IN (" . implode(",", $conditionSubtypeParts) . ") )";
}
if (is_array($classnames) and !empty($classnames[0])) {
if (in_array("folder", $subtypes)) {
$classnames[] = "folder";
}
foreach ($classnames as $classname) {
$conditionClassnameParts[] = $db->quote($classname);
}
$conditionParts[] = "( subtype IN (" . implode(",", $conditionClassnameParts) . ") )";
}
if (count($conditionParts) > 0) {
$condition = implode(" AND ", $conditionParts);
//echo $condition; die();
$searcherList->setCondition($condition);
}
$searcherList->setOffset($offset);
$searcherList->setLimit($limit);
// do not sort per default, it is VERY SLOW
//$searcherList->setOrder("desc");
//$searcherList->setOrderKey("modificationdate");
if ($this->getParam("sort")) {
// we need a special mapping for classname as this is stored in subtype column
$sortMapping = ["classname" => "subtype"];
$sort = $this->getParam("sort");
if (array_key_exists($this->getParam("sort"), $sortMapping)) {
$sort = $sortMapping[$this->getParam("sort")];
}
$searcherList->setOrderKey($sort);
}
if ($this->getParam("dir")) {
$searcherList->setOrder($this->getParam("dir"));
}
$hits = $searcherList->load();
$elements = array();
foreach ($hits as $hit) {
$element = Element\Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());
if ($element->isAllowed("list")) {
if ($element instanceof Object\AbstractObject) {
$data = Object\Service::gridObjectData($element, $fields);
} else {
if ($element instanceof Document) {
$data = Document\Service::gridDocumentData($element);
} else {
if ($element instanceof Asset) {
$data = Asset\Service::gridAssetData($element);
}
}
}
$elements[] = $data;
} else {
//TODO: any message that view is blocked?
//$data = Element\Service::gridElementData($element);
}
}
// only get the real total-count when the limit parameter is given otherwise use the default limit
if ($this->getParam("limit")) {
$totalMatches = $searcherList->getTotalCount();
} else {
$totalMatches = count($elements);
}
$this->_helper->json(array("data" => $elements, "success" => true, "total" => $totalMatches));
$this->removeViewRenderer();
}
示例5: getVariantsAction
public function getVariantsAction()
{
// get list of variants
if ($this->getParam("language")) {
$this->setLanguage($this->getParam("language"), true);
}
if ($this->getParam("xaction") == "update") {
$data = \Zend_Json::decode($this->getParam("data"));
// save
$object = Object::getById($data["id"]);
if ($object->isAllowed("publish")) {
$objectData = [];
foreach ($data as $key => $value) {
$parts = explode("~", $key);
if (substr($key, 0, 1) == "~") {
$type = $parts[1];
$field = $parts[2];
$keyid = $parts[3];
$getter = "get" . ucfirst($field);
$setter = "set" . ucfirst($field);
$keyValuePairs = $object->{$getter}();
if (!$keyValuePairs) {
$keyValuePairs = new Object\Data\KeyValue();
$keyValuePairs->setObjectId($object->getId());
$keyValuePairs->setClass($object->getClass());
}
$keyValuePairs->setPropertyWithId($keyid, $value, true);
$object->{$setter}($keyValuePairs);
} elseif (count($parts) > 1) {
$brickType = $parts[0];
$brickKey = $parts[1];
$brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
$fieldGetter = "get" . ucfirst($brickField);
$brickGetter = "get" . ucfirst($brickType);
$valueSetter = "set" . ucfirst($brickKey);
$brick = $object->{$fieldGetter}()->{$brickGetter}();
if (empty($brick)) {
$classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
$brickSetter = "set" . ucfirst($brickType);
$brick = new $classname($object);
$object->{$fieldGetter}()->{$brickSetter}($brick);
}
$brick->{$valueSetter}($value);
} else {
$objectData[$key] = $value;
}
}
$object->setValues($objectData);
try {
$object->save();
$this->_helper->json(["data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true]);
} catch (\Exception $e) {
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
} else {
throw new \Exception("Permission denied");
}
} else {
$parentObject = Object\Concrete::getById($this->getParam("objectId"));
if (empty($parentObject)) {
throw new \Exception("No Object found with id " . $this->getParam("objectId"));
}
if ($parentObject->isAllowed("view")) {
$class = $parentObject->getClass();
$className = $parentObject->getClass()->getName();
$start = 0;
$limit = 15;
$orderKey = "o_id";
$order = "ASC";
$fields = [];
$bricks = [];
if ($this->getParam("fields")) {
$fields = $this->getParam("fields");
foreach ($fields as $f) {
$parts = explode("~", $f);
if (count($parts) > 1) {
$bricks[$parts[0]] = $parts[0];
}
}
}
if ($this->getParam("limit")) {
$limit = $this->getParam("limit");
}
if ($this->getParam("start")) {
$start = $this->getParam("start");
}
$orderKey = "o_id";
$order = "ASC";
$colMappings = ["filename" => "o_key", "fullpath" => ["o_path", "o_key"], "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate"];
$sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
if ($sortingSettings['orderKey'] && $sortingSettings['order']) {
$orderKey = $sortingSettings['orderKey'];
if (array_key_exists($orderKey, $colMappings)) {
$orderKey = $colMappings[$orderKey];
}
$order = $sortingSettings['order'];
}
if ($this->getParam("dir")) {
$order = $this->getParam("dir");
}
//.........这里部分代码省略.........
示例6: gridProxyAction
public function gridProxyAction()
{
$requestedLanguage = $this->getParam("language");
if ($requestedLanguage) {
if ($requestedLanguage != "default") {
$this->setLanguage($requestedLanguage, true);
}
} else {
$requestedLanguage = $this->getLanguage();
}
if ($this->getParam("data")) {
if ($this->getParam("xaction") == "update") {
try {
$data = \Zend_Json::decode($this->getParam("data"));
// save
$object = Object::getById($data["id"]);
/** @var Object\ClassDefinition $class */
$class = $object->getClass();
if (!$object->isAllowed("publish")) {
throw new \Exception("Permission denied. You don't have the rights to save this object.");
}
$user = Tool\Admin::getCurrentUser();
$allLanguagesAllowed = false;
if (!$user->isAdmin()) {
$languagePermissions = $object->getPermissions("lEdit", $user);
//sets allowed all languages modification when the lEdit column is empty
$allLanguagesAllowed = $languagePermissions["lEdit"] == '';
$languagePermissions = explode(",", $languagePermissions["lEdit"]);
}
$objectData = [];
foreach ($data as $key => $value) {
$parts = explode("~", $key);
if (substr($key, 0, 1) == "~") {
$type = $parts[1];
$field = $parts[2];
$keyid = $parts[3];
if ($type == "classificationstore") {
$groupKeyId = explode("-", $keyid);
$groupId = $groupKeyId[0];
$keyid = $groupKeyId[1];
$getter = "get" . ucfirst($field);
if (method_exists($object, $getter)) {
/** @var $classificationStoreData Object\Classificationstore */
$classificationStoreData = $object->{$getter}();
$classificationStoreData->setLocalizedKeyValue($groupId, $keyid, $value, $requestedLanguage);
}
} else {
$getter = "get" . ucfirst($field);
$setter = "set" . ucfirst($field);
$keyValuePairs = $object->{$getter}();
if (!$keyValuePairs) {
$keyValuePairs = new Object\Data\KeyValue();
$keyValuePairs->setObjectId($object->getId());
$keyValuePairs->setClass($object->getClass());
}
$keyValuePairs->setPropertyWithId($keyid, $value, true);
$object->{$setter}($keyValuePairs);
}
} elseif (count($parts) > 1) {
$brickType = $parts[0];
$brickKey = $parts[1];
$brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
$fieldGetter = "get" . ucfirst($brickField);
$brickGetter = "get" . ucfirst($brickType);
$valueSetter = "set" . ucfirst($brickKey);
$brick = $object->{$fieldGetter}()->{$brickGetter}();
if (empty($brick)) {
$classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
$brickSetter = "set" . ucfirst($brickType);
$brick = new $classname($object);
$object->{$fieldGetter}()->{$brickSetter}($brick);
}
$brick->{$valueSetter}($value);
} else {
if (!$user->isAdmin() && $languagePermissions) {
$fd = $class->getFieldDefinition($key);
if (!$fd) {
// try to get via localized fields
$localized = $class->getFieldDefinition("localizedfields");
if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) {
$field = $localized->getFieldDefinition($key);
if ($field) {
$currentLocale = (string) \Zend_Registry::get("Zend_Locale");
if (!$allLanguagesAllowed && !in_array($currentLocale, $languagePermissions)) {
continue;
}
}
}
}
}
$objectData[$key] = $value;
}
}
$object->setValues($objectData);
$object->save();
$this->_helper->json(["data" => Object\Service::gridObjectData($object, $this->getParam("fields"), $requestedLanguage), "success" => true]);
} catch (\Exception $e) {
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
}
//.........这里部分代码省略.........
示例7: findAction
//.........这里部分代码省略.........
if (null !== $conditionFilters) {
//add condition query for non localised fields
$conditionParts[] = "( id IN (SELECT `object_" . $class->getId() . "`.o_id FROM object_" . $class->getId() . $join . " WHERE " . $conditionFilters . ") )";
}
if (null !== $localizedConditionFilters) {
//add condition query for localised fields
$conditionParts[] = "( id IN (SELECT `object_localized_data_" . $class->getId() . "`.ooo_id FROM object_localized_data_" . $class->getId() . $join . " WHERE " . $localizedConditionFilters . " GROUP BY ooo_id " . ") )";
}
}
if (is_array($types) and !empty($types[0])) {
foreach ($types as $type) {
$conditionTypeParts[] = $db->quote($type);
}
if (in_array("folder", $subtypes)) {
$conditionTypeParts[] = $db->quote('folder');
}
$conditionParts[] = "( maintype IN (" . implode(",", $conditionTypeParts) . ") )";
}
if (is_array($subtypes) and !empty($subtypes[0])) {
foreach ($subtypes as $subtype) {
$conditionSubtypeParts[] = $db->quote($subtype);
}
$conditionParts[] = "( type IN (" . implode(",", $conditionSubtypeParts) . ") )";
}
if (is_array($classnames) and !empty($classnames[0])) {
if (in_array("folder", $subtypes)) {
$classnames[] = "folder";
}
foreach ($classnames as $classname) {
$conditionClassnameParts[] = $db->quote($classname);
}
$conditionParts[] = "( subtype IN (" . implode(",", $conditionClassnameParts) . ") )";
}
//filtering for tags
$tagIds = $this->getParam("tagIds");
if ($tagIds) {
foreach ($tagIds as $tagId) {
foreach ($types as $type) {
if ($this->getParam("considerChildTags") == "true") {
$tag = Pimcore\Model\Element\Tag::getById($tagId);
if ($tag) {
$tagPath = $tag->getFullIdPath();
$conditionParts[] = "id IN (SELECT cId FROM tags_assignment INNER JOIN tags ON tags.id = tags_assignment.tagid WHERE ctype = " . $db->quote($type) . " AND (id = " . intval($tagId) . " OR idPath LIKE " . $db->quote($tagPath . "%") . "))";
}
} else {
$conditionParts[] = "id IN (SELECT cId FROM tags_assignment WHERE ctype = " . $db->quote($type) . " AND tagid = " . intval($tagId) . ")";
}
}
}
}
if (count($conditionParts) > 0) {
$condition = implode(" AND ", $conditionParts);
//echo $condition; die();
$searcherList->setCondition($condition);
}
$searcherList->setOffset($offset);
$searcherList->setLimit($limit);
// do not sort per default, it is VERY SLOW
//$searcherList->setOrder("desc");
//$searcherList->setOrderKey("modificationdate");
$sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
if ($sortingSettings['orderKey']) {
// we need a special mapping for classname as this is stored in subtype column
$sortMapping = ["classname" => "subtype"];
$sort = $sortingSettings['orderKey'];
if (array_key_exists($sortingSettings['orderKey'], $sortMapping)) {
$sort = $sortMapping[$sortingSettings['orderKey']];
}
$searcherList->setOrderKey($sortingSettings['orderKey']);
}
if ($sortingSettings['order']) {
$searcherList->setOrder($sortingSettings['order']);
}
$hits = $searcherList->load();
$elements = [];
foreach ($hits as $hit) {
$element = Element\Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());
if ($element->isAllowed("list")) {
if ($element instanceof Object\AbstractObject) {
$data = Object\Service::gridObjectData($element, $fields);
} elseif ($element instanceof Document) {
$data = Document\Service::gridDocumentData($element);
} elseif ($element instanceof Asset) {
$data = Asset\Service::gridAssetData($element);
}
$elements[] = $data;
} else {
//TODO: any message that view is blocked?
//$data = Element\Service::gridElementData($element);
}
}
// only get the real total-count when the limit parameter is given otherwise use the default limit
if ($this->getParam("limit")) {
$totalMatches = $searcherList->getTotalCount();
} else {
$totalMatches = count($elements);
}
$this->_helper->json(["data" => $elements, "success" => true, "total" => $totalMatches]);
$this->removeViewRenderer();
}