
########################################################################################################################
                                            TrendOne Documentation
########################################################################################################################
This Documentation will explain the different functions used in the TrendOne Module.

############## Contents ##############

### JS Files
    ## verscFunctions.js
    From #1 - #23
        #1 function "setSession(token, host)"
        #2 function "setElements()"
        #3 function "getGeneralChartData()"
        #4 function "getMicrotrendsTabData()"
        #5 function "sT()"
        #6 "window.onclick = function(event)"
        #7 function "toggleText(box)"
        #8 function "modalToggle()"
        #8.5 function "modalToggleLayerTwo(action)"
        #9 function "rippleEffect(event ,divName)"
        #10 function "clearFilter()"
        #11 function "toggleFilterBox()"
        #12 function "switchProfileTable()"
        #13 async function "searchInputHandler(drillseries, word)"
        #14 function "microtrendSearchEvent(e)"
        #15 function "megaMacroSearchEvent(e)"
        #19 function "setFocusSearchBox()"
        #21 function "moreInfoModal(infoType)"
        #21.5 async function "displayProtectedImage(imageElement, imageUrl, authToken, host)"
        #22 function "setPath()"
        #22.5 function "goToGraph(mega, macro)"
        #23 function "setCurrentFilter(induData, categoryData, word)"

    ## fetchData.js
    From #24 - #28
        #24 async function "login(token, host)"
        #25 async function "getChartDBD(filter)"
        #26 async function "getMicroTabData(filter)"
        #27 async function "getAPIdata(filter)"
        #27.5 async function "fetchWithAuthentication(url, authToken, host)"
        #28 async function "getMicrotrendData(sendData)"

    ## createTables.js
    From #29 - #40
        #29 function "setFilter()"
        #30 function "customCategorySelect()"
        #31 function "closeAllSelect(elmnt)"
        #31.5 function "closeAllCheckboxFilters()"
        #32 function "searchFilterTable(data)"
        #33 function "clearMicroTabMicrotrends()"
        #34 function "drawMicro(data, language, value, tab)"
        #35 function "clearMicro()"
        #36 function "clearProfiles()"
        #37 function "clearMicroModalContent()"
        #38 function "buildProfileTable(profileData, base)"
        #39 function "setMicrotrend(id)"
        #40 function "buildMicroCrunchProfileModal(initiator)"

    ## createTreemapChart.js
    From #41 - #46
        #41 function "getChart(points, drillseries, drillup)"
        #42 function "clearAllOldContend()"
        #43 function "goToTrendMacro"
        #43.5 callClearFilter()
        #44 function "singleReflowEvent"
        #45 function "reflowEvent"
        #46 function "searchInputEvent"

    ## createMacrotrendChart.js
    From #47 - #49
        #47 function "createMacroChart( dataVal, cName, lName, divUsed)"
        #48 function macrotrendChartReflow
        #49 function "getMacroChartData(id, lang, div )"

    ## createTopMacrotrends.js
    From #50 - #54
        #50 async function "getMacrotrends(sendData)"
        #51 function "buildMacrotrends()"
        #52 function "clearOldTopContent()"
        #53 async function "buildTime(u, locales, context, timeConnect)"
        #54 function "moreInfoIcon()"

    ## litSwitchTabs.js
    From #55 - #55
        #55

    ## createMacrotrendMap.js
    From #56 - #59
        #56 function "createMacroMap(dataVal, div)"
        #57 function "getMacroMapData(id, lang, div)"
        #58 function "macrotrendMapReflow"
        #59 function "macrotrendMapReflowTopTrends"

### php Files
    ## getSessionData.php
    From #60 - #61
        #60 function "hexToRgba($hex, $opas)"
        #61 function "resolveAccessPath($path)"

    ## apiData.php
    From #62 - #65
        #62 function "getData($url)"
        #63 function "getConnectedCrunchProfils($data)"
        #64 function "getConnectedProfils($data)"
        #64.5 function "getImg($data)"
        #65 function "importProfiles($data)"

    ## topMacrotrendsData.php
    From #66 - #70
        #66 function "getMostCreatedLastMonth()"
        #67 function "updateTime($timeBack)"
        #68 function "getTopMacroGes()"
        #69 function "getTopGrowingMacro()"
        #70 function "getInfoBoxData($id_meg, $id_mac , $lang)"

    ## dbData.php

    ## getdbData.php
    From #71 - #85
        #71 public function "getFilterObjects()"
        #72 public function "getFilter($filter)"
        #73 public function "insertionSort($array)"
        #74 public function "getMacroMegaHighchartData($filter, $chartSel)"
        #75 public function "getTimeMacroChart($time, $timeBack)"
        #76 public function "getMacroTrendData($filter, $id, $filterCheck)"
        #77 public function "getMicrotrendData($query, $id, $rowsStart)"
        #78 public function "getNextRows($filter, $id, $rowsStart)"
        #79 public function "getExtraMicrotrendData($categoryID, $macrotrendIDs, $industryIDs )"
        #80 public function "getMicrotrends($filter, $id, $rowsStart)"
        #81 public function "getNewMicrotrends($filter, $word, $rowStart)"
        #82 public function "getArticles($id)"
        #83 public function "updateTime($timeBack)"
        #84 public function "getMacrotrendMapData($filter, $id, $filterCheck)"
        #85 public function "getMicrotrend($id)"

    ## envData.php

    ## trendoneDBupdate.php
    From #86 - #103
        #86 function "getAccessKey()"
        #87 function "getUpdatedTrends()"
        #88 function "getUpdateDate()"
        #89 function "getDeleteDate()"
        #90 function "updateTrends($dataUpdate, $dataDelete, $method)"
        #91 function "getData($url, $method)"
        #92 function "updateTime($timeBack)"
        #93 function "setOldDate($lastUpdate, $lastDelete)"
        #94 function "updateDelMega($dataVal)"
        #95 function "updateDelMacro($dataVal)"
        #96 function "updateDelMicro($dataVal)"
        #97 function "updateMega($dataVal)"
        #98 function "updateMacro($dataVal)"
        #99 function "updateMicro($dataVal)"
        #100 function "setArticles()"
        #101 function "updateIndustryData()"
        #102 function "updateCategorygroupCategory()"
        #103 function "getCategory($obj):array"

    ## countryCodeTableFill.php
    From #104 - #105
        #104 function "setCountryCodes()"
        #105 function "getData($url)"

    ## trendoneData.php
    From #106 - #116
        #106 function "getAccessKey()"
        #107 function "checkPoints()"
        #108 function "getData($method, $url)"
        #109 function "insertTime()"
        #110 function "insertIndustryData()"
        #111  function "insertMegaData()"
        #112 function "insertMacroData()"
        #113 function "insertCategorygroup()"
        #114 function "insertMicrotrends()"
        #115 function "getCategory($obj,$token):array"
        #116 function "updateTime($timeBack)"



########################################################################################################################
#############################################First Section JS Files#####################################################
########################################################################################################################
From #1 - #59

    #############################################################
    #############################################################
    ##################In File "verscFunctions.js"################
    #############################################################
    #############################################################
    From #1 - #23

