public function save(Object_Concrete $object) { $tableName = $this->model->getDefinition()->getTableName($object->getClass()); $data = array("o_id" => $object->getId(), "index" => $this->model->getIndex(), "fieldname" => $this->model->getFieldname()); try { foreach ($this->model->getDefinition()->getFieldDefinitions() as $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); } else { if ($fd->getColumnType()) { if (is_array($fd->getColumnType())) { $insertDataArray = $fd->getDataForResource($this->model->{$getter}(), $object); $data = array_merge($data, $insertDataArray); } else { $data[$fd->getName()] = $fd->getDataForResource($this->model->{$getter}(), $object); } } } } $this->db->insert($tableName, $data); } catch (Exception $e) { throw $e; } }
/** * @param Object_Concrete $object * @return array */ public function load(Object_Concrete $object) { $fieldDef = $object->getClass()->getFieldDefinition($this->model->getFieldname()); $values = array(); foreach ($fieldDef->getAllowedTypes() as $type) { try { $definition = Object_Objectbrick_Definition::getByKey($type); } catch (Exception $e) { continue; } $tableName = $definition->getTableName($object->getClass(), false); try { $results = $this->db->fetchAll("SELECT * FROM " . $tableName . " WHERE o_id = ? AND fieldname = ?", array($object->getId(), $this->model->getFieldname())); } catch (Exception $e) { $results = array(); } //$allRelations = $this->db->fetchAll("SELECT * FROM object_relations_" . $object->getO_classId() . " WHERE src_id = ? AND ownertype = 'objectbrick' AND ownername = ?", array($object->getO_id(), $this->model->getFieldname())); $fieldDefinitions = $definition->getFieldDefinitions(); $brickClass = "Object_Objectbrick_Data_" . ucfirst($type); foreach ($results as $result) { $brick = new $brickClass($object); $brick->setFieldname($result["fieldname"]); $brick->setObject($object); foreach ($fieldDefinitions as $key => $fd) { /*if ($fd->isRelationType()) { $relations = array(); foreach ($allRelations as $relation) { if ($relation["fieldname"] == $key) { $relations[] = $relation; } } $brick->setValue( $key, $fd->getDataFromResource($relations)); }*/ if (method_exists($fd, "load")) { // datafield has it's own loader $value = $fd->load($brick); if ($value === 0 || !empty($value)) { $brick->setValue($key, $value); } } else { if (is_array($fd->getColumnType())) { $multidata = array(); foreach ($fd->getColumnType() as $fkey => $fvalue) { $multidata[$key . "__" . $fkey] = $result[$key . "__" . $fkey]; } $brick->setValue($key, $fd->getDataFromResource($multidata)); } else { $brick->setValue($key, $fd->getDataFromResource($result[$key])); } } } $setter = "set" . ucfirst($type); $this->model->{$setter}($brick); $values[] = $brick; } } return $values; }
/** * @static * @return bool */ public static function doGetInheritedValues(Object_Concrete $object = null) { if (self::$getInheritedValues && $object !== null) { $class = $object->getClass(); return $class->getAllowInherit(); } return self::$getInheritedValues; }
/** * 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; }
public function delete(Object_Concrete $object) { // empty or create all relevant tables $fieldDef = $object->getClass()->getFieldDefinition($this->model->getFieldname()); foreach ($fieldDef->getAllowedTypes() as $type) { try { $definition = Object_Fieldcollection_Definition::getByKey($type); } catch (Exception $e) { continue; } $tableName = $definition->getTableName($object->getClass()); try { $this->db->delete($tableName, $this->db->quoteInto("o_id = ?", $object->getId()) . " AND " . $this->db->quoteInto("fieldname = ?", $this->model->getFieldname())); } catch (Exception $e) { // create definition if it does not exist $definition->createUpdateTable($object->getClass()); } } // empty relation table $this->db->delete("object_relations_" . $object->getO_classId(), "ownertype = 'fieldcollection' AND " . $this->db->quoteInto("ownername = ?", $this->model->getFieldname()) . " AND " . $this->db->quoteInto("src_id = ?", $object->getId())); }
/** * @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; } }
/** * @param Object_Concrete $object * @return Object_Concrete */ protected function getLatestVersion(Object_Concrete $object) { $modificationDate = $object->getModificationDate(); $latestVersion = $object->getLatestVersion(); if ($latestVersion) { $latestObj = $latestVersion->loadData(); if ($latestObj instanceof Object_Concrete) { $object = $latestObj; $object->setModificationDate($modificationDate); // set de modification-date from published version to compare it in js-frontend } } return $object; }
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); }
/** * @param mixed $data * @param Object_Concrete $ownerObject * @param array $blockedTags */ public function getCacheTags($data, $ownerObject, $tags = array()) { $tags = is_array($tags) ? $tags : array(); if (is_array($data) && count($data) > 0) { foreach ($data as $object) { if (!array_key_exists($object->getCacheTag(), $tags)) { if (!$ownerObject instanceof Element_Interface || $object->getId() != $ownerObject->getId()) { $tags = $object->getCacheTags($tags); } } } } return $tags; }
/** * @param Object_Concrete|Object_Fieldcollection_Data_Abstract|Object_Localizedfield $object * @return null | array */ public function load($object, $params = array()) { $db = Pimcore_Resource::get(); if ($object instanceof Object_Concrete) { if (!method_exists($this, "getLazyLoading") or !$this->getLazyLoading() or $params["force"]) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'object' ORDER BY `index` ASC", array($object->getO_id(), $this->getName())); return $this->getDataFromResource($relations); } else { return null; } } else { if ($object instanceof Object_Fieldcollection_Data_Abstract) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'fieldcollection' AND ownername = ? AND position = ? ORDER BY `index` ASC", array($object->getObject()->getId(), $this->getName(), $object->getFieldname(), $object->getIndex())); return $this->getDataFromResource($relations); } else { if ($object instanceof Object_Localizedfield) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'localizedfield' AND ownername = 'localizedfield' AND position = ? ORDER BY `index` ASC", array($object->getObject()->getId(), $this->getName(), $params["language"])); return $this->getDataFromResource($relations); } else { if ($object instanceof Object_Objectbrick_Data_Abstract) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'objectbrick' AND ownername = ? ORDER BY `index` ASC", array($object->getObject()->getId(), $this->getName(), $object->getFieldname())); return $this->getDataFromResource($relations); } } } } }
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())); } }
/** * @param Object_Concrete $object * @return void */ public function delete(Object_Concrete $object) { // update data for store table $tableName = $this->model->getDefinition()->getTableName($object->getClass(), false); $this->db->delete($tableName, $this->db->quoteInto("o_id = ?", $object->getId())); // update data for query table $tableName = $this->model->getDefinition()->getTableName($object->getClass(), true); $this->db->delete($tableName, $this->db->quoteInto("o_id = ?", $object->getId())); //update data for relations table $this->db->delete("object_relations_" . $object->getO_classId(), "src_id = " . $object->getId() . " AND ownertype = 'objectbrick' AND ownername = '" . $this->model->getFieldname() . "'"); }
/** * @param Object_Concrete|Object_Fieldcollection_Data_Abstract|Object_Localizedfield $object * @return null | array */ public function load($object, $params = array()) { $db = Pimcore_Resource::get(); $data = null; if ($object instanceof Object_Concrete) { if (!method_exists($this, "getLazyLoading") or !$this->getLazyLoading() or $params["force"]) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'object'", array($object->getO_id(), $this->getName())); } else { return null; } } else { if ($object instanceof Object_Fieldcollection_Data_Abstract) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'fieldcollection' AND ownername = ? AND position = ?", array($object->getObject()->getId(), $this->getName(), $object->getFieldname(), $object->getIndex())); } else { if ($object instanceof Object_Localizedfield) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'localizedfield' AND ownername = 'localizedfield' AND position = ?", array($object->getObject()->getId(), $this->getName(), $params["language"])); } else { if ($object instanceof Object_Objectbrick_Data_Abstract) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'objectbrick' AND ownername = ? AND position = ?", array($object->getObject()->getId(), $this->getName(), $object->getFieldname(), $object->getType())); // THIS IS KIND A HACK: it's necessary because of this bug PIMCORE-1454 and therefore cannot be removed if (count($relations) < 1) { $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'objectbrick' AND ownername = ? AND (position IS NULL OR position = '')", array($object->getObject()->getId(), $this->getName(), $object->getFieldname())); } // HACK END } } } } // using PHP sorting to order the relations, because "ORDER BY index ASC" in the queries above will cause a // filesort in MySQL which is extremly slow especially when there are millions of relations in the database usort($relations, function ($a, $b) { if ($a["index"] == $b["index"]) { return 0; } return $a["index"] < $b["index"] ? -1 : 1; }); $data = $this->getDataFromResource($relations); return $data; }
/** * @param Object_Concrete $object * @return void */ public function delete($object) { $db = Pimcore_Resource::get(); $db->delete("object_metadata_" . $object->getO_classId(), $db->quoteInto("o_id = ?", $object->getId()) . " AND " . $db->quoteInto("fieldname = ?", $this->getName())); }
/** * call the getters of each object field, in case some of the are lazy loading and we need the data to be loaded * * @static * @param Object_Concrete $object * @return void */ public static function loadAllObjectFields($object) { if ($object instanceof Object_Concrete) { //load all in case of lazy loading fields $fd = $object->getO_class()->getFieldDefinitions(); foreach ($fd as $def) { $getter = "get" . ucfirst($def->getName()); if (method_exists($object, $getter)) { $object->{$getter}(); } } } }
/** * @param mixed $data * @param Object_Concrete $ownerObject * @param array $blockedTags */ public function getCacheTags($data, $ownerObject, $tags = array()) { $tags = is_array($tags) ? $tags : array(); if ($data instanceof Document || $data instanceof Asset || $data instanceof Object_Abstract) { if (!array_key_exists($data->getCacheTag(), $tags)) { if (!$ownerObject instanceof Element_Interface || $data->getId() != $ownerObject->getId()) { $tags = $data->getCacheTags($tags); } } } return $tags; }
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); } }