Skip to content

Commit

Permalink
Add ProgramFunctions/Template.fnc.php|before_get & `ProgramFunction…
Browse files Browse the repository at this point in the history
…s/Template.fnc.php|before_save` action hooks
  • Loading branch information
francoisjacquet committed Jan 19, 2024
1 parent eac8f24 commit a73cff3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changes in 11.4.1
- Fix PHP warning use reset() instead of guessing if $errors[1] is set in ErrorMessage.fnc.php & diagnostic.php
- Add arguments to Action tags PHPDoc in Actions.php
- Add `Students/Letters.php|header` action hook in Actions.php & Letters.php
- Add `ProgramFunctions/Template.fnc.php|before_get` & `ProgramFunctions/Template.fnc.php|before_save` action hooks in Actions.php & Template.fnc.php

Changes in 11.4
---------------
Expand Down
36 changes: 29 additions & 7 deletions ProgramFunctions/Template.fnc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @since 3.6
* @since 10.2.3 Get template from last school year (rollover ID)
* @since 11.4.1 Add `ProgramFunctions/Template.fnc.php|before_get` action hook
*
* @example GetTemplate( $_REQUEST['modname'], User( 'STAFF_ID' ) )
*
Expand Down Expand Up @@ -59,6 +60,19 @@ function GetTemplate( $modname = '', $staff_id = 0 ) {
$staff_id_sql .= ",'" . $staff_id . "'";
}

/**
* Template before get
* Filter &$modname var
*
* @since 11.4.1
*/
do_action( 'ProgramFunctions/Template.fnc.php|before_get', [ &$modname ] );

if ( ! $modname )
{
return '';
}

$template = DBGetOne( "SELECT TEMPLATE
FROM templates
WHERE MODNAME='" . $modname . "'
Expand All @@ -75,14 +89,15 @@ function GetTemplate( $modname = '', $staff_id = 0 ) {
*
* @since 3.6
* @since 5.0 Save Template even if no default template found.
* @since 11.4.1 Add `ProgramFunctions/Template.fnc.php|before_save` action hook
*
* @example SaveTemplate( DBEscapeString( SanitizeHTML( $_POST['inputfreetext'] ) ) );
*
* @param string $template Template text or HTML (use DBEscapeString() & SanitizeHTML() first!).
* @param string $modname Specify program name (optional) defaults to current program.
* @param integer $staff_id User ID (optional), defaults to logged in User, use 0 for default template.
*
* @return boolean False if no template found, else true if saved.
* @return boolean False if no modname, else true if saved.
*/
function SaveTemplate( $template, $modname = '', $staff_id = -1 )
{
Expand All @@ -96,17 +111,24 @@ function SaveTemplate( $template, $modname = '', $staff_id = -1 )
$staff_id = User( 'STAFF_ID' );
}

/**
* Template before save
* Filter &$modname, &$staff_id var
*
* @since 11.4.1
*/
do_action( 'ProgramFunctions/Template.fnc.php|before_save', [ &$modname, &$staff_id ] );

if ( ! $modname )
{
return false;
}

$is_template_update = DBGet( "SELECT STAFF_ID
FROM templates
WHERE MODNAME='" . $modname . "'
AND STAFF_ID IN(0,'" . $staff_id . "')", [], [ 'STAFF_ID' ] );

/*if ( ! $is_template_update )
{
// Default template not found for modname.
return false;
}*/

DBUpsert(
'templates',
[ 'TEMPLATE' => $template ],
Expand Down
16 changes: 16 additions & 0 deletions functions/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@
* @since 11.4.1
*/
/*'Students/Letters.php|header' => [],
/**
* Template before get
* Filter &$modname var
*
* @since 11.4.1
*/
/*'ProgramFunctions/Template.fnc.php|before_get' => [ &$modname ],
/**
* Template before save
* Filter &$modname, &$staff_id var
*
* @since 11.4.1
*/
/*'ProgramFunctions/Template.fnc.php|before_save' => [ &$modname, &$staff_id ],
);*/

/**
Expand Down

0 comments on commit a73cff3

Please sign in to comment.