Beispiel #1
0
 /**
  * @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;
 }
Beispiel #2
0
 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()));
 }
Beispiel #3
0
 /**
  * @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() . "'");
 }
Beispiel #4
0
 public static function hasInheritableParentObject(Object_Concrete $object)
 {
     if ($object->getO_class()->getAllowInherit()) {
         if ($object->getO_parent() instanceof Object_Abstract) {
             $parent = $object->getO_parent();
             while ($parent && $parent->getO_type() == "folder") {
                 $parent = $parent->getO_parent();
             }
             if ($parent && ($parent->getO_type() == "object" || $parent->getO_type() == "variant")) {
                 if ($parent->getO_classId() == $object->getO_classId()) {
                     return $parent;
                 }
             }
         }
     }
 }
 /**
  * @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()));
 }