function SetPeriod($relation, $DateConcept, $srcAtom, $Period)
{
    emitLog("SetPeriod({$relation},{$DateConcept},{$srcAtom},{$Period})");
    // Insert the pair ($srcAtom,$srcAtom + $period) into $relation
    if (($dt1 = strtotime($srcAtom)) === false) {
        ExecEngineSHOUTS("SetPeriod: Illegal date {$dt1} specified in srcAtom (3rd arg): {$srcAtom}");
    }
    if (($dt3 = strtotime($srcAtom . $Period)) === false) {
        ExecEngineSHOUTS("SetPeriod: Illegal period {$dt3} specified as period (4th arg): {$Period}");
    }
    $tgtAtom = date('d-m-Y', $dt3);
    global $execEngineWhispers;
    // Defined in 'pluginsettings.php'
    $execEngineWhispers = false;
    // ExecEngineWhispers("SetPeriod: InsPair($relation,$DateConcept,$srcAtom,$DateConcept,$tgtAtom)");
    // Als '$tgtAtom' nog niet in de database bestaat als een instantie van $DateConcept, dan moet die nog wel worden toegevoegd:
    if (!isAtomInConcept($tgtAtom, $DateConcept)) {
        addAtomToConcept($tgtAtom, $DateConcept);
    }
    InsPair($relation, $DateConcept, $srcAtom, $DateConcept, $tgtAtom);
    return;
}
function NewStruct()
{
    // We start with parsing the first one or two arguments
    $ConceptC = func_get_arg(0);
    // Name of concept for which atom is to be created
    $AtomC = mkUniqueAtomByTime($ConceptC);
    // Default marker for atom-to-be-created.
    if (func_num_args() % 5 == 2) {
        $AtomC = func_get_arg(1);
        // If so, we'll be using this to create the new atom
    } elseif (func_num_args() % 5 != 1) {
        ExecEngineSHOUTS("NewStruct: Illegal number of arguments: " . func_num_args());
        die;
    }
    // Then, we create a new atom of type $ConceptC
    ExecEngineWhispers("Creating a structure based on an atom '{$AtomC}' for concept '{$ConceptC}'");
    addAtomToConcept($AtomC, $ConceptC);
    // insert new atom in database
    // Next, for every relation that follows in the argument list, we create a link
    for ($i = func_num_args() % 5; $i < func_num_args(); $i = $i + 5) {
        emitLog("i = {$i}");
        $relation = func_get_arg($i);
        $srcConcept = func_get_arg($i + 1);
        $srcAtom = func_get_arg($i + 2);
        $tgtConcept = func_get_arg($i + 3);
        $tgtAtom = func_get_arg($i + 4);
        // populate relation r1, first checking for allowed syntax:
        if (!($srcAtom === 'NULL' or $tgtAtom === 'NULL')) {
            ExecEngineSHOUTS("NewStruct: relation {$relation} requires that atom {$srcAtom} or {$tgtAtom} must be NULL");
            throw new Exception("Failure 1 in NewStruct in InsDelPairAtom.php");
        }
        if (!($srcConcept == $ConceptC or $tgtConcept == $ConceptC)) {
            ExecEngineSHOUTS("NewStruct: relation {$relation} requires that concept {$srcConcept} or {$tgtConcept} must be {$ConceptC}");
            throw new Exception("Failure 2 in NewStruct in InsDelPairAtom.php");
        }
        if ($srcConcept == $ConceptC) {
            if ($srcAtom === 'NULL') {
                $srcAtom = $AtomC;
            }
        }
        if ($tgtConcept == $ConceptC) {
            if ($tgtAtom === 'NULL') {
                $tgtAtom = $AtomC;
            }
        }
        /* Als '$tgtAtom' nog niet in de database bestaat als een instantie van $tgtConcept, dan moet die nog wel worden toegevoegd; dat gebeurt bijvoorbeeld als '$tgtAtom' ontstaat uit de volgende ADL tekst: 
        VIOLATION (TXT "{EX} NewStruct;Beslissing"
                       ,TXT ";op;Beslissing;NULL;Verzoek;", SRC I 
                   ...
                       ,TXT ";reden;Beslissing;NULL;Reden;'Voldoen aan artikel 2 lid 10 Wet aanpassing arbeidsduur'"
                   ...                                  -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deze tekst moet als een instantie van het concept 'Reden' worden toegevoegd (als-ie nog niet als een Reden bestaat).
                       )
        */
        if (!isAtomInConcept($tgtAtom, $tgtConcept)) {
            addAtomToConcept($tgtAtom, $tgtConcept);
        }
        // Any logging is done by InsPair:
        InsPair($relation, $srcConcept, $srcAtom, $tgtConcept, $tgtAtom);
    }
    ExecEngineWhispers("Completed structure creation.");
}
Exemple #3
0
function timeofdayGT($relation, $TimeofdayConcept, $srcAtom, $tgtAtom)
{
    emitLog("timeofdayGT({$relation},{$TimeofdayConcept},{$srcAtom},{$tgtAtom})");
    if (($dt1 = strtotime($srcAtom)) === false) {
        ExecEngineSHOUTS("timeofdayGT: Illegal timeofday {$dt1} specified in srcAtom (3rd arg): {$srcAtom}");
    }
    if (($dt2 = strtotime($tgtAtom)) === false) {
        ExecEngineSHOUTS("timeofdayGT: Illegal timeofday {$dt2} specified in tgtAtom (4th arg): {$tgtAtom}");
    }
    global $execEngineWhispers;
    // Defined in 'pluginsettings.php'
    $execEngineWhispers = false;
    if ($dt1 > $dt2) {
        InsPair($relation, $TimeofdayConcept, $srcAtom, $TimeofdayConcept, $tgtAtom);
    }
    return;
}
function ExecuteAllMappingRules()
{
    global $allRulesSql;
    // for every rule, (almost) all relevant info
    global $allRoles;
    // for every role, a list of all rules that the role must maintain
    global $execEningeIsVerySilent;
    // set in 'pluginsettings.php'
    global $MappingEngineRules;
    // array met alle ruleNames van de MappingEngine
    if (!isset($MappingEngineRules)) {
        foreach ($allRoles as $role) {
            if ($role['name'] == 'MappingEngine') {
                $MappingEngineRules = $role['ruleNames'];
            }
        }
    }
    $error = '';
    foreach ($MappingEngineRules as $ruleName) {
        // Check if Ampersand wants to change something:
        while (GetSMF('pause')) {
            echo "Value of semaphore: " . json_encode(GetPauseSMF()) . ".\n";
            echo "Interupted by high priority process, backing off for 1 second...\n";
            sleep(1);
        }
        $ruleSql = $allRulesSql[$ruleName];
        // Get (almost) all relevant info about the rule
        $rows = DB_doquerErr($ruleSql['violationsSQL'], $error);
        // execute violationsSQL to check for violations
        if ($error) {
            error("While evaluating rule '{$ruleName}': " . $error);
        }
        // if there are rows (i.e. violations)
        if (count($rows) != 0) {
            emitLog('Rule ' . $ruleSql['name'] . ' is repaired');
            $pairView = $ruleSql['pairView'];
            // pairView contains an array with the fragments of the violations message (if specified)
            foreach ($rows as $violation) {
                if ($pairView[0]['segmentType'] == 'Text' && strpos($pairView[0]['Text'], '{EX}') === 0) {
                    $theMessage = execPair($violation['src'], $ruleSql['srcConcept'], $violation['tgt'], $ruleSql['tgtConcept'], $pairView);
                    $theCleanMessage = strip_tags($theMessage);
                    $theCleanMessage = substr($theCleanMessage, 4);
                    // Strip {EX} tag
                    $functionsToBeCalled = explode('{EX}', $theCleanMessage);
                    // Split off subsequent function calls
                    if (count($functionsToBeCalled) > 1) {
                        ExecEngineWhispers("[[START]]");
                    }
                    foreach ($functionsToBeCalled as $functionToBeCalled) {
                        $params = explode(';', $functionToBeCalled);
                        // Split off variables
                        $cleanparams = array();
                        foreach ($params as $param) {
                            $cleanparams[] = trim($param);
                        }
                        $params = $cleanparams;
                        unset($cleanparams);
                        ExecEngineWhispers($functionToBeCalled);
                        $func = array_shift($params);
                        // First parameter is function name
                        if (function_exists($func)) {
                            call_user_func_array($func, $params);
                        } else {
                            ExecEngineSHOUTS("TODO: Create function {$func} with " . count($params) . " parameters.");
                        }
                    }
                    if (count($functionsToBeCalled) > 1) {
                        ExecEngineWhispers("[[DONE]]");
                    }
                }
            }
        }
    }
    return;
}