how to customize logic for an asset module with php

17 views
Skip to first unread message

Patrick Pliessnig

unread,
Nov 1, 2016, 8:17:54 PM11/1/16
to Simple Groupware
the usage of php in sgs is quite unconventional in some parts. I try to give some hints to help you to add logic with php functions to a module definition.
  1. the sgs documentation's proposition to put custom functions in a central place in the system is in my opinion not an ideal choice.
    I propose to put all custom functions related to a asset module together in a single php file per module. this way you have the schema file (xml) for the definition of the data structure and the associated php file for the custom logic. both files together define assets of a certain type with complete behaviour.
  2. in php there is an element called class definition. a class definition is meant to be a template for a class of objects. it contains normal functions that always relates to an object of that class and static functions that relates only to the class of objects as a whole. in sgs however the class definition is very often used just as a package of static functions without objects.
  3. to add functions to an asset module, you simply pack those functions as static functions in a class definition and put this class definition in a php file.
    for example: if you have an asset module called invoices stored in a file invoices.xml, simply add an invoices.php file.
    in this file you add the class: class invoices {}. you can then add the static functions between the brackets. normally it looks like this:
    <?php
    class invoices {
      static function() A {
        do something here;
      }

      static function() B {

        do something here;
      }
    }
  4. locations:
    put the xml file in: .../custom/modules/schema/invoices.xml
    put the php file in: .../custom/core/classes/invoices.php
  5. You can then define and call the functions according to the sgsml reference.
  6. for example:
    to only show the first 20 characters of an invoice item you could write a function static function first20characters() { do something here; }.
    in the definition of the item field of the schema you would then add the tag function="
    invoices::first20characters"
    sgs
    would then call the invoices::first20characters function each time before it displays an invoice item on the screen.

I hope this helps

Patrick

Reply all
Reply to author
Forward
0 new messages