/** * Gets a object by it's id and replaces the placeholder width the value form the called "method" * * example: %Object(object_id,{"method" : "getId"}); * @return string */ public function getReplacement() { $string = ''; if ($object = Object_Concrete::getById($this->getValue())) { if (is_string($this->getPlaceholderConfig()->method) && method_exists($object, $this->getPlaceholderConfig()->method)) { $string = $object->{$this->getPlaceholderConfig()->method}($this->getLocale()); } } return $string; }
/** * @param int $id * @return Webservice_Data_Object_Concrete_Out */ public function getObjectConcreteById($id) { try { $object = Object_Concrete::getById($id); if ($object instanceof Object_Concrete) { // load all data (eg. lazy loaded fields like multihref, object, ...) Object_Service::loadAllObjectFields($object); $apiObject = Webservice_Data_Mapper::map($object, "Webservice_Data_Object_Concrete_Out", "out"); return $apiObject; } throw new Exception("Object with given ID (" . $id . ") does not exist."); } catch (Exception $e) { Logger::error($e); throw $e; } }
public function getVariantsAction() { // get list of variants if ($this->_getParam("xaction") == "update") { $data = Zend_Json::decode($this->_getParam("data")); // save $object = Object_Abstract::getById($data["id"]); $objectData = array(); foreach ($data as $key => $value) { $parts = explode("~", $key); if (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 = "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(array("data" => Object_Service::gridObjectData($object, $this->_getParam("fields")), "success" => true)); } catch (Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { $parentObject = Object_Concrete::getById($this->_getParam("objectId")); if (empty($parentObject)) { throw new Exception("No Object found with id " . $this->_getParam("objectId")); } $class = $parentObject->getO_class(); $className = $parentObject->getO_class()->getName(); $start = 0; $limit = 15; $orderKey = "o_id"; $order = "ASC"; $fields = array(); $bricks = array(); 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"); } if ($this->_getParam("sort")) { if ($this->_getParam("sort") == "fullpath") { $orderKey = array("o_path", "o_key"); } else { if ($this->_getParam("sort") == "id") { $orderKey = "o_id"; } else { if ($this->_getParam("sort") == "published") { $orderKey = "o_published"; } else { if ($this->_getParam("sort") == "modificationDate") { $orderKey = "o_modificationDate"; } else { if ($this->_getParam("sort") == "creationDate") { $orderKey = "o_creationDate"; } else { $orderKey = $this->_getParam("sort"); } } } } } } if ($this->_getParam("dir")) { $order = $this->_getParam("dir"); } $listClass = "Object_" . ucfirst($className) . "_List"; $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 .= " AND (" . $this->_getParam("condition") . ")"; } $list = new $listClass(); if (!empty($bricks)) { foreach ($bricks as $b) { $list->addObjectbrick($b); } } $list->setCondition($conditionFilters); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $list->setIgnoreLocale(true); $list->setObjectTypes(array(Object_Abstract::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 addCollectionsAction() { $ids = \Zend_Json::decode($this->getParam("collectionIds")); if ($ids) { $db = \Pimcore\Db::get(); $query = "select * from classificationstore_groups g, classificationstore_collectionrelations c where colId IN (" . implode(",", $ids) . ") and g.id = c.groupId"; $mappedData = array(); $groupsData = $db->fetchAll($query); foreach ($groupsData as $groupData) { $mappedData[$groupData["id"]] = $groupData; } $groupIdList = array(); $allowedGroupIds = null; if ($this->getParam("oid")) { $object = Object_Concrete::getById($this->getParam("oid")); $class = $object->getClass(); $fd = $class->getFieldDefinition($this->getParam("fieldname")); $allowedGroupIds = $fd->getAllowedGroupIds(); } foreach ($groupsData as $groupItem) { $groupId = $groupItem["groupId"]; if (!$allowedGroupIds || $allowedGroupIds && in_array($groupId, $allowedGroupIds)) { $groupIdList[] = $groupId; } } $groupCondition = "id in (" . implode(",", $groupIdList) . ")"; $groupList = new Classificationstore\GroupConfig\Listing(); $groupList->setCondition($groupCondition); // $groupList->setOrderKey(array("sorter", "id")); // $groupList->setOrder(array("ASC", "ASC")); $groupList = $groupList->load(); $keyCondition = "groupId in (" . implode(",", $groupIdList) . ")"; $keyList = new Classificationstore\KeyGroupRelation\Listing(); $keyList->setCondition($keyCondition); $keyList->setOrderKey(array("sorter", "id")); $keyList->setOrder(array("ASC", "ASC")); $keyList = $keyList->load(); foreach ($groupList as $groupData) { $data[$groupData->getId()] = array("name" => $groupData->getName(), "id" => $groupData->getId(), "description" => $groupData->getDescription(), "keys" => array(), "collectionId" => $mappedData[$groupId]["colId"]); } foreach ($keyList as $keyData) { $groupId = $keyData->getGroupId(); $keyList = $data[$groupId]["keys"]; $definition = $keyData->getDefinition(); $keyList[] = array("name" => $keyData->getName(), "id" => $keyData->getKeyId(), "description" => $keyData->getDescription(), "definition" => json_decode($definition)); $data[$groupId]["keys"] = $keyList; } } return $this->_helper->json($data); }
public function groupsAction() { if ($this->_getParam("data")) { $dataParam = $this->_getParam("data"); $data = \Zend_Json::decode($dataParam); $id = $data["id"]; $config = Classificationstore\GroupConfig::getById($id); foreach ($data as $key => $value) { if ($key != "id") { $setter = "set" . $key; $config->{$setter}($value); } } $config->save(); $this->_helper->json(array("success" => true, "data" => $config)); } else { $start = 0; $limit = 15; $orderKey = "name"; $order = "ASC"; if ($this->_getParam("dir")) { $order = $this->_getParam("dir"); } if ($this->_getParam("sort")) { $orderKey = $this->_getParam("sort"); } if ($this->_getParam("limit")) { $limit = $this->_getParam("limit"); } if ($this->_getParam("start")) { $start = $this->_getParam("start"); } if ($this->_getParam("overrideSort") == "true") { $orderKey = "id"; $order = "DESC"; } $list = new Classificationstore\GroupConfig\Listing(); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $condition = ""; if ($this->_getParam("filter")) { $filterString = $this->_getParam("filter"); $filters = json_decode($filterString); $db = Resource::get(); $count = 0; foreach ($filters as $f) { if ($count > 0) { $condition .= " OR "; } $count++; $condition .= $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } } if ($this->getParam("oid")) { $object = Object_Concrete::getById($this->getParam("oid")); $class = $object->getClass(); $fd = $class->getFieldDefinition($this->getParam("fieldname")); $allowedGroupIds = $fd->getAllowedGroupIds(); if ($allowedGroupIds) { if ($condition) { $condition = "(" . $condition . ") AND "; } $condition .= "ID in (" . implode(",", $allowedGroupIds) . ")"; } } $list->setCondition($condition); $list->load(); $configList = $list->getList(); $rootElement = array(); $data = array(); foreach ($configList as $config) { $name = $config->getName(); if (!$name) { $name = "EMPTY"; } $item = array("id" => $config->getId(), "name" => $name, "description" => $config->getDescription()); if ($config->getCreationDate()) { $item["creationDate"] = $config->getCreationDate(); } if ($config->getModificationDate()) { $item["modificationDate"] = $config->getModificationDate(); } $data[] = $item; } $rootElement["data"] = $data; $rootElement["success"] = true; $rootElement["total"] = $list->getTotalCount(); return $this->_helper->json($rootElement); } }