getClass() public method

public getClass ( ) : ClassDefinition
return ClassDefinition
 /**
  * @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 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;
     }
 }
Esempio n. 3
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());
     }
 }
 private function getDataForObject(Object\Concrete $object, $objectFromVersion = false)
 {
     foreach ($object->getClass()->getFieldDefinitions() as $key => $def) {
         $this->getDataForField($object, $key, $def, $objectFromVersion);
     }
 }
Esempio n. 5
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();
 }
Esempio n. 6
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;
 }
Esempio n. 7
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;
 }
 /**
  * @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()));
 }
Esempio n. 9
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() . "/%") . ")");
 }
Esempio n. 10
0
 public function performFieldcollectionModificationCheck(Object\Concrete $object, $originalModificationDate, $data)
 {
     $modificationDate = $this->getParam("modificationDate");
     if ($modificationDate != $originalModificationDate) {
         $fielddefinitions = $object->getClass()->getFieldDefinitions();
         foreach ($fielddefinitions as $fd) {
             if ($fd instanceof Object\ClassDefinition\Data\Fieldcollections) {
                 if (isset($data[$fd->getName()])) {
                     $allowedTypes = $fd->getAllowedTypes();
                     foreach ($allowedTypes as $type) {
                         /** @var  $fdDef Object\Fieldcollection\Definition */
                         $fdDef = Object\Fieldcollection\Definition::getByKey($type);
                         $childDefinitions = $fdDef->getFieldDefinitions();
                         foreach ($childDefinitions as $childDef) {
                             if ($childDef instanceof Object\ClassDefinition\Data\Localizedfields) {
                                 $this->_helper->json(["success" => false, "message" => "Could be that someone messed around with the fieldcollection in the meantime. Please reload and try again"]);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 11
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};
 }