Inheritance: extends Pimcore\Model\Object\ClassDefinition\Data\Relations\AbstractRelations
コード例 #1
0
 /**
  * @param Object\Concrete $object
  * @return void
  */
 public function save($object, $params = array())
 {
     $objectsMetadata = $this->getDataFromObjectParam($object, $params);
     $classId = null;
     $objectId = null;
     if ($object instanceof Object\Concrete) {
         $objectId = $object->getId();
     } else {
         if ($object instanceof Object\Fieldcollection\Data\AbstractData) {
             $objectId = $object->getObject()->getId();
         } else {
             if ($object instanceof Object\Localizedfield) {
                 $objectId = $object->getObject()->getId();
             } else {
                 if ($object instanceof Object\Objectbrick\Data\AbstractData) {
                     $objectId = $object->getObject()->getId();
                 }
             }
         }
     }
     if ($object instanceof Object\Localizedfield) {
         $classId = $object->getClass()->getId();
     } else {
         if ($object instanceof Object\Objectbrick\Data\AbstractData || $object instanceof Object\Fieldcollection\Data\AbstractData) {
             $classId = $object->getObject()->getClassId();
         } else {
             $classId = $object->getClassId();
         }
     }
     $table = "object_metadata_" . $classId;
     $db = Resource::get();
     $this->enrichRelation($object, $params, $classId, $relation);
     $position = isset($relation["position"]) && $relation["position"] ? $relation["position"] : "0";
     $sql = $db->quoteInto("o_id = ?", $objectId) . " AND " . $db->quoteInto("fieldname = ?", $this->getName()) . " AND " . $db->quoteInto("position = ?", $position);
     $db->delete($table, $sql);
     if (!empty($objectsMetadata)) {
         if ($object instanceof Object\Localizedfield || $object instanceof Object\Objectbrick\Data\AbstractData || $object instanceof Object\Fieldcollection\Data\AbstractData) {
             $objectConcrete = $object->getObject();
         } else {
             $objectConcrete = $object;
         }
         foreach ($objectsMetadata as $meta) {
             $ownerName = isset($relation["ownername"]) ? $relation["ownername"] : null;
             $ownerType = isset($relation["ownertype"]) ? $relation["ownertype"] : null;
             $meta->save($objectConcrete, $ownerType, $ownerName, $position);
         }
     }
     parent::save($object, $params);
 }
コード例 #2
0
ファイル: ObjectsMetadata.php プロジェクト: solverat/pimcore
 /**
  * @param Element\AbstractElement $object
  * @return void
  */
 public function save($object, $params = [])
 {
     $objectsMetadata = $this->getDataFromObjectParam($object, $params);
     $classId = null;
     $objectId = null;
     if ($object instanceof Object\Concrete) {
         $objectId = $object->getId();
     } elseif ($object instanceof Object\Fieldcollection\Data\AbstractData) {
         $objectId = $object->getObject()->getId();
     } elseif ($object instanceof Object\Localizedfield) {
         $objectId = $object->getObject()->getId();
     } elseif ($object instanceof Object\Objectbrick\Data\AbstractData) {
         $objectId = $object->getObject()->getId();
     }
     if ($object instanceof Object\Localizedfield) {
         $classId = $object->getClass()->getId();
     } elseif ($object instanceof Object\Objectbrick\Data\AbstractData || $object instanceof Object\Fieldcollection\Data\AbstractData) {
         $classId = $object->getObject()->getClassId();
     } else {
         $classId = $object->getClassId();
     }
     $table = "object_metadata_" . $classId;
     $db = Db::get();
     $this->enrichRelation($object, $params, $classId, $relation);
     $position = isset($relation["position"]) && $relation["position"] ? $relation["position"] : "0";
     if ($params && $params["context"] && $params["context"]["containerType"] == "fieldcollection" && $params["context"]["subContainerType"] == "localizedfield") {
         $context = $params["context"];
         $index = $context["index"];
         $containerName = $context["fieldname"];
         $sql = $db->quoteInto("o_id = ?", $objectId) . " AND ownertype = 'localizedfield' AND " . $db->quoteInto("ownername LIKE ?", "/fieldcollection~" . $containerName . "/" . $index . "/%") . " AND " . $db->quoteInto("fieldname = ?", $this->getName()) . " AND " . $db->quoteInto("position = ?", $position);
     } else {
         $sql = $db->quoteInto("o_id = ?", $objectId) . " AND " . $db->quoteInto("fieldname = ?", $this->getName()) . " AND " . $db->quoteInto("position = ?", $position);
     }
     $db->delete($table, $sql);
     if (!empty($objectsMetadata)) {
         if ($object instanceof Object\Localizedfield || $object instanceof Object\Objectbrick\Data\AbstractData || $object instanceof Object\Fieldcollection\Data\AbstractData) {
             $objectConcrete = $object->getObject();
         } else {
             $objectConcrete = $object;
         }
         foreach ($objectsMetadata as $meta) {
             $ownerName = isset($relation["ownername"]) ? $relation["ownername"] : null;
             $ownerType = isset($relation["ownertype"]) ? $relation["ownertype"] : null;
             $meta->save($objectConcrete, $ownerType, $ownerName, $position);
         }
     }
     parent::save($object, $params);
 }