public function showAction() { $offset = $this->getParam("start"); $limit = $this->getParam("limit"); $orderby = "ORDER BY id DESC"; $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $orderby = "ORDER BY " . $sortingSettings['orderKey'] . " " . $sortingSettings['order']; } $queryString = " WHERE 1=1"; if ($this->getParam("priority") != "-1" && ($this->getParam("priority") == "0" || $this->getParam("priority"))) { $levels = []; foreach (["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"] as $level) { $levels[] = "priority = '" . $level . "'"; if ($this->getParam("priority") == $level) { break; } } $queryString .= " AND (" . implode(" OR ", $levels) . ")"; } if ($this->getParam("fromDate")) { $datetime = $this->getParam("fromDate"); if ($this->getParam("fromTime")) { $datetime = substr($datetime, 0, 11) . $this->getParam("fromTime") . ":00"; } $queryString .= " AND timestamp >= '" . $datetime . "'"; } if ($this->getParam("toDate")) { $datetime = $this->getParam("toDate"); if ($this->getParam("toTime")) { $datetime = substr($datetime, 0, 11) . $this->getParam("toTime") . ":00"; } $queryString .= " AND timestamp <= '" . $datetime . "'"; } if ($this->getParam("component")) { $queryString .= " AND component = '" . $this->getParam("component") . "'"; } if ($this->getParam("relatedobject")) { $queryString .= " AND relatedobject = " . $this->getParam("relatedobject"); } if ($this->getParam("message")) { $queryString .= " AND message like '%" . $this->getParam("message") . "%'"; } $db = Db::get(); $count = $db->fetchCol("SELECT count(*) FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . $queryString); $total = $count[0]; $result = $db->fetchAll("SELECT * FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . $queryString . " {$orderby} LIMIT {$offset}, {$limit}"); $errorDataList = array(); if (!empty($result)) { foreach ($result as $r) { $parts = explode("/", $r['filelink']); $filename = $parts[count($parts) - 1]; $fileobject = str_replace(PIMCORE_DOCUMENT_ROOT, "", $r['fileobject']); $errorData = array("id" => $r['id'], "pid" => $r['pid'], "message" => $r['message'], "timestamp" => $r['timestamp'], "priority" => $this->getPriorityName($r['priority']), "filename" => $filename, "fileobject" => $fileobject, "relatedobject" => $r['relatedobject'], "component" => $r['component'], "source" => $r['source']); $errorDataList[] = $errorData; } } $results = array("p_totalCount" => $total, "p_results" => $errorDataList); $this->_helper->json($results); }
public function showAction() { $offset = $this->_getParam("start"); $limit = $this->_getParam("limit"); $orderby = "ORDER BY id DESC"; $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $orderby = "ORDER BY " . $sortingSettings['orderKey'] . " " . $sortingSettings['order']; } $queryString = " WHERE 1=1"; if ($this->_getParam("priority") != "-1" && ($this->_getParam("priority") == "0" || $this->_getParam("priority"))) { $queryString .= " AND priority <= " . $this->_getParam("priority"); } else { $queryString .= " AND (priority = 6 OR priority = 5 OR priority = 4 OR priority = 3 OR priority = 2 OR priority = 1 OR priority = 0)"; } if ($this->_getParam("fromDate")) { $datetime = $this->_getParam("fromDate"); if ($this->_getParam("fromTime")) { $datetime = substr($datetime, 0, 11) . $this->_getParam("fromTime") . ":00"; } $queryString .= " AND timestamp >= '" . $datetime . "'"; } if ($this->_getParam("toDate")) { $datetime = $this->_getParam("toDate"); if ($this->_getParam("toTime")) { $datetime = substr($datetime, 0, 11) . $this->_getParam("toTime") . ":00"; } $queryString .= " AND timestamp <= '" . $datetime . "'"; } if ($this->_getParam("component")) { $queryString .= " AND component = '" . $this->_getParam("component") . "'"; } if ($this->_getParam("relatedobject")) { $queryString .= " AND relatedobject = " . $this->_getParam("relatedobject"); } if ($this->_getParam("message")) { $queryString .= " AND message like '%" . $this->_getParam("message") . "%'"; } $db = Db::get(); $count = $db->fetchCol("SELECT count(*) FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . $queryString); $total = $count[0]; $result = $db->fetchAll("SELECT * FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . $queryString . " {$orderby} LIMIT {$offset}, {$limit}"); $errorDataList = array(); if (!empty($result)) { foreach ($result as $r) { $parts = explode("/", $r['filelink']); $filename = $parts[count($parts) - 1]; $fileobject = str_replace(PIMCORE_DOCUMENT_ROOT, "", $r['fileobject']); $errorData = array("id" => $r['id'], "message" => $r['message'], "timestamp" => $r['timestamp'], "priority" => $this->getPriorityName($r['priority']), "filename" => $filename, "fileobject" => $fileobject, "relatedobject" => $r['relatedobject'], "component" => $r['component'], "source" => $r['source']); $errorDataList[] = $errorData; } } $results = array("p_totalCount" => $total, "p_results" => $errorDataList); $this->_helper->json($results); }
public function noteListAction() { $this->checkPermission("notes_events"); $list = new Element\Note\Listing(); $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey'] && $sortingSettings['order']) { $list->setOrderKey($sortingSettings['orderKey']); $list->setOrder($sortingSettings['order']); } else { $list->setOrderKey(["date", "id"]); $list->setOrder(["DESC", "DESC"]); } $conditions = []; if ($this->getParam("filter")) { $conditions[] = "(`title` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `description` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `type` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . ")"; } if ($this->getParam("cid") && $this->getParam("ctype")) { $conditions[] = "(cid = " . $list->quote($this->getParam("cid")) . " AND ctype = " . $list->quote($this->getParam("ctype")) . ")"; } if (!empty($conditions)) { $list->setCondition(implode(" AND ", $conditions)); } $list->load(); $notes = []; foreach ($list->getNotes() as $note) { $cpath = ""; if ($note->getCid() && $note->getCtype()) { if ($element = Element\Service::getElementById($note->getCtype(), $note->getCid())) { $cpath = $element->getRealFullPath(); } } $e = ["id" => $note->getId(), "type" => $note->getType(), "cid" => $note->getCid(), "ctype" => $note->getCtype(), "cpath" => $cpath, "date" => $note->getDate(), "title" => $note->getTitle(), "description" => $note->getDescription()]; // prepare key-values $keyValues = []; if (is_array($note->getData())) { foreach ($note->getData() as $name => $d) { $type = $d["type"]; $data = $d["data"]; if ($type == "document" || $type == "object" || $type == "asset") { if ($d["data"] instanceof Element\ElementInterface) { $data = ["id" => $d["data"]->getId(), "path" => $d["data"]->getRealFullPath(), "type" => $d["data"]->getType()]; } } elseif ($type == "date") { if (is_object($d["data"])) { $data = $d["data"]->getTimestamp(); } } $keyValue = ["type" => $type, "name" => $name, "data" => $data]; $keyValues[] = $keyValue; } } $e["data"] = $keyValues; // prepare user data if ($note->getUser()) { $user = Model\User::getById($note->getUser()); if ($user) { $e["user"] = ["id" => $user->getId(), "name" => $user->getName()]; } else { $e["user"] = ""; } } $notes[] = $e; } $this->_helper->json(["data" => $notes, "success" => true, "total" => $list->getTotalCount()]); }
public function blacklistAction() { if (!$this->getUser()->isAllowed("emails")) { throw new \Exception("Permission denied, user needs 'emails' permission."); } if ($this->getParam("data")) { $data = \Zend_Json::decode($this->getParam("data")); if (is_array($data)) { foreach ($data as &$value) { $value = trim($value); } } if ($this->getParam("xaction") == "destroy") { $address = Tool\Email\Blacklist::getByAddress($data); $address->delete(); $this->_helper->json(array("success" => true, "data" => array())); } elseif ($this->getParam("xaction") == "update") { $address = Tool\Email\Blacklist::getByAddress($data["address"]); $address->setValues($data); $address->save(); $this->_helper->json(array("data" => $address, "success" => true)); } elseif ($this->getParam("xaction") == "create") { unset($data["id"]); $address = new Tool\Email\Blacklist(); $address->setValues($data); $address->save(); $this->_helper->json(array("data" => $address, "success" => true)); } } else { // get list of routes $list = new Tool\Email\Blacklist\Listing(); $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $orderKey = $sortingSettings['orderKey']; } if ($sortingSettings['order']) { $order = $sortingSettings['order']; } if ($this->getParam("filter")) { $list->setCondition("`address` LIKE " . $list->quote("%" . $this->getParam("filter") . "%")); } $data = $list->load(); $this->_helper->json(array("success" => true, "data" => $data, "total" => $list->getTotalCount())); } $this->_helper->json(false); }
public function websiteSettingsAction() { try { if ($this->getParam("data")) { $this->checkPermission("website_settings"); $data = \Zend_Json::decode($this->getParam("data")); if (is_array($data)) { foreach ($data as &$value) { $value = trim($value); } } if ($this->getParam("xaction") == "destroy") { if (\Pimcore\Tool\Admin::isExtJS6()) { $id = $data["id"]; } else { $id = $data; } $setting = WebsiteSetting::getById($id); $setting->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->getParam("xaction") == "update") { // save routes $setting = WebsiteSetting::getById($data["id"]); switch ($setting->getType()) { case "document": case "asset": case "object": if (isset($data["data"])) { $path = $data["data"]; $element = Element\Service::getElementByPath($setting->getType(), $path); $data["data"] = $element ? $element->getId() : null; } break; } $setting->setValues($data); $setting->save(); $data = $this->getWebsiteSettingForEditMode($setting); $this->_helper->json(array("data" => $data, "success" => true)); } else { if ($this->getParam("xaction") == "create") { unset($data["id"]); // save route $setting = new WebsiteSetting(); $setting->setValues($data); $setting->save(); $this->_helper->json(array("data" => $setting, "success" => true)); } } } } else { // get list of routes $list = new WebsiteSetting\Listing(); $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $list->setOrderKey($sortingSettings['orderKey']); $list->setOrder($sortingSettings['order']); } else { $list->setOrderKey("name"); $list->setOrder("asc"); } if ($this->getParam("filter")) { $list->setCondition("`name` LIKE " . $list->quote("%" . $this->getParam("filter") . "%")); } $totalCount = $list->getTotalCount(); $list = $list->load(); $settings = array(); foreach ($list as $item) { $resultItem = $this->getWebsiteSettingForEditMode($item); $settings[] = $resultItem; } $this->_helper->json(array("data" => $settings, "success" => true, "total" => $totalCount)); } } catch (\Exception $e) { throw $e; $this->_helper->json(false); } $this->_helper->json(false); }
/** * @return void */ public function findAction() { $user = $this->getUser(); $query = $this->getParam("query"); if ($query == "*") { $query = ""; } $query = str_replace("%", "*", $query); $types = explode(",", $this->getParam("type")); $subtypes = explode(",", $this->getParam("subtype")); $classnames = explode(",", $this->getParam("class")); if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) { $subtypes = ["object", "variant", "folder"]; } $offset = intval($this->getParam("start")); $limit = intval($this->getParam("limit")); $offset = $offset ? $offset : 0; $limit = $limit ? $limit : 50; $searcherList = new Data\Listing(); $conditionParts = []; $db = \Pimcore\Db::get(); //exclude forbidden assets if (in_array("asset", $types)) { if (!$user->isAllowed("assets")) { $forbiddenConditions[] = " `type` != 'asset' "; } else { $forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user); if (count($forbiddenAssetPaths) > 0) { for ($i = 0; $i < count($forbiddenAssetPaths); $i++) { $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")"; } $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths); } } } //exclude forbidden documents if (in_array("document", $types)) { if (!$user->isAllowed("documents")) { $forbiddenConditions[] = " `type` != 'document' "; } else { $forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user); if (count($forbiddenDocumentPaths) > 0) { for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) { $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")"; } $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths); } } } //exclude forbidden objects if (in_array("object", $types)) { if (!$user->isAllowed("objects")) { $forbiddenConditions[] = " `type` != 'object' "; } else { $forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user); if (count($forbiddenObjectPaths) > 0) { for ($i = 0; $i < count($forbiddenObjectPaths); $i++) { $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")"; } $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths); } } } if ($forbiddenConditions) { $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")"; } if (!empty($query)) { $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )"; // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index // if the query is numeric the user might want to search by id //if(is_numeric($query)) { //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )"; //} $conditionParts[] = $queryCondition; } //For objects - handling of bricks $fields = []; $bricks = []; if ($this->getParam("fields")) { $fields = $this->getParam("fields"); foreach ($fields as $f) { $parts = explode("~", $f); if (substr($f, 0, 1) == "~") { // $type = $parts[1]; // $field = $parts[2]; // $keyid = $parts[3]; // key value, ignore for now } elseif (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) . ") )"; } //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(); }
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"); } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = ["o_parentId = " . $parentObject->getId()]; // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_VARIANT]); $list->load(); $objects = []; foreach ($list->getObjects() as $object) { if ($object->isAllowed("view")) { $o = Object\Service::gridObjectData($object, $fields); $objects[] = $o; } } $this->_helper->json(["data" => $objects, "success" => true, "total" => $list->getTotalCount()]); } else { throw new \Exception("Permission denied"); } } }
public function propertiesAction() { if ($this->getParam("data")) { $dataParam = $this->getParam("data"); $data = \Zend_Json::decode($dataParam); $id = $data["id"]; $config = Classificationstore\KeyConfig::getById($id); foreach ($data as $key => $value) { if ($key != "id") { $setter = "set" . $key; if (method_exists($config, $setter)) { $config->{$setter}($value); } } } $config->save(); $item = $this->getConfigItem($config); $this->_helper->json(array("success" => true, "data" => $item)); } else { $start = 0; $limit = 15; $orderKey = "name"; $order = "ASC"; if ($this->getParam("dir")) { $order = $this->getParam("dir"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey'] && $sortingSettings['order']) { $orderKey = $sortingSettings['orderKey']; $order = $sortingSettings['order']; } if ($this->getParam("overrideSort") == "true") { $orderKey = "id"; $order = "DESC"; } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $list = new Classificationstore\KeyConfig\Listing(); if ($limit > 0) { $list->setLimit($limit); } $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $condition = ""; $db = \Pimcore\Db::get(); $searchfilter = $this->getParam("searchfilter"); if ($searchfilter) { $condition = "(name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR description LIKE " . $db->quote("%" . $searchfilter . "%") . ")"; } if ($this->getParam("filter")) { $filterString = $this->getParam("filter"); $filters = json_decode($filterString); $count = 0; foreach ($filters as $f) { if ($count > 0) { $condition .= " AND "; } $count++; if (\Pimcore\Tool\Admin::isExtJS6()) { $condition .= $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } else { $condition .= $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } } } $list->setCondition($condition); if ($this->getParam("groupIds") || $this->getParam("keyIds")) { $db = Db::get(); if ($this->getParam("groupIds")) { $ids = \Zend_Json::decode($this->getParam("groupIds")); $col = "group"; } else { $ids = \Zend_Json::decode($this->getParam("keyIds")); $col = "id"; } $condition = $db->getQuoteIdentifierSymbol() . $col . $db->getQuoteIdentifierSymbol() . " IN ("; $count = 0; foreach ($ids as $theId) { if ($count > 0) { $condition .= ","; } $condition .= $theId; $count++; } $condition .= ")"; $list->setCondition($condition); } $list->load(); $configList = $list->getList(); $rootElement = array(); $data = array(); foreach ($configList as $config) { $item = $this->getConfigItem($config); $data[] = $item; } $rootElement["data"] = $data; $rootElement["success"] = true; $rootElement["total"] = $list->getTotalCount(); return $this->_helper->json($rootElement); } }
public function translationsAction() { $admin = $this->getParam("admin"); if ($admin) { $class = "\\Pimcore\\Model\\Translation\\Admin"; $this->checkPermission("translations_admin"); } else { $class = "\\Pimcore\\Model\\Translation\\Website"; $this->checkPermission("translations"); } $tableName = call_user_func($class . "\\Dao::getTableName"); // clear translation cache Translation\Website::clearDependentCache(); if ($this->getParam("data")) { $data = \Zend_Json::decode($this->getParam("data")); if ($this->getParam("xaction") == "destroy") { $data = \Zend_Json::decode($this->getParam("data")); if (\Pimcore\Tool\Admin::isExtJS6()) { $t = $class::getByKey($data["key"]); } else { $t = $class::getByKey($data); } $t->delete(); $this->_helper->json(["success" => true, "data" => []]); } elseif ($this->getParam("xaction") == "update") { $t = $class::getByKey($data["key"]); foreach ($data as $key => $value) { if ($key != "key") { $t->addTranslation($key, $value); } } if ($data["key"]) { $t->setKey($data["key"]); } $t->setModificationDate(time()); $t->save(); $return = array_merge(["key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()], $t->getTranslations()); $this->_helper->json(["data" => $return, "success" => true]); } elseif ($this->getParam("xaction") == "create") { try { $t = $class::getByKey($data["key"]); } catch (\Exception $e) { $t = new $class(); $t->setKey($data["key"]); $t->setCreationDate(time()); $t->setModificationDate(time()); foreach (Tool::getValidLanguages() as $lang) { $t->addTranslation($lang, ""); } $t->save(); } $return = array_merge(["key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()], $t->getTranslations()); $this->_helper->json(["data" => $return, "success" => true]); } } else { // get list of types if ($admin) { $list = new Translation\Admin\Listing(); } else { $list = new Translation\Website\Listing(); } $validLanguages = $this->getUser()->getAllowedLanguagesForViewingWebsiteTranslations(); $list->setOrder("asc"); $list->setOrderKey($tableName . ".key", false); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); $joins = []; if ($sortingSettings['orderKey']) { if (in_array($sortingSettings['orderKey'], $validLanguages)) { $joins[] = ["language" => $sortingSettings['orderKey']]; $list->setOrderKey($sortingSettings['orderKey']); } else { $list->setOrderKey($tableName . "." . $sortingSettings['orderKey'], false); } } if ($sortingSettings['order']) { $list->setOrder($sortingSettings['order']); } $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $condition = $this->getGridFilterCondition($tableName); $filters = $this->getGridFilterCondition($tableName, true); if ($filters) { $joins = array_merge($joins, $filters["joins"]); } if ($condition) { $list->setCondition($condition); } $this->extendTranslationQuery($joins, $list, $tableName, $filters); $list->load(); $translations = []; foreach ($list->getTranslations() as $t) { $translations[] = array_merge($t->getTranslations(), ["key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()]); } $this->_helper->json(["data" => $translations, "success" => true, "total" => $list->getTotalCount()]); } }
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()]); } } } else { // get list of objects $folder = Object::getById($this->getParam("folderId")); $class = Object\ClassDefinition::getById($this->getParam("classId")); $className = $class->getName(); $colMappings = ["filename" => "o_key", "fullpath" => ["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 = []; $bricks = []; 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]; // $keyid = $parts[3]; // key value, ignore for now if ($type == "classificationstore") { } } elseif (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); $doNotQuote = false; if ($sortingSettings['order']) { $order = $sortingSettings['order']; } if (strlen($sortingSettings['orderKey']) > 0) { $orderKey = $sortingSettings['orderKey']; if (!(substr($orderKey, 0, 1) == "~")) { if (array_key_exists($orderKey, $colMappings)) { $orderKey = $colMappings[$orderKey]; } elseif ($class->getFieldDefinition($orderKey) instanceof Object\ClassDefinition\Data\QuantityValue) { $orderKey = "concat(" . $orderKey . "__unit, " . $orderKey . "__value)"; $doNotQuote = true; } elseif (strpos($orderKey, "~") !== false) { $orderKeyParts = explode("~", $orderKey); if (count($orderKeyParts) == 2) { $orderKey = $orderKeyParts[1]; } } } } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = []; if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "o_parentId = " . $folder->getId(); } else { $conditionFilters[] = "(o_path = '" . $folder->getRealFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getRealFullPath() . "/") . "%')"; } if (!$this->getUser()->isAdmin()) { $userIds = $this->getUser()->getRoles(); $userIds[] = $this->getUser()->getId(); $conditionFilters[] .= " (\n (select list 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 list 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 )"; } $featureJoins = []; $featureFilters = false; // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); $featureFilters = Object\Service::getFeatureFilters($this->getParam("filter"), $class); if ($featureFilters) { $featureJoins = array_merge($featureJoins, $featureFilters["joins"]); } } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); if (isset($sortingSettings["isFeature"]) && $sortingSettings["isFeature"]) { $orderKey = "cskey_" . $sortingSettings["fieldname"] . "_" . $sortingSettings["groupId"] . "_" . $sortingSettings["keyId"]; $list->setOrderKey($orderKey); $list->setGroupBy("o_id"); $featureJoins[] = $sortingSettings; } else { $list->setOrderKey($orderKey, !$doNotQuote); } $list->setOrder($order); if ($class->getShowVariants()) { $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT]); } Object\Service::addGridFeatureJoins($list, $featureJoins, $class, $featureFilters, $requestedLanguage); $list->load(); $objects = []; foreach ($list->getObjects() as $object) { $o = Object\Service::gridObjectData($object, $fields, $requestedLanguage); $objects[] = $o; } $this->_helper->json(["data" => $objects, "success" => true, "total" => $list->getTotalCount()]); } }
public function translationsAction() { $admin = $this->getParam("admin"); if ($admin) { $class = "\\Pimcore\\Model\\Translation\\Admin"; $this->checkPermission("translations_admin"); } else { $class = "\\Pimcore\\Model\\Translation\\Website"; $this->checkPermission("translations"); } // clear translation cache Translation\Website::clearDependentCache(); if ($this->getParam("data")) { $data = \Zend_Json::decode($this->getParam("data")); if ($this->getParam("xaction") == "destroy") { $data = \Zend_Json::decode($this->getParam("data")); if (\Pimcore\Tool\Admin::isExtJS6()) { $t = $class::getByKey($data["key"]); } else { $t = $class::getByKey($data); } $t->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->getParam("xaction") == "update") { $t = $class::getByKey($data["key"]); foreach ($data as $key => $value) { if ($key != "key") { $t->addTranslation($key, $value); } } if ($data["key"]) { $t->setKey($data["key"]); } $t->setModificationDate(time()); $t->save(); $return = array_merge(array("key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()), $t->getTranslations()); $this->_helper->json(array("data" => $return, "success" => true)); } else { if ($this->getParam("xaction") == "create") { try { $t = $class::getByKey($data["key"]); } catch (\Exception $e) { $t = new $class(); $t->setKey($data["key"]); $t->setCreationDate(time()); $t->setModificationDate(time()); foreach (Tool::getValidLanguages() as $lang) { $t->addTranslation($lang, ""); } $t->save(); } $return = array_merge(array("key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate()), $t->getTranslations()); $this->_helper->json(array("data" => $return, "success" => true)); } } } } else { // get list of types if ($admin) { $list = new Translation\Admin\Listing(); } else { $list = new Translation\Website\Listing(); } $list->setOrder("asc"); $list->setOrderKey("key"); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $list->setOrderKey($sortingSettings['orderKey']); } if ($sortingSettings['order']) { $list->setOrder($sortingSettings['order']); } $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $condition = $this->getGridFilterCondition(); if ($condition) { $list->setCondition($condition); } $list->load(); $translations = array(); foreach ($list->getTranslations() as $t) { $translations[] = array_merge($t->getTranslations(), array("key" => $t->getKey(), "creationDate" => $t->getCreationDate(), "modificationDate" => $t->getModificationDate())); } $this->_helper->json(array("data" => $translations, "success" => true, "total" => $list->getTotalCount())); } }
public function gridProxyAction() { if ($this->getParam("data")) { if ($this->getParam("xaction") == "update") { //TODO probably not needed } } else { $db = \Pimcore\Db::get(); // get list of objects $folder = Asset::getById($this->getParam("folderId")); $start = 0; $limit = 20; $orderKey = "id"; $order = "ASC"; if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $orderKey = $sortingSettings['orderKey']; if ($orderKey == "fullpath") { $orderKey = ["path", "filename"]; } $order = $sortingSettings['order']; } $conditionFilters = []; if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "parentId = " . $folder->getId(); } else { $conditionFilters[] = "path LIKE '" . ($folder->getRealFullPath() == "/" ? "/%'" : $folder->getRealFullPath() . "/%'"); } $conditionFilters[] = "type != 'folder'"; $filterJson = $this->getParam("filter"); if ($filterJson) { $filters = \Zend_Json::decode($filterJson); foreach ($filters as $filter) { $operator = "="; if ($filter["type"] == "string") { $operator = "LIKE"; } elseif ($filter["type"] == "numeric") { if ($filter["comparison"] == "lt") { $operator = "<"; } elseif ($filter["comparison"] == "gt") { $operator = ">"; } elseif ($filter["comparison"] == "eq") { $operator = "="; } } elseif ($filter["type"] == "date") { if ($filter["comparison"] == "lt") { $operator = "<"; } elseif ($filter["comparison"] == "gt") { $operator = ">"; } elseif ($filter["comparison"] == "eq") { $operator = "="; } $filter["value"] = strtotime($filter["value"]); } elseif ($filter["type"] == "list") { $operator = "="; } elseif ($filter["type"] == "boolean") { $operator = "="; $filter["value"] = (int) $filter["value"]; } // system field $value = $filter["value"]; if ($operator == "LIKE") { $value = "%" . $value . "%"; } $field = "`" . $filter["field"] . "` "; if ($filter["field"] == "fullpath") { $field = "CONCAT(path,filename)"; } $conditionFilters[] = $field . $operator . " " . $db->quote($value); } } $list = new Asset\Listing(); $condition = implode(" AND ", $conditionFilters); $list->setCondition($condition); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $list->load(); $assets = []; foreach ($list->getAssets() as $asset) { /** @var $asset Asset */ $filename = PIMCORE_ASSET_DIRECTORY . "/" . $asset->getRealFullPath(); $size = @filesize($filename); $assets[] = ["id" => $asset->getid(), "type" => $asset->getType(), "fullpath" => $asset->getRealFullPath(), "creationDate" => $asset->getCreationDate(), "modificationDate" => $asset->getModificationDate(), "size" => formatBytes($size), "idPath" => $data["idPath"] = Element\Service::getIdPath($asset)]; } $this->_helper->json(["data" => $assets, "success" => true, "total" => $list->getTotalCount()]); } }
public function unitProxyAction() { if ($this->getParam("data")) { if ($this->getParam("xaction") == "destroy") { $data = Zend_Json::decode($this->getParam("data")); $id = $data["id"]; $unit = \Pimcore\Model\Object\QuantityValue\Unit::getById($id); if (!empty($unit)) { $unit->delete(); $this->_helper->json(["data" => [], "success" => true]); } else { throw new \Exception("Unit with id " . $id . " not found."); } } elseif ($this->getParam("xaction") == "update") { $data = Zend_Json::decode($this->getParam("data")); $unit = Pimcore\Model\Object\QuantityValue\Unit::getById($data['id']); if (!empty($unit)) { $unit->setValues($data); $unit->save(); $this->_helper->json(["data" => get_object_vars($unit), "success" => true]); } else { throw new \Exception("Unit with id " . $data['id'] . " not found."); } } elseif ($this->getParam("xaction") == "create") { $data = Zend_Json::decode($this->getParam("data")); unset($data['id']); $unit = new Pimcore\Model\Object\QuantityValue\Unit(); $unit->setValues($data); $unit->save(); $this->_helper->json(["data" => get_object_vars($unit), "success" => true]); } } else { $list = new Pimcore\Model\Object\QuantityValue\Unit\Listing(); $orderKey = "abbreviation"; $order = "asc"; $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $orderKey = $sortingSettings['orderKey']; } if ($sortingSettings['order']) { $order = $sortingSettings['order']; } $list->setOrder($order); $list->setOrderKey($orderKey); $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $condition = "1 = 1"; if ($this->getParam("filter")) { $filterString = $this->getParam("filter"); $filters = json_decode($filterString); $db = \Pimcore\Db::get(); foreach ($filters as $f) { if ($f->type == "string") { $condition .= " AND " . $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } elseif ($f->type == "numeric") { $operator = $this->getOperator($f->comparison); $condition .= " AND " . $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " " . $operator . " " . $db->quote($f->value); } } $list->setCondition($condition); } $list->load(); $units = []; foreach ($list->getUnits() as $u) { $units[] = get_object_vars($u); } $this->_helper->json(["data" => $units, "success" => true, "total" => $list->getTotalCount()]); } }
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]; // $keyid = $parts[3]; // key value, ignore for now } elseif (count($parts) > 1) { $bricks[$parts[0]] = $parts[0]; } } } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['order']) { $order = $sortingSettings['order']; } if (strlen($sortingSettings['orderKey']) > 0) { $orderKey = $sortingSettings['orderKey']; if (!(substr($orderKey, 0, 1) == "~")) { if (array_key_exists($orderKey, $colMappings)) { $orderKey = $colMappings[$orderKey]; } } } $listClass = "\\Pimcore\\Model\\Object\\" . ucfirst($className) . "\\Listing"; $conditionFilters = array(); if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "o_parentId = " . $folder->getId(); } else { $conditionFilters[] = "(o_path = '" . $folder->getFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getFullPath() . "/") . "%')"; } // create filter condition if ($this->getParam("filter")) { $conditionFilters[] = Object\Service::getFilterCondition($this->getParam("filter"), $class); } if ($this->getParam("condition")) { $conditionFilters[] = "(" . $this->getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition(implode(" AND ", $conditionFilters)); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); if ($class->getShowVariants()) { $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT]); } $list->load(); $objects = array(); foreach ($list->getObjects() as $object) { $o = Object\Service::gridObjectData($object, $fields); $objects[] = $o; } $this->_helper->json(array("data" => $objects, "success" => true, "total" => $list->getTotalCount())); } }
public function listAction() { if ($this->getParam("xaction") == "destroy") { $item = Recyclebin\Item::getById(\Pimcore\Admin\Helper\QueryParams::getRecordIdForGridRequest($this->getParam("data"))); $item->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { $list = new Recyclebin\Item\Listing(); $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $list->setOrderKey("date"); $list->setOrder("DESC"); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $list->setOrderKey($sortingSettings['orderKey']); $list->setOrder($sortingSettings['order']); } $conditionFilters = array(); if ($this->getParam("filterFullText")) { $conditionFilters[] = "path LIKE " . $list->quote("%" . $this->getParam("filterFullText") . "%"); } $filters = $this->getParam("filter"); if ($filters) { $filters = \Zend_Json::decode($filters); foreach ($filters as $filter) { $operator = "="; $filterField = $filter["field"]; $filterOperator = $filter["comparison"]; if (\Pimcore\Tool\Admin::isExtJS6()) { $filterField = $filter["property"]; $filterOperator = $filter["operator"]; } if ($filter["type"] == "string") { $operator = "LIKE"; } elseif ($filter["type"] == "numeric") { if ($filterOperator == "lt") { $operator = "<"; } elseif ($filterOperator == "gt") { $operator = ">"; } elseif ($filterOperator == "eq") { $operator = "="; } } elseif ($filter["type"] == "date") { if ($filterOperator == "lt") { $operator = "<"; } elseif ($filterOperator == "gt") { $operator = ">"; } elseif ($filterOperator == "eq") { $operator = "="; } $filter["value"] = strtotime($filter["value"]); } elseif ($filter["type"] == "list") { $operator = "="; } elseif ($filter["type"] == "boolean") { $operator = "="; $filter["value"] = (int) $filter["value"]; } // system field $value = $filter["value"]; if ($operator == "LIKE") { $value = "%" . $value . "%"; } $field = "`" . $filterField . "` "; if ($filter["field"] == "fullpath") { $field = "CONCAT(path,filename)"; } $conditionFilters[] = $field . $operator . " '" . $value . "' "; } } if (!empty($conditionFilters)) { $condition = implode(" AND ", $conditionFilters); $list->setCondition($condition); } $items = $list->load(); $this->_helper->json(array("data" => $items, "success" => true, "total" => $list->getTotalCount())); } }
public function dataAction() { $offset = $this->getParam("start", 0); $limit = $this->getParam("limit", 40); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $sort = $sortingSettings['orderKey']; $dir = $sortingSettings['order']; } $filters = $this->getParam("filter") ? json_decode($this->getParam("filter"), true) : null; $drillDownFilters = $this->getParam("drillDownFilters", null); $config = CustomReport\Config::getByName($this->getParam("name")); $configuration = $config->getDataSourceConfig(); $adapter = CustomReport\Config::getAdapter($configuration, $config); $result = $adapter->getData($filters, $sort, $dir, $offset, $limit, null, $drillDownFilters, $config); $this->_helper->json(["success" => true, "data" => $result['data'], "total" => $result['total']]); }
public function propertiesAction() { if ($this->getParam("data")) { $dataParam = $this->getParam("data"); $data = \Zend_Json::decode($dataParam); $id = $data["id"]; $config = Classificationstore\KeyConfig::getById($id); foreach ($data as $key => $value) { if ($key != "id") { $setter = "set" . $key; if (method_exists($config, $setter)) { $config->{$setter}($value); } } } $config->save(); $item = $this->getConfigItem($config); $this->_helper->json(["success" => true, "data" => $item]); } else { $storeId = $this->getParam("storeId"); $frameName = $this->getParam("frameName"); $db = \Pimcore\Db::get(); $conditionParts = []; if ($frameName) { $keyCriteria = " FALSE "; $frameConfig = Classificationstore\CollectionConfig::getByName($frameName, $storeId); if ($frameConfig) { // get all keys within that collection / frame $frameId = $frameConfig->getId(); $groupList = new Pimcore\Model\Object\Classificationstore\CollectionGroupRelation\Listing(); $groupList->setCondition("colId = " . $db->quote($frameId)); $groupList = $groupList->load(); $groupIdList = []; foreach ($groupList as $groupEntry) { $groupIdList[] = $groupEntry->getGroupId(); } if ($groupIdList) { $keyIdList = new Classificationstore\KeyGroupRelation\Listing(); $keyIdList->setCondition("groupId in (" . implode(",", $groupIdList) . ")"); $keyIdList = $keyIdList->load(); if ($keyIdList) { $keyIds = []; /** @var $keyEntry Classificationstore\KeyGroupRelation */ foreach ($keyIdList as $keyEntry) { $keyIds[] = $keyEntry->getKeyId(); } if ($keyIds) { $keyCriteria = " id in (" . implode(",", $keyIds) . ")"; } } } } if ($keyCriteria) { $conditionParts[] = $keyCriteria; } } $start = 0; $limit = 15; $orderKey = "name"; $order = "ASC"; if ($this->getParam("dir")) { $order = $this->getParam("dir"); } $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey'] && $sortingSettings['order']) { $orderKey = $sortingSettings['orderKey']; $order = $sortingSettings['order']; } if ($this->getParam("overrideSort") == "true") { $orderKey = "id"; $order = "DESC"; } if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $list = new Classificationstore\KeyConfig\Listing(); if ($limit > 0) { $list->setLimit($limit); } $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $searchfilter = $this->getParam("searchfilter"); if ($searchfilter) { $conditionParts[] = "(name LIKE " . $db->quote("%" . $searchfilter . "%") . " OR description LIKE " . $db->quote("%" . $searchfilter . "%") . ")"; } if ($storeId) { $conditionParts[] = "(storeId = " . $storeId . ")"; } if ($this->getParam("filter")) { $filterString = $this->getParam("filter"); $filters = json_decode($filterString); foreach ($filters as $f) { if (\Pimcore\Tool\Admin::isExtJS6()) { $conditionParts[] = $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } else { $conditionParts[] = $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } } } $condition = implode(" AND ", $conditionParts); $list->setCondition($condition); if ($this->getParam("groupIds") || $this->getParam("keyIds")) { $db = Db::get(); if ($this->getParam("groupIds")) { $ids = \Zend_Json::decode($this->getParam("groupIds")); $col = "group"; } else { $ids = \Zend_Json::decode($this->getParam("keyIds")); $col = "id"; } $condition = $db->getQuoteIdentifierSymbol() . $col . $db->getQuoteIdentifierSymbol() . " IN ("; $count = 0; foreach ($ids as $theId) { if ($count > 0) { $condition .= ","; } $condition .= $theId; $count++; } $condition .= ")"; $list->setCondition($condition); } $list->load(); $configList = $list->getList(); $rootElement = []; $data = []; foreach ($configList as $config) { $item = $this->getConfigItem($config); $data[] = $item; } $rootElement["data"] = $data; $rootElement["success"] = true; $rootElement["total"] = $list->getTotalCount(); return $this->_helper->json($rootElement); } }