Exemplo n.º 1
0
 /**
  * @return string
  */
 public function getOwnerClassName()
 {
     //fallback for legacy data
     if (empty($this->ownerClassName)) {
         $class = Object_Class::getById($this->ownerClassId);
         $this->ownerClassName = $class->getName();
     }
     return $this->ownerClassName;
 }
Exemplo n.º 2
0
 /**
  * Loads a list of object-classes for the specicifies parameters, returns an array of Object_Class elements
  *
  * @return array
  */
 public function load()
 {
     $classes = array();
     $classesRaw = $this->db->fetchCol("SELECT id FROM classes" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($classesRaw as $classRaw) {
         $classes[] = Object_Class::getById($classRaw);
     }
     $this->model->setClasses($classes);
     return $classes;
 }
Exemplo n.º 3
0
 /**
  * creates a class called "unittest" containing all Object_Class_Data Types currently available.
  * @return void
  * @depends testFieldCollectionCreate
  */
 public function testClassCreate()
 {
     $conf = new Zend_Config_Xml(TESTS_PATH . "/resources/objects/class-import.xml");
     $importData = $conf->toArray();
     $layout = Object_Class_Service::generateLayoutTreeFromArray($importData["layoutDefinitions"]);
     $class = Object_Class::create();
     $class->setName("unittest");
     $class->setUserOwner(1);
     $class->save();
     $id = $class->getId();
     $this->assertTrue($id > 0);
     $class = Object_Class::getById($id);
     $class->setLayoutDefinitions($layout);
     $class->setUserModification(1);
     $class->setModificationDate(time());
     $class->save();
 }
 public function saveAction()
 {
     $class = Object_Class::getById(intval($this->getParam("id")));
     $class_config = Zend_Json::decode($this->getParam("configuration"));
     $class_name = strtolower($class->getName());
     $classes = $this->config->getClasses();
     unset($classes->{$class_name});
     $classes->addChild($class_name);
     $this->setSphinxValues($class_config, $class_name, $classes);
     if ($classes->{$class_name}->count() == 0) {
         unset($classes->{$class_name});
     }
     // remove empty classes
     $this->config->writeXml();
     $this->config->writeSphinxConfig();
     $this->_helper->json(array("success" => true));
 }
 public function gridProxyAction()
 {
     if ($this->_getParam("language")) {
         $this->setLanguage($this->_getParam("language"));
     }
     if ($this->_getParam("data")) {
         if ($this->_getParam("xaction") == "update") {
             $data = Zend_Json::decode($this->_getParam("data"));
             // save
             $object = Object_Abstract::getById($data["id"]);
             $objectData = array();
             foreach ($data as $key => $value) {
                 $parts = explode("~", $key);
                 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);
                     }
                     $brick->{$valueSetter}($value);
                 } else {
                     $objectData[$key] = $value;
                 }
             }
             $object->setValues($objectData);
             try {
                 $object->save();
                 $this->_helper->json(array("data" => Object_Service::gridObjectData($object, $this->_getParam("fields")), "success" => true));
             } catch (Exception $e) {
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         }
     } else {
         // get list of objects
         $folder = Object_Abstract::getById($this->_getParam("folderId"));
         $class = Object_Class::getById($this->_getParam("classId"));
         $className = $class->getName();
         $colMappings = array("filename" => "o_key", "fullpath" => array("o_path", "o_key"), "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate");
         $start = 0;
         $limit = 20;
         $orderKey = "o_id";
         $order = "ASC";
         $fields = array();
         $bricks = array();
         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");
         }
         if ($this->_getParam("sort")) {
             if (array_key_exists($this->_getParam("sort"), $colMappings)) {
                 $orderKey = $colMappings[$this->_getParam("sort")];
             } else {
                 $orderKey = $this->_getParam("sort");
             }
         }
         if ($this->_getParam("dir")) {
             $order = $this->_getParam("dir");
         }
         $listClass = "Object_" . ucfirst($className) . "_List";
         // create filter condition
         if ($this->_getParam("filter")) {
             $conditionFilters = Object_Service::getFilterCondition($this->_getParam("filter"), $class);
         }
         if ($this->_getParam("condition")) {
             $conditionFilters = " AND (" . $this->_getParam("condition") . ")";
         }
         $list = new $listClass();
         if (!empty($bricks)) {
             foreach ($bricks as $b) {
                 $list->addObjectbrick($b);
             }
         }
         if ($this->_getParam("only_direct_children") == "true") {
             $pathCondition = "o_parentId = " . $folder->getId();
         } else {
             $pathCondition = "(o_path = '" . $folder->getFullPath() . "' OR o_path LIKE '" . str_replace("//", "/", $folder->getFullPath() . "/") . "%')";
         }
         $list->setCondition($pathCondition . $conditionFilters);
         $list->setLimit($limit);
         $list->setOffset($start);
         $list->setOrder($order);
         $list->setOrderKey($orderKey);
         $list->setIgnoreLocale(true);
         $list->load();
         $objects = array();
         foreach ($list->getObjects() as $object) {
             $o = Object_Service::gridObjectData($object, $fields);
             $objects[] = $o;
         }
         $this->_helper->json(array("data" => $objects, "success" => true, "total" => $list->getTotalCount()));
     }
 }
Exemplo n.º 6
0
 /**
  * @return Object_Class
  */
 public function getClass()
 {
     $class = Object_Class::getById($this->getClassId());
     return $class;
 }
Exemplo n.º 7
0
 /**
  * @return void
  */
 public function delete()
 {
     $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/objectbricks";
     $fieldFile = $fieldCollectionFolder . "/" . $this->getKey() . ".psf";
     @unlink($fieldFile);
     $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Objectbrick/Data";
     $fieldClass = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php";
     @unlink($fieldClass);
     $processedClasses = array();
     if (!empty($this->classDefinitions)) {
         foreach ($this->classDefinitions as $cl) {
             unset($this->oldClassDefinitions[$cl['classname']]);
             if (!$processedClasses[$cl['classname']]) {
                 $class = Object_Class::getById($cl['classname']);
                 $this->getResource()->delete($class);
                 $processedClasses[$cl['classname']] = true;
                 foreach ($class->getFieldDefinitions() as $fieldDef) {
                     if ($fieldDef instanceof Object_Class_Data_Objectbricks) {
                         $allowedTypes = $fieldDef->getAllowedTypes();
                         $idx = array_search($this->getKey(), $allowedTypes);
                         if ($idx !== false) {
                             array_splice($allowedTypes, $idx, 1);
                         }
                         $fieldDef->setAllowedTypes($allowedTypes);
                     }
                 }
                 $class->save();
             }
         }
     }
     // update classes
     $classList = new Object_Class_List();
     $classes = $classList->load();
     if (is_array($classes)) {
         foreach ($classes as $class) {
             foreach ($class->getFieldDefinitions() as $fieldDef) {
                 if ($fieldDef instanceof Object_Class_Data_Objectbricks) {
                     if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) {
                         //remove objectbrick from class
                         //$this->getResource()->delete($class);
                         break;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * @return Object_Class
  */
 public function getO_class()
 {
     if (!$this->o_class) {
         $this->setO_class(Object_Class::getById($this->getO_classId()));
     }
     return $this->o_class;
 }
Exemplo n.º 9
0
 public function getClassDefinitionForColumnConfigAction()
 {
     $class = Object_Class::getById(intval($this->_getParam("id")));
     $class->setFieldDefinitions(null);
     $result = array();
     $result['objectColumns']['childs'] = $class->getLayoutDefinitions()->getChilds();
     $result['objectColumns']['nodeLabel'] = "object_columns";
     $result['objectColumns']['nodeType'] = "object";
     $systemColumnNames = Object_Concrete::$systemColumnNames;
     // array("id", "fullpath", "published", "creationDate", "modificationDate", "filename", "classname");
     $systemColumns = array();
     foreach ($systemColumnNames as $systemColumn) {
         $systemColumns[] = array("title" => $systemColumn, "name" => $systemColumn, "datatype" => "data", "fieldtype" => "system");
     }
     $result['systemColumns']['nodeLabel'] = "system_columns";
     $result['systemColumns']['nodeType'] = "system";
     $result['systemColumns']['childs'] = $systemColumns;
     $list = new Object_Objectbrick_Definition_List();
     $list = $list->load();
     foreach ($list as $brickDefinition) {
         $classDefs = $brickDefinition->getClassDefinitions();
         if (!empty($classDefs)) {
             foreach ($classDefs as $classDef) {
                 if ($classDef['classname'] == $class->getId()) {
                     $key = $brickDefinition->getKey();
                     $result[$key]['nodeLabel'] = $key;
                     $result[$key]['nodeType'] = "objectbricks";
                     $result[$key]['childs'] = $brickDefinition->getLayoutdefinitions()->getChilds();
                     break;
                 }
             }
         }
     }
     $this->_helper->json($result);
 }
Exemplo n.º 10
0
 public function getClasses()
 {
     if ($this->getChildAmount()) {
         $classIds = $this->db->fetchCol("SELECT o_classId FROM objects WHERE o_path LIKE ? AND o_type = 'object' GROUP BY o_classId", $this->model->getFullPath() . "%");
         $classes = array();
         foreach ($classIds as $classId) {
             $classes[] = Object_Class::getById($classId);
         }
         return $classes;
     } else {
         return array();
     }
 }
Exemplo n.º 11
0
 /**
  * @param $e
  * @return array
  */
 protected function exceptionHandler($e)
 {
     // create view if it doesn't exist already // HACK
     if (preg_match("/Base table or view not found/", $e->getMessage()) && $this->firstException) {
         $this->firstException = false;
         $localizedFields = new Object_Localizedfield();
         $localizedFields->setClass(Object_Class::getById($this->model->getClassId()));
         $localizedFields->createUpdateTable();
         return $this->load();
     }
     throw $e;
 }
Exemplo n.º 12
0
 public function getBatchJobsAction()
 {
     $folder = Object_Abstract::getById($this->_getParam("folderId"));
     $class = Object_Class::getById($this->_getParam("classId"));
     if ($this->_getParam("filter")) {
         $conditionFilters = Object_Service::getFilterCondition($this->_getParam("filter"), $class);
     }
     if ($this->_getParam("condition")) {
         $conditionFilters = " AND (" . $this->_getParam("condition") . ")";
     }
     $className = $class->getName();
     $listClass = "Object_" . ucfirst($className) . "_List";
     $list = new $listClass();
     $list->setCondition("o_path = ? OR o_path LIKE '" . str_replace("//", "/", $folder->getFullPath() . "/") . "%'" . $conditionFilters, array($folder->getFullPath()));
     $list->setOrder("ASC");
     $list->setOrderKey("o_id");
     if ($this->_getParam("objecttype")) {
         $list->setObjectTypes(array($this->_getParam("objecttype")));
     }
     $jobs = $list->loadIdList();
     $this->_helper->json(array("success" => true, "jobs" => $jobs));
 }