#1 function "setSession(token, host)"
    This function can be found in "verscFunctions.js" at row 1 and is the first point of contact outside the html.
    It gets called on load of the html body. It is given the "AccessToken" and "AccessHost" which is used to determine
    on which side the user accesses the module ("AccessHost") and what settings the user has set, e.g. language and colors ("AccessToken").

    setSession(token, host) sends the token and host to the "async function login(token, host)" (#24) located in "fetchData.js" which will then
    send the "token" and "host" to the "getSessionData.php" file, which will return the settings of the user based on the "AccessToken".
    These settings get send back to the "setSession" function in which the "language", the "sessionToken" and the "host" ('host' => 'https://'.$host,)
    get set into the sessionStorage as "language, sT, host".
    The other returned elements are colors which the user has set on their profile like "primaryColor", "chartColor" and lighter versions of these colors.
    The colors are "rgba" and will be set as "root.style.setProperty".

    At the end of this function "setElements()" (#2) and "setFilter()" (File createTables.js #29) are called and the Element with the className "layout" (layout is a div which surround almost all the html. It is set as "display = none" on first load of the html)
    is set "flex" in order for the module to appear as a hole and not show the side when it is not fully loaded yet.



#2 function "setElements()"
    This functions sole purpose is to set the description of the text elements in the right language.
    It has an if statements which decides what language is used and only appends text nodes of this language.



#3 function "getGeneralChartData()"
    This function is the starting point for creating the Mega/Macrotrends Chart.
    First the loading Symbol gets shown after that the filters get checked, to know what filters got used. This gets saved into the filter element.
    The date we are going to send to the php file, to get the needed elements, gets build with "action", "filter" and "chart" (chart = chart type).
        var sendData = {
                "action" : "getMegaMacro",
                "filter" : JSON.stringify(filter),
                "chart": chart,
            };

    Now the data gets send to "getChartDBD(sendData)" (#25) after getting the returned data we are checking for eventlisteners which got set while building the Chart.
    If they exist, we remove them, so the garbage collector can remove the last iteration of the chart.
    After that is done. We check if the data we got has the right filter set on it. This is done by checking if the last set sessionData filter == the current filter.
    If not then we dont go further her and wait till the right data is returned.
        if(lastSetFilter == sendData.filter)

    If the data is the right data, we clear all old contend with the function "clearAllOldContend();" (#42) this function can be found in the createTreemapChart.js file
    If everything is right up to this point, we set the Chart visible again and call the "getChart(point, drillseries, lang);" (#41) function with the data we got.



#4 function "getMicrotrendsTabData()"
    This function is the starting point for creating the "Microtrend List" in the "Microtrends" Tab.
    First we show a loader Symbol after that we check the filters to know which got used this will then be put together
    into a var sendData with "action", "filter", "extraWord" (Search Term) and "count" (tells us how many rows got displayed till now ).
        var sendData = {
                "action" : "newMicrotrends",
                "filter" : JSON.stringify(filter),
                "extraWord": document.getElementById("microtrendSearch").value,
                "count": 0
            };

    We set that as a sessionStorage Item, as we will use it in another function later.
    Now we send the sendData away (to #26).
        getMicroTabData(sendData).then(dataVal=>{

    After we received the data we check, if it's the most recent one, by checking if the last set session filter == current filter and last set session word == the current word
        if((lastSetFilter == sendData.filter) && (lastWord == sendData.extraWord)){

    now we call the function clearMicroTabMicrotrends(); (#33) to clear the old table if the new data.length == 0 we display a text for that if not
    we call drawMicro(data, language, value, tab) (#34) with the data we have.




#5 function "sT()"
    Function which on switching tabs inside the "Trendexplorer" Tab always goes to the Top of the content.
    Function gets called when ever a switch Tab gets clicked.



#6 "window.onclick = function(event)"
    This function is primarily used to close boxes if a click happens outside the box, e.g. filter or modal boxes.
    This function gets the event position and then checks if the click was made inside an opened box, if not the box gets closed.



#7 function "toggleText(box)"
    This function toggles the text boxes for "Macrotrend Description" and "Megatrend Description", it also changes the arrow pointing direction.



#8 function "modalToggle(action)"
    This function makes microtrend modal appear/disappear, if a microtrend got clicked.



#8.5 function "modalToggleLayerTwo(action)"
    This function makes modal, which overlays the current modal appear/disappear.



#9 function "rippleEffect(event ,divName)"
    This function adds the ripple effect on filters.
        "divName" gives us the name of the div we want the ripple effect on.
        "event" gives us event information.

    A span element gets created, this element then gets appended to the current div ("divName").
    After that the position of the ripple element gets set, inorder for the ripple effect to go from the middle of the div, outwards.
    After 300ms ripple gets removed. This creates the ripple effect.



#10 function "clearFilter()"
    This function clears the filters on the "Trendexplorer" Tab before going to the previously selected Macrotrend, from the "Top Trends" Tab.
    If this is not happening, the Macrotrend could potentially not be found.
    The getGeneralChartData(); (#3) gets called last. It starts building the new Chart.


#11 function "toggleFilterBox()"
    This function toggles the filter boxes "Industries, CategoryGroup and Search..." on the Trendexplorer Tab



#12 function "switchProfileTable()"
    This function gets called from the Related Profiles Tab and makes Portfolio or Crunchbase Profiles appear or disappear if selected or unselected.



#13 async function "searchInputHandler(drillseries, word)"
    This function searches the currently used elements for the chart (variable drillseries) and searches them for the search term (variable word).
    If found, the path and name of that element gets saved.
        macroObject = {
                            id_macro: drillseries[index].data[result].id,
                            id_mega: megaId,
                            name: drillseries[index].data[result].name,

                        };
    and after that send to "searchFilterTable(macroPoint);" (#32)



#14 function "microtrendSearchEvent(e)"
    This function gets called from a EventListener that checks for new input (defined in #29)
    It checks for what got put into the input and how long ago new input got set.
    Based on that, the "getMicrotrendsTabData()" (#4) function gets called or not.



#15 function "megaMacroSearchEvent(e)"
    This function gets called from a EventListener that checks for new input (defined in #29)
     It checks for what got put into the input and how long ago new input got set.
     Based on that, the "getGeneralChartData()" (#3) function gets called or not.



#19 function "setFocusSearchBox()"
    This function sets the focus inside the input filed if the search icon got clicked.



#21 function "moreInfoModal(infoType)"
    This function makes the content of the Info modal appear depending on which Info button was clicked.
    This is determent by the value of the variable infoType.



#21.5 async function "displayProtectedImage(imageElement, imageUrl, authToken, host)"
    This function get img data, converts it into an blob, creates an ObjectURL which then gets put into the img Element.
    This exists inorder for portfolio images to be shown in the App.



#22 function "setPath()"
    This function sets the url path based on what tab we are on.



#22.5 function "goToGraph(mega, macro)"
    This function lets us click the macro/megatrends inside the microtrend modal and then sends us the corresponding point inside the
    Treemap/Pie chart.



#23 function "setCurrentFilter(induData, categoryData, word)"
    This function set the filter elements and the search word. Based on what AccessPath was given.





    #############################################################
    #############################################################
    ####################In File "fetchData.js"###################
    #############################################################
    #############################################################
    From #24 - #28

#24 async function "login(token, host)"
    This function connects to the "getSessionData.php" file with a fetch. It gets the "token" and "host" variables. These get put into sendData which then
    gets put into data and is sent inside the body.

    var sendData = {
            "token" : token,
            "host" : host
        }



#25 async function "getChartDBD(filter)"
    This function connects to the "dbData.php" file and gets the variable filter, which has an element that is called filter in it.
    This filter element possesses the knowledge of which filters got used for the chart. This gets set as the "lastSendFilter" this variable will be used to determine
    if the data which got send back is infect the right data (the logic for that will be explained in #3).
    The filter variable ("getChartDBD(filter)") has the filter, the action (decides what will be done inside "dbData.php") and the chart type inside it. This variable get send to "dbData.php"
    with a fetch request.

    var sendData = {
            "action" : What to do inside "dbData.php",
            "filter" : Which filter elements got selected,
            "chart": Which chart currently is selected,
        };



#26 async function "getMicroTabData(filter)"
    This function connects to the "dbData.php" file and is used for the "Microtrends Tab" inside the Module.
    This works almost the same as #25 except that this time the "lastSendFilterTabMicro" gets saved which is the last send filter but for the "Microtrends" Tab
    and the "lastSearchWord" also gets saved. This is to know if the returned data is in fact the right data.
    The filter this time has the "action" (decides what will be done inside "dbData.php"), the "filter", the "extraWord" (Search Word) and the "count" (how many rows currently get displayed in order for the load more button to work)
    inside it.

    var sendData = {
            "action" : What to do inside "dbData.php",
            "filter" : Which filter elements got selected,
            "extraWord": The search term,
            "count": How many rows currently get displayed inorder for the load more button to work
        };



#27 async function "getAPIdata(filter)"
    This function connects to the "apiData.php" file. Its filter variable looks like this

    var requestData = {
                            "megaTitle" : The Title of the current selected Megatrend,
                            "macroTitle": The Title of the current selected Macrotrend,
                            "session": Session Token,
                            "host": host,
                            'action': What to do in "apiData.php"
                             }
    It works with a await fetch request.



#27.5 async function "fetchWithAuthentication(url, authToken, host)"
    This function makes an request to a php file which then will return img data.



 #28 async function "getMicrotrendData(sendData)"
    This function does the same as the getChartDBD function but without setting the "lastfilter" element into the sessionStorage



    #############################################################
    #############################################################
    ##################In File "createTables.js"##################
    #############################################################
    #############################################################
    From #29 - #40

#29 function "setFilter()"
    This function sends a request to "getChartDBD(method)" (#25) with the action to get the elements which then can be filtered after.
    After that a Table for Industries with input type "checkbox" each having a different id (Logic is "I" for Industry and then the real id after that ("I12"), for Industry
    filter on Microtrends Side it is "2I12") and for Category with element "option" gets build.

    Industry eg. <div class="checksIndustryItemBox">
                    <label class="checksLabel">
                        <input type="checkbox" id="I1" class="fObj">
                        <span class="checkmark"></span>Transportation &amp; Mobility
                    </label>
                 </div>

    Category eg. <option value="2">Online</option>

    value "no" means no Category selected.
    And id="op1" is the one that gets shown as default.

    Both filters will be set in the "Trendexplorer" Tab and the "Microtrends" Tab.
    At the same time, an Object with filter elements gets build. This is so we later know which element corresponds to which id.

    Industry element eg. element = {
                        id: The Elements id in the html,
                        value: The Elements real id in the database,
                        check: If it got checked or not (String "true", "false"),
                        name: The name of the element
                    };

    Category element eg.  element = {
                                     id:"catFil",
                                     value: "No",
                                     check: "false"
                                 };

    KeywordElement eg. let keywordElement = {
                                id:"keyWord",
                                value: "",
                                check: "false" <-- If nothing is set then this is false
                            };

    After that the function "customCategorySelect()" (#30) gets called this function turns selects like the Category Select into something more visual appealing.
    Next a few Selects get made, for the module to be set up correctly (this happens depending on what AccessPath is set), also event handlers get added in order for changes in the filters to
    instantly change the data which is shown.
    The function also sets some sessionStorage for some checks which will be used later in the program.



#30 function "customCategorySelect()"
    This function creates the visible selects. For adding a new select element, you have to first create an else if and append it to the existing ones.

     if(i == 1){
                a.id = "categButton";
                a.innerHTML = "";

                var currBox = document.createElement("div");
                currBox.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
                currBox.id = "cateFilterCurrEleBox";
                currBox.style.color = "var(--aumentoo-secondary-text-color)";

                a.appendChild(currBox);
            }else if(i == 0){ //Trendexplorer Chart select filter
                a.id = "chartSelectButton";
            }   //i = 1 is select on Top Trends Tab
            else if(i == 2){ //Top Trends Filter 1
                a.id = "profileListSelectButton";
            }
            else if(i == 3){ //Top Trends Filter 1
                a.id = "tabSelectButton";
            }else if(i == 4){ //Top Trends Filter 2
                a.id = "tabSelectLastMonthButton";
            }

     Selects get created in a loop
        x = document.getElementsByClassName("custom-CategorySelect");

     x[i] determines which select is currently used so if you want to add one then you have to know at which x[i] your wanted select is used.
     The order goes from top to bottom and from left to right so Chart Select on the "Trendexplorer" side would be first after that Category select would be second and so on.
     If you know your x[i] then you have to set up your "else if" for that "i".

     The next thing you have to know is if your select should be selected from the start for example like the Chart select in #24
        var selectedChart = document.getElementById("filterBox").getElementsByClassName("select-items")[0].querySelectorAll("div");
             selectedChart[0].click();

     In this case you dont have to do anything just build it like
         else if(i == 2){
                      a.id = "Here unique id";
                      }

     In the other case if you want to build it like Category Select then you have to build it like this.
         else if(i == 5){
                a.id = "Here unique id";
                a.innerHTML = ""; <-- leave it like that
                var currBox = document.createElement("div"); <-- create div
                currBox.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
                currBox.id = "cateFilterCurrEleBox"; <-- give div id
                currBox.style.color = "var(--aumentoo-secondary-text-color)"; <-- give div wanted color
                a.appendChild(currBox); <-- and append it
                }

         The next thing is to got to around line 1178 and create an if that works for you, select build it like the if, which is currently placed her
         but change what you have to.

     The next steps have to be done regardless of what select you want to create.
     Around line 1226 there are "else if"s these look something like.
        else if((s.options[0].value == "no") && (document.getElementById("tab03").selected == true)){
                                   getMicrotrendsTabData();
                                }
        The else if tells us what select we are using right now, whats inside the else if is what you want to run if the select got changed
        eg. Chart got changed from "By Macrotrends" to "By Microtrends".

     The rippleEffect gets added around line 1258 these if else check which select got clicked.
         if (document.getElementById("categButton").contains(e.target)) {       <-- "categButton" == the a.id we set before
                            rippleEffect(e, "categButton"); <-- This get called
                        }




#31 function "closeAllSelect(elmnt)"
    This function closes all selects except the current select box



#31.5 function "closeAllCheckboxFilters()"
    This function closes all checkbox filters. It gets called whenever a select filter gets clicked, that way we only ever have one filter box open at a time.



#32 function "searchFilterTable(data)"
    This function builds the Table for "Macrotrend..." search field in the "Trendexplorer Tab".
    The variable data has objects of elements which have the search term in them.
    If there are no such macrotrends (data.length == 0)  then a "Nothing Found" box will get displayed.



#33 function "clearMicroTabMicrotrends()"
    This function clears the microtrends List in the "Microtrends" tab.



#34 function "drawMicro(data, language, value, tab)"
    This function builds the list for the microtrends
        data = the actual microtrends
        language = the language the user uses
        value = the total amount of entries the DB has to this specific search
        tab = the div container we are going to load the data in //1 = Trendexplorer Related Microtrends // 2 = Microtrends tab

    These Lists are build like Tables, so we create a row on which we then put the title and a snippet of the microtrend.
    With row.onclick we register if a row was clicked and let the specified code run.
    In the case of a microtrend we first clear the modal content with (#37) and run a request to get more data.

        var requestDataMicrotrend = {
                        'action': 'extraMicroData',
                        'macrotrendIDs' : data[i].macrotrendIDs,
                        'industryIDs' : data[i].industryIDs,
                        'categoryID' : data[i].categoryID
                    }
    We send this request to getChartDBD (#25)
    after that, we just fill up the modal content with the data we got.

    The special thing in this list we create is, that we have a load more button.
    At the end of this function we check in which tab we created the table and if there is still more data in the DB we could load.

    In the "Trendexplorer" tab we always load a max of 25 entries at once, so the "if" looks like this.
        if (data.length == rowAmount && ((dataS.count+rowAmount) < value))
    The load more row will be displayed if the length of the data we got == the total length we display on one load and
    the last start row + the amount of rows we will be loading next is still less than the total amount of data available.
    If we want to change the amount of rows that we load then we change var rowAmount and also have to change the DB query in #77

    In the "Microtrends" tab we always load a max of 20 entries at once, so the "if" looks like this.
        if (data.length == rowAmount && ((dataS.count+rowAmount) < value))
    The load more row will be displayed if the length of the data we got == the total length we display on one load and
    the last start row + the amount of rows we will be loading next is still less than the total amount of data available.
    If we want to change the amount of rows loaded then we change var rowAmount and also have to change the DB query in #81

    After this we just create a row which onclick will send a request
        var sendData = {
                            "action": "nextMicroRow",
                            "filter": dataS.filter,
                            "id": dataS.id, <-- The id of the macrotrend
                            "count": row
                        };
    save this request and send it
    to a php file to get the next data sent after receiving the data we just call drawMicro (#34) again.



#35 function "clearMicro()"
    This function clears the microtrends list inside the "Trendexplorer" tab.



#36 function "clearProfiles()"
    This function clears the articles list, "Related Profiles" and the macrotrend description.



#37 function "clearMicroModalContent()"
    This function clears the modal content that appears if the user clicks on a microtrend.



#38 function "buildProfileTable(profileData, base)"
    This function builds the list for "Articles" and "Related Profiles"
        nP = Portfolio Profiles
        cP = Crunchbase Profiles
        aP = Articles
    These lists get build in the same way the lists in #34 get build (in a table structure).
    We first create rows, which we fill with the data we got.
    We check for a click on these row with row.onclick = function.
    If that happens, we start the code we created for these events.



#39 function "setMicrotrend(id)"
    This function sends a request to get the Microtrend data based on a Microtrend id.
    With the Data it got, the Microtrend info will be set inside the modal, which will then appear.
    This function only runs if the AccessPath lead to a Microtrend.



#40 function "buildMicroCrunchProfileModal(initiator)"
    This function sets up everything we need to load the Crunchbase Profiles, which could be connected to the initiators of a microtrend.
    After clicking an initiator inside the Microtrend modal, this function gets called. Here be build the request object and send it the corresponding php file.
    The data we receive then gets send to the buildProfileTable, which will then build the table that holds the results.



    #############################################################
    #############################################################
    ################In File "createTreemapChart.js"##############
    #############################################################
    #############################################################
    From #41 - #46

#41 function "getChart(points, drillseries, drillup)"
    In this function the Mega/Macrotrend Chart gets build with the use of Highcharts.
        points = Megatrends put in a form for Highcharts
            $megaP = [
                            'id' => Megatrend id,
                            'name' => Megatrend Title DE,
                            'name_en' => Megatrend Title EN,
                            'value'=> Amount of Macrotrends to Megatrend,
                            'y' => Amount of Microtrends to Megatrend,
                            'text_de' => Description DE,
                            'text_en' => Description EN,
                            'created' => Date of creation,
                            'updated' => Date of last update,
                            'visual' =>  picture,
                            'drilldown' => drilldown id which is 'd' + megatrend id eg. 'd12'
                        ];

        drillseries = the drilldown object for the points (Macrotrends for each Megatrend)
            $drillObject = [
                            'id' => 'd'. $points[$index]['id'] id is coresponding to drilldown in $megaP so its 'd' + the id of macrotrend which this drilldown Object is under eg. 'd12',
                            'name' => 'Microtrends', <-- This will show up while hovering the Chart
                            'type' => $chartSel, //'treemap' <-- type depends if 'treemap' or 'pie' is selected in select
                            'layoutAlgorithm' => 'squarified', <-- always 'squarified' because of Treemap. Will get ignored for 'pie' Chart
                            'borderWidth' => 2, <-- just borderWidth
                            'data' =>  Here are Macrotrends in the form of $megaP but without 'drilldown'
                        ];

        drillup = The text the drillup button should show.

    This next part is almost all build with Highchart, so if there a questions that dont get addressed here, then check the Highcharts Documentation.

    First we check which chart type is currently selected, based on that a few settings get dynamically changed.
    With const chartTr = Highcharts.chart('charContainer' we start the process of building our Chart.
    'charContainer' = the div we want our Chart to appear in.

    credits: <-- If we want to have credits shown or not.
    tooltip: <-- This is what gets shown, if we hover over the chart. We use html to style this.
    noData: <-- This is how the chart gets styled if there is no data in it.
    plotOptions: <-- These are Options we set for specific chart types or for all chart types together (series)
        pie: <-- Inside plot option we set options for the pie chart specifically. These only get used if the chart type = pie
        series: <-- Inside plot option these are options which get used for every chart type. If there are option set in pie which are also set in series the options in pie will get used.
              color: <-- Color inside series sets the color of the treemap fields. The Hover options is buggy her so we go into css and do it ourselves by finding the path and setting a color on hover. Should be in style.css around line 630
              dataLabels: <-- Style for microtrend labels.
              point: <-- Setting something for a specific point.
                events: <-- Inside point these are events on points.
                    unselect: <-- This triggers if a point gets clicked twice or if another point gets clicked. This also triggers after the normal click event.
                                    In our case we don't want to unselect a point if it gets clicked twice only if another point get clicked, or we go back to megatrends.
                                    We check if the last selected point (set in session storage in click event) == the last point (this.id <-- this is unselected point)
                                    if this is true we check for the Chart we currently use because for pie chart we dont want a change in color we want to slice the selected point
                                    also using the select logic to change color didn't really work, so we did it ourselves again (style.css around line 630).
                                    return false stops the unselect process and the point is still selected.

                    click: <-- This triggers if a point is clicked. This happens before every other click event is triggered, but we only want it for clicks on macrotrends
                                for that to work we have to check if we are already on that level this can be done by checking is this.name != null (this.name == null on the megatrend level becaus on that level you get name with e.point.name)
                                The next thing we do is check if the clicked point was already clicked if that happens we skip everything else to not load stuff again we already loaded.
                                There are exception to this thou. If we want to load a point regardless then we set the sessionStorage item "chartDataLoadMegaMacro" to "true". This happens for example if we imported a profile otherwise the imported profile wouldn't appear in the portfolio profiles.
                                Next we set the id of the currently selected Macrotrend to use in the unselect event and if we change Charts.
                                We only select manually otherwise multiselects are possible in Highcharts and we dont want that.
                                The next part is just clearing old tables of microtrends, macrotrend description, profiles and articles and sending request to
                                the corresponding php files to get the data we need after the data arrives we call the function to build these tables.

    chart: <-- These are option we set for the chart, like plotBorderWidth, height, backgroundColor and spacing.
        events: <-- These are chart events
            drilldown: <-- This triggers if a point with a drilldown element gets clicked.
                            To not still have selected point in the new point we drilldown we first need to unselect every point because drillup doesn't do that for us.
                            After that we are setting the megatrend id into the sessionStorage to use it when we change Charts we also set the title of the chart to the
                            name of the megatrend and set the title and description of the megatrend.

            drillup: <-- This gets triggered when ever the drillup button is pressed.
                         On drillup we dont have any mega or macrotrend selected that's why we need to clear the content that was displayed before
                         we do that by calling the clearAllOldContent() function (#42). We also want to change the title of the chart because we don't have any megatrend selected currently
                         that why we do chartTr.setTitle({text: "Megatrends"});

    series: <-- Here the setting for the displayed data get set like the point object which has our data inside it.
    title: <-- Here the title of the chart is set.
    drilldown: <-- Here the setting for the displayed drilldown elements get set like the drillseries object we got from our php file.

    At this point the global function #43 is defined.

    After this we sometimes get an error because we call chartTr.reflow() to early, that's why we wait till the chart is fully finished.
    If the chart type got changed we want to navigate to the previously selected macrotrend. Every chart change called #3 and in that #42 gets called
    but in #42 we check if chart got changed if it didn't we overwrite the sessionStorage item for mega and macrotrend id and change them to "no".
    But if it did change we fire click events that bring us to the right macrotrend.

    The other way why we need to got to a macrotrend dynamically is because we selected it in the "Top Trends" tab.
    That first clear every filter and then sets the sessionStorage item for "gotClear" to true. If that happens we at this point call "goToTrendMacro()" #43

    The next event listener is checks if we clicked a macrotrend title in the "Top Trends" tab info box
    There are also event listeners that fire if we go to the "Trendexplorer" tab these start reflow events to scale the Chart to its div because that
    isn't done by Highcharts if the chart isn't currently showing.



#42 function "clearAllOldContend()"
    This function clears all content on the "Trendexplorer" tab, this happens if a new chart gets created and if drillup is called.
    It also checks if it got called because the chart type got switched, in that case it sets a check, so we later know and can navigate to the previous displayed macrotrend.



#43 function "goToTrendMacro" <-- Inside #41
    This function is global. It gets destroyed in #3. Its purpose is to dynamically drilldown the chart to a specific macrotrend.
    It does this by first making sure we are on the top most level and then getting the mega and macrotrend ids we want to go to.
    After that, we get the point with "chartTr.get(id_mega);" and fire a click event on it with "firePointEvent('click');"
    Because this function get called from the "Top Trends" tab, we also need to go to the "Trendexplorer" tab and like always after
    making programmatic changes to the switch tabs, we need to call an update to apply them.



#43.5 callClearFilter()
    This function exists inorder for us to be able to remove an eventlistener



#44 function "singleReflowEvent" <-- Inside #41
    This function is defined global and reflows the chart.



#45 function "reflowEvent" <-- Inside #41
    This function is defined global and reflows the chart, if a specific area got clicked on.



#46 function "searchInputEvent" <-- Inside #41
    This function is defined global and gets called when ever the macrotrend search in the "Trenexplorer" tab gets used.
    Its purpose is to check how many characters are inserted into the input filed and if enough time has passed since the last input.
    If everything is correct then the function "searchInputHandler" (#13) gets called and give the characters that were entered and the macrotrends (drillseries)



    #############################################################
    #############################################################
    ##############In File "createMacrotrendChart.js"#############
    #############################################################
    #############################################################
    From #47 - #49

#47 function "createMacroChart( dataVal, cName, lName, divUsed)"
    This function builds the macrotrend line chart with Highcharts.
    Please look at the Highcharts documentation for the things I'm not going to address her.
        dataVal = The data we get from our php files. It has "creaColData" and "lineData" loaded onto it.
        cName = How the column is named.
        lName = How the line is named.
        divUsed = In what div the chart will be loaded into.

    We start defining the chart with this const chartt = Highcharts.chart(divUsed, <-- Here we put divUsed
    Next are just setting for the chart to make it look the way we want.
    Inside series there is yAxis we have yAxis: 0 and yAxis: 1 this makes it, so we have two yAxis on one we put creaColData inside data and on the other we put lineData inside data.

    We also set eventlisteners for reflow events her, otherwise the chart will be too big or too small after changing the window size.



#48 function macrotrendChartReflow <-- Inside #47
    This function is global and reflows the macrotrend chart



#49 function "getMacroChartData(id, lang, div )"
    This function is the starting point for building the macrotrend chart.
        id = id of the macrotrend we will build the chart for.
        lang = the language the user uses.
        div = the div we want the chart to be in.

    First we get the filter because these also get applied to the macrotrend chart.
    Then we check in which div we want the chart to be put in. If it's the div inside the "Top Trends" tab then we don't want the filters to be applied, that's why we set "filterCheck" to "no".
    Now we build the request data and send it to the php file.
    After getting the returned data, we first need to remove old event listeners and delete the global function inside #40, in order for the garbage collection to work.
    The last thing we do is call "createMacroChart" (#47).



    #############################################################
    #############################################################
    ##############In File "createTopMacrotrends.js"#############
    #############################################################
    #############################################################
    From #50 - #54

#50 async function "getMacrotrends(sendData)"
    This function connects the JS file with the "topMacrotrendsData.php" file.
    It uses a fetch request.



#51 function "buildMacrotrends()"
    This function builds the list in the "Top Trends" tab.
    It does this by first clearing all old content (#52) and then checking what filters are set.
    Based on that, an action gets set inside "sendData". This then gets send to "getMacrotrends" (#50) which then goes to the php files and returns the data we want.
    After we get the data, we build the list like a table. That means we create a row with title, snipped and based on what list we want to display, something list specific.
    To catch if a row got clicked, we use "row.onclick". This then starts the request to build the macrotrend chart (#49) and also build another
    request object to sent to a php file to get the data we want in our info box displayed (#50) after getting the data, our info box will get filled up.
    A change in the filters will start this hole cycle again.



#52 function "clearOldTopContent()"
    This function clears all the content in the "Top Trends" tab.



#53 async function "buildTime(u, locales, context, timeConnect)"
    This function converts date time to a local time string.
        u = new date Object with the datetime we want to convert.
        locales = 'de-DE' or 'en-US'
        context = the context the time should be displayed at eg. Hour:minute PM.
        timeConnect = how the date and the time are connected eg. "um " or "at ".
    This function sends back the new time string.



#54 function "moreInfoIcon()"
    This function fills the modal for the Top Trends List Info Icon dynamically and makes it appear.
    It looks at what filter is currently used and fills the modal with content for that filter.



    #############################################################
    #############################################################
    ##################In File "litSwitchTabs.js"#################
    #############################################################
    #############################################################
    From #55 - #55

#55 To set another property for the switch tab elements just go to litSwitchTabs.js go to class Tab extends LitElement and put what you want next to xtitle and selected
    If you want to add another switch tab. Go to the html and build it like the following.
        <switch-tabs id="t0"> <-- This is the switch tab overall. The id has to be unique
                        <switch-tab id="tab01" xtitle="Trendexplorer"> <-- This is a single tab inside the switch tab. Unique id and xtitle will be how the tab is called
                            Here comes the content you want inside the switch tab
                        </switch-tab>
                        <switch-tab id = " " xtitle = " "> <-- We can make how many we want
                        </switch-tab>
        </switch-tabs>



    #############################################################
    #############################################################
    ###############In File "createMacrotrendMap.js"##############
    #############################################################
    #############################################################
    From #56 - #59

#56 function "createMacroMap(dataVal, div)"
    This function creates the Highcharts Map with the Microtrends of a specific Macrotrend.
        div = the div in which the map will be displayed
        dataVal = the data we need to display the map



#57 function "getMacroMapData(id, lang, div)"
     This function is the starting point for building the Macrotrend map. Here the data which will be sent to the php file is set and send.
     This function also removes the event listeners from previous Highcharts maps, that way they can be garbage collected.
        id = The id of the Macrotrend
        lang = the language used
        div = the div in which the map should be displayed



#58 function "macrotrendMapReflow"
    This function reflows the Macrotrend map, which got build in the "Trendexplorer" tab.



#59 function "macrotrendMapReflowTopTrends"
    This function reflows the Macrotrend map, which got build in the "Top Trends" tab.



########################################################################################################################
############################################Seconde Section php Files###################################################
########################################################################################################################


    #############################################################
    #############################################################
    #################In File "getSessionData.php"################
    #############################################################
    #############################################################
    From #60 - #61

This file is used to login the user and get the users branding, so we can use it later to dynamically display the module in the users settings.
First we get the token and the host, which we both use to log the user in and get the authorization token.
With this token, we can then send another request to the api and get the branding of the user.
We use "Guzzle" to send these request, so that we don't have to care about CORS.

We get the branding, now we have a primary color and are charts color both as hex colors, but we need more variations of these colors that's why
we convert hex to rgba and send this to a function (#60) which then returns the color with different opacities.
We put all of these colors into one object and return it to the JS file.



#60 function "hexToRgba($hex, $opas)"
    This function gets a hex color ($hex) and an opacity ($opas) and then converts the hex color into an rgba color with the given opacity.
    This new color will then get returned as a rgba color.



#61 function "resolveAccessPath($path)"
    This function gets the AccessPath, and splits it up. Based on the AccessPath elements, an Object get build which will be sent back to the js files
    and then used to determine what position the module should be in.



    #############################################################
    #############################################################
    ####################In File "apiData.php"####################
    #############################################################
    #############################################################
    From #62 - #65

This File is used to handle all request send to the "aumentoo api"
We first get the session data (token) and the action.
The action then decides what function will get called inside the switch case.



#62 function "getData($url)"
    This function sends the request to the api. It gets the token and the $url which we want to call.
    After that, it returns the body of the response.



#63 function "getConnectedCrunchProfils($data)"
    This function will return all the "Crunchbase" profiles, which are related to a specific macrotrend.
        $data = the data we got from the js file, in this case it is the macrotrend title.
    We take the macrotrend title and connect it to the url, which we then send to (#62) in return we get the "Crunchbase" profiles.
    After getting the response, we create profile objects with a loop with data from each profile. These objects then get pushed onto an array
    which then gets returned and send back to the JS file.



#64 function "getConnectedProfils($data)"
    This function will return all portfolio profiles, which are related to a specific macrotrend.
        $data = the data we got from the js file, in this case it is the macrotrend title.
    Here, we first have to replace certain words from the search term, otherwise the results are going to be inaccurate.
    After that we build the $url and send it to #50 with the results we get we build profile objects, which we load onto an
    array, which then gets send back to the JS file.



#64.5 function "getImg($data)"
    This function makes a request to get img data with the session token, this data will then get send to the js file.
    If an error happens no data will be send back.



#65 function "importProfiles($data)"
    This function will send an api request to import a certain profile into the portfolio.
        $data = date we get from the JS file, this time it is a Crunchbase id.
    We create the url and send an api request with the Crunchbase id.
    This then imports the profile into the portfolio and if successful returns {"success": true}



    #############################################################
    #############################################################
    ###############In File "topMacrotrendsData.php"##############
    #############################################################
    #############################################################
    From #66 - #70

This file handles the request from the "Top Trends" tab.
We first get the action from the data, then we set up a DB connection.
With the switch case, we call what ever function the action wants.



#66 function "getMostCreatedLastMonth()"
    This function get the macrotrends with the most new created microtrends under them in the last month.
    We call the function "updateTime(1)" (#67) to get the datetime the DB got last updated and go back one month.
    This datetime gets used in the Query to know what time frame we look for.
    The data we get from the DB will then get placed into an object and loaded onto an array, which then will be sent back.



#67 function "updateTime($timeBack)"
    This function gets the datetime the database got last updated and then changes that date to
    how many months we want to go back. How many month we go back is regulated through the $timeBack variable.



#68 function "getTopMacroGes()"
    This function gets the macrotrends with the most microtrends attached to them, sorted from most to least.
    After getting the data from the DB we put it into an object which we load onto an array and send back to the JS file.



#69 function "getTopGrowingMacro()"
    This function gets the macrotrends order after the trendValue we assigned it. But first we filter out the trends that in the last
    3 months before the current month didn't have more than 3 new microtrends assigned to them.
    After we get the data from the DB we put it into an object, which we load onto an array and send back to the JS file.



#70 function "getInfoBoxData($id_meg, $id_mac , $lang)"
    This function gets the data for the info box in the "Top Trends" tab
        $id_meg = megatrend id
        $id_mac = macrotrends id
        $lang = the language used by the user
    This works by creating a query that gets the data from the DB. After getting the data we put it into an object and load all of it
    into an array which we send back after that.



    #############################################################
    #############################################################
    #####################In File "dbData.php"####################
    #############################################################
    #############################################################
    From * - *

This files purpose is to manage what function will get called int the "getdbData.php" file.
This works through the action we send from the JS file which determines what case of the switch case gets used
and therefore what function gets called.



    #############################################################
    #############################################################
    ###################In File "getdbData.php"###################
    #############################################################
    #############################################################
    From #71 - #85

This file holds the functions which get called from the "dbData.php" file.
First we create a DB connection in the constructor and after that the functions will get used.



#71 public function "getFilterObjects()"
    This function will get the industries and category groups which we use to build our filters in the JS file.



#72 public function "getFilter($filter)"
    This functions purpose is to dynamically build a string with the filter elements inside it, which we then are abel to insert in every query to
    only get elements that have the filters applied to them.
    This has to be handled really care fully because we cant use prepared statements her. That's why It's important to check that only none malicious
    code can be inserted into the string.
        $filter = Hold the filter elements which we get from the JS file.
    We run through the data we get from the JS file in loops and check which element was selected. Then we insert that into the query string.
    $checkIndus, $checkCate, $checkKeyWord is for checking if it's the first element we inserted from this filter type or not. That important because of how the
    individual strings are connected after, otherwise the query won't work.
    If there is no filters set the $query variable will look like this $query = " "; (a white-space).



#73 public function "insertionSort($array)"
    This function works the insertion sort on the given array and returns it sorted.



#74 public function "getMacroMegaHighchartData($filter, $chartSel)"
    This function gets the mega and macrotrends from the DB and puts them into the form we need for Highcharts
        $filter = Holds the filter elements which we get from the JS file.
        $chartSel = The chart type currently selected.
    The $filter gets send to "getFilter" (#72) to get the string we put into our Query's.
    The next thing we do is check if a filter got applied and execute the right statement.
    With the data we get we create megatrend objects and put them into $points.
    Now we get the macrotrends, which we also create objects for each on.
    These get put into an 2D array with the first array increment being the megatrendID.
    The next thing to do is put them into the form we need them for Highcharts. That's why we create drillObjects which have the "id" 'd'+ The megatrendID.
    The 'data' variable of these $drillObjects will be the macrotrends with the corresponding megatrend id in the array which they got loaded onto.
    The last thing we do is send them back to the JS file to display them in the Highchart.



#75 public function "getTimeMacroChart($time, $timeBack)"
    This function get a datetime ($time) and how many month we want to go back ($timeBack) and with these it modifies the $time and returns it.



#76 public function "getMacroTrendData($filter, $id, $filterCheck)"
    This function gets the data for the macrotrend chart.
        $filter = Holds the filter elements we get from the JS.
        $id = macrotrendID.
        $filterCheck = If we want to apply the filters or not.
    First we get the last updated date. Then we take that datetime and go back 12 months (#75), to know how many microtrends the macrotrend had at that point.
    After that we take the date 12 months ago and the date 11 months ago and look how many got created in that time span.
    With that we have the first column of the chart. This number also gets added to the total microtrends from 12 months ago the get the total
    number of microtrend to this macrotrend 11 months ago. This then gets repeated until we have all the data we need.
    After we got all the data, we send it back to the JS file.



#77 public function "getMicrotrendData($query, $id, $rowsStart)"
    This function gets the data we need to display the microtrend list.
        $query = array that olds the filter query and the search term.
        $id = macrotrendID.
        $rowsStart = The row from which point onward we want the data from the DB.
    First we select the right query and execute it. Then we put each microtrend into an object and load it onto an array which then will get send back.



#78 public function "getNextRows($filter, $id, $rowsStart)"
    This function determines if we want the data for the microtrend list in the "Trendexplorer" tab or for the "Microtrends" tab.
    If no numeric id is set, we want it for the "Microtrends" tab.
        $filter = The filter elements we get from the JS file.
        $id = macrotrendID or something none numeric.
        $rowsStart = From which row onward we want the data from the DB.



#79 public function "getExtraMicrotrendData($categoryID, $macrotrendIDs, $industryIDs )"
    This function get the data we need to display the microtrend modal for when we click a microtrend.
        $categoryID = categoryID the microtrend is in.
        $macrotrendIDs = The connected macrotrend to the selected microtrends.
        $industryIDs = The ids of the industries connected to the microtrend.
    First we build query's for getting the category title, the industry titles and the mega and macrotrend titles.
    We then execute all of them and combine the data we get in an array which will then get send back.



#80 public function "getMicrotrends($filter, $id, $rowsStart)"
    This function originally calculated the trendValue but now it only connects to "getMicrotrendData" (#77)
        $filter = The filter elements we get from the JS file.
        $id = macrotrendID
        $rowsStart = From which row onward we want the data from the DB.



#81 public function "getNewMicrotrends($filter, $word, $rowStart)"
    This function gets the data for the "Microtrends" tab.
        $filter = The filter elements we get from the JS file.
        $word = The search term.
        $rowStart = The row we want to start to get data from the DB.
    We first send the filter elements to the "getFilter" (#72) function that's where we get the string we need to set into our query,
    to apply the filters. Then we check if $rowStart is numeric to prevent SQL injections.
    We execute the right query's to get the data from the DB and collect them into an array which will then get send back to the JS.



#82 public function "getArticles($id)"
    This function gets the articles which are connected to the selected macrotrend and returns them.
    The articles are in a JSON format.



#83 public function "updateTime($timeBack)"
    This function takes the current date and then goes back the number of months specified in the $timeBack variable.



#84 public function "getMacrotrendMapData($filter, $id, $filterCheck)"
    This function send a request to the DB in which we get all the data we need to build the Macrotrend map.
    This data then gets put into an object and send back to the js file.
        $filter = The filters used for building the map
        $id = The macrotrend id
        $filterCheck = If the filter should be used for the DB request or not (Inside the "Top Trends" tab the filter will never be used



#85 public function "getMicrotrend($id)"
    This function gets all the data for a single Microtrend.
    It is used for getting the data we need to build the Microtrend modal based on the AccessPath.
        $id = Microtrend id



    #############################################################
    #############################################################
    ####################In File "envData.php"####################
    #############################################################
    #############################################################
    From * - *

This file hold the login for the DB, Trendone_API and Serp-API.



    #############################################################
    #############################################################
    ###############In File "trendoneDBupdate.php"################
    #############################################################
    #############################################################
    From #86 - #103

This file is used to update the Database.
First we Establish a DB connection then we get the AccessKey for the "trendexplorer" api (#86)
If we successfully got the AccessKey we then call the function "getUpdatedTrends()" (#87) with this we start the DB update.

#86 function "getAccessKey()"
    This function gets the AccessKey from the "Trendexplorer" api which we need to send request to this api.



#87 function "getUpdatedTrends()"
    This function first gets the last updated/deleted date builds the urls we need for the "Trendexplorer" api.
    These urls get send to "getData" (#91) which then returns the data from the API. It then gets instantly turn into an array and loaded into a variable.
    The data inside the variable then gets send to the "updateTrends" (#90) function which then sends it to the correct end function.
    If nothing went wrong, this is the end of the update file. If not then the old update date will be set again (#93)


#88 function "getUpdateDate()"
    This function gets the date at which we last updated the DB and sets the current date as the last updated date.
    This is important, so we know which time span we have to check for new added trends.



#89 function "getDeleteDate()"
    This function get the last time we check for deleted data and sets the current datetime as the new datetime we checked.
    This is important, so we know which time span we have to check for new deleted data.



#90 function "updateTrends($dataUpdate, $dataDelete, $method)"
    This function sends the data it gets to the right function depending on which $method (action) got send.



#91 function "getData($url, $method)"
    This function send the request to the "Trendexplorer" API and returns the data it got.
        $url = The url used for the request.
        $method = If its a category we get or not.
    We first send a request to get the number of pages the result will have, because data gets send in a JSON form in pages from the "Trendexplorer" API.
    After that we send another request which is inside a loop that updated the page number we are requesting each iteration.
    The data we get gets loaded onto an array which then gets returned.



#92 function "updateTime($timeBack)"
    This gets the current datetime and transforms the datetime into the number of months you want to go back ($timeBack) it returns the datetime we created.



#93 function "setOldDate($lastUpdate, $lastDelete)"
    This function set the old update datetime again if an error accrued during the update process.
    If the old update datetime is set again we look at the error time span again and include it in the update the next time.



#94 function "updateDelMega($dataVal)"
    This function updates the deleted megatrends and sets the status of these to deactivated.
        $dataVal = The new data we will set into the DB.



#95 function "updateDelMacro($dataVal)"
    This function updates the deleted macrotrends and sets the status of these to deactivated.
        $dataVal = The new data we will set into the DB.


#96 function "updateDelMicro($dataVal)"
    This function updates the deleted microtrends and sets the status of these to deactivated.
        $dataVal = The new data we will set into the DB.



#97 function "updateMega($dataVal)"
    This function updates the megatrends.
        $dataVal = The data we need to update.



#98 function "updateMacro($dataVal)"
    This function updates the macrotrends.
        $dataVal = The data we need to update.
    After we set the updated macrotrends we have to set new values for them like "micValue" and "trendValue".
    This happens after we updated the microtrends.
    First we have to get the number of microtrend connected to a macrotrend after that we set that number into the macrotrend DB element for the specific macrotrend.
    The next thing we do is calculate the "trendValue" and set it for the specific macrotrend.
    The last thing this function does is call the "setArticles" function (#100).



#99 function "updateMicro($dataVal)"
    This function updates the microtrends
        $dataVal = The data we need to update



#100 function "setArticles()"
    This function set the articles for the macrotrends.
    The articles come from the serp api.
    The data we get will then be JSON encoded an loaded into the DB for each macrotrend.



#101 function "updateIndustryData()"
    This function will get the industries from the "Trendexplorer" API.
    It also truncates the industry table and the refills it with the new industries.



#102 function "updateCategorygroupCategory()"
    This function updates the Category Groups and the Categories.
    It calls the "getData" function (#91) to get the data needed for the update.
    It then Truncates the "categoryGroup" DB table and the "categroy" DB table both will get filled up again in the next step.



#103 function "getCategory($obj):array"
    This function get the categories and pushes it onto the $obj array. This array then gets send back.



    #############################################################
    #############################################################
    #############In File "countryCodeTableFill.php"##############
    #############################################################
    #############################################################
    From #104 - #105

This file logs into the "aumentoo" api and gets countries (country code connected to country name).
After that it will fill the DB table "countryCodes".



#104 function "setCountryCodes()"
    This function creates the url for the request on the "aumentoo" api.
    It then send the url to the "getData" (#105) function to get the data which then gets put into the DB table.



#105 function "getData($url)"
    This function gets the request url ($url) and sends a request to it.
    The data response gets returned.



    #############################################################
    #############################################################
    #################In File "trendoneData.php"##################
    #############################################################
    #############################################################
    From #106 - #116

This file is for filling the DB again, if all data is lost (every table is truncated).
Pleas note articles get added with the update script and not with this one.
Also the table "countryCodes" has a different file for filling it.

First we set variables for checkpoints because we load a lot of data and this can be very error heavy.
The next step is to connect to our DB and get the "Trendexplorer" access key. If everything goes right we get to the control point of this script
the "checkPoints()" function (#94)



#106 function "getAccessKey()"
    This function get the "Trendexplorer" access token which we need to send request to the "Trendexplorer API".
    This token will get set into a global variable so we can use it later.



#107 function "checkPoints()"
    This function is the control point of this script. From her we access the different functions one after another
    and make sure to repeat a request if not all data was received.
    We set the check point variable to 1 if the function was successful we also reset the global variables that we use to keep track of where we are in the request.



#108 function "getData($method, $url)"
    This function gets a method ($method) and the request url ($url) and with this send the request to the "Trendexplorer API".
    The first thing we do is, get the total page count of the JSON data we receive. Important her is that we cant load every page in one request.
    That will lead to a timeout eventually, that's why we need to do it in steps. We only load 100 pages at a time to make sure there are no errors.
    Next we check if the last page we loaded + 100 is still less than the total pages available. If not then we set $nextPoint (The end point of each loop) to the number of total pages.
    After that we begin the for loop and get the wanted data. After 100 iterations we set the last page we loaded to the currentPage (this is a global variable).
    If an error accrues inside the request we call the function "checkPoints()" (#107) which sends us back to this function with the last saved $currentPage.
    If no error accrues and we are in the last loop ($nextPoint == totalPages), we set the global variable "$loopEnd" to 1, which lets us exit the loop that exists in
    the function that we used to call "getData" (#108).
    In the end the data we got will be send to the function that called this function.



#109 function "insertTime()"
    This function inserts the current DateTime into the DB as the lastUpdated date and the lastDeleted date.



#110 function "insertIndustryData()"
    This function build the "Trendexplorer API" request url which gets send to the "getData()" function (#108) which then returns the data we need to fill the DB table (industry).
    Calling "getData()" (#108) and loading data into the DB happens in a loop, because of the reasons that were named in (#108).
    This loop end as soon as there is not more data we can get for this specific DB table.



#111  function "insertMegaData()"
    This function build the "Trendexplorer API" request url which gets send to the "getData()" function (#108) which then returns the data we need to fill the DB table (megatrend).
    Calling "getData()" (#108) and loading data into the DB happens in a loop, because of the reasons that were named in (#108).
    This loop end as soon as there is not more data we can get for this specific DB table.



#112 function "insertMacroData()"
    The first paar to this function works exactly like #111 and #110 but for the "macrotrend" table.
    The next part is for adding the micValue (the amount of microtrends connected to one macrotrend) and the trendValue(how many % more microtrends got added to this macrotrend
    in the last month compared the the 3 months before that).



#113 function "insertCategorygroup()"
    This function build the "Trendexplorer API" request url which gets send to the "getData()" function (#108) which then returns the data we need to fill the DB tables for "categoryGroup" and "category".
    Calling "getData()" (#108) and loading data into the DB happens in a loop, because of the reasons that were named in (#108).
    This loop end as soon as there is not more data we can get for this specific DB table.



#114 function "insertMicrotrends()"
    This function build the "Trendexplorer API" request url which gets send to the "getData()" function (#108) which then returns the data we need to fill the DB table (microtrend).
    Calling "getData()" (#108) and loading data into the DB happens in a loop because, of the reasons that were named in (#108).
    This loop end as soon as there is not more data we can get for this specific DB table.



#115 function "getCategory($obj,$token):array"
    This function gets the categories foreach categorygroup from the "Trendexplorer API" this then gets put into the array of the categorygroup the categories are in.
    This array then gets returned.



#116 function "updateTime($timeBack)"
    This function changes the datetime we have right now to the same datetime but changes the month to the month that was $timeBack before the current month. eg. 04.05.2020 $timeBack = 2 --> 04.03.2020





