php Pimcore-Model-Object-ClassDefinition类(方法)实例源码

下面列出了php Pimcore-Model-Object-ClassDefinition 类(方法)源码代码实例,从而了解它的用法。

作者:solvera    项目:pimcor   
/**
  * @param Object\ClassDefinition $class
  * @param bool $query
  * @return string
  */
 public function getTableName(Object\ClassDefinition $class, $query = false)
 {
     if ($query) {
         return "object_brick_query_" . $this->model->getKey() . "_" . $class->getId();
     } else {
         return "object_brick_store_" . $this->model->getKey() . "_" . $class->getId();
     }
 }

作者:Pegasu    项目:membe   
/**
  * @param string $name
  */
 public function removeClass($name)
 {
     $class = ClassDefinition::getByName($name);
     if ($class) {
         $class->delete();
     }
 }

作者:Pegasu    项目:membe   
public static function isInstalled()
 {
     $memberClass = ClassDefinition::getByName('Member');
     if ($memberClass) {
         return true;
     }
     return false;
 }

作者:ChristophWurs    项目:pimcor   
/**
  * 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\ClassDefinition::getById($classRaw);
     }
     $this->model->setClasses($classes);
     return $classes;
 }

作者:basilico    项目:pimcore-plugin-prototype   
/**
  * @todo refactor steps into proper methods instead of doing it all in the action
  * @throws Exception
  */
 public function indexAction()
 {
     // reachable via http://your.domain/plugin/Prototyper/admin/index
     $this->view->previewData = null;
     $this->view->csvText = $this->getParam('csv');
     $this->view->classname = $this->getParam('classname');
     $csvData = array();
     $rowNr = 0;
     $rows = str_getcsv($this->view->csvText, "\n");
     //parse the rows
     foreach ($rows as $row) {
         $rowNr++;
         $rowData = str_getcsv($row, ";");
         $csvData[] = $rowData;
         if ($rowNr == 1) {
             $fieldNames = array();
             $fieldTitles = array();
             foreach ($rowData as $cell) {
                 $fieldTitles[] = $cell;
                 $fieldNames[] = $this->getFieldName($cell);
             }
             $csvData[] = $fieldNames;
         }
         if ($rowNr > 10) {
             break;
         }
     }
     $this->view->previewTable = $csvData;
     $fieldList = array();
     foreach ($fieldNames as $fieldName) {
         $fieldTitle = array_shift($fieldTitles);
         ob_start();
         include __DIR__ . "/../classes/field.json.php";
         $fieldList[] = ob_get_clean();
     }
     $fields = implode(',', $fieldList);
     ob_start();
     include __DIR__ . "/../classes/object.json.php";
     $jsonText = ob_get_clean();
     if ($this->getParam('generate') != '') {
         $class = Object\ClassDefinition::getByName($this->correctClassname($this->getParam("classname")));
         if ($class == null) {
             $class = Object\ClassDefinition::create(array('name' => $this->correctClassname($this->getParam("classname")), 'userOwner' => $this->user->getId()));
             $class->save();
         }
         $class = Object\ClassDefinition::getById($class->getId());
         $success = Object\ClassDefinition\Service::importClassDefinitionFromJson($class, $jsonText);
         if ($success) {
             $this->view->successMessage = '<strong>Class generation successful.</strong>';
         }
     }
 }

作者:krugerk    项目:pimcor   
/**
  * @param $e
  * @return array
  * @throws
  * @throws \Exception
  */
 protected function exceptionHandler($e)
 {
     // create view if it doesn't exist already // HACK
     $pdoMySQL = preg_match("/Base table or view not found/", $e->getMessage());
     $Mysqli = preg_match("/Table (.*) doesn't exist/", $e->getMessage());
     if (($Mysqli || $pdoMySQL) && $this->firstException) {
         $this->firstException = false;
         $localizedFields = new Object\Localizedfield();
         $localizedFields->setClass(Object\ClassDefinition::getById($this->model->getClassId()));
         $localizedFields->createUpdateTable();
         return $this->load();
     }
     throw $e;
 }

作者:solvera    项目:pimcor   
/**
  * @param null $classId
  * @throws \Exception
  */
 public function __construct($classId = null)
 {
     $class = null;
     if (is_string($classId)) {
         $class = Object\ClassDefinition::getByName($classId);
     } elseif (is_int($classId)) {
         $class = Object\ClassDefinition::getById($classId);
     } elseif ($classId !== null) {
         throw new \Exception("No valid class identifier given (class name or ID)");
     }
     if ($class instanceof Object\ClassDefinition) {
         $this->setClass($class);
     }
 }

