Skip to content
Snippets Groups Projects
contentProcess.js 3.53 KiB
Newer Older
import("system.datetime");
import("system.logging");
import("Util_lib");
import("system.translate");
Tobias Feldmann's avatar
Tobias Feldmann committed
import("system.result");
Tobias Feldmann's avatar
Tobias Feldmann committed
import("Context_lib");

if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param") 
    && vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param"))
{
    var contextList = JSON.parse(vars.get("$param.ObjectType_param"));
    var contactId = JSON.parse(vars.get("$param.ObjectRowId_param"));
    var data = _get360Data(contactId, contextList);
    result.object(data);   
 * collects all data for the 360Degree tree.
 * @param {String} pContactId, the main Contactid that will be used for the Connections
 * @param {String[]} pContextList, a list of Contexts that should be displayed
 *  
 *  @return {String[][]} the resulting data
function _get360Data(pContactId, pContextList)
{   
    var resultList = [];
    var filter = vars.get("$sys.filter");
    for(var context in pContextList) 
        var group = ContextUtils.getTitle(context, true);
        if(pContextList[context].hasOwnProperty("setGroupBy") && pContextList[context].hasOwnProperty("groupByKeyword"))
            var groupKeyword = Utils.objectFromMap(new Map(KeywordUtils.getEntryNamesAndIdsByContainer(pContextList[context]["groupByKeyword"])));

        var res = ContextUtils.getContextDataViaReadEntity(context, pContextList[context], filter, pContactId);
        if(res.length > 0)
                var uid = JSON.stringify({
                    "id": row["#UID"], 
                    "type": context
                });
                var targetid = row["#UID"];
                var title = row["#CONTENTTITLE"];
                var description = row["#CONTENTDESCRIPTION"];
                var dataDate = row["DATE_NEW"];
                var active = row["ACTIVE"];
                if(pContextList[context].hasOwnProperty("setGroupBy"))
                    group = row[pContextList[context]["setGroupBy"]]
                

                if(pContextList[context].hasOwnProperty("setGroupBy"))
                {
                    if( pContextList[context].hasOwnProperty("groupByKeyword") && groupKeyword)
                        group = groupKeyword[row[pContextList[context]["setGroupBy"]]]
                    else
                        group = row[pContextList[context]["setGroupBy"]]
                }
                
                resultList.push([
                    uid,                                          // UID
                    targetid,                                     // TARGET_ID
                    context,                                      // TARGET_CONTEXT
                    translate.text(pContextList[context]),        // TARGET_CONTEXT.displayValue
                    title,                                        // TITLE
                    description,                                  // DESCRIPTION
                    dataDate,                                     // DATE
                    datetime.toDate(dataDate, "yyyy"),            // YEAR
                    ContextUtils.getEntity(context),              // ENTITY_NAME
                    translate.text(group),                        // GROUP
                    active                                        // ACTIVE
                    ]); 
            });
        }
    }
    var sortArr = [9, false]
    resultList = ArrayUtils.sortMulti(resultList, sortArr)
Heinz Boesl's avatar
Heinz Boesl committed
    return resultList;