Skip to content

Commit

Permalink
Add conditional variants of exec-engine functions InsPair and SetConc…
Browse files Browse the repository at this point in the history
…ept.
  • Loading branch information
Michiel-s authored and hanjoosten committed Mar 18, 2017
1 parent 1ec655d commit fc9053e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions static/zwolle/extensions/ExecEngine/functions/insDelPairAtom.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,51 @@ function ClearConcept($concept, $atom){
Logger::getUserLogger()->error('ClearConcept: ' . $e->getMessage());
}
}


/**************************************************************
* Conditional variants of the above functions
*************************************************************/

// SetConcept is skipped when $bool string value equals: "0", "false", "off", "no", "" or "_NULL"
function InsPairCond($relationName, $srcConceptName, $srcAtom, $tgtConceptName, $tgtAtom, $bool){
Logger::getLogger('EXECENGINE')->info("InsPairCond($relationName, $srcConceptName, $srcAtom, $tgtConceptName, $tgtAtom, $bool)");

try{
if(func_num_args() != 6) throw new Exception("Wrong number of arguments supplied for function SetConceptCond(): ".func_num_args()." arguments", 500);

// Skip when $bool evaluates to false or equals '_NULL'.
// _Null is the exec-engine special for zero results from Ampersand expression
if(filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === false || $bool === '_NULL'){
Logger::getLogger('EXECENGINE')->debug("InsPairCond skipped because bool evaluation results in false");
return;
}

InsPair($relationName, $srcConceptName, $srcAtom, $tgtConceptName, $tgtAtom);

}catch(Exception $e){
Logger::getUserLogger()->error('InsPairCond: ' . $e->getMessage());
}
}

// SetConcept is skipped when $bool string value equals: "0", "false", "off", "no", "" or "_NULL"
function SetConceptCond($conceptA, $conceptB, $atom, $bool){
Logger::getLogger('EXECENGINE')->info("SetConceptCond($conceptA, $conceptB, $atom, $bool)");

try{
if(func_num_args() != 4) throw new Exception("Wrong number of arguments supplied for function SetConceptCond(): ".func_num_args()." arguments", 500);

// Skip when $bool evaluates to false or equals '_NULL'.
// _Null is the exec-engine special for zero results from Ampersand expression
if(filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === false || $bool === '_NULL'){
Logger::getLogger('EXECENGINE')->debug("SetConcept skipped because bool evaluation results in false");
return;
}

SetConcept($conceptA, $conceptB, $atom);

}catch(Exception $e){
Logger::getUserLogger()->error('SetConceptCond: ' . $e->getMessage());
}
}
?>

0 comments on commit fc9053e

Please sign in to comment.