Esempio n. 1
0
/**
 * Call a program based on a prepare done before.
 * @param \ToolkitApi\CW\DataDescription $program   Program object created in the preparation stage.
 * @param array           $params    Input params with key=>value pairs (possibly nested),
 *                                   keys matching what was specified in prepare stage.
 * @param array            $retvals  Output params (optional)
 *                                   Fields get created based on names of output parms.
 * @return boolean         True if successful, false if not.
 */
function i5_program_call(\ToolkitApi\CW\DataDescription $program, $params, $retvals = array())
{
    // @todo check type of $program and give toolkit-like messages
    $inputValues = $params;
    // convert from old to new param format, inserting input values
    $newInputParams = $program->generateNewToolkitParams($inputValues);
    if ($program->callProgram($newInputParams)) {
        if ($retvals && is_array($retvals)) {
            $pgmOutput = $program->getPgmOutput();
            $exportedThem = $program->getConnection()->setOutputVarsToExport($retvals, $pgmOutput);
            //$exportedThem = exportPgmOutputVars($retvals, $pgmOutput);
            if (!$exportedThem) {
                return false;
            }
        }
        noError();
        return true;
    } else {
        // @todo if particular xml errors,
        // such as errnoxml = 1000005 or errnoile = 3025 means can't find program,
        // specify them.
        // Return "toolkit-style" CPF errno codes/messages
        // Set the i5error object based on this.
        $conn = $program->getConnection();
        if ($conn->getErrorCode()) {
            i5CpfError($conn->getErrorCode(), $conn->getErrorMsg());
            return false;
        }
        return false;
    }
}