/** * Overwritten in order to load key-value pairs declared by annotations */ protected function updateValue() { parent::updateValue(); if ($this->getObjSourceObject() != null && $this->getStrSourceProperty() != "") { $objReflection = new class_reflection($this->getObjSourceObject()); //try to find the matching source property $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_TEMPLATEDIR_ANNOTATION); $strSourceProperty = null; foreach ($arrProperties as $strPropertyName => $strValue) { if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) { $strSourceProperty = $strPropertyName; } } if ($strSourceProperty == null) { return; } $strTemplateDir = $objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_TEMPLATEDIR_ANNOTATION); //load templates $arrTemplates = class_resourceloader::getInstance()->getTemplatesInFolder($strTemplateDir); $arrTemplatesDD = array(); if (count($arrTemplates) > 0) { foreach ($arrTemplates as $strTemplate) { $arrTemplatesDD[$strTemplate] = $strTemplate; } } $this->setArrKeyValues($arrTemplatesDD); } }
/** * Overwritten in order to load key-value pairs declared by annotations */ protected function updateValue() { parent::updateValue(); if ($this->getObjSourceObject() != null && $this->getStrSourceProperty() != "") { $objReflection = new class_reflection($this->getObjSourceObject()); //try to find the matching source property $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_DDVALUES_ANNOTATION); $strSourceProperty = null; foreach ($arrProperties as $strPropertyName => $strValue) { if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) { $strSourceProperty = $strPropertyName; } } if ($strSourceProperty == null) { return; } $strDDValues = $objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_DDVALUES_ANNOTATION); if ($strDDValues !== null && $strDDValues != "") { $arrDDValues = array(); foreach (explode(",", $strDDValues) as $strOneKeyVal) { $strOneKeyVal = uniSubstr(trim($strOneKeyVal), 1, -1); $arrOneKeyValue = explode("=>", $strOneKeyVal); $strKey = trim($arrOneKeyValue[0]) == "" ? " " : trim($arrOneKeyValue[0]); if (count($arrOneKeyValue) == 2) { $strValue = class_carrier::getInstance()->getObjLang()->getLang(trim($arrOneKeyValue[1]), $this->getObjSourceObject()->getArrModule("modul")); if ($strValue == "!" . trim($arrOneKeyValue[1]) . "!") { $strValue = $arrOneKeyValue[1]; } $arrDDValues[$strKey] = $strValue; } } $this->setArrKeyValues($arrDDValues); } } }
/** * @dataProvider additionProvider */ public function testGetPropertiesWithAnnotation($a) { $objAnnotations = new class_reflection(new B()); $this->assertEquals(3, count($objAnnotations->getPropertiesWithAnnotation("@propertyTest"))); $arrProps = $objAnnotations->getPropertiesWithAnnotation("@propertyTest"); $arrKeys = array_keys($arrProps); $arrValues = array_values($arrProps); $this->assertEquals("valA1", $arrValues[0]); $this->assertEquals("propertyA1", $arrKeys[0]); $this->assertEquals("valB1", $arrValues[1]); $this->assertEquals("propertyB1", $arrKeys[1]); $this->assertEquals("valB2", $arrValues[2]); $this->assertEquals("propertyB2", $arrKeys[2]); $this->assertEquals("valB1", $objAnnotations->getAnnotationValueForProperty("propertyB1", "@propertyTest")); $this->assertEquals("valA1", $objAnnotations->getAnnotationValueForProperty("propertyA1", "@propertyTest")); $this->assertNull($objAnnotations->getAnnotationValueForProperty("propertyA1", "@notAPropertyTest")); }
/** * Restores all properties marked as versionable * * @param interface_versionable $objObject * @param class_date $objTimestamp */ public function restoreObject(interface_versionable $objObject, class_date $objTimestamp) { $objReflection = new class_reflection($objObject); $arrProperties = $objReflection->getPropertiesWithAnnotation(self::ANNOTATION_PROPERTY_VERSIONABLE); foreach ($arrProperties as $strProperty => $strAnnotation) { $this->restoreProperty($objObject, $objTimestamp, $strProperty); } }
/** * Injects the lazy loading objects for assignment properties into the current object * @return void */ private function initAssignmentProperties() { $objReflection = new class_reflection($this->getObjObject()); //get the mapped properties $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS()); foreach ($arrProperties as $strPropertyName => $arrValues) { $objPropertyLazyLoader = new class_orm_assignment_array($this->getObjObject(), $strPropertyName, $this->getIntCombinedLogicalDeletionConfig()); $strSetter = $objReflection->getSetter($strPropertyName); if ($strSetter !== null) { call_user_func(array($this->getObjObject(), $strSetter), $objPropertyLazyLoader); } } }
/** * Clears the assignments of the current object, if given * * @return bool */ private function deleteAssignments() { $bitReturn = true; $objReflection = new class_reflection($this->getObjObject()); $objDB = class_carrier::getInstance()->getObjDB(); //get the mapped properties $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS()); foreach ($arrProperties as $strPropertyName => $arrValues) { $objCfg = class_orm_assignment_config::getConfigForProperty($this->getObjObject(), $strPropertyName); $bitReturn = $bitReturn && $objDB->_pQuery("DELETE FROM " . $objDB->encloseTableName(_dbprefix_ . $objCfg->getStrTableName()) . " WHERE " . $objDB->encloseColumnName($objCfg->getStrSourceColumn()) . " = ? ", array($this->getObjObject()->getSystemid())); } return $bitReturn; }
/** * Creates an model based on an serialized string * * @return interface_model */ public static function unserialize($strData) { $arrData = json_decode($strData, true); $objModel = self::getObjectFromJson($arrData); $objReflection = new class_reflection(get_class($objModel)); $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrProperties as $strAttributeName => $strAttributeValue) { $strSetter = $objReflection->getSetter($strAttributeName); if ($strSetter != null && isset($arrData[$strAttributeName])) { $objModel->{$strSetter}($arrData[$strAttributeName]); } } return $objModel; }
/** * Reads the properties marked with templateExport from the current object * * @return void */ private function readPropertiesFromObject() { $objReflection = new class_reflection($this->objObject); $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_ANNOTATION_TEMPLATEEXPORT); foreach (array_keys($arrProperties) as $strOneProperty) { $strGetter = $objReflection->getGetter($strOneProperty); //get the templatemapper $strMapper = $objReflection->getAnnotationValueForProperty($strOneProperty, self::STR_ANNOTATION_TEMPLATEMAPPER); if ($strMapper == null) { $strMapper = "default"; } $this->addPlaceholder($strOneProperty, call_user_func(array($this->objObject, $strGetter)), $strMapper); } }
private function getSourceDir() { if ($this->getObjSourceObject() != null && $this->getStrSourceProperty() != "") { $objReflection = new class_reflection($this->getObjSourceObject()); //try to find the matching source property $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_SOURCEDIR_ANNOTATION); $strSourceProperty = null; foreach ($arrProperties as $strPropertyName => $strValue) { if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) { $strSourceProperty = $strPropertyName; } } if ($strSourceProperty != null) { $strDir = $objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_SOURCEDIR_ANNOTATION); if ($strDir !== null && $strDir != "") { return $strDir; } } } return null; }
/** * Returns a textual representation of the formentries' value. * May contain html, but should be stripped down to text-only. * * @return string */ public function getValueAsText() { //load all matching and possible values based on the prefix if ($this->getObjSourceObject() == null || $this->getStrSourceProperty() == "") { return $this->getStrValue() . " Error: No target object mapped or missing @fieldValuePrefix annotation!"; } $objReflection = new class_reflection($this->getObjSourceObject()); //try to find the matching source property $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_VALUE_ANNOTATION); $strSourceProperty = null; foreach ($arrProperties as $strPropertyName => $strValue) { if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) { $strSourceProperty = $strPropertyName; } } if ($strSourceProperty == null) { return $this->getStrValue(); } $strPrefix = trim($objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_VALUE_ANNOTATION)); if ($this->getStrValue() !== null && $this->getStrValue() !== "") { return $this->getObjSourceObject()->getLang($strPrefix . $this->getStrValue()); } return ""; }
/** * Scans the passed object and tries to find all properties marked with the annotation @versionable. * @param interface_versionable|class_model $objCurrentObject * * @return array|null */ private function readVersionableProperties(interface_versionable $objCurrentObject) { if (!$this->isVersioningAvailable($objCurrentObject)) { return null; } if (validateSystemid($objCurrentObject->getSystemid())) { $arrCurrentValues = array(); $objReflection = new class_reflection($objCurrentObject); $arrProperties = $objReflection->getPropertiesWithAnnotation(self::ANNOTATION_PROPERTY_VERSIONABLE); foreach ($arrProperties as $strProperty => $strAnnotation) { $strValue = ""; //all prerequisites match, start creating query $strGetter = $objReflection->getGetter($strProperty); if ($strGetter !== null) { $strValue = call_user_func(array($objCurrentObject, $strGetter)); } if (is_array($strValue) || $strValue instanceof ArrayAccess) { $arrNewValues = array(); foreach ($strValue as $objOneValue) { if (is_object($objOneValue) && $objOneValue instanceof class_root) { $arrNewValues[] = $objOneValue->getSystemid(); } else { $arrNewValues[] = $objOneValue . ""; } } sort($arrNewValues); $strValue = implode(",", $arrNewValues); } $arrCurrentValues[$strProperty] = $strValue; } return $arrCurrentValues; } return null; }
/** * @param interface_usersources_group|class_model $objGroup * * @return class_admin_formgenerator */ private function getGroupForm(interface_usersources_group $objGroup) { $objForm = new class_admin_formgenerator("group", $objGroup); //add the global group-name $objForm->addField(new class_formentry_text("group", "name"))->setBitMandatory(true)->setStrLabel($this->getLang("group_name"))->setStrValue($this->getParam("group_name")); if ($objGroup->isEditable()) { //adding elements is more generic right here - load all methods $objAnnotations = new class_reflection($objGroup); $arrProperties = $objAnnotations->getPropertiesWithAnnotation("@fieldType"); foreach ($arrProperties as $strProperty => $strValue) { $objForm->addDynamicField($strProperty); } } $objGroup->updateAdminForm($objForm); return $objForm; }
/** * Generates the order by statement * * @param class_reflection $objReflection * * @return string */ private function getOrderBy(class_reflection $objReflection) { //try to load the sort criteria $arrPropertiesOrder = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_LISTORDER); $arrOrderByCriteria = array(); foreach ($this->arrOrderBy as $objOneOrder) { $arrOrderByCriteria[] = $objOneOrder->getStrOrderBy(); } if (count($arrPropertiesOrder) > 0) { $arrPropertiesORM = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrPropertiesOrder as $strProperty => $strAnnotation) { if (isset($arrPropertiesORM[$strProperty])) { $arrColumn = explode(".", $arrPropertiesORM[$strProperty]); if (count($arrColumn) == 2) { $strColumn = $arrColumn[1]; } else { $strColumn = $arrColumn[0]; } //get order $strOrder = uniStrtoupper($strAnnotation) == "DESC" ? "DESC" : "ASC"; //get column if ($strColumn != "") { $arrOrderByCriteria[] = " " . $strColumn . " " . $strOrder . " "; } } } } $arrOrderByCriteria[] = " system_sort ASC "; $strOrderBy = ""; if (count($arrOrderByCriteria) > 0) { $strOrderBy = "ORDER BY " . implode(" , ", $arrOrderByCriteria) . " "; } return $strOrderBy; }
/** * Triggers the indexing of a single object. * * @param class_model $objInstance * * @return void */ public function indexObject(class_model $objInstance = null) { if (!self::isIndexAvailable()) { return; } if ($objInstance != null && $objInstance instanceof class_module_pages_pageelement) { $objInstance = $objInstance->getConcreteAdminInstance(); if ($objInstance != null) { $objInstance->loadElementData(); } } if ($objInstance == null) { return; } $objSearchDocument = new class_module_search_document(); $objSearchDocument->setDocumentId(generateSystemid()); $objSearchDocument->setStrSystemId($objInstance->getSystemid()); if ($objInstance instanceof interface_search_portalobject) { $objSearchDocument->setBitPortalObject(true); $objSearchDocument->setStrContentLanguage($objInstance->getContentLang()); } $objReflection = new class_reflection($objInstance); $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_ANNOTATION_ADDSEARCHINDEX); foreach ($arrProperties as $strPropertyName => $strAnnotationValue) { $getter = $objReflection->getGetter($strPropertyName); $strContent = $objInstance->{$getter}(); $objSearchDocument->addContent($strPropertyName, $strContent); } //trigger event-listeners class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_search_eventidentifier::EVENT_SEARCH_OBJECTINDEXED, array($objInstance, $objSearchDocument)); $this->updateSearchDocumentToDb($objSearchDocument); }
/** * Triggers the update sequence for assignment properties * @return bool */ private function updateAssignments() { $bitReturn = true; $objReflection = new class_reflection($this->getObjObject()); //get the mapped properties $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS()); foreach ($arrProperties as $strPropertyName => $arrValues) { $objCfg = class_orm_assignment_config::getConfigForProperty($this->getObjObject(), $strPropertyName); //try to load the orm config of the arrayObject - if given $strGetter = $objReflection->getGetter($strPropertyName); $arrValues = null; if ($strGetter !== null) { $arrValues = call_user_func(array($this->getObjObject(), $strGetter)); } $objAssignmentDeleteHandling = $this->getIntCombinedLogicalDeletionConfig(); if ($arrValues != null && $arrValues instanceof class_orm_assignment_array) { $objAssignmentDeleteHandling = $arrValues->getObjDeletedHandling(); } //try to restore the object-set from the database using the same config as when initializing the object $objOldHandling = $this->getIntCombinedLogicalDeletionConfig(); $this->setObjHandleLogicalDeleted($objAssignmentDeleteHandling); $arrAssignmentsFromObject = $this->getAssignmentValuesFromObject($strPropertyName, $objCfg->getArrTypeFilter()); $arrAssignmentsFromDatabase = $this->getAssignmentsFromDatabase($strPropertyName); $this->setObjHandleLogicalDeleted($objOldHandling); //if the delete handling was set to excluded when loading the assignment, the logically deleted nodes should be merged with the values from db if ($objAssignmentDeleteHandling->equals(class_orm_deletedhandling_enum::EXCLUDED())) { $this->setObjHandleLogicalDeleted(class_orm_deletedhandling_enum::EXCLUSIVE()); $arrDeletedIds = $this->getAssignmentsFromDatabase($strPropertyName); $this->setObjHandleLogicalDeleted($objOldHandling); foreach ($arrDeletedIds as $strOneId) { if (!in_array($strOneId, $arrAssignmentsFromDatabase)) { $arrAssignmentsFromDatabase[] = $strOneId; } if (!in_array($strOneId, $arrAssignmentsFromObject)) { $arrAssignmentsFromObject[] = $strOneId; } } } sort($arrAssignmentsFromObject); sort($arrAssignmentsFromDatabase); //only do s.th. if the array differs $arrNewAssignments = array_diff($arrAssignmentsFromObject, $arrAssignmentsFromDatabase); $arrDeletedAssignments = array_diff($arrAssignmentsFromDatabase, $arrAssignmentsFromObject); //skip in case there's nothing to do if (count($arrNewAssignments) == 0 && count($arrDeletedAssignments) == 0) { continue; } $objDB = class_carrier::getInstance()->getObjDB(); $arrInserts = array(); foreach ($arrAssignmentsFromObject as $strOneTargetId) { $arrInserts[] = array($this->getObjObject()->getSystemid(), $strOneTargetId); } $bitReturn = $bitReturn && $objDB->_pQuery("DELETE FROM " . $objDB->encloseTableName(_dbprefix_ . $objCfg->getStrTableName()) . " WHERE " . $objDB->encloseColumnName($objCfg->getStrSourceColumn()) . " = ?", array($this->getObjObject()->getSystemid())); $bitReturn = $bitReturn && $objDB->multiInsert($objCfg->getStrTableName(), array($objCfg->getStrSourceColumn(), $objCfg->getStrTargetColumn()), $arrInserts); $bitReturn = $bitReturn && class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_system_eventidentifier::EVENT_SYSTEM_OBJECTASSIGNMENTSUPDATED, array(array_values($arrNewAssignments), array_values($arrDeletedAssignments), array_values($arrAssignmentsFromObject), $this->getObjObject(), $strPropertyName)); if ($objReflection->hasPropertyAnnotation($strPropertyName, class_module_system_changelog::ANNOTATION_PROPERTY_VERSIONABLE)) { $objChanges = new class_module_system_changelog(); $objChanges->setOldValueForSystemidAndProperty($this->getObjObject()->getSystemid(), $strPropertyName, implode(",", $arrAssignmentsFromDatabase)); } } return $bitReturn; }
/** * @xml * @permissions edit * @return string */ protected function actionUpdateObjectProperty() { $strReturn = ""; //get the object to update /** @var $objObject class_module_pages_element */ $objObject = class_objectfactory::getInstance()->getObject($this->getSystemid()); if ($objObject->rightEdit()) { //differ between two modes - page-elements or regular objects if ($objObject instanceof class_module_pages_pageelement) { $strPageSystemid = $objObject->getPrevId(); $objLockmanager = new class_lockmanager($objObject->getSystemid()); if (!$objLockmanager->isLocked()) { $objLockmanager->lockRecord(); } if ($objLockmanager->isLockedByCurrentUser()) { //and finally create the object /** @var class_module_pages_pageelement $objElement */ $strElementClass = str_replace(".php", "", $objObject->getStrClassAdmin()); //and finally create the object /** @var $objElement class_element_admin */ $objElement = new $strElementClass(); $objElement->setSystemid($this->getSystemid()); $arrElementData = $objElement->loadElementData(); //see if we could set the param to the element if ($this->getParam("property") != "") { $strProperty = null; //try to fetch the matching setter $objReflection = new class_reflection($objElement); //try to fetch the property based on the orm annotations $strTargetTable = $objReflection->getAnnotationValuesFromClass(class_orm_base::STR_ANNOTATION_TARGETTABLE); if (count($strTargetTable) > 0) { $strTargetTable = $strTargetTable[0]; } $arrTable = explode(".", $strTargetTable); if (count($arrTable) == 2) { $strTargetTable = $arrTable[0]; } $arrOrmProperty = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrOrmProperty as $strCurProperty => $strValue) { if ($strValue == $strTargetTable . "." . $this->getParam("property")) { $strProperty = $strCurProperty; } } if ($strProperty == null) { $strProperty = $this->getParam("property"); } $strSetter = $objReflection->getSetter($strProperty); if ($strSetter != null) { call_user_func(array($objElement, $strSetter), $this->getParam("value")); } else { $arrElementData[$this->getParam("property")] = $this->getParam("value"); $objElement->setArrParamData($arrElementData); } } //pass the data to the element, maybe the element wants to update some data $objElement->doBeforeSaveToDb(); //check, if we could save the data, so the element needn't to //woah, we are soooo great $objElement->updateForeignElement(); //Edit Date of page & unlock $objPage = class_objectfactory::getInstance()->getObject($strPageSystemid); $objPage->updateObjectToDb(); $objLockmanager->unlockRecord(); //allow the element to run actions after saving $objElement->doAfterSaveToDb(); //Loading the data of the corresp site $this->flushCompletePagesCache(); $strReturn = "<message><success>element update succeeded</success></message>"; } } else { //any other object - try to find the matching property and write the value if ($this->getParam("property") == "") { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST); return "<message><error>missing property param</error></message>"; } $objReflection = new class_reflection($objObject); $strSetter = $objReflection->getSetter($this->getParam("property")); if ($strSetter == null) { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST); return "<message><error>setter not found</error></message>"; } call_user_func(array($objObject, $strSetter), $this->getParam("value")); $objObject->updateObjectToDb(); $this->flushCompletePagesCache(); $strReturn = "<message><success>object update succeeded</success></message>"; } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED); $strReturn = "<message><error>" . $this->getLang("ds_gesperrt") . "." . $this->getLang("commons_error_permissions") . "</error></message>"; } return $strReturn; }
/** * Crreates an object of type '$strClassType'. * Only properties which are annotated with @var will be considered * * @param string $strClassType - the name of the class as a string * @param string $strParentId - the parent id of the object to be created * @param array $arrExcludeFillProperty - array of poperty names which will not be set * @param array $arrPropertyValues - assoziative array which has as key the property name and as value the to be set for the property * @param boolean $bitAutofillProperties - if true all properties which have annotation @tablecolumn will be filled with random values * * @return class_model */ protected function createObject($strClassType, $strParentId, array $arrExcludeFillProperty = array(), array $arrPropertyValues = array(), $bitAutofillProperties = true) { //get properties with an tablecolumn annotation $objObject = new $strClassType(); $objReflection = new class_reflection($strClassType); $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); $arrProperties = array_merge($objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST), $arrProperties); //exclude class_root properties $objRootReflection = new class_reflection("class_root"); $arrExcludeFillProperty = array_merge($arrExcludeFillProperty, array_keys($objRootReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN))); foreach ($arrProperties as $strPropName => $strValue) { //Exclude properties to be set if (in_array($strPropName, $arrExcludeFillProperty)) { continue; } //Set properties from array $arrPropertyValues if (array_key_exists($strPropName, $arrPropertyValues)) { $strSetterMethod = $objReflection->getSetter($strPropName); if ($strSetterMethod !== null) { $objValue = $arrPropertyValues[$strPropName]; $objObject->{$strSetterMethod}($objValue); continue; } } //check if the property is annotated with @tablecolumn if ($bitAutofillProperties) { if ($objReflection->hasPropertyAnnotation($strPropName, class_orm_base::STR_ANNOTATION_TABLECOLUMN)) { $strSetterMethod = $objReflection->getSetter($strPropName); if ($strSetterMethod !== null) { //determine the field type $strDataType = $objReflection->getAnnotationValueForProperty($strPropName, "@var"); $strFieldType = $objReflection->getAnnotationValueForProperty($strPropName, "@fieldType"); $objMethodValue = null; if ($strDataType == "string") { if ($strFieldType == "text" || $strFieldType == "textarea") { $objMethodValue = $strPropName . "_" . $objObject->getStrSystemid(); if (uniStrlen($objMethodValue) > 10) { $objMethodValue = uniStrTrim($objMethodValue, 10, ""); } } } else { if ($strDataType == "int" || $strDataType == "numeric") { if ($strFieldType != "dropdown") { $objMethodValue = 1; } } else { if ($strDataType == "class_date") { $objMethodValue = new class_date(); } else { if ($strDataType == "bool") { $objMethodValue = false; } else { continue; //continue with foreach } } } } $objObject->{$strSetterMethod}($objMethodValue); } } } } //save it $objObject->updateObjectToDb($strParentId); return $objObject; }
/** * This is the most dynamically way to build a form. * Using this method, the current object is analyzed regarding its * methods and annotation. As soon as a matching property is found, the field * is added to the current list of form-entries. * Therefore the internal method addDynamicField is used. * In order to identify a field as relevant, the getter has to be marked with a fieldType annotation. * * @return void */ public function generateFieldsFromObject() { //load all methods $objAnnotations = new class_reflection($this->objSourceobject); $arrProperties = $objAnnotations->getPropertiesWithAnnotation("@fieldType"); foreach ($arrProperties as $strPropertyName => $strDataType) { $this->addDynamicField($strPropertyName); } return; }
/** * Makes a copy of the current element and saves it attached to the given page. * This copy includes the records in the elements' foreign tables * * @param string $strNewPage * @param bool $bitChangeTitle * * @throws class_exception * @return class_module_pages_pageelement the new element or null in case of an error */ public function copyObject($strNewPage = "", $bitChangeTitle = true, $bitCopyChilds = true) { class_logger::getInstance()->addLogRow("copy pageelement " . $this->getSystemid(), class_logger::$levelInfo); $this->objDB->transactionBegin(); //fetch all values to insert after the general copy process - mainly the foreign table $objElement = $this->getConcreteAdminInstance(); $arrElementData = $objElement->loadElementData(); //duplicate the current elements - afterwards $this is the new element parent::copyObject($strNewPage, $bitChangeTitle, $bitCopyChilds); //copy the old contents into the new elements $objElement = $this->getConcreteAdminInstance(); $arrNewElementData = $objElement->loadElementData(); $arrElementData["content_id"] = $arrNewElementData["content_id"]; $arrElementData["page_element_id"] = $arrNewElementData["page_element_id"]; $arrElementData["system_id"] = $arrNewElementData["system_id"]; $objElement->setArrParamData($arrElementData); //try to find setters to inject the values $objAnnotation = new class_reflection($objElement); $arrMappedProperties = $objAnnotation->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrElementData as $strColumn => $strValue) { foreach ($arrMappedProperties as $strPropertyname => $strAnnotation) { $strMappedColumn = uniSubstr($strAnnotation, uniStrpos($strAnnotation, ".") + 1); if ($strColumn == $strMappedColumn) { $objSetter = $objAnnotation->getSetter($strPropertyname); if ($objSetter != null) { call_user_func_array(array($objElement, $objSetter), array($strValue)); } } } } $objElement->doBeforeSaveToDb(); $objElement->updateForeignElement(); $objElement->doAfterSaveToDb(); $this->objDB->transactionCommit(); return $this; }
/** * Returns a short description of the saved content * Overwrite if needed * * @return string */ public function getContentTitle() { $objAnnotations = new class_reflection($this); $arrProperties = $objAnnotations->getPropertiesWithAnnotation(class_element_admin::STR_ANNOTATION_ELEMENTCONTENTTITLE); if (count($arrProperties) > 0) { $this->loadElementData(); $arrKeys = array_keys($arrProperties); $strGetter = $objAnnotations->getGetter($arrKeys[0]); if ($strGetter != null) { //explicit casts required? could be relevant, depending on the target column type / database system return call_user_func(array($this, $strGetter)); } } return ""; }
/** * Processes all object assignments in order to generate the relevant tables * * @param $strClass * * @return array */ private function collectAssignmentDefinitions($strClass) { $arrAssignmentTables = array(); $objReflection = new class_reflection($strClass); //get the mapped properties $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS()); foreach ($arrProperties as $strPropertyName => $arrValues) { $strTableName = $objReflection->getAnnotationValueForProperty($strPropertyName, class_orm_base::STR_ANNOTATION_OBJECTLIST); if (!isset($arrValues["source"]) || !isset($arrValues["target"]) || empty($strTableName)) { continue; } $objTable = new class_orm_schemamanager_table($strTableName); $objTable->addRow(new class_orm_schemamanager_row($arrValues["source"], class_db_datatypes::STR_TYPE_CHAR20, false, true)); $objTable->addRow(new class_orm_schemamanager_row($arrValues["target"], class_db_datatypes::STR_TYPE_CHAR20, false, true)); $arrAssignmentTables[] = $objTable; } return $arrAssignmentTables; }
/** * Returns an array with all property names * * @return array */ public function getPropertyNames() { $objReflection = new class_reflection($this->objObject); $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_ANNOTATION_JSONEXPORT); return array_keys($arrProperties); }
/** * Searches the current class for properties marked with a given annotation. * If found, the name of the property plus the (optional) value of the property is returned. * The base classes are queried, too. * * @param string $strAnnotation * @param class_reflection_enum $objEnum - whether to return annotation values or parameters, default is values * @return string[] ["propertyname" => "annotationvalue"] */ public function getPropertiesWithAnnotation($strAnnotation, class_reflection_enum $objEnum = null) { if ($objEnum == null) { $objEnum = class_reflection_enum::VALUES(); } if (isset($this->arrCurrentCache[self::$STR_PROPERTIES_CACHE][$strAnnotation . "_" . $objEnum])) { return $this->arrCurrentCache[self::$STR_PROPERTIES_CACHE][$strAnnotation . "_" . $objEnum]; } $arrReturn = array(); $arrProperties = $this->objReflectionClass->getProperties(); //check if there's a base-class -> inheritance, so base class before extending class $objBaseClass = $this->objReflectionClass->getParentClass(); if ($objBaseClass !== false) { $objBaseAnnotations = new class_reflection($objBaseClass->getName()); $arrReturn = array_merge($arrReturn, $objBaseAnnotations->getPropertiesWithAnnotation($strAnnotation, $objEnum)); } foreach ($arrProperties as $objOneProperty) { $arrFirstAnnotation = $this->searchFirstAnnotationInDoc($objOneProperty->getDocComment(), $strAnnotation); if ($arrFirstAnnotation !== false) { if ($objEnum->equals(class_reflection_enum::VALUES())) { $arrFirstAnnotation = $arrFirstAnnotation["values"][0]; } else { if ($objEnum->equals(class_reflection_enum::PARAMS())) { $arrFirstAnnotation = $arrFirstAnnotation["params"][0]; } } $arrReturn[$objOneProperty->getName()] = $arrFirstAnnotation; } } $this->arrCurrentCache[self::$STR_PROPERTIES_CACHE][$strAnnotation . "_" . $objEnum] = $arrReturn; self::$bitCacheSaveRequired = true; return $arrReturn; }
private function getValueForAnnotations(&$strPrefix, &$arrDepends) { $objReflection = new class_reflection($this->getObjSourceObject()); //try to find the matching source property $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_VALUE_ANNOTATION); $strSourceProperty = null; foreach ($arrProperties as $strPropertyName => $strValue) { if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) { $strSourceProperty = $strPropertyName; } } if ($strSourceProperty == null) { return; } $strPrefix = trim($objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_VALUE_ANNOTATION)); $strDependant = trim($objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_DEPENDS_ANNOTATION)); $arrDepends = explode(" ", $strDependant); array_walk($arrDepends, function (&$strValue) { $strValue = trim($strValue); }); }