⟵ hearthere ⟶
  • Quick start
  • Install MIT
  • Install PRO
  • Updating
  • Optimization
  • Update v4-v6
  • Backups
  • Console utility bin/totum
  • Basics for users
  • Interface and Layout
  • Tables and their parameters
  • Prefilter
  • Fields and their parameters
  • Syntax
  • Code, actions, formatting
  • Relational relationships
  • Calculation order and calculation units
  • Auto-complete calculations and timing
  • Duplicate rows and cycles
  • Comparisons
  • Functions
  • Debugging
  • Print and CSV
  • API
  • Roles and users
  • Notifications
  • Scheduled Actions
  • System tables
  • Trees
  • Anonymous tables
  • External Forms
  • Exporting and importing tables
  • [PRO] MeiliSearch
  • [PRO] Databases
  • [PRO] Custom CSS
  • [PRO] Custom docs
  • [PRO] LDAP AD
  • [PRO] File versions
  • [PRO] List-unsubscribe
  • [PRO] Dynamic fields
  • [PRO] Only Office
  • [PRO] Auth Tokens
  • [PRO] 2FA
  • [PRO] Superlang
  • [PRO] Daemons
  • [PRO] Profiler
  • Connecting functions
  • Placement Requirements
  • Connecting an Additional Interface
  • [SRV] Installation and Connection
  • [SRV] Export, PDF, Upload, and Preview
  • [SRV] XLSX/DOCX Generators
  • PRO Connecting Custom Functions

    To connect an additional function, you need to create it in the CalculateExtensions.php file, which is located at the root of the deployed TOTUM (in the folder with Conf.php).

    For example, let's connect the extHello function:

    The function name must start with ext*

    <?php
    
    use totum\common\errorException;
    $CalculateExtensions = new \stdClass();
    $CalculateExtensions->jsTemplates = '[{"name":"extHello","t":"(name: \"\")","d":false,"p":["name"],"m":[],"n":["name"]}]';
    $CalculateExtensions->extHello=function ($params){
        $params=$this->getParamsArray($params);
        return 'Hello, '.$params['name'];
    };
    

    The jsTemplates parameter must contain a json formatted description of all additional functions.

    Where:

    • name — the name of the function;

    • t — template for auto-completion;

    • d — whether the function is deprecated;

    • p — list of acceptable parameters;

    • m — list of multiple parameters (can be present multiple times in the call);

    • n — list of required parameters.

    When called, the function is executed from the Calculate, CalculateAction, CalculateFormat, or CalculateSelect* object — and can use all their functions. For example, getParamsArray.

    When called, the function receives the $params variable, containing a string! with parameters inside the parentheses after the function name. To get the parameters calculated according to TOTUM logic, you need to call the $this->getParamsArray($params) function. This function also has default parameters that can be set as needed:

    function getParamsArray($paramsString, $arrayParams = [], $notExecParams = [], $threePartParams = ['where', 'filter', 'key'])
    

    Where:

    • $paramsString — the string with parameters received by the function;

    • $arrayParams — parameters that can occur multiple times (multiple parameters from the template) - they will be returned as an array regardless of whether they occurred once or multiple times;

    • $notExecParams — parameters that will be returned as an unparsed string (useful when the code is executed conditionally);

    • $threePartParams — parameters consisting of three parts 'field' = "value" — returned as an associative array/list of associative arrays {"field" :"field", "operator":"=", "value": $value}.

    If the function needs to return an error, an exception is thrown:

    throw new errorException("Error text");
    

    An error thrown in the action code interrupts the recalculation chain, and changes are not saved.

    An error thrown when calculating the field value will set the calculated (and final, if the field is not fixed) field value to ERROR!

    Complex variant:

    If the current method of connecting ext* functions is not convenient for you, you can override the functions of the parent ConfParent.php class responsible for the operation of connected functions in the Conf.php class:

    ConfParent::getCalculateExtensionFunction
    
    ConfParent::getExtFunctionsTemplates
    

    Placement Requirements

    IT IS GOOD PRACTICE TO MAINTAIN THE FUNCTIONALITY OF THE STANDARD UPDATE UTILITY bin/totum git-update!

    To do this:

    • Do not modify system files.

    • CalculateExtensions.php is in git ignore and will not be overwritten.

    • Place additional scripts in /totum/ext/* — this folder will never be used in the master branch of core developers.

    • Adding dependencies to composer is possible, but in this case, you will need to perform a merge when dependencies are updated in the main development branch.

      • After you have made changes to composer.json and composer.lockadd them to the commit so that subsequent updates automatically trigger a git merge where possible.
    • If you have created a separate branch for development on the client's local machine:

      UNDER NO CIRCUMSTANCES MERGE IT INTO MASTER!!!

      YOU NEED TO COPY THE ADDED FILES MANUALLY!!!

      • Therefore, the following scheme seems most workable to us:

        • Create a folder next to the totum installation folder — totum_ext

        • Run git init there

        • Drop the development files there

        • From the main totum folder, create the necessary links ln -s ... (for CalculateExtensions.php and the /totum/ext/ folder)

        • Run git add * in the additional development folder

        • git commit -m 'comment text'

        • Connect to an external repository if desired

    Connecting an Additional Interface

    To add an additional interface, you need to add a folder to the totum/moduls directory — you can copy the existing anonymous tables interface (An) or the Table interface. This module will become available in TOTUM at the path /yourfoldername/

    If you connect the js and css files of TOTUM, you can use the built-in interface capabilities to call tables. The frontend sources are published in the dev branch of the repository https://github.com/.../totum-front. Changes occur frequently.