public function setValueToObject() { $objReflection = new class_reflection($this->getObjSourceObject()); $strSetter = $objReflection->getSetter($this->getStrSourceProperty()); if ($strSetter !== null && uniStrtolower(uniSubstr($strSetter, 0, 6)) == "setobj" && !$this->getStrValue() instanceof class_date && $this->getStrValue() > 0) { $this->setStrValue(new class_date($this->getStrValue())); } return parent::setValueToObject(); }
public function setValueToObject() { $objSourceObject = $this->getObjSourceObject(); if ($objSourceObject == null) { return ""; } $objReflection = new class_reflection($objSourceObject); $strSetter = $objReflection->getSetter($this->getStrSourceProperty()); if ($strSetter === null) { throw new class_exception("unable to find setter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR); } return call_user_func(array($objSourceObject, $strSetter), json_encode($this->getStrValue())); }
/** * 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); } } }
/** * 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; }
/** * Restores a single property marked as versionable * * @param interface_versionable|class_model $objObject * @param class_date $objTimestamp * @param $strProperty */ public function restoreProperty(interface_versionable $objObject, class_date $objTimestamp, $strProperty) { //there are a few properties not to change if ($strProperty == "intRecordStatus") { return; } //load the value from the changelog $strValue = $this->getValueForDate($objObject->getSystemid(), $strProperty, $objTimestamp); if ($strValue === false) { $strValue = null; } //remove the system-id temporary to avoid callbacks and so on $strSystemid = $objObject->getSystemid(); $objObject->unsetSystemid(); //all prerequisites match, start creating query $objReflection = new class_reflection($objObject); $strSetter = $objReflection->getSetter($strProperty); if ($strSetter !== null) { call_user_func(array($objObject, $strSetter), $strValue); } $objObject->setSystemid($strSystemid); }
public function setValueToObject() { $objSourceObject = $this->getObjSourceObject(); if ($objSourceObject == null) { return ""; } $objReflection = new class_reflection($objSourceObject); // get database object which we can not change $strGetter = $objReflection->getGetter($this->getStrSourceProperty()); if ($strGetter === null) { throw new class_exception("unable to find getter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR); } $arrObjects = call_user_func(array($objSourceObject, $strGetter)); $arrNotObjects = array_values(array_filter((array) $arrObjects, function (class_model $objObject) { return !$objObject->rightView(); })); // merge objects $arrNewObjects = array_merge($this->toObjectArray(), $arrNotObjects); // filter double object ids $arrObjects = array(); foreach ($arrNewObjects as $objObject) { $arrObjects[$objObject->getStrSystemid()] = $objObject; } $arrObjects = array_values($arrObjects); // set value $strSetter = $objReflection->getSetter($this->getStrSourceProperty()); if ($strSetter === null) { throw new class_exception("unable to find setter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR); } return call_user_func(array($objSourceObject, $strSetter), $arrObjects); }
/** * @dataProvider additionProvider */ public function testGetSetters($a) { $objReflection = new class_reflection(new A()); $this->assertEquals(strtolower("setStrPropertyA1"), strtolower($objReflection->getSetter("propertyA1"))); $objReflection = new class_reflection(new B()); $this->assertEquals(strtolower("setStrPropertyA1"), strtolower($objReflection->getSetter("propertyA1"))); $this->assertEquals(strtolower("setIntPropertyB1"), strtolower($objReflection->getSetter("propertyB1"))); }
/** * @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; }
/** * 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; }
/** * A default implementation for copy-operations. * Overwrite this method if you want to execute additional statements. * Please be aware that you are working on the new object afterwards! * * @param string $strNewPrevid * @param bool $bitChangeTitle * @param bool $bitCopyChilds * * @throws class_exception * @return bool */ public function copyObject($strNewPrevid = "", $bitChangeTitle = true, $bitCopyChilds = true) { $this->objDB->transactionBegin(); $strOldSysid = $this->getSystemid(); if ($strNewPrevid == "") { $strNewPrevid = $this->strPrevId; } //any date-objects to copy? if ($this->objStartDate != null || $this->objEndDate != null || $this->objSpecialDate != null) { $this->bitDatesChanges = true; } //check if there's a title field, in most cases that could be used to change the title if ($bitChangeTitle) { $objReflection = new class_reflection($this); $strGetter = $objReflection->getGetter("strTitle"); $strSetter = $objReflection->getSetter("strTitle"); if ($strGetter != null && $strSetter != null) { $strTitle = call_user_func(array($this, $strGetter)); if ($strTitle != "") { call_user_func(array($this, $strSetter), $strTitle . "_copy"); } } } //prepare the current object $this->unsetSystemid(); $this->arrInitRow = null; $bitReturn = $this->updateObjectToDb($strNewPrevid); //call event listeners $bitReturn = $bitReturn && class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_system_eventidentifier::EVENT_SYSTEM_RECORDCOPIED, array($strOldSysid, $this->getSystemid(), $this)); if ($bitCopyChilds) { //process subrecords //validate, if there are subrecords, so child nodes to be copied to the current record $arrChilds = $this->objDB->getPArray("SELECT system_id FROM " . _dbprefix_ . "system where system_prev_id = ? ORDER BY system_sort ASC", array($strOldSysid)); foreach ($arrChilds as $arrOneChild) { if (validateSystemid($arrOneChild["system_id"])) { $objInstance = class_objectfactory::getInstance()->getObject($arrOneChild["system_id"]); if ($objInstance !== null) { $objInstance->copyObject($this->getSystemid(), false); } } } } if ($bitReturn) { $this->objDB->transactionCommit(); } else { $this->objDB->transactionRollback(); } $this->objDB->flushQueryCache(); $bitReturn = $bitReturn && class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_system_eventidentifier::EVENT_SYSTEM_RECORDCOPYFINISHED, array($strOldSysid, $this->getSystemid(), $this)); return $bitReturn; }