<commit_before>﻿component implements="system.interfaces.com.irCMS.cms.navigationCRUD" {
    public navigationCRUD function init(required validator formValidator, required string tablePrefix, required string datasource) {
        variables.formValidator = arguments.formValidator;
        variables.tablePrefix   = arguments.tablePrefix;
        variables.datasource    = arguments.datasource;
        
        return this;
    }

    public struct function getNavigationInformation(required string sesLink, required string language) {
        var qGetNavigationInformation = new Query().setDatasource(variables.datasource)
                                                   .setSQL("     SELECT cv.navigationId, cv.sesLink, "
                                                          &"            regExp_matches(:sesLink, '^(' || cv.sesLink || ')/*' || cv.entityRegExp || '$') sesMatches"
                                                          &"       FROM #variables.tablePrefix#_ContentVersion cv "
                                                          &" INNER JOIN #variables.tablePrefix#_navigation     n  ON cv.navigationId=n.navigationId "
                                                          &" INNER JOIN #variables.tablePrefix#_contentStatus  cs ON cv.contentStatusId = cs.contentStatusId "
                                                          &"      WHERE cs.online  = :online "
                                                          &"        AND n.active   = :active "
                                                          &"        AND n.language = :language ")
                                                   .addParam(name="sesLink",  value=arguments.sesLink,  cfsqltype="cf_sql_varchar")
                                                   .addParam(name="language", value=arguments.language, cfsqltype="cf_sql_varchar")
                                                   .addParam(name="online",   value=true,               cfsqltype="cf_sql_bit")
                                                   .addParam(name="active",   value=true,               cfsqltype="cf_sql_bit")
                                                   .execute()
                                                   .getResult();

        if(qGetNavigationInformation.recordCount == 1) {
            return {
                entityMatches: this.cleanEntityMatches(arrayMerge([], qGetNavigationInformation.sesMatches[1])),
                navigationId:  qGetNavigationInformation.navigationId[1],
                sesLink:       qGetNavigationInformation.sesLink[1]
            };
        }
        else {
            throw(type="notFound", message="Navigation was found", detail=arguments.sesLink);
        }
    }

    private array function cleanEntityMatches(required array sesMatches) {
        var cleanedMatches = duplicate(arguments.sesMatches);
        // delete the SES
        arrayDeleteAt(cleanedMatches, 1);
        
        // remove blank entries
        for(var i = arrayLen(cleanedMatches); i >= 1; i--) {
            if(cleanedMatches[i] == '') {
                arrayDeleteAt(cleanedMatches, i);
            }
        }

        // split matches into their sibblings
        var splitMatches = [];
        cleanedMatches.each(function(item) {
            splitMatches.append(listToArray(item, '/'), true);
        });
        
        return splitMatches;
    }

    public navigationPoint function getActualNavigation(required struct navigationInformation) {
        if(! isNull(arguments.navigationInformation.entityMatches) && ! isNull(arguments.navigationInformation.navigationId) && ! isNull(arguments.navigationInformation.sesLink)) {
            return new navigationPoint(variables.tablePrefix, variables.datasource, arguments.navigationInformation);
        }
        else {
            return null;
        }
    }
    
    public array function getHierarchy(required string position, required string language, required numeric parentNavigationId) cachedWithin="#createTimespan(0,0,1,0)#" {
        var hierarchy = [];

        var qGetTopLevel = new Query().setDatasource(variables.datasource)
                                      .setSQL("         SELECT cv.navigationId, cv.contentVersionId, "
                                             &"                cv.version, cv.content, m.path, m.moduleName, cv.moduleAttributes, cv.linkName, cv.sesLink, cv.entityRegExp, "
                                             &"                cv.title, cv.description, cv.keywords, cv.canonical, cv.showContentForEntity "
                                             &"           FROM #variables.tablePrefix#_navigation     n "
                                             &"     INNER JOIN #variables.tablePrefix#_contentVersion cv ON n.navigationId     = cv.navigationId "
                                             &"     INNER JOIN #variables.tablePrefix#_contentStatus  cs ON cv.contentStatusId = cs.contentStatusId "
                                             &"LEFT OUTER JOIN #variables.tablePrefix#_module         m  ON cv.moduleId        = m.moduleId "
                                             &"          WHERE cs.online            = :online "
                                             &"            AND n.position           = :position "
                                             &"            AND n.language           = :language "
                                             &"            AND n.active             = :active "
                                             &"            AND n.parentNavigationId " & (arguments.parentNavigationId == 0 ? " is null " : "= :parentNavigationId ")
                                             &"       ORDER BY n.position, n.sortOrder ASC")
                                      .addParam(name="online",             value=true,                         cfsqltype="cf_sql_bit")
                                      .addParam(name="active",             value=true,                         cfsqltype="cf_sql_bit")
                                      .addParam(name="language",           value=arguments.language,           cfsqltype="cf_sql_varchar")
                                      .addParam(name="position",           value=arguments.position,           cfsqltype="cf_sql_varchar")
                                      .addParam(name="parentNavigationId", value=arguments.parentNavigationId, cfsqltype="cf_sql_numeric")
                                      .execute()
                                      .getResult();

        for(var i = 1; i <= qGetTopLevel.getRecordCount(); i++) {
            hierarchy[i] = {};
            hierarchy[i].linkname = qGetTopLevel.linkName[i];
            hierarchy[i].sesLink  = qGetTopLevel.sesLink[i];
            hierarchy[i].title    = qGetTopLevel.title[i];
            hierarchy[i].children = this.getHierarchy(position=arguments.position, language=arguments.language, parentNavigationId=qGetTopLevel.navigationId[i]);
        }

        return hierarchy;
    }
    
    /**
     * Navigation header
     **/
    public boolean function addNavigation(required struct navigationData) {
        return true;
    }

    public boolean function editNavigation(required numeric navigationId, required numeric version, required struct navigationData) {
        return true;
    }
    
    public boolean function deleteNavigation(required numeric navigationId) {
        return true;
    }
    
    /**
     *  Content Version
     **/
    public struct function addContentVersion(required numeric navigationId, required numeric userId, required numeric version, required struct versionData) {
        var formValidation = this.validateVersionData(arguments.versionData);
        
        formValidation.navigationId = isDefined("arguments.navigationId")                ? variables.formValidator.validate(content=arguments.navigationId,                ruleName='Id')      : false;
        formValidation.version      = isDefined("arguments.version")                     ? variables.formValidator.validate(content=arguments.version,                     ruleName='Version') : false;
        formValidation.status       = isDefined("arguments.versionData.contentStatusId") ? variables.formValidator.validate(content=arguments.versionData.contentStatusId, ruleName='Id')      : false; 
        
        formValidation.status       = this.statusExists(contentStatusId    = arguments.versionData.contentStatusId);
        formValidation.navigationId = this.navigationIdExists(navigationId = arguments.navigationId);
        formValidation.version      = this.versionAvailable(navigationId   = arguments.navigationId, version  = arguments.version);
        formValidation.linkName     = this.linkNameAvailable(navigationId  = arguments.navigationId, linkName = arguments.versionData.linkName);
        formValidation.sesLink      = this.sesLinkAvailable(navigationId   = arguments.navigationId, sesLink  = arguments.versionData.sesLink); 
        
        formValidation.success = this.allSuccessfull(formValidation);

        if(formValidation.success) {
            new Query().setDatasource(variables.datasource)
                       .setSQL("INSERT INTO #variables.tablePrefix#_contentVersion "
                              &"            ( "
                              &"              navigationId, "
                              &"              version, "
                              &"              contentStatusId, "
                              &"              content, "
                              &"              moduleId, "
                              &"              moduleAttributes, "
                              &"              linkName, "
                              &"              sesLink, "
                              &"              entityRegExp, "
                              &"              title, "
                              &"              description, "
                              &"              keywords, "
                              &"              userId, "
                              &"              showContentForEntity "
                              &"            ) "
                              &"     VALUES ( "
                              &"              :navigationId, "
                              &"              :version, "
                              &"              :contentStatusId, "
                              &"              :content, "
                              &"              :moduleId, "
                              &"              :moduleAttributes, "
                              &"              :linkName, "
                              &"              :sesLink, "
                              &"              :entityRegExp, "
                              &"              :title, "
                              &"              :description, "
                              &"              :keywords, "
                              &"              :userId, "
                              &"              :showContentForEntity "
                              &"            ) ")
                       .addParam(name="navigationId",         value=arguments.navigationId,                     cfsqltype="cf_sql_numeric")
                       .addParam(name="version",              value=arguments.version,                          cfsqltype="cf_sql_float",   scale="2")
                       .addParam(name="contentStatusId",      value=arguments.versionData.statusId,             cfsqltype="cf_sql_numeric")
                       .addParam(name="content",              value=arguments.versionData.content,              cfsqltype="cf_sql_varchar", null="#arguments.versionData.content              == '' ? true : false#")<commit_msg>Fixed the naming of a variable<commit_after>﻿component implements="system.interfaces.com.irCMS.cms.navigationCRUD" {
    public navigationCRUD function init(required validator formValidator, required string tablePrefix, required string datasource) {
        variables.formValidator = arguments.formValidator;
        variables.tablePrefix   = arguments.tablePrefix;
        variables.datasource    = arguments.datasource;
        
        return this;
    }

    public struct function getNavigationInformation(required string sesLink, required string language) {
        var qGetNavigationInformation = new Query().setDatasource(variables.datasource)
                                                   .setSQL("     SELECT cv.navigationId, cv.sesLink, "
                                                          &"            regExp_matches(:sesLink, '^(' || cv.sesLink || ')/*' || cv.entityRegExp || '$') sesMatches"
                                                          &"       FROM #variables.tablePrefix#_ContentVersion cv "
                                                          &" INNER JOIN #variables.tablePrefix#_navigation     n  ON cv.navigationId=n.navigationId "
                                                          &" INNER JOIN #variables.tablePrefix#_contentStatus  cs ON cv.contentStatusId = cs.contentStatusId "
                                                          &"      WHERE cs.online  = :online "
                                                          &"        AND n.active   = :active "
                                                          &"        AND n.language = :language ")
                                                   .addParam(name="sesLink",  value=arguments.sesLink,  cfsqltype="cf_sql_varchar")
                                                   .addParam(name="language", value=arguments.language, cfsqltype="cf_sql_varchar")
                                                   .addParam(name="online",   value=true,               cfsqltype="cf_sql_bit")
                                                   .addParam(name="active",   value=true,               cfsqltype="cf_sql_bit")
                                                   .execute()
                                                   .getResult();

        if(qGetNavigationInformation.recordCount == 1) {
            return {
                entityMatches: this.cleanEntityMatches(arrayMerge([], qGetNavigationInformation.sesMatches[1])),
                navigationId:  qGetNavigationInformation.navigationId[1],
                sesLink:       qGetNavigationInformation.sesLink[1]
            };
        }
        else {
            throw(type="notFound", message="Navigation was found", detail=arguments.sesLink);
        }
    }

    private array function cleanEntityMatches(required array sesMatches) {
        var cleanedMatches = duplicate(arguments.sesMatches);
        // delete the SES
        arrayDeleteAt(cleanedMatches, 1);
        
        // remove blank entries
        for(var i = arrayLen(cleanedMatches); i >= 1; i--) {
            if(cleanedMatches[i] == '') {
                arrayDeleteAt(cleanedMatches, i);
            }
        }

        // split matches into their sibblings
        var splitMatches = [];
        cleanedMatches.each(function(item) {
            splitMatches.append(listToArray(item, '/'), true);
        });
        
        return splitMatches;
    }

    public navigationPoint function getActualNavigation(required struct navigationInformation) {
        if(! isNull(arguments.navigationInformation.entityMatches) && ! isNull(arguments.navigationInformation.navigationId) && ! isNull(arguments.navigationInformation.sesLink)) {
            return new navigationPoint(variables.tablePrefix, variables.datasource, arguments.navigationInformation);
        }
        else {
            return null;
        }
    }
    
    public array function getHierarchy(required string position, required string language, required numeric parentNavigationId) cachedWithin="#createTimespan(0,0,1,0)#" {
        var hierarchy = [];

        var qGetTopLevel = new Query().setDatasource(variables.datasource)
                                      .setSQL("         SELECT cv.navigationId, cv.contentVersionId, "
                                             &"                cv.version, cv.content, m.path, m.moduleName, cv.moduleAttributes, cv.linkName, cv.sesLink, cv.entityRegExp, "
                                             &"                cv.title, cv.description, cv.keywords, cv.canonical, cv.showContentForEntity "
                                             &"           FROM #variables.tablePrefix#_navigation     n "
                                             &"     INNER JOIN #variables.tablePrefix#_contentVersion cv ON n.navigationId     = cv.navigationId "
                                             &"     INNER JOIN #variables.tablePrefix#_contentStatus  cs ON cv.contentStatusId = cs.contentStatusId "
                                             &"LEFT OUTER JOIN #variables.tablePrefix#_module         m  ON cv.moduleId        = m.moduleId "
                                             &"          WHERE cs.online            = :online "
                                             &"            AND n.position           = :position "
                                             &"            AND n.language           = :language "
                                             &"            AND n.active             = :active "
                                             &"            AND n.parentNavigationId " & (arguments.parentNavigationId == 0 ? " is null " : "= :parentNavigationId ")
                                             &"       ORDER BY n.position, n.sortOrder ASC")
                                      .addParam(name="online",             value=true,                         cfsqltype="cf_sql_bit")
                                      .addParam(name="active",             value=true,                         cfsqltype="cf_sql_bit")
                                      .addParam(name="language",           value=arguments.language,           cfsqltype="cf_sql_varchar")
                                      .addParam(name="position",           value=arguments.position,           cfsqltype="cf_sql_varchar")
                                      .addParam(name="parentNavigationId", value=arguments.parentNavigationId, cfsqltype="cf_sql_numeric")
                                      .execute()
                                      .getResult();

        for(var i = 1; i <= qGetTopLevel.getRecordCount(); i++) {
            hierarchy[i] = {};
            hierarchy[i].linkname = qGetTopLevel.linkName[i];
            hierarchy[i].sesLink  = qGetTopLevel.sesLink[i];
            hierarchy[i].title    = qGetTopLevel.title[i];
            hierarchy[i].children = this.getHierarchy(position=arguments.position, language=arguments.language, parentNavigationId=qGetTopLevel.navigationId[i]);
        }

        return hierarchy;
    }
    
    /**
     * Navigation header
     **/
    public boolean function addNavigation(required struct navigationData) {
        return true;
    }

    public boolean function editNavigation(required numeric navigationId, required numeric version, required struct navigationData) {
        return true;
    }
    
    public boolean function deleteNavigation(required numeric navigationId) {
        return true;
    }
    
    /**
     *  Content Version
     **/
    public struct function addContentVersion(required numeric navigationId, required numeric userId, required numeric version, required struct versionData) {
        var formValidation = this.validateVersionData(arguments.versionData);
        
        formValidation.navigationId = isDefined("arguments.navigationId")                ? variables.formValidator.validate(content=arguments.navigationId,                ruleName='Id')      : false;
        formValidation.version      = isDefined("arguments.version")                     ? variables.formValidator.validate(content=arguments.version,                     ruleName='Version') : false;
        formValidation.status       = isDefined("arguments.versionData.contentStatusId") ? variables.formValidator.validate(content=arguments.versionData.contentStatusId, ruleName='Id')      : false; 
        
        formValidation.status       = this.statusExists(contentStatusId    = arguments.versionData.contentStatusId);
        formValidation.navigationId = this.navigationIdExists(navigationId = arguments.navigationId);
        formValidation.version      = this.versionAvailable(navigationId   = arguments.navigationId, version  = arguments.version);
        formValidation.linkName     = this.linkNameAvailable(navigationId  = arguments.navigationId, linkName = arguments.versionData.linkName);
        formValidation.sesLink      = this.sesLinkAvailable(navigationId   = arguments.navigationId, sesLink  = arguments.versionData.sesLink); 
        
        formValidation.success = this.allSuccessfull(formValidation);

        if(formValidation.success) {
            new Query().setDatasource(variables.datasource)
                       .setSQL("INSERT INTO #variables.tablePrefix#_contentVersion "
                              &"            ( "
                              &"              navigationId, "
                              &"              version, "
                              &"              contentStatusId, "
                              &"              content, "
                              &"              moduleId, "
                              &"              moduleAttributes, "
                              &"              linkName, "
                              &"              sesLink, "
                              &"              entityRegExp, "
                              &"              title, "
                              &"              description, "
                              &"              keywords, "
                              &"              userId, "
                              &"              showContentForEntity "
                              &"            ) "
                              &"     VALUES ( "
                              &"              :navigationId, "
                              &"              :version, "
                              &"              :contentStatusId, "
                              &"              :content, "
                              &"              :moduleId, "
                              &"              :moduleAttributes, "
                              &"              :linkName, "
                              &"              :sesLink, "
                              &"              :entityRegExp, "
                              &"              :title, "
                              &"              :description, "
                              &"              :keywords, "
                              &"              :userId, "
                              &"              :showContentForEntity "
                              &"            ) ")
                       .addParam(name="navigationId",         value=arguments.navigationId,                     cfsqltype="cf_sql_numeric")
                       .addParam(name="version",              value=arguments.version,                          cfsqltype="cf_sql_float",   scale="2")
                       .addParam(name="contentStatusId",      value=arguments.versionData.contentstatusId,      cfsqltype="cf_sql_numeric")
                       .addParam(name="content",              value=arguments.versionData.content,              cfsqltype="cf_sql_varchar", null="#arguments.versionData.content              == '' ? true : false#")
{'fraction_non_alphanumeric': 0.08555334378044133, 'fraction_numerical': 0.0011011816526195416, 'mean_word_length': 1.221469564399285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 248, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1566214', 'n_tokens_mistral': 5092, 'n_tokens_neox': 4982, 'n_words': 836}