作者:Cube-Solution    项目:pimcore-coresho   
/**
  * @return boolean $isInstalled
  */
 public static function isInstalled()
 {
     $entry = Object\ClassDefinition::getByName('CoreShopProduct');
     $category = Object\ClassDefinition::getByName('CoreShopProduct');
     $cartItem = Object\ClassDefinition::getByName('CoreShopCart');
     $cart = Object\ClassDefinition::getByName('CoreShopCartItem');
     $order = Object\ClassDefinition::getByName('CoreShopOrder');
     $orderItem = Object\ClassDefinition::getByName('CoreShopOrderItem');
     $orderPayment = Object\ClassDefinition::getByName('CoreShopPayment');
     //$cartRule = Object\ClassDefinition::getByName('CoreShopCartRule');
     $orderState = Object\ClassDefinition::getByName('CoreShopOrderState');
     if ($entry && $category && $cart && $cartItem && $order && $orderItem && $orderPayment && $orderState) {
         return true;
     }
     return false;
 }

作者:Ahmad-Hilal    项目:pimcor   
public function getClasses()
 {
     if ($this->getChildAmount()) {
         $path = $this->model->getFullPath();
         if (!$this->model->getId() || $this->model->getId() == 1) {
             $path = "";
         }
         $classIds = $this->db->fetchCol("SELECT o_classId FROM objects WHERE o_path LIKE ? AND o_type = 'object' GROUP BY o_classId", $path . "/%");
         $classes = array();
         foreach ($classIds as $classId) {
             $classes[] = Object\ClassDefinition::getById($classId);
         }
         return $classes;
     } else {
         return array();
     }
 }

作者:yonetic    项目:pimcore-coreshop-dem   
/**
  * @param $objectBrick
  * @param $json
  * @return bool
  */
 public static function importObjectBrickFromJson($objectBrick, $json, $throwException = false)
 {
     $importData = \Zend_Json::decode($json);
     // reverse map the class name to the class ID, see: self::generateObjectBrickJson()
     if (is_array($importData["classDefinitions"])) {
         foreach ($importData["classDefinitions"] as &$cd) {
             if (!is_numeric($cd["classname"])) {
                 $class = Object\ClassDefinition::getByName($cd["classname"]);
                 if ($class) {
                     $cd["classname"] = $class->getId();
                 }
             }
         }
     }
     $layout = self::generateLayoutTreeFromArray($importData["layoutDefinitions"], $throwException);
     $objectBrick->setLayoutDefinitions($layout);
     $objectBrick->setClassDefinitions($importData["classDefinitions"]);
     $objectBrick->setParentClass($importData["parentClass"]);
     $objectBrick->save();
     return true;
 }

作者:ChristophWurs    项目:pimcor   
/**
  * @return void
  */
 public function findAction()
 {
     $user = $this->getUser();
     $query = $this->getParam("query");
     if ($query == "*") {
         $query = "";
     }
     $query = str_replace("%", "*", $query);
     $types = explode(",", $this->getParam("type"));
     $subtypes = explode(",", $this->getParam("subtype"));
     $classnames = explode(",", $this->getParam("class"));
     if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
         $subtypes = array("object", "variant", "folder");
     }
     $offset = intval($this->getParam("start"));
     $limit = intval($this->getParam("limit"));
     $offset = $offset ? $offset : 0;
     $limit = $limit ? $limit : 50;
     $searcherList = new Data\Listing();
     $conditionParts = array();
     $db = \Pimcore\Db::get();
     //exclude forbidden assets
     if (in_array("asset", $types)) {
         if (!$user->isAllowed("assets")) {
             $forbiddenConditions[] = " `type` != 'asset' ";
         } else {
             $forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
             if (count($forbiddenAssetPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
                     $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
             }
         }
     }
     //exclude forbidden documents
     if (in_array("document", $types)) {
         if (!$user->isAllowed("documents")) {
             $forbiddenConditions[] = " `type` != 'document' ";
         } else {
             $forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
             if (count($forbiddenDocumentPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
                     $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
             }
         }
     }
     //exclude forbidden objects
     if (in_array("object", $types)) {
         if (!$user->isAllowed("objects")) {
             $forbiddenConditions[] = " `type` != 'object' ";
         } else {
             $forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
             if (count($forbiddenObjectPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
                     $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
             }
         }
     }
     if ($forbiddenConditions) {
         $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
     }
     if (!empty($query)) {
         $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
         // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
         // if the query is numeric the user might want to search by id
         //if(is_numeric($query)) {
         //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
         //}
         $conditionParts[] = $queryCondition;
     }
     //For objects - handling of bricks
     $fields = array();
     $bricks = array();
     if ($this->getParam("fields")) {
         $fields = $this->getParam("fields");
         foreach ($fields as $f) {
             $parts = explode("~", $f);
             if (substr($f, 0, 1) == "~") {
                 //                    $type = $parts[1];
                 //                    $field = $parts[2];
                 //                    $keyid = $parts[3];
                 // key value, ignore for now
             } else {
                 if (count($parts) > 1) {
                     $bricks[$parts[0]] = $parts[0];
                 }
             }
         }
     }
     // filtering for objects
     if ($this->getParam("filter") && $this->getParam("class")) {
         $class = Object\ClassDefinition::getByName($this->getParam("class"));
//.........这里部分代码省略.........

作者:emanuel-londo    项目:pimcor   
/**
  * @return Object\ClassDefinition
  */
 public function getClass()
 {
     $class = Object\ClassDefinition::getById($this->getClassId());
     return $class;
 }

作者:yonetic    项目:pimcore-coreshop-dem   
/**
  *
  */
 public function enrichLayoutDefinition($object)
 {
     $classId = $this->allowedClassId;
     $class = Object\ClassDefinition::getById($classId);
     if (!$classId) {
         return;
     }
     if (!$this->visibleFields) {
         return;
     }
     $this->visibleFieldDefinitions = array();
     $t = \Zend_Registry::get("Zend_Translate");
     $visibleFields = explode(',', $this->visibleFields);
     foreach ($visibleFields as $field) {
         $fd = $class->getFieldDefinition($field);
         if (!$fd) {
             $fieldFound = false;
             if ($localizedfields = $class->getFieldDefinitions()['localizedfields']) {
                 if ($fd = $localizedfields->getFieldDefinition($field)) {
                     $this->visibleFieldDefinitions[$field]["name"] = $fd->getName();
                     $this->visibleFieldDefinitions[$field]["title"] = $fd->getTitle();
                     $this->visibleFieldDefinitions[$field]["fieldtype"] = $fd->getFieldType();
                     if ($fd instanceof Object\ClassDefinition\Data\Select) {
                         $this->visibleFieldDefinitions[$field]["options"] = $fd->getOptions();
                     }
                     $fieldFound = true;
                 }
             }
             if (!$fieldFound) {
                 $this->visibleFieldDefinitions[$field]["name"] = $field;
                 $this->visibleFieldDefinitions[$field]["title"] = $t->translate($field);
                 $this->visibleFieldDefinitions[$field]["fieldtype"] = "input";
             }
         } else {
             $this->visibleFieldDefinitions[$field]["name"] = $fd->getName();
             $this->visibleFieldDefinitions[$field]["title"] = $fd->getTitle();
             $this->visibleFieldDefinitions[$field]["fieldtype"] = $fd->getFieldType();
             $this->visibleFieldDefinitions[$field]["noteditable"] = true;
             if ($fd instanceof Object\ClassDefinition\Data\Select) {
                 $this->visibleFieldDefinitions[$field]["options"] = $fd->getOptions();
             }
         }
     }
 }

作者:emanuel-londo    项目:pimcor   
/**
  * @param Object\ClassDefinition $class
  * @return string
  */
 public function getTableName(Object\ClassDefinition $class)
 {
     return "object_collection_" . $this->model->getKey() . "_" . $class->getId();
 }

作者:yonetic    项目:pimcore-coreshop-dem   
$newsletter = Model\Tool\Newsletter\Config::getByName($argv[1]);
if ($newsletter) {
    $pidFile = $newsletter->getPidFile();
    if (file_exists($pidFile)) {
        \Logger::alert("Cannot send newsletters because there's already one active sending process");
        exit;
    }
    $elementsPerLoop = 10;
    $objectList = "\\Pimcore\\Model\\Object\\" . ucfirst($newsletter->getClass()) . "\\Listing";
    $list = new $objectList();
    $conditions = array("(newsletterActive = 1 AND newsletterConfirmed = 1)");
    if ($newsletter->getObjectFilterSQL()) {
        $conditions[] = $newsletter->getObjectFilterSQL();
    }
    if ($newsletter->getPersonas()) {
        $class = Model\Object\ClassDefinition::getByName($newsletter->getClass());
        if ($class && $class->getFieldDefinition("persona")) {
            $personas = array();
            $p = explode(",", $newsletter->getPersonas());
            if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Persona) {
                foreach ($p as $value) {
                    if (!empty($value)) {
                        $personas[] = $list->quote($value);
                    }
                }
                $conditions[] = "persona IN (" . implode(",", $personas) . ")";
            } else {
                if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Personamultiselect) {
                    $personasCondition = array();
                    foreach ($p as $value) {
                        $personasCondition[] = "persona LIKE " . $list->quote("%," . $value . ",%");

作者:solvera    项目:pimcor   
/**
  * Create a new definition
  *
  * @param $name
  * @return AbstractModel
  */
 protected function createDefinition($name)
 {
     $class = new ClassDefinition();
     $class->setName($name);
     return $class;
 }

作者:AtomLa    项目:pimcor   
/**
  * @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\ClassDefinition::getById($cl['classname']);
                 $this->getDao()->delete($class);
                 $processedClasses[$cl['classname']] = true;
                 foreach ($class->getFieldDefinitions() as $fieldDef) {
                     if ($fieldDef instanceof Object\ClassDefinition\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\ClassDefinition\Listing();
     $classes = $classList->load();
     if (is_array($classes)) {
         foreach ($classes as $class) {
             foreach ($class->getFieldDefinitions() as $fieldDef) {
                 if ($fieldDef instanceof Object\ClassDefinition\Data\Objectbricks) {
                     if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) {
                         break;
                     }
                 }
             }
         }
     }
 }

作者:emanuel-londo    项目:pimcor   
/**
  *
  * Checks if an object is an allowed relation
  * @param Model\Object\AbstractObject $object
  * @return boolean
  */
 protected function allowObjectRelation($object)
 {
     //only relations of owner type are allowed
     $ownerClass = Object\ClassDefinition::getByName($this->getOwnerClassName());
     if ($ownerClass->getId() > 0 and $ownerClass->getId() == $object->getClassId()) {
         $fd = $ownerClass->getFieldDefinition($this->getOwnerFieldName());
         if ($fd instanceof Object\ClassDefinition\Data\Objects) {
             return $fd->allowObjectRelation($object);
         }
     } else {
         return false;
     }
 }

作者:solvera    项目:pimcor   
/**
  * @param $name
  * @param $value
  * @param null $language
  * @return void
  */
 public function setLocalizedValue($name, $value, $language = null)
 {
     if (self::$strictMode) {
         if (!$language || !in_array($language, Tool::getValidLanguages())) {
             throw new \Exception("Language " . $language . " not accepted in strict mode");
         }
     }
     $language = $this->getLanguage($language);
     if (!$this->languageExists($language)) {
         $this->items[$language] = [];
     }
     $contextInfo = $this->getContext();
     if ($contextInfo && $contextInfo["containerType"] == "block") {
         $classId = $contextInfo["classId"];
         $containerDefinition = ClassDefinition::getById($classId);
         $blockDefinition = $containerDefinition->getFieldDefinition($contextInfo["fieldname"]);
         $fieldDefinition = $blockDefinition->getFieldDefinition("localizedfields");
     } else {
         if ($contextInfo && $contextInfo["containerType"] == "fieldcollection") {
             $containerKey = $contextInfo["containerKey"];
             $containerDefinition = Fieldcollection\Definition::getByKey($containerKey);
         } else {
             $containerDefinition = $this->getObject()->getClass();
         }
         $localizedFieldDefinition = $containerDefinition->getFieldDefinition("localizedfields");
         $fieldDefinition = $localizedFieldDefinition->getFieldDefinition($name);
     }
     if (method_exists($fieldDefinition, "preSetData")) {
         $value = $fieldDefinition->preSetData($this, $value, ["language" => $language, "name" => $name]);
     }
     $this->items[$language][$name] = $value;
     return $this;
 }

作者:cannoner    项目:pimcor   
public function batchAction()
 {
     $success = true;
     try {
         $object = Object::getById($this->getParam("job"));
         if ($object) {
             $className = $object->getClassName();
             $class = Object\ClassDefinition::getByName($className);
             $value = $this->getParam("value");
             if ($this->getParam("valueType") == "object") {
                 $value = \Zend_Json::decode($value);
             }
             $name = $this->getParam("name");
             $parts = explode("~", $name);
             if (substr($name, 0, 1) == "~") {
                 $type = $parts[1];
                 $field = $parts[2];
                 $keyid = $parts[3];
                 $getter = "get" . ucfirst($field);
                 $setter = "set" . ucfirst($field);
                 $keyValuePairs = $object->{$getter}();
                 if (!$keyValuePairs) {
                     $keyValuePairs = new Object\Data\KeyValue();
                     $keyValuePairs->setObjectId($object->getId());
                     $keyValuePairs->setClass($object->getClass());
                 }
                 $keyValuePairs->setPropertyWithId($keyid, $value, true);
                 $object->{$setter}($keyValuePairs);
             } else {
                 if (count($parts) > 1) {
                     // check for bricks
                     $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 = "\\Pimcore\\Model\\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 {
                         // check if it is a localized field
                         if ($this->getParam("language")) {
                             $localizedField = $class->getFieldDefinition("localizedfields");
                             if ($localizedField) {
                                 $field = $localizedField->getFieldDefinition($name);
                                 if ($field) {
                                     $object->{"set" . $name}($value, $this->getParam("language"));
                                 }
                             }
                         }
                         // 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->setUserModification($this->getUser()->getId());
                 $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));
 }


问题


面经


文章

微信
公众号

扫码关注公众号