ODT Template erstellen: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
Tag: 2017 source edit
 
Line 86: Line 86:
'''htdocs/mymodule/core/substitutions/functions_mymodule.lib.php'''
'''htdocs/mymodule/core/substitutions/functions_mymodule.lib.php'''
* Inside this file, just write one function like this:
* Inside this file, just write one function like this:
<source lang="php">
<syntaxhighlight lang="PHP">
/** Function called to complete substitution array (before generating on ODT, or a personalized email)
/** Function called to complete substitution array (before generating on ODT, or a personalized email)
  * functions xxx_completesubstitutionarray are called by make_substitutions() if file
  * functions xxx_completesubstitutionarray are called by make_substitutions() if file
Line 103: Line 103:
   $substitutionarray['myowntag']=$myvalue;
   $substitutionarray['myowntag']=$myvalue;
}
}
</source>
</syntaxhighlight>


Function will be called before generating document to complete the array used for substitution and to replace tag myowntag with value $myvalue. You can add as many tags as you need and put all personalized code you want to define values (search into database, into files, calculation, from received parameters or from global variables)...  
Function will be called before generating document to complete the array used for substitution and to replace tag myowntag with value $myvalue. You can add as many tags as you need and put all personalized code you want to define values (search into database, into files, calculation, from received parameters or from global variables)...  
Line 113: Line 113:
* Build your own module (See page [[Module development]]) with its descriptor file.
* Build your own module (See page [[Module development]]) with its descriptor file.
* Check your module descriptor file contains an entry to declare this module has a substitutions file
* Check your module descriptor file contains an entry to declare this module has a substitutions file
<source lang="php">
<syntaxhighlight lang="PHP">
$this->module_parts = array('substitutions' => 1)  
$this->module_parts = array('substitutions' => 1)  
</source>
</syntaxhighlight>
* Enable your module (module must be enabled and disabled each time you change the descriptor).
* Enable your module (module must be enabled and disabled each time you change the descriptor).


Line 128: Line 128:
* Create or edit the same file as before (see the previous chapter).
* Create or edit the same file as before (see the previous chapter).
* Here are the twists: in the file, write another function with almost the same name but with '_lines' appended, and also add a new $lines variable:
* Here are the twists: in the file, write another function with almost the same name but with '_lines' appended, and also add a new $lines variable:
<source lang="php">
<syntaxhighlight lang="PHP">
/** Function called to complete substitution array for lines (before generating on ODT, or a personalized email)
/** Function called to complete substitution array for lines (before generating on ODT, or a personalized email)
  * functions xxx_completesubstitutionarray_lines are called by make_substitutions() if file
  * functions xxx_completesubstitutionarray_lines are called by make_substitutions() if file
Line 146: Line 146:
   $substitutionarray['myowntag']=$myvalue;
   $substitutionarray['myowntag']=$myvalue;
}
}
</source>
</syntaxhighlight>


Contrary to the previous function which was called only once, this function will be called everytime a line of product will be processed, giving you each time a new $line object that you can process. This allows you to do different substitutions for each product.
Contrary to the previous function which was called only once, this function will be called everytime a line of product will be processed, giving you each time a new $line object that you can process. This allows you to do different substitutions for each product.