Skip to content
Snippets Groups Projects
Commit f0d5a0b8 authored by S.Listl's avatar S.Listl
Browse files

1057723 Missing functions in Attribute_lib restored

parent e68a7951
No related branches found
No related tags found
No related merge requests found
......@@ -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");
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment