From f0d5a0b862a47a820a7f69490448501005984e2f Mon Sep 17 00:00:00 2001 From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local> Date: Wed, 13 May 2020 10:35:22 +0200 Subject: [PATCH] 1057723 Missing functions in Attribute_lib restored --- .../recordcontainers/jdito/contentProcess.js | 2 +- process/Attribute_lib/process.js | 98 +++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js index 63ea76a92e..9d50cc58b4 100644 --- a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js @@ -16,7 +16,7 @@ var childType = vars.get("$param.ChildType_param"); var objectType = vars.get("$param.ObjectType_param"); var filteredIds = vars.getString("$param.FilteredAttributeIds_param") ? JSON.parse(vars.getString("$param.FilteredAttributeIds_param")) : null var attributeCountObj = vars.get("$param.AttributeCount_param") ? JSON.parse(vars.getString("$param.AttributeCount_param")) : null; -vars.getString("$param.DisplaySimpleName_param") == "true" ? true : false; +var displaySimpleName = vars.getString("$param.DisplaySimpleName_param") == "true" ? true : false; var themeObjectRowId = vars.get("$param.ThemeObjectRowId_param"); diff --git a/process/Attribute_lib/process.js b/process/Attribute_lib/process.js index 2bd5cfbb0b..40eed67b87 100644 --- a/process/Attribute_lib/process.js +++ b/process/Attribute_lib/process.js @@ -1686,4 +1686,102 @@ AttributeRelationQuery.prototype.insertAttribute = function (pValue, pOmitValida new SqlBuilder().insertFields(attrData, "AB_ATTRIBUTERELATION", "AB_ATTRIBUTERELATIONID"); return true; +} + +/** + * deletes all attribute relations with the given rowId and objectType + * + * @return {Number} count of deleted rows + */ +AttributeRelationQuery.prototype.deleteAllAttributes = function () +{ + if (!this._rowId) + throw new Error("AttributeRelationQuery: Row id is required for delete"); + + return newWhere("AB_ATTRIBUTERELATION.OBJECT_ROWID", this._rowId) + .andIfSet("AB_ATTRIBUTERELATION.OBJECT_TYPE", this._objectType) + .deleteData(); +} + +/** + * Object representing one attribute relation in the database. Don't use this constructor in you own code! + * Instances of this should only be created by functions in this library. + * + * @param {String} pAttributeRelationId attribute relation id + * @param {String} pAttributeId attribute id + * @param {String} pValue value of the attribute + * @param {String} pAttributeName name of the attribute + * @param {String} pAttributeType type of the attribute + * @param {String} pObjectRowId rowId of the linked object + * @param {String} pObjectType context of the linked object + */ +function AttributeRelation (pAttributeRelationId, pAttributeId, pValue, pAttributeName, pAttributeType, pObjectRowId, pObjectType) +{ + if (!pAttributeRelationId) + throw new Error("AttributeRelation: pAttributeRelationId must be provided"); + + this.attributeRelationId = pAttributeRelationId; + this.attributeId = pAttributeId; + this.value = pValue; + this.attributeName = pAttributeName; + this.attributeType = pAttributeType; + this.objectRowId = pObjectRowId; + this.objectType = pObjectType; + this.displayValue = undefined; + this.fullAttributeName = undefined; +} + +/** + * updates the value of the attribute in the database + * + * @param {String} pValue the new value of the attribute relation + * @return {Boolean} currently the function always returns true (if some kind of validation is implemented in the future, + * it will return false if the validation fails) + */ +AttributeRelation.prototype.updateAttribute = function (pValue) +{ + if (pValue == undefined || pValue == "") + throw new Error("AttributeRelation: no value provided for update"); + + var attrData = { + "DATE_EDIT" : vars.get("$sys.date"), + "USER_EDIT" : vars.get("$sys.user") + }; + + var valueField = AttributeTypeUtil.getDatabaseField(this.attributeType); + if (valueField) + attrData[valueField] = pValue; + + newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", this.attributeRelationId) + .updateFields(attrData); + return true; +} + +/** + * deletes the attribute relation from the database + * + * @param {Boolean} [pOmitValidation=false] if set to true, the function won't check if the min count prohibits the deletion + * @retun {Boolean} true if it was deleted and false if the min count doesn't allow the deletion + */ +AttributeRelation.prototype.deleteAttribute = function (pOmitValidation) +{ + if (!pOmitValidation) + { + var minCount = newSelect("MIN_COUNT") + .from("AB_ATTRIBUTEUSAGE") + .where("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", this.attributeId) + .and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", this.objectType) + .cell(); + + if (minCount && minCount != 0) + { + let timesUsed = new AttributeRelationQuery(this.objectRowId, this.attributeId, this.objectType).getAttributeCount(); + if (timesUsed <= minCount) + return false; + } + } + + newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", this.attributeRelationId) + .deleteData(); + return true; } \ No newline at end of file -- GitLab