Inheritance: extends AbstractObject
 /**
  * @param Model\Object\Concrete $object
  * @throws \Exception
  */
 public function save(Model\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;
     }
 }
Beispiel #2
0
 /**
  * @throws \Exception
  * @param Object\Concrete $object
  * @return void
  */
 public function delete(Object\Concrete $object)
 {
     // this is to clean up also the inherited values
     $fieldDef = $object->getClass()->getFieldDefinition($this->model->getFieldname());
     foreach ($fieldDef->getAllowedTypes() as $type) {
         try {
             $definition = Object\Objectbrick\Definition::getByKey($type);
         } catch (\Exception $e) {
             continue;
         }
         $tableName = $definition->getTableName($object->getClass(), true);
         $this->db->delete($tableName, "o_id = " . $object->getId());
     }
 }
 /**
  * @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 = "\\Pimcore\\Model\\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 (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;
 }
 /**
  * @param $name
  * @param null $language
  * @return 
  */
 public function getLocalizedValue($name, $language = null, $ignoreFallbackLanguage = false)
 {
     $data = null;
     $language = $this->getLanguage($language);
     $fieldDefinition = $this->getObject()->getClass()->getFieldDefinition("localizedfields")->getFieldDefinition($name);
     if ($fieldDefinition instanceof Model\Object\ClassDefinition\Data\CalculatedValue) {
         $valueData = new Model\Object\Data\CalculatedValue($fieldDefinition->getName());
         $valueData->setContextualData("localizedfield", "localizedfields", null, $language);
         $data = Service::getCalculatedFieldValue($this->getObject(), $valueData);
         return $data;
     }
     if ($this->languageExists($language)) {
         if (array_key_exists($name, $this->items[$language])) {
             $data = $this->items[$language][$name];
         }
     }
     // check for inherited value
     $doGetInheritedValues = AbstractObject::doGetInheritedValues();
     if ($fieldDefinition->isEmpty($data) && $doGetInheritedValues) {
         $object = $this->getObject();
         $class = $object->getClass();
         $allowInherit = $class->getAllowInherit();
         if ($allowInherit) {
             if ($object->getParent() instanceof AbstractObject) {
                 $parent = $object->getParent();
                 while ($parent && $parent->getType() == "folder") {
                     $parent = $parent->getParent();
                 }
                 if ($parent && ($parent->getType() == "object" || $parent->getType() == "variant")) {
                     if ($parent->getClassId() == $object->getClassId()) {
                         $method = "getLocalizedfields";
                         if (method_exists($parent, $method)) {
                             $localizedFields = $parent->getLocalizedFields();
                             if ($localizedFields instanceof Localizedfield) {
                                 if ($localizedFields->object->getId() != $this->object->getId()) {
                                     $data = $localizedFields->getLocalizedValue($name, $language, true);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // check for fallback value
     if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) {
         foreach (Tool::getFallbackLanguagesFor($language) as $l) {
             if ($this->languageExists($l)) {
                 if (array_key_exists($name, $this->items[$l])) {
                     $data = $this->getLocalizedValue($name, $l);
                 }
             }
         }
     }
     if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) {
         $data = $fieldDefinition->preGetData($this, array("data" => $data, "language" => $language, "name" => $name));
     }
     return $data;
 }
Beispiel #5
0
 /**
  * @static
  * @return bool
  */
 public static function doGetInheritedValues(Concrete $object = null)
 {
     if (self::$getInheritedValues && $object !== null) {
         $class = $object->getClass();
         return $class->getAllowInherit();
     }
     return self::$getInheritedValues;
 }
Beispiel #6
0
 /**
  * @param $keyId
  * @param $groupId
  * @param string $language
  * @param bool|false $ignoreFallbackLanguage
  * @return null
  */
 public function getLocalizedKeyValue($groupId, $keyId, $language = "default", $ignoreFallbackLanguage = false, $ignoreDefaultLanguage = false)
 {
     $oid = $this->object->getId();
     $keyConfig = Model\Object\Classificationstore\DefinitionCache::get($keyId);
     if ($keyConfig->getType() == "calculatedValue") {
         $data = new Model\Object\Data\CalculatedValue($this->getFieldname());
         $childDef = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
         $data->setContextualData("classificationstore", $this->getFieldname(), null, $language, $groupId, $keyId, $childDef);
         $data = Model\Object\Service::getCalculatedFieldValueForEditMode($this->getObject(), $data);
         return $data;
     }
     $fieldDefinition = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
     $language = $this->getLanguage($language);
     $data = null;
     if (array_key_exists($groupId, $this->items) && array_key_exists($keyId, $this->items[$groupId]) && array_key_exists($language, $this->items[$groupId][$keyId])) {
         $data = $this->items[$groupId][$keyId][$language];
     }
     // check for fallback value
     if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) {
         $data = $this->getFallbackValue($groupId, $keyId, $language, $fieldDefinition);
     }
     if ($fieldDefinition->isEmpty($data) && !$ignoreDefaultLanguage && $language != "default") {
         $data = $this->items[$groupId][$keyId]["default"];
     }
     // check for inherited value
     $doGetInheritedValues = AbstractObject::doGetInheritedValues();
     if ($fieldDefinition->isEmpty($data) && $doGetInheritedValues) {
         $object = $this->getObject();
         $class = $object->getClass();
         $allowInherit = $class->getAllowInherit();
         if ($allowInherit) {
             if ($object->getParent() instanceof AbstractObject) {
                 $parent = $object->getParent();
                 while ($parent && $parent->getType() == "folder") {
                     $parent = $parent->getParent();
                 }
                 if ($parent && ($parent->getType() == "object" || $parent->getType() == "variant")) {
                     if ($parent->getClassId() == $object->getClassId()) {
                         $method = "getLocalizedfields";
                         if (method_exists($parent, $method)) {
                             $getter = "get" . ucfirst($this->fieldname);
                             $classificationStore = $parent->{$getter}();
                             if ($classificationStore instanceof Classificationstore) {
                                 if ($classificationStore->object->getId() != $this->object->getId()) {
                                     $data = $classificationStore->getLocalizedKeyValue($groupId, $keyId, $language, false);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) {
         $data = $fieldDefinition->preGetData($this, array("data" => $data, "language" => $language, "name" => $groupId . "-" . $keyId));
     }
     return $data;
 }
Beispiel #7
0
 /**
  * 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 = '';
     $object = is_object($this->getValue()) ? $this->getValue() : Model\Object\Concrete::getById($this->getValue());
     if ($object) {
         if (is_string($this->getPlaceholderConfig()->method) && method_exists($object, $this->getPlaceholderConfig()->method)) {
             $string = $object->{$this->getPlaceholderConfig()->method}($this->getLocale());
         }
     }
     return $string;
 }
Beispiel #8
0
 /**
  * @param Model\Tool\Newsletter\Config $newsletter
  * @param Object\Concrete $object
  */
 public static function sendMail($newsletter, $object, $emailAddress = null, $hostUrl = null)
 {
     $params = ["gender" => $object->getGender(), 'firstname' => $object->getFirstname(), 'lastname' => $object->getLastname(), "email" => $object->getEmail(), 'token' => $object->getProperty("token"), "object" => $object];
     $mail = new Mail();
     $mail->setIgnoreDebugMode(true);
     if (\Pimcore\Config::getSystemConfig()->newsletter->usespecific) {
         $mail->init("newsletter");
     }
     if (!Tool::getHostUrl() && $hostUrl) {
         $mail->setHostUrl($hostUrl);
     }
     if ($emailAddress) {
         $mail->addTo($emailAddress);
     } else {
         $mail->addTo($object->getEmail());
     }
     $mail->setDocument(Document::getById($newsletter->getDocument()));
     $mail->setParams($params);
     // render the document and rewrite the links (if analytics is enabled)
     if ($newsletter->getGoogleAnalytics()) {
         if ($content = $mail->getBodyHtmlRendered()) {
             include_once "simple_html_dom.php";
             $html = str_get_html($content);
             if ($html) {
                 $links = $html->find("a");
                 foreach ($links as $link) {
                     if (preg_match("/^(mailto)/", trim(strtolower($link->href)))) {
                         continue;
                     }
                     $glue = "?";
                     if (strpos($link->href, "?")) {
                         $glue = "&";
                     }
                     $link->href = $link->href . $glue . "utm_source=Newsletter&utm_medium=Email&utm_campaign=" . $newsletter->getName();
                 }
                 $content = $html->save();
                 $html->clear();
                 unset($html);
             }
             $mail->setBodyHtml($content);
         }
     }
     $mail->send();
 }
Beispiel #9
0
 public function testAction()
 {
     //        $t = new OnlineShop_Framework_AbstractProduct();
     //        p_r($t);
     $x = OnlineShop_Framework_Factory::getInstance();
     //        p_r($x);
     $e = $x->getEnvironment();
     $e->setCurrentUserId(-1);
     p_r($e);
     //        p_r($e->getAllCustomItems());
     $cm = $x->getCartManager();
     //        $key = $cm->createCart(array("name" => "mycart"));
     $cm->addToCart(\Pimcore\Model\Object\Concrete::getById(430), 4, 14, array());
     //array("key" => 'mycart', "itemid" => 4459, "count" => 4));
     //        $e->setCustomItem("myitem2", "88776688");
     //        $e->save();
     $e = $x->getEnvironment();
     p_r($e);
     $x->saveState();
     //        $p = new OnlineShop_Plugin();
     //        p_r($p);
     die("meins");
 }
 /**
  * @param Object\Concrete $object
  * @return void
  */
 public function delete($object)
 {
     $db = Resource::get();
     $db->delete("object_metadata_" . $object->getClassId(), $db->quoteInto("o_id = ?", $object->getId()) . " AND " . $db->quoteInto("fieldname = ?", $this->getName()));
 }
Beispiel #11
0
 /** Calculates the super layout definition for the given object.
  * @param Concrete $object
  * @return mixed
  */
 public static function getSuperLayoutDefinition(Concrete $object)
 {
     $masterLayout = $object->getClass()->getLayoutDefinitions();
     $superLayout = unserialize(serialize($masterLayout));
     self::createSuperLayout($superLayout);
     return $superLayout;
 }
Beispiel #12
0
 /**
  * @param $object
  * @param $data Model\Object\Data\CalculatedValue
  * @return mixed|null
  */
 public static function getCalculatedFieldValue($object, $data)
 {
     if (!$data) {
         return null;
     }
     $fieldname = $data->getFieldname();
     $ownerType = $data->getOwnerType();
     /** @var $fd Model\Object\ClassDefinition\Data\CalculatedValue */
     if ($ownerType == "object") {
         $fd = $object->getClass()->getFieldDefinition($fieldname);
     } else {
         if ($ownerType == "localizedfield") {
             $fd = $object->getClass()->getFieldDefinition("localizedfields")->getFieldDefinition($fieldname);
         } else {
             if ($ownerType == "classificationstore") {
                 $fd = $data->getKeyDefinition();
             } else {
                 if ($ownerType == "fieldcollection" || $ownerType == "objectbrick") {
                     $fd = $data->getKeyDefinition();
                 }
             }
         }
     }
     if (!$fd) {
         return null;
     }
     $className = $fd->getCalculatorClass();
     if (!$className || !\Pimcore\Tool::classExists($className)) {
         \Logger::error("Class does not exsist: " . $className);
         return null;
     }
     if (method_exists($className, 'compute')) {
         $inheritanceEnabled = Model\Object\Concrete::getGetInheritedValues();
         Model\Object\Concrete::setGetInheritedValues(true);
         $result = call_user_func($className . '::compute', $object, $data);
         Model\Object\Concrete::setGetInheritedValues($inheritanceEnabled);
         return $result;
     }
     return null;
 }
Beispiel #13
0
 public function getNicePathAction()
 {
     $source = \Zend_Json::decode($this->getParam("source"));
     if ($source["type"] != "object") {
         throw new \Exception("currently only objects as source elements are supported");
     }
     $result = [];
     $id = $source["id"];
     $source = Object\Concrete::getById($id);
     if ($this->getParam("context")) {
         $context = \Zend_Json::decode($this->getParam("context"));
     } else {
         $context = [];
     }
     $ownerType = $context["containerType"];
     $fieldname = $context["fieldname"];
     if ($ownerType == "object") {
         $fd = $source->getClass()->getFieldDefinition($fieldname);
     } elseif ($ownerType == "localizedfield") {
         $fd = $source->getClass()->getFieldDefinition("localizedfields")->getFieldDefinition($fieldname);
     } elseif ($ownerType == "objectbrick") {
         $fdBrick = Object\Objectbrick\Definition::getByKey($context["containerKey"]);
         $fd = $fdBrick->getFieldDefinition($fieldname);
     } elseif ($ownerType == "fieldcollection") {
         $containerKey = $context["containerKey"];
         $fdCollection = Object\Fieldcollection\Definition::getByKey($containerKey);
         if ($context["subContainerType"] == "localizedfield") {
             $fdLocalizedFields = $fdCollection->getFieldDefinition("localizedfields");
             $fd = $fdLocalizedFields->getFieldDefinition($fieldname);
         } else {
             $fd = $fdCollection->getFieldDefinition($fieldname);
         }
     }
     if (method_exists($fd, "getPathFormatterClass")) {
         $formatterClass = $fd->getPathFormatterClass();
         if (Pimcore\Tool::classExists($formatterClass)) {
             $targets = \Zend_Json::decode($this->getParam("targets"));
             $result = call_user_func($formatterClass . "::formatPath", $result, $source, $targets, ["fd" => $fd, "context" => $context]);
         } else {
             Logger::error("Formatter Class does not exist: " . $formatterClass);
         }
     }
     $this->_helper->json(["success" => true, "data" => $result]);
 }
Beispiel #14
0
 /**
  * @param $id
  *
  * @return \Pimcore\Model\Object\Concrete|null
  */
 protected function loadProduct($id)
 {
     return \Pimcore\Model\Object\Concrete::getById($id);
 }
Beispiel #15
0
 /**
  * @param Object\Concrete $object
  * @return void
  */
 public function delete($object, $params = [])
 {
     $db = Db::get();
     if ($params && $params["context"] && $params["context"]["containerType"] == "fieldcollection" && $params["context"]["subContainerType"] == "localizedfield") {
         $context = $params["context"];
         $index = $context["index"];
         $containerName = $context["fieldname"];
         $db->delete("object_metadata_" . $object->getClassId(), $db->quoteInto("o_id = ?", $object->getId()) . " AND ownertype = 'localizedfield' AND " . $db->quoteInto("ownername LIKE ?", "/fieldcollection~" . $containerName . "/" . $index . "/%") . " AND " . $db->quoteInto("fieldname = ?", $this->getName()));
     } else {
         $db->delete("object_metadata_" . $object->getClassId(), $db->quoteInto("o_id = ?", $object->getId()) . " AND " . $db->quoteInto("fieldname = ?", $this->getName()));
     }
 }
 /**
  * enables inheritance for field collections, if xxxInheritance field is available and set to string 'true'
  *
  * @param string $key
  * @return mixed|\Pimcore\Model\Object\Fieldcollection
  */
 public function preGetValue($key)
 {
     if ($this->getClass()->getAllowInherit() && \Pimcore\Model\Object\AbstractObject::doGetInheritedValues() && $this->getClass()->getFieldDefinition($key) instanceof \Pimcore\Model\Object\ClassDefinition\Data\Fieldcollections) {
         $checkInheritanceKey = $key . "Inheritance";
         if ($this->{'get' . $checkInheritanceKey}() == "true") {
             $parentValue = $this->getValueFromParent($key);
             $data = $this->{$key};
             if (!$data) {
                 $data = $this->getClass()->getFieldDefinition($key)->preGetData($this);
             }
             if (!$data) {
                 return $parentValue;
             } else {
                 if (!empty($parentValue)) {
                     $value = new \Pimcore\Model\Object\Fieldcollection($parentValue->getItems());
                     if (!empty($data)) {
                         foreach ($data as $entry) {
                             $value->add($entry);
                         }
                     }
                 } else {
                     $value = new \Pimcore\Model\Object\Fieldcollection($data->getItems());
                 }
                 return $value;
             }
         }
     }
     return parent::preGetValue($key);
 }
Beispiel #17
0
 public function testmagicAction()
 {
     $obj = Object\Concrete::getById(61071);
     $pairs = $obj->getKeyValuePairs();
     $value = $pairs->getab123();
     \Logger::debug("value=" . $value);
     $pairs->setab123("new valuexyz");
     $pairs->setdddd("dvalue");
     $obj->save();
 }
 /**
  * @param Object\Concrete $object
  */
 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->getClassId(), "ownertype = 'fieldcollection' AND " . $this->db->quoteInto("ownername = ?", $this->model->getFieldname()) . " AND " . $this->db->quoteInto("src_id = ?", $object->getId()));
 }
Beispiel #19
0
 /**
  * @param  Document|Asset|ConcreteObject $element
  * @return Document|Asset|ConcreteObject
  */
 protected function getLatestVersion($element)
 {
     //TODO move this maybe to a service method, since this is also used in ObjectController and DocumentControllers
     if ($element instanceof Document) {
         $latestVersion = $element->getLatestVersion();
         if ($latestVersion) {
             $latestDoc = $latestVersion->loadData();
             if ($latestDoc instanceof Document) {
                 $element = $latestDoc;
                 $element->setModificationDate($element->getModificationDate());
             }
         }
     }
     if ($element instanceof Object\Concrete) {
         $modificationDate = $element->getModificationDate();
         $latestVersion = $element->getLatestVersion();
         if ($latestVersion) {
             $latestObj = $latestVersion->loadData();
             if ($latestObj instanceof ConcreteObject) {
                 $element = $latestObj;
                 $element->setModificationDate($modificationDate);
             }
         }
     }
     return $element;
 }
 /**
  * @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;
 }
Beispiel #21
0
 /**
  * @param Object\Concrete $object
  */
 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 {
             /** @var  $definition Definition */
             $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());
         }
         if ($definition->getFieldDefinition("localizedfields")) {
             $tableName = $definition->getLocalizedTableName($object->getClass());
             try {
                 $this->db->delete($tableName, $this->db->quoteInto("ooo_id = ?", $object->getId()) . " AND " . $this->db->quoteInto("fieldname = ?", $this->model->getFieldname()));
             } catch (\Exception $e) {
                 \Logger::error($e);
             }
         }
         $childDefinitions = $definition->getFielddefinitions();
         if (is_array($childDefinitions)) {
             foreach ($childDefinitions as $fd) {
                 if (method_exists($fd, "delete")) {
                     $fd->delete($object, ["context" => ["containerType" => "fieldcollection", "containerKey" => $type, "fieldname" => $this->model->getFieldname()]]);
                 }
             }
         }
     }
     // empty relation table
     $this->db->delete("object_relations_" . $object->getClassId(), "(ownertype = 'fieldcollection' AND " . $this->db->quoteInto("ownername = ?", $this->model->getFieldname()) . " AND " . $this->db->quoteInto("src_id = ?", $object->getId()) . ")" . " OR (ownertype = 'localizedfield' AND " . $this->db->quoteInto("ownername LIKE ?", "/fieldcollection~" . $this->model->getFieldname() . "/%") . ")");
 }
Beispiel #22
0
 /**
  * @param $id
  *
  * @return \Pimcore\Model\Object\Concrete|null
  */
 protected function loadCategory($id)
 {
     return \Pimcore\Model\Object\Concrete::getById($id);
 }
Beispiel #23
0
 protected function checkcredential(Concrete $identity)
 {
     /** @var \Pimcore\Model\Object\ClassDefinition\Data\Password $credentialField */
     $credentialField = $identity->getClass()->getFieldDefinition($this->credentialColumn);
     $hashed = $credentialField->getDataForResource($this->credential);
     return $hashed === $identity->{$this->credentialColumn};
 }
Beispiel #24
0
 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");
         }
     }
 }
Beispiel #25
0
 /**
  * @param Object\Concrete $object
  * @return void
  */
 public function delete(Object\Concrete $object)
 {
     // update data for store table
     $storeTable = $this->model->getDefinition()->getTableName($object->getClass(), false);
     $this->db->delete($storeTable, $this->db->quoteInto("o_id = ?", $object->getId()));
     // update data for query table
     $queryTable = $this->model->getDefinition()->getTableName($object->getClass(), true);
     $oldData = $this->db->fetchRow("SELECT * FROM " . $queryTable . " WHERE o_id = ?", $object->getId());
     $this->db->delete($queryTable, $this->db->quoteInto("o_id = ?", $object->getId()));
     //update data for relations table
     $this->db->delete("object_relations_" . $object->getClassId(), "src_id = " . $object->getId() . " AND ownertype = 'objectbrick' AND ownername = '" . $this->model->getFieldname() . "' AND position = '" . $this->model->getType() . "'");
     $this->inheritanceHelper = new Object\Concrete\Dao\InheritanceHelper($object->getClassId(), "o_id", $storeTable, $queryTable);
     $this->inheritanceHelper->resetFieldsToCheck();
     $objectVars = get_object_vars($this->model);
     foreach ($objectVars as $key => $value) {
         $fd = $this->model->getDefinition()->getFieldDefinition($key);
         if ($fd) {
             if ($fd->getQueryColumnType()) {
                 //exclude untouchables if value is not an array - this means data has not been loaded
                 //get changed fields for inheritance
                 if ($fd instanceof Object\ClassDefinition\Data\CalculatedValue) {
                     continue;
                 }
                 if ($fd->isRelationType()) {
                     if ($oldData[$key] != null) {
                         $this->inheritanceHelper->addRelationToCheck($key, $fd);
                     }
                 } else {
                     if ($oldData[$key] != null) {
                         $this->inheritanceHelper->addFieldToCheck($key, $fd);
                     }
                 }
                 if (method_exists($fd, "delete")) {
                     $fd->delete($object);
                 }
             }
         }
     }
     $this->inheritanceHelper->doDelete($object->getId());
     $this->inheritanceHelper->resetFieldsToCheck();
 }
Beispiel #26
0
 /**
  *
  * Performs an action
  *
  * @param mixed $actionName
  * @param array $formData
  * @throws \Exception
  */
 public function performAction($actionName, $formData = [])
 {
     //store the current action data
     $this->setActionData($formData);
     \Pimcore::getEventManager()->trigger("workflowmanagement.preAction", $this, ['actionName' => $actionName]);
     //refresh the local copy after the event
     $formData = $this->getActionData();
     $actionConfig = $this->workflow->getActionConfig($actionName, $this->getElementStatus());
     $additional = $formData['additional'];
     //setup event listeners
     $this->registerActionEvents($actionConfig);
     //setup an array to hold the additional data that is not saved via a setterFn
     $actionNoteData = [];
     //process each field in the additional fields configuration
     if (isset($actionConfig['additionalFields']) && is_array($actionConfig['additionalFields'])) {
         foreach ($actionConfig['additionalFields'] as $additionalFieldConfig) {
             /**
             * Additional Field example
             * [
                             'name' => 'dateLastContacted',
                             'fieldType' => 'date',
                             'label' => 'Date of Conversation',
                             'required' => true,
                             'setterFn' => ''
                             ]
             */
             $fieldName = $additionalFieldConfig['name'];
             //check required
             if ($additionalFieldConfig['required'] && empty($additional[$fieldName])) {
                 throw new \Exception("Workflow::performAction, fieldname [{$fieldName}] required for action [{$actionName}]");
             }
             //work out whether or not to set the value directly to the object or to add it to the note data
             if (!empty($additionalFieldConfig['setterFn'])) {
                 $setter = $additionalFieldConfig['setterFn'];
                 try {
                     //todo check here that the setter is being called on an Object
                     //TODO check that the field has a fieldType, (i.e if a workflow config has getter then the field should only be a pimcore tag and therefore 'fieldType' rather than 'type'.
                     //otherwise we could be erroneously setting pimcore fields
                     $additional[$fieldName] = Workflow\Service::getDataFromEditmode($additional[$fieldName], $additionalFieldConfig['fieldType']);
                     $this->element->{$setter}($additional[$fieldName]);
                 } catch (\Exception $e) {
                     Logger::error($e->getMessage());
                     throw new \Exception("Workflow::performAction, cannot set fieldname [{$fieldName}] using setter [{$setter}] in action [{$actionName}]");
                 }
             } else {
                 $actionNoteData[] = Workflow\Service::createNoteData($additionalFieldConfig, $additional[$fieldName]);
             }
         }
     }
     //save the old state and status in the form so that we can reference it later
     $formData['oldState'] = $this->getElementState();
     $formData['oldStatus'] = $this->getElementStatus();
     if ($this->element instanceof Concrete || $this->element instanceof Document\PageSnippet) {
         if (!$this->workflow->getAllowUnpublished() || in_array($this->getElementStatus(), $this->workflow->getPublishedStatuses())) {
             $this->element->setPublished(true);
             if ($this->element instanceof Concrete) {
                 $this->element->setOmitMandatoryCheck(false);
             }
             $task = 'publish';
         } else {
             $this->element->setPublished(false);
             if ($this->element instanceof Concrete) {
                 $this->element->setOmitMandatoryCheck(true);
             }
             $task = 'unpublish';
         }
     } else {
         //all other elements do not support published or unpublished
         $task = "publish";
     }
     try {
         $response = \Pimcore::getEventManager()->trigger("workflowmanagement.action.before", $this, ['actionConfig' => $actionConfig, 'data' => $formData]);
         //todo add some support to stop the action given the result from the event
         $this->element->setUserModification($this->user->getId());
         if ($task === "publish" && $this->element->isAllowed("publish") || $task === "unpublish" && $this->element->isAllowed("unpublish")) {
             $this->element->save();
         } elseif ($this->element instanceof Concrete || $this->element instanceof Document\PageSnippet) {
             $this->element->saveVersion();
         } else {
             throw new \Exception("Operation not allowed for this element");
         }
         //transition the element
         $this->setElementState($formData['newState']);
         $this->setElementStatus($formData['newStatus']);
         // record a note against the object to show the transition
         $decorator = new Workflow\Decorator($this->workflow);
         $description = $formData['notes'];
         // create a note for this action
         $note = Workflow\Service::createActionNote($this->element, $decorator->getNoteType($actionName, $formData), $decorator->getNoteTitle($actionName, $formData), $description, $actionNoteData);
         //notify users
         if (isset($actionConfig['notificationUsers']) && is_array($actionConfig['notificationUsers'])) {
             Workflow\Service::sendEmailNotification($actionConfig['notificationUsers'], $note);
         }
         \Pimcore::getEventManager()->trigger("workflowmanagement.action.success", $this, ['actionConfig' => $actionConfig, 'data' => $formData]);
     } catch (\Exception $e) {
         \Pimcore::getEventManager()->trigger("workflowmanagement.action.failure", $this, ['actionConfig' => $actionConfig, 'data' => $formData, 'exception' => $e]);
     }
     $this->unregisterActionEvents();
     \Pimcore::getEventManager()->trigger("workflowmanagement.postAction", $this, ['actionName' => $actionName]);
 }
Beispiel #27
0
 /**
  * @param $id
  * @throws \Exception
  */
 public function getObjectMetadataById($id)
 {
     try {
         $object = Object\Concrete::getById($id);
         if ($object instanceof Object\Concrete) {
             // load all data (eg. lazy loaded fields like multihref, object, ...)
             $classId = $object->getClassId();
             return $this->getClassById($classId);
         }
         throw new \Exception("Object with given ID (" . $id . ") does not exist.");
     } catch (\Exception $e) {
         \Logger::error($e);
         throw $e;
     }
 }
 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 = [];
         $groupsData = $db->fetchAll($query);
         foreach ($groupsData as $groupData) {
             $mappedData[$groupData["id"]] = $groupData;
         }
         $groupIdList = [];
         $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;
             }
         }
         if ($groupIdList) {
             $groupList = new Classificationstore\GroupConfig\Listing();
             $groupCondition = "id in (" . implode(",", $groupIdList) . ")";
             $groupList->setCondition($groupCondition);
             $groupList = $groupList->load();
             $keyCondition = "groupId in (" . implode(",", $groupIdList) . ")";
             $keyList = new Classificationstore\KeyGroupRelation\Listing();
             $keyList->setCondition($keyCondition);
             $keyList->setOrderKey(["sorter", "id"]);
             $keyList->setOrder(["ASC", "ASC"]);
             $keyList = $keyList->load();
             foreach ($groupList as $groupData) {
                 $data[$groupData->getId()] = ["name" => $groupData->getName(), "id" => $groupData->getId(), "description" => $groupData->getDescription(), "keys" => [], "collectionId" => $mappedData[$groupId]["colId"]];
             }
             foreach ($keyList as $keyData) {
                 $groupId = $keyData->getGroupId();
                 $keyList = $data[$groupId]["keys"];
                 $definition = $keyData->getDefinition();
                 $keyList[] = ["name" => $keyData->getName(), "id" => $keyData->getKeyId(), "description" => $keyData->getDescription(), "definition" => json_decode($definition)];
                 $data[$groupId]["keys"] = $keyList;
             }
         }
     }
     return $this->_helper->json($data);
 }