/** * 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; }