Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * @return mixed
  */
 public function getDefinition()
 {
     $definition = Object_Objectbrick_Definition::getByKey($this->getType());
     return $definition;
 }
Ejemplo n.º 3
0
 public function objectbrickDeleteAction()
 {
     $fc = Object_Objectbrick_Definition::getByKey($this->_getParam("id"));
     $fc->delete();
     $this->_helper->json(array("success" => true));
 }
Ejemplo n.º 4
0
 public function addObjectbrick($type)
 {
     if (empty($type)) {
         throw new Exception("No objectbrick given");
     }
     Object_Objectbrick_Definition::getByKey($type);
     $this->objectBrickConfigs[] = $type;
 }
Ejemplo n.º 5
0
 /**
  * Checks if data is valid for current data field
  *
  * @param mixed $data
  * @param boolean $omitMandatoryCheck
  * @throws Exception
  */
 public function checkValidity($data, $omitMandatoryCheck = false)
 {
     if (!$omitMandatoryCheck) {
         if ($data instanceof Object_Objectbrick) {
             $items = $data->getItems();
             foreach ($items as $item) {
                 if ($item->getDoDelete()) {
                     continue;
                 }
                 if (!$item instanceof Object_Objectbrick_Data_Abstract) {
                     continue;
                 }
                 try {
                     $collectionDef = Object_Objectbrick_Definition::getByKey($item->getType());
                 } catch (Exception $e) {
                     continue;
                 }
                 foreach ($collectionDef->getFieldDefinitions() as $fd) {
                     $key = $fd->getName();
                     $getter = "get" . ucfirst($key);
                     $fd->checkValidity($item->{$getter}());
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
// array of existing collections
/** @var Object_Objectbrick_Definition $class */
foreach ($classes as $class) {
    $classes_array[$class->getKey()] = true;
}
$files = glob(PIMCORE_DOCUMENT_ROOT . '/data/objectbricks/*');
// get all file names
// tworzenie kolekcji na podstawie plików
foreach ($files as $file) {
    // iterate files
    if (is_file($file)) {
        $string = file_get_contents($file);
        $classname = basename($file, ".json");
        unset($classes_array[$classname]);
        try {
            $class = Object_Objectbrick_Definition::getByKey($classname);
            Object_Class_Service::importObjectbrickFromJson($class, $string);
        } catch (Exception $e) {
            $newClass = new Object_Objectbrick_Definition();
            $newClass->setKey($classname);
            Object_Class_Service::importObjectbrickFromJson($newClass, $string);
        }
    }
}
// usuwanie kolekcji
/** @var Object_Objectbrick_Definition $class */
foreach ($classes_array as $classname => $tmp) {
    $class = Object_Objectbrick_Definition::getByKey($classname);
    $class->delete();
    echo "Delete objectbrick: " . $classname . "\n";
}
Ejemplo n.º 7
0
 /**
  *
  * @param string $filterJson
  * @param Object_Class $class
  * @return string
  */
 public static function getFilterCondition($filterJson, $class)
 {
     $systemFields = array("o_path", "o_key", "o_id", "o_published", "o_creationDate", "o_modificationDate");
     // create filter condition
     $conditionPartsFilters = array();
     if ($filterJson) {
         $filters = Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             if ($filter["type"] == "string") {
                 $operator = "LIKE";
             } else {
                 if ($filter["type"] == "numeric") {
                     if ($filter["comparison"] == "lt") {
                         $operator = "<";
                     } else {
                         if ($filter["comparison"] == "gt") {
                             $operator = ">";
                         } else {
                             if ($filter["comparison"] == "eq") {
                                 $operator = "=";
                             }
                         }
                     }
                 } else {
                     if ($filter["type"] == "date") {
                         if ($filter["comparison"] == "lt") {
                             $operator = "<";
                         } else {
                             if ($filter["comparison"] == "gt") {
                                 $operator = ">";
                             } else {
                                 if ($filter["comparison"] == "eq") {
                                     $operator = "=";
                                 }
                             }
                         }
                         $filter["value"] = strtotime($filter["value"]);
                     } else {
                         if ($filter["type"] == "list") {
                             $operator = "=";
                         } else {
                             if ($filter["type"] == "boolean") {
                                 $operator = "=";
                                 $filter["value"] = (int) $filter["value"];
                             }
                         }
                     }
                 }
             }
             $field = $class->getFieldDefinition($filter["field"]);
             $brickField = null;
             $brickType = null;
             if (!$field) {
                 // if the definition doesn't exist check for a localized field
                 $localized = $class->getFieldDefinition("localizedfields");
                 if ($localized instanceof Object_Class_Data_Localizedfields) {
                     $field = $localized->getFieldDefinition($filter["field"]);
                 }
                 //if the definition doesn't exist check for object brick
                 $keyParts = explode("~", $filter["field"]);
                 if (count($keyParts) > 1) {
                     $brickType = $keyParts[0];
                     $brickKey = $keyParts[1];
                     $key = self::getFieldForBrickType($class, $brickType);
                     $field = $class->getFieldDefinition($key);
                     $brickClass = Object_Objectbrick_Definition::getByKey($brickType);
                     $brickField = $brickClass->getFieldDefinition($brickKey);
                 }
             }
             if ($field instanceof Object_Class_Data_Objectbricks) {
                 // custom field
                 $db = Pimcore_Resource::get();
                 if (is_array($filter["value"])) {
                     $fieldConditions = array();
                     foreach ($filter["value"] as $filterValue) {
                         $fieldConditions[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filterValue, $operator);
                     }
                     $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                 } else {
                     $conditionPartsFilters[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filter["value"], $operator);
                 }
             } else {
                 if ($field instanceof Object_Class_Data) {
                     // custom field
                     if (is_array($filter["value"])) {
                         $fieldConditions = array();
                         foreach ($filter["value"] as $filterValue) {
                             $fieldConditions[] = $field->getFilterCondition($filterValue, $operator);
                         }
                         $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                     } else {
                         $conditionPartsFilters[] = $field->getFilterCondition($filter["value"], $operator);
                     }
                 } else {
                     if (in_array("o_" . $filter["field"], $systemFields)) {
                         // system field
                         $conditionPartsFilters[] = "`o_" . $filter["field"] . "` " . $operator . " '" . $filter["value"] . "' ";
                     }
                 }
             }
         }
     }
     $conditionFilters = "";
     if (count($conditionPartsFilters) > 0) {
         $conditionFilters = " AND (" . implode(" AND ", $conditionPartsFilters) . ")";
     }
     Logger::log("ObjectController filter condition:" . $conditionFilters);
     return $conditionFilters;
 }
Ejemplo n.º 8
0
 public function batchAction()
 {
     $success = true;
     try {
         $object = Object_Abstract::getById($this->_getParam("job"));
         if ($object) {
             $className = $object->getO_className();
             $class = Object_Class::getByName($className);
             $value = $this->_getParam("value");
             if ($this->_getParam("valueType") == "object") {
                 $value = Zend_Json::decode($value);
             }
             $name = $this->_getParam("name");
             $parts = explode("~", $name);
             // check for bricks
             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);
                 }
                 $brickClass = Object_Objectbrick_Definition::getByKey($brickType);
                 $field = $brickClass->getFieldDefinition($brickKey);
                 $brick->{$valueSetter}($field->getDataFromEditmode($value, $object));
             } else {
                 // everything else
                 $field = $class->getFieldDefinition($name);
                 if ($field) {
                     $object->setValue($name, $field->getDataFromEditmode($value, $object));
                 } else {
                     // seems to be a system field, this is actually only possible for the "published" field yet
                     if ($name == "published") {
                         if ($value == "false" || empty($value)) {
                             $object->setPublished(false);
                         } else {
                             $object->setPublished(true);
                         }
                     }
                 }
             }
             try {
                 // don't check for mandatory fields here
                 $object->setOmitMandatoryCheck(true);
                 $object->save();
                 $success = true;
             } catch (Exception $e) {
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         } else {
             Logger::debug("ObjectController::batchAction => There is no object left to update.");
             $this->_helper->json(array("success" => false, "message" => "ObjectController::batchAction => There is no object left to update."));
         }
     } catch (Exception $e) {
         Logger::err($e);
         $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
     }
     $this->_helper->json(array("success" => $success));
 }
Ejemplo n.º 9
0
 /**
  * @param  Element_Interface  $element
  * @return void
  */
 public function setDataFromElement($element)
 {
     $this->data = null;
     $this->id = new Search_Backend_Data_Id($element);
     $this->fullPath = $element->getFullPath();
     $this->creationDate = $element->getCreationDate();
     $this->modificationDate = $element->getModificationDate();
     $this->userModification = $element->getUserModification();
     $this->userOwner = $element->getUserOwner();
     $this->type = $element->getType();
     if ($element instanceof Object_Concrete) {
         $this->subtype = $element->getO_className();
     } else {
         $this->subtype = $this->type;
     }
     $this->properties = "";
     $properties = $element->getProperties();
     if (is_array($properties)) {
         foreach ($properties as $nextProperty) {
             if ($nextProperty->getType() == 'text') {
                 $this->properties .= $nextProperty->getData() . " ";
             }
         }
     }
     $this->data = "";
     if ($element instanceof Document) {
         if ($element instanceof Document_Folder) {
             $this->data = $element->getKey();
             $this->published = true;
         } else {
             if ($element instanceof Document_Link) {
                 $this->published = $element->isPublished();
                 $this->data = $element->getName() . " " . $element->getTitle() . " " . $element->getHref();
             } else {
                 if ($element instanceof Document_PageSnippet) {
                     $this->published = $element->isPublished();
                     $elements = $element->getElements();
                     if (is_array($elements) && !empty($elements)) {
                         foreach ($elements as $tag) {
                             if ($tag instanceof Document_Tag_Interface) {
                                 ob_start();
                                 $this->data .= strip_tags($tag->frontend()) . " ";
                                 $this->data .= ob_get_clean();
                             }
                         }
                     }
                     if ($element instanceof Document_Page) {
                         $this->published = $element->isPublished();
                         $this->data .= " " . $element->getName() . " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getKeywords();
                     }
                 }
             }
         }
     } else {
         if ($element instanceof Asset) {
             $this->data = $element->getFilename();
             $this->published = true;
         } else {
             if ($element instanceof Object_Abstract) {
                 if ($element instanceof Object_Concrete) {
                     $getInheritedValues = Object_Abstract::doGetInheritedValues();
                     Object_Abstract::setGetInheritedValues(true);
                     $this->published = $element->isPublished();
                     foreach ($element->getClass()->getFieldDefinitions() as $key => $value) {
                         // Object_Class_Data_Fieldcollections, Object_Class_Data_Localizedfields and Object_Class_Data_Objectbricks is special because it doesn't support the csv export
                         if ($value instanceof Object_Class_Data_Fieldcollections) {
                             $getter = "get" . $value->getName();
                             $fcData = $element->{$getter}();
                             if ($fcData instanceof Object_Fieldcollection) {
                                 foreach ($fcData as $item) {
                                     if (!$item instanceof Object_Fieldcollection_Data_Abstract) {
                                         continue;
                                     }
                                     try {
                                         $collectionDef = Object_Fieldcollection_Definition::getByKey($item->getType());
                                     } catch (Exception $e) {
                                         continue;
                                     }
                                     foreach ($collectionDef->getFieldDefinitions() as $fd) {
                                         $this->data .= $fd->getForCsvExport($item) . " ";
                                     }
                                 }
                             }
                             //$this->data .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->$getter(), $element))." ";
                         } else {
                             if ($value instanceof Object_Class_Data_Localizedfields) {
                                 // only for text-values at the moment, because the CSV doesn't work for localized fields (getter-problem)
                                 $getter = "get" . $value->getName();
                                 $lfData = $element->{$getter}();
                                 if ($lfData instanceof Object_Localizedfield) {
                                     foreach ($lfData->getItems() as $language => $values) {
                                         foreach ($values as $lData) {
                                             if (is_string($lData)) {
                                                 $this->data .= $lData . " ";
                                             }
                                         }
                                     }
                                 }
                                 //$this->data .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->$getter(), $element))." ";
                             } else {
                                 if ($value instanceof Object_Class_Data_Objectbricks) {
                                     $getter = "get" . $value->getName();
                                     $obData = $element->{$getter}();
                                     if ($obData instanceof Object_Objectbrick) {
                                         $items = $obData->getItems();
                                         foreach ($items as $item) {
                                             if (!$item instanceof Object_Objectbrick_Data_Abstract) {
                                                 continue;
                                             }
                                             try {
                                                 $collectionDef = Object_Objectbrick_Definition::getByKey($item->getType());
                                             } catch (Exception $e) {
                                                 continue;
                                             }
                                             foreach ($collectionDef->getFieldDefinitions() as $fd) {
                                                 $this->data .= $fd->getForCsvExport($item) . " ";
                                             }
                                         }
                                     }
                                     //$this->data .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->$getter(), $element))." ";
                                 } else {
                                     $this->data .= $value->getForCsvExport($element) . " ";
                                 }
                             }
                         }
                     }
                     Object_Abstract::setGetInheritedValues($getInheritedValues);
                 } else {
                     if ($element instanceof Object_Folder) {
                         $this->data = $element->getKey();
                         $this->published = true;
                     }
                 }
             } else {
                 Logger::crit("Search_Backend_Data received an unknown element!");
             }
         }
     }
     if ($element instanceof Element_Interface) {
         $this->data = "ID: " . $element->getId() . "  \nPath: " . $this->getFullPath() . "  \n" . $this->cleanupData($this->data);
     }
 }