Public Member Functions | Data Fields

ilTestCertificate Class Reference
[Modules/Test]

Export test results as PDF certificates. More...

Public Member Functions

 ilTestCertificate (&$a_object)
 ilTestCertificate constructor
 getCertificatePath ()
 Returns the filesystem path of the certificate.
 getBackgroundImagePath ()
 Returns the filesystem path of the background image.
 getBackgroundImageName ()
 Returns the filename of the background image.
 getBackgroundImageThumbPath ()
 Returns the filesystem path of the background image thumbnail.
 getBackgroundImageTempfilePath ()
 Returns the filesystem path of the background image temp file during upload.
 getXSLPath ()
 Returns the filesystem path of the XSL-FO file.
 getXSLName ()
 Returns the filename of the XSL-FO file.
 getBackgroundImagePathWeb ()
 Returns the web path of the background image.
 deleteBackgroundImage ()
 Deletes the background image of a certificate.
 deleteCertificate ()
 Deletes the certificate and all it's data.
 checkCertificateInput ($form_fields)
 Checks the certificate fields for errors prior to saving the certificate.
 processFO2XHTML ()
 Convert the XSL-FO to the certificate text and the form settings using XSL transformation.
 processXHTML2FO ($form_data, $for_export=FALSE)
 Convert the certificate text to XSL-FO using XSL transformation.
 saveCertificateVisibility ($a_value)
 Saves the visibility settings of the certificate.
 exchangeCertificateVariables ($certificate_text, $user_data=array())
 Exchanges the variables in the certificate text with given values.
 createArchiveDirectory ()
 addPDFtoArchiveDirectory ($pdfdata, $dir, $filename)
 outCertificates ($userfilter="", $passedonly=FALSE)
 Creates a ZIP file with user certificates.
 outCertificate ($active_id, $pass, $deliver=TRUE, $userfilter="", $passedonly=FALSE)
 Creates a PDF preview of the XSL-FO certificate.
 createPreview ()
 Creates a PDF preview of the XSL-FO certificate.
 saveCertificate ($xslfo, $filename="")
 Saves the XSL-FO code to the ILIAS web directory.
 uploadBackgroundImage ($image_tempfilename)
 Uploads a background image for the certificate.
 hasBackgroundImage ()
 Checks for the background image of the certificate.
 isComplete ()
 Checks the status of the certificate.
 _isComplete ($obj_id)
 Checks the status of the certificate.
 getPageFormats ()
 Retrieves predefined page formats.
 deliverExportFileXML ()
 Builds an export file in ZIP format and delivers it.
 importCertificate ($zipfile, $filename)
 Reads an import ZIP file and creates a certificate of it.

Data Fields

 $object
 $ctrl
 $tree
 $ilias
 $tpl
 $lng

Detailed Description

Export test results as PDF certificates.

This class defines everything to export test results as PDF certificates using XML-FO techniques

Author:
Helmut Schottmüller <helmut.schottmueller@mac.com>
Version:
Id:
class.ilTestCertificate.php 17757 2008-10-27 10:12:58Z hschottm

Definition at line 34 of file class.ilTestCertificate.php.


Member Function Documentation

ilTestCertificate::_isComplete ( obj_id  ) 

Checks the status of the certificate.

Checks the status of the certificate

Returns:
boolean Returns TRUE if the certificate is complete, FALSE otherwise private

Definition at line 799 of file class.ilTestCertificate.php.

References getXSLName().

Referenced by ilTestEvaluationGUI::outEvaluation().

        {
                $certificatepath = CLIENT_WEB_DIR . "/assessment/certificates/" . $obj_id . "/";
                if (file_exists($certificatepath))
                {
                        $xslpath = CLIENT_WEB_DIR . "/assessment/certificates/" . $obj_id . "/" . ilTestCertificate::getXSLName();
                        if (file_exists($xslpath) && (filesize($xslpath) > 0))
                        {
                                return TRUE;
                        }
                }
                return FALSE;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::addPDFtoArchiveDirectory ( pdfdata,
dir,
filename 
)

Definition at line 548 of file class.ilTestCertificate.php.

References $dir, and $filename.

Referenced by outCertificates().

        {
                $fh = fopen($dir . $filename, "wb");
                fwrite($fh, $pdfdata);
                fclose($fh);
        }

Here is the caller graph for this function:

ilTestCertificate::checkCertificateInput ( form_fields  ) 

Checks the certificate fields for errors prior to saving the certificate.

Checks the certificate fields for errors prior to saving the certificate

Parameters:
array $form_fields An associative array containing the form fields of the certificate editor
Returns:
TRUE if the check succeeded, an error message otherwise public

Definition at line 270 of file class.ilTestCertificate.php.

        {
                // 1. check the required fields
                if ((strlen($form_fields["padding_top"]) == 0) ||
                        (strlen($form_fields["margin_body_top"]) == 0) ||
                        (strlen($form_fields["margin_body_right"]) == 0) ||
                        (strlen($form_fields["margin_body_bottom"]) == 0) ||
                        (strlen($form_fields["margin_body_left"]) == 0) ||
                        (strlen($form_fields["certificate_text"]) == 0))
                {
                        return $this->lng->txt("fill_out_all_required_fields");
                }
                
                $unitexpression = "^([\d\.]+)(pt|pc|px|em|mm|cm|in){0,1}\$";
                if (!preg_match("/$unitexpression/", $form_fields["padding_top"], $matches))
                {
                        return $this->lng->txt("certificate_wrong_unit");
                }
                if (strcmp($form_fields["pageformat"], "custom") == 0)
                {
                        if (!preg_match("/$unitexpression/", $form_fields["pageheight"], $matches))
                        {
                                return $this->lng->txt("certificate_wrong_unit");
                        }
                        if (!preg_match("/$unitexpression/", $form_fields["pagewidth"], $matches))
                        {
                                return $this->lng->txt("certificate_wrong_unit");
                        }
                }
                if (!preg_match("/$unitexpression/", $form_fields["margin_body_top"], $matches))
                {
                        return $this->lng->txt("certificate_wrong_unit");
                }
                if (!preg_match("/$unitexpression/", $form_fields["margin_body_right"], $matches))
                {
                        return $this->lng->txt("certificate_wrong_unit");
                }
                if (!preg_match("/$unitexpression/", $form_fields["margin_body_bottom"], $matches))
                {
                        return $this->lng->txt("certificate_wrong_unit");
                }
                if (!preg_match("/$unitexpression/", $form_fields["margin_body_left"], $matches))
                {
                        return $this->lng->txt("certificate_wrong_unit");
                }
                if (strlen($form_fields["certificate_text"]) == 0)
                {
                        return $this->lng->txt("certificate_missing_text");
                }
                if (strlen($form_fields["certificate_text"]) > 0)
                {
                        include_once "class.ilXMLChecker.php";
                        $check = new ilXMLChecker();
                        $check->setXMLContent(str_replace("&nbsp;", " ", "<html>" . $form_fields["certificate_text"] . "</html>"));
                        $check->startParsing();
                        if ($check->hasError())
                        {
                                return $this->lng->txt("certificate_not_well_formed");
                        }
                }
                return TRUE;
        }

ilTestCertificate::createArchiveDirectory (  ) 

Definition at line 540 of file class.ilTestCertificate.php.

References $dir, getCertificatePath(), and ilUtil::makeDirParents().

Referenced by deliverExportFileXML(), importCertificate(), and outCertificates().

        {
                $dir = $this->getCertificatePath() . time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificate/";
                include_once "./Services/Utilities/classes/class.ilUtil.php";
                ilUtil::makeDirParents($dir);
                return $dir;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::createPreview (  ) 

Creates a PDF preview of the XSL-FO certificate.

Creates a PDF preview of the XSL-FO certificate and delivers it

private

Definition at line 671 of file class.ilTestCertificate.php.

References ilUtil::deliverData(), exchangeCertificateVariables(), and getXSLPath().

        {
                $xslfo = file_get_contents($this->getXSLPath());
                include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
                $fo2pdf = new ilFO2PDF();
                $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo));
                $result = $fo2pdf->send();
                include_once "./Services/Utilities/classes/class.ilUtil.php";
                ilUtil::deliverData($result, "certificate.pdf", "application/pdf");
        }

Here is the call graph for this function:

ilTestCertificate::deleteBackgroundImage (  ) 

Deletes the background image of a certificate.

Deletes the background image of a certificate

Returns:
boolean TRUE if the process succeeds public

Definition at line 222 of file class.ilTestCertificate.php.

References $ilLog, getBackgroundImagePath(), getBackgroundImageTempfilePath(), and getBackgroundImageThumbPath().

        {
                global $ilLog;
                $result = TRUE;
                if (file_exists($this->getBackgroundImageThumbPath()))
                {
                        $ilLog->write("delete " . $this->getBackgroundImageThumbPath());
                        $result = $result & unlink($this->getBackgroundImageThumbPath());
                }
                if (file_exists($this->getBackgroundImagePath()))
                {
                        $ilLog->write("delete " . $this->getBackgroundImagePath());
                        $result = $result & unlink($this->getBackgroundImagePath());
                }
                if (file_exists($this->getBackgroundImageTempfilePath()))
                {
                        $ilLog->write("delete " . $this->getBackgroundImageTempfilePath());
                        $result = $result & unlink($this->getBackgroundImageTempfilePath());
                }
                return $result;
        }

Here is the call graph for this function:

ilTestCertificate::deleteCertificate (  ) 

Deletes the certificate and all it's data.

Deletes the certificate and all it's data

public

Definition at line 251 of file class.ilTestCertificate.php.

References $ilLog, ilUtil::delDir(), and getCertificatePath().

        {
                global $ilLog;
                if (file_exists($this->getCertificatePath()))
                {
                        include_once "./Services/Utilities/classes/class.ilUtil.php";
                        ilUtil::delDir($this->getCertificatePath());
                }
        }

Here is the call graph for this function:

ilTestCertificate::deliverExportFileXML (  ) 

Builds an export file in ZIP format and delivers it.

Builds an export file in ZIP format and delivers it

private

Definition at line 876 of file class.ilTestCertificate.php.

References createArchiveDirectory(), ilUtil::delDir(), ilUtil::deliverFile(), getBackgroundImageName(), getBackgroundImagePath(), getCertificatePath(), getXSLName(), getXSLPath(), hasBackgroundImage(), ilUtil::makeDir(), saveCertificate(), and ilUtil::zip().

        {
                include_once "./Services/Utilities/classes/class.ilUtil.php";
                $exportpath = $this->createArchiveDirectory();
                ilUtil::makeDir($exportpath);
                $xsl = file_get_contents($this->getXSLPath());
                $xslexport = str_replace($this->getCertificatePath(), "", $xsl);
                // save export xsl file
                $this->saveCertificate($xslexport, $exportpath . $this->getXSLName());
                // save background image
                if ($this->hasBackgroundImage())
                {
                        copy($this->getBackgroundImagePath(), $exportpath . $this->getBackgroundImageName());
                }
                $zipfile = time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificate.zip";
                ilUtil::zip($exportpath, $this->getCertificatePath() . $zipfile);
                ilUtil::delDir($exportpath);
                ilUtil::deliverFile($this->getCertificatePath() . $zipfile, $zipfile, "application/zip");
        }

Here is the call graph for this function:

ilTestCertificate::exchangeCertificateVariables ( certificate_text,
user_data = array() 
)

Exchanges the variables in the certificate text with given values.

Exchanges the variables in the certificate text with given values

Parameters:
string $certificate_text The XSL-FO certificate text
array $user_data An associative array containing the variables and the values to replace
Returns:
string XSL-FO code private

Definition at line 506 of file class.ilTestCertificate.php.

References ilFormat::formatDate(), ilUtil::prepareFormOutput(), and ilFormat::unixtimestamp2datetime().

Referenced by createPreview(), and outCertificate().

        {
                if (count($user_data) == 0)
                {
                        include_once "./classes/class.ilFormat.php";
                        $user_data = array(
                                "[USER_FULLNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_fullname")),
                                "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_firstname")),
                                "[USER_LASTNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_lastname")),
                                "[USER_TITLE]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_title")),
                                "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_institution")),
                                "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_department")),
                                "[USER_STREET]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_street")),
                                "[USER_CITY]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_city")),
                                "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_zipcode")),
                                "[USER_COUNTRY]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_country")),
                                "[RESULT_PASSED]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_passed")),
                                "[RESULT_POINTS]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_points")),
                                "[RESULT_PERCENT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_percent")),
                                "[MAX_POINTS]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_max_points")),
                                "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_mark_short")),
                                "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_mark_long")),
                                "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
                                "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date"),
                                "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE)
                        );
                }
                foreach ($user_data as $var => $value)
                {
                        $certificate_text = str_replace($var, $value, $certificate_text);
                }
                return $certificate_text;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::getBackgroundImageName (  ) 

Returns the filename of the background image.

Returns the filename of the background image

Returns:
string The filename of the background image public

Definition at line 142 of file class.ilTestCertificate.php.

Referenced by deliverExportFileXML(), getBackgroundImagePath(), getBackgroundImagePathWeb(), getBackgroundImageThumbPath(), and uploadBackgroundImage().

        {
                return "background.jpg";
        }

Here is the caller graph for this function:

ilTestCertificate::getBackgroundImagePath (  ) 

Returns the filesystem path of the background image.

Returns the filesystem path of the background image

Returns:
string The filesystem path of the background image public

Definition at line 129 of file class.ilTestCertificate.php.

References getBackgroundImageName().

Referenced by deleteBackgroundImage(), deliverExportFileXML(), hasBackgroundImage(), importCertificate(), processXHTML2FO(), and uploadBackgroundImage().

        {
                return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName();
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::getBackgroundImagePathWeb (  ) 

Returns the web path of the background image.

Returns the web path of the background image

Returns:
string The web path of the background image public

Definition at line 207 of file class.ilTestCertificate.php.

References getBackgroundImageName(), and ilUtil::removeTrailingPathSeparators().

        {
                include_once "./Services/Utilities/classes/class.ilUtil.php";
                $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName();
                return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
        }

Here is the call graph for this function:

ilTestCertificate::getBackgroundImageTempfilePath (  ) 

Returns the filesystem path of the background image temp file during upload.

Returns the filesystem path of the background image temp file during upload

Returns:
string The filesystem path of the background image temp file public

Definition at line 168 of file class.ilTestCertificate.php.

Referenced by deleteBackgroundImage(), and uploadBackgroundImage().

        {
                return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/background_upload";
        }

Here is the caller graph for this function:

ilTestCertificate::getBackgroundImageThumbPath (  ) 

Returns the filesystem path of the background image thumbnail.

Returns the filesystem path of the background image thumbnail

Returns:
string The filesystem path of the background image thumbnail public

Definition at line 155 of file class.ilTestCertificate.php.

References getBackgroundImageName().

Referenced by deleteBackgroundImage(), importCertificate(), and uploadBackgroundImage().

        {
                return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName() . ".thumb.jpg";
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::getCertificatePath (  ) 

Returns the filesystem path of the certificate.

Returns the filesystem path of the certificate

Returns:
string The filesystem path of the certificate public

Definition at line 116 of file class.ilTestCertificate.php.

Referenced by createArchiveDirectory(), deleteCertificate(), deliverExportFileXML(), importCertificate(), isComplete(), outCertificates(), saveCertificate(), and uploadBackgroundImage().

        {
                return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/";
        }

Here is the caller graph for this function:

ilTestCertificate::getPageFormats (  ) 

Retrieves predefined page formats.

Retrieves predefined page formats

Returns:
array Associative array containing page formats private

Definition at line 821 of file class.ilTestCertificate.php.

Referenced by processXHTML2FO().

        {
                return array(
                        "a4" => array(
                                "name" => $this->lng->txt("certificate_a4"), // (297 mm x 210 mm)
                                "value" => "a4",
                                "width" => "210mm",
                                "height" => "297mm"
                        ),
                        "a4landscape" => array(
                                "name" => $this->lng->txt("certificate_a4_landscape"), // (210 mm x 297 mm)",
                                "value" => "a4landscape",
                                "width" => "297mm",
                                "height" => "210mm"
                        ),
                        "a5" => array(
                                "name" => $this->lng->txt("certificate_a5"), // (210 mm x 148.5 mm)
                                "value" => "a5",
                                "width" => "148mm",
                                "height" => "210mm"
                        ),
                        "a5landscape" => array(
                                "name" => $this->lng->txt("certificate_a5_landscape"), // (148.5 mm x 210 mm)
                                "value" => "a5landscape",
                                "width" => "210mm",
                                "height" => "148mm"
                        ),
                        "letter" => array(
                                "name" => $this->lng->txt("certificate_letter"), // (11 inch x 8.5 inch)
                                "value" => "letter",
                                "width" => "8.5in",
                                "height" => "11in"
                        ),
                        "letterlandscape" => array(
                                "name" => $this->lng->txt("certificate_letter_landscape"), // (11 inch x 8.5 inch)
                                "value" => "letterlandscape",
                                "width" => "8.5in",
                                "height" => "11in"
                        ),
                        "custom" => array(
                                "name" => $this->lng->txt("certificate_custom"),
                                "value" => "custom",
                                "width" => "",
                                "height" => ""
                        )
                );
        }

Here is the caller graph for this function:

ilTestCertificate::getXSLName (  ) 

Returns the filename of the XSL-FO file.

Returns the filename of the XSL-FO file

Returns:
string The filename of the XSL-FO file public

Definition at line 194 of file class.ilTestCertificate.php.

Referenced by _isComplete(), deliverExportFileXML(), and getXSLPath().

        {
                return "certificate.xml";
        }

Here is the caller graph for this function:

ilTestCertificate::getXSLPath (  ) 

Returns the filesystem path of the XSL-FO file.

Returns the filesystem path of the XSL-FO file

Returns:
string The filesystem path of the XSL-FO file public

Definition at line 181 of file class.ilTestCertificate.php.

References getXSLName().

Referenced by createPreview(), deliverExportFileXML(), isComplete(), outCertificate(), processFO2XHTML(), and saveCertificate().

        {
                return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getXSLName();
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::hasBackgroundImage (  ) 

Checks for the background image of the certificate.

Checks for the background image of the certificate

Returns:
boolean Returns TRUE if the certificate has a background image, FALSE otherwise private

Definition at line 759 of file class.ilTestCertificate.php.

References getBackgroundImagePath().

Referenced by deliverExportFileXML(), and processXHTML2FO().

        {
                if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
                {
                        return TRUE;
                }
                else
                {
                        return FALSE;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::ilTestCertificate ( &$  a_object  ) 

ilTestCertificate constructor

The constructor takes possible arguments an creates an instance of the ilTestCertificate object.

Parameters:
object $a_object A reference to the test container object public

Definition at line 96 of file class.ilTestCertificate.php.

References $ilCtrl, $ilias, $lng, $tpl, and $tree.

        {
                global $lng, $tpl, $ilCtrl, $ilias, $tree;

    $this->lng =& $lng;
    $this->tpl =& $tpl;
                $this->ctrl =& $ilCtrl;
                $this->ilias =& $ilias;
                $this->object =& $a_object;
                $this->tree =& $tree;
        }

ilTestCertificate::importCertificate ( zipfile,
filename 
)

Reads an import ZIP file and creates a certificate of it.

Reads an import ZIP file and creates a certificate of it

Returns:
boolean TRUE if the import succeeds, FALSE otherwise private

Definition at line 904 of file class.ilTestCertificate.php.

References $file, $filename, ilUtil::convertImage(), createArchiveDirectory(), ilUtil::delDir(), getBackgroundImagePath(), getBackgroundImageThumbPath(), getCertificatePath(), ilUtil::getDir(), ilUtil::moveUploadedFile(), saveCertificate(), and ilUtil::unzip().

        {
                include_once "./Services/Utilities/classes/class.ilUtil.php";
                $importpath = $this->createArchiveDirectory();
                if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename))
                {
                        ilUtil::delDir($importpath);
                        return FALSE;
                }
                ilUtil::unzip($importpath . $filename, TRUE);
                $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
                $copydir = "";
                if (is_dir($importpath . $subdir))
                {
                        $dirinfo = ilUtil::getDir($importpath . $subdir);
                        $copydir = $importpath . $subdir;
                }
                else
                {
                        $dirinfo = ilUtil::getDir($importpath);
                        $copydir = $importpath;
                }
                $xmlfiles = 0;
                $otherfiles = 0;
                foreach ($dirinfo as $file)
                {
                        if (strcmp($file["type"], "file") == 0)
                        {
                                if (strpos($file["entry"], ".xml") !== FALSE) 
                                {
                                        $xmlfiles++;
                                }
                                else if (strpos($file["entry"], ".zip") !== FALSE)
                                {
                                }
                                else
                                {
                                        $otherfiles++;
                                }
                        }
                }
                // if one XML file is in the archive, we try to import it
                if ($xmlfiles == 1)
                {
                        foreach ($dirinfo as $file)
                        {
                                if (strcmp($file["type"], "file") == 0)
                                {
                                        if (strpos($file["entry"], ".xml") !== FALSE) 
                                        {
                                                $xsl = file_get_contents($copydir . $file["entry"]);
                                                // as long as we cannot make RPC calls in a given directory, we have
                                                // to add the complete path to every url
                                                $xsl = preg_replace("/url\([']{0,1}(.*?)[']{0,1}\)/", "url(" . $this->getCertificatePath() . "\${1})", $xsl);
                                                $this->saveCertificate($xsl);
                                        }
                                        else if (strpos($file["entry"], ".zip") !== FALSE)
                                        {
                                        }
                                        else
                                        {
                                                @copy($copydir . $file["entry"], $this->getCertificatePath() . $file["entry"]);
                                                if (strcmp($this->getBackgroundImagePath(), $this->getCertificatePath() . $file["entry"]) == 0)
                                                {
                                                        // upload of the background image, create a preview
                                                        ilUtil::convertImage($this->getBackgroundImagePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100);
                                                }
                                        }
                                }
                        }
                }
                else
                {
                        ilUtil::delDir($importpath);
                        return FALSE;
                }
                ilUtil::delDir($importpath);
                return TRUE;
        }

Here is the call graph for this function:

ilTestCertificate::isComplete (  ) 

Checks the status of the certificate.

Checks the status of the certificate

Returns:
boolean Returns TRUE if the certificate is complete, FALSE otherwise private

Definition at line 779 of file class.ilTestCertificate.php.

References getCertificatePath(), and getXSLPath().

        {
                if (file_exists($this->getCertificatePath()))
                {
                        if (file_exists($this->getXSLPath()) && (filesize($this->getXSLPath()) > 0))
                        {
                                return TRUE;
                        }
                }
                return FALSE;
        }

Here is the call graph for this function:

ilTestCertificate::outCertificate ( active_id,
pass,
deliver = TRUE,
userfilter = "",
passedonly = FALSE 
)

Creates a PDF preview of the XSL-FO certificate.

Creates a PDF preview of the XSL-FO certificate and delivers it

private

Definition at line 595 of file class.ilTestCertificate.php.

References ilObjUser::_lookupFields(), ilUtil::deliverData(), exchangeCertificateVariables(), ilFormat::formatDate(), getXSLPath(), ilUtil::prepareFormOutput(), and ilFormat::unixtimestamp2datetime().

Referenced by outCertificates().

        {
                if (strlen($pass))
                {
                        $result_array =& $this->object->getTestResult($active_id, $pass);
                }
                else
                {
                        $result_array =& $this->object->getTestResult($active_id);
                }
                if (($passedonly) && ($result_array["test"]["passed"] == FALSE)) return "";
                $passed = $result_array["test"]["passed"] ? $this->lng->txt("certificate_passed") : $this->lng->txt("certificate_failed");
                if (!$result_array["test"]["total_max_points"])
                {
                        $percentage = 0;
                }
                else
                {
                        $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
                }
                $mark_obj = $this->object->mark_schema->getMatchingMark($percentage);
                $user_id = $this->object->_getUserIdFromActiveId($active_id);
                include_once './Services/User/classes/class.ilObjUser.php';
                $user_data = ilObjUser::_lookupFields($user_id);
                if (strlen($userfilter))
                {
                        if (!@preg_match("/$userfilter/i", $user_data["lastname"] . ", " . $user_data["firstname"] . " " . $user_data["title"]))
                        {
                                return "";
                        }
                }
                include_once "./classes/class.ilFormat.php";
                $user_data = array(
                        "[USER_FULLNAME]" => ilUtil::prepareFormOutput(trim($user_data["title"] . " " . $user_data["firstname"] . " " . $user_data["lastname"])),
                        "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($user_data["firstname"]),
                        "[USER_LASTNAME]" => ilUtil::prepareFormOutput($user_data["lastname"]),
                        "[USER_TITLE]" => ilUtil::prepareFormOutput($user_data["title"]),
                        "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($user_data["institution"]),
                        "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($user_data["department"]),
                        "[USER_STREET]" => ilUtil::prepareFormOutput($user_data["street"]),
                        "[USER_CITY]" => ilUtil::prepareFormOutput($user_data["city"]),
                        "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($user_data["zipcode"]),
                        "[USER_COUNTRY]" => ilUtil::prepareFormOutput($user_data["country"]),
                        "[RESULT_PASSED]" => ilUtil::prepareFormOutput($passed),
                        "[RESULT_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_reached_points"]),
                        "[RESULT_PERCENT]" => sprintf("%2.2f", $percentage) . "%",
                        "[MAX_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_max_points"]),
                        "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($mark_obj->getShortName()),
                        "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($mark_obj->getOfficialName()),
                        "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
                        "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date"),
                        "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE)
                );
                $xslfo = file_get_contents($this->getXSLPath());
                include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
                $fo2pdf = new ilFO2PDF();
                $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo, $user_data));
                $result = $fo2pdf->send();
                if ($deliver)
                {
                        include_once "./Services/Utilities/classes/class.ilUtil.php";
                        ilUtil::deliverData($result, "certificate.pdf", "application/pdf");
                }
                else
                {
                        return $result;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::outCertificates ( userfilter = "",
passedonly = FALSE 
)

Creates a ZIP file with user certificates.

Creates a ZIP file with user certificates

private

Definition at line 562 of file class.ilTestCertificate.php.

References addPDFtoArchiveDirectory(), createArchiveDirectory(), ilUtil::delDir(), ilUtil::deliverFile(), ilUtil::getASCIIFilename(), getCertificatePath(), outCertificate(), and ilUtil::zip().

        {
                global $ilUser;
                
                include_once "./Services/Utilities/classes/class.ilUtil.php";
                $archive_dir = $this->createArchiveDirectory();
                $total_users = array();
                $total_users =& $this->object->evalTotalPersonsArray();
                if (count($total_users))
                {
                        foreach ($total_users as $active_id => $name)
                        {
                                $user_id = $this->object->_getUserIdFromActiveId($active_id);
                                $pdf = $this->outCertificate($active_id, "", FALSE, $userfilter, $passedonly);
                                if (strlen($pdf))
                                {
                                        $this->addPDFtoArchiveDirectory($pdf, $archive_dir, $user_id . "_" . str_replace(" ", "_", ilUtil::getASCIIFilename($name)) . ".pdf");
                                }
                        }
                        $zipfile = time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificates.zip";
                        ilUtil::zip($archive_dir, $this->getCertificatePath() . $zipfile);
                        ilUtil::delDir($archive_dir);
                        ilUtil::deliverFile($this->getCertificatePath() . $zipfile, $zipfile, "application/zip");
                }
        }

Here is the call graph for this function:

ilTestCertificate::processFO2XHTML (  ) 

Convert the XSL-FO to the certificate text and the form settings using XSL transformation.

Convert the XSL-FO to the certificate text and the form settings using XSL transformation

private

Definition at line 340 of file class.ilTestCertificate.php.

References getXSLPath(), xslt_create(), xslt_error(), xslt_free(), and xslt_process().

        {
                if (file_exists($this->getXSLPath()))
                {
                        $xslfo = file_get_contents($this->getXSLPath());
                }
                // retrieve form information (using a dirty way with regular expressions)
                $pagewidth = "21cm";
                if (preg_match("/page-width\=\"([^\"]+)\"/", $xslfo, $matches))
                {
                        $pagewidth = $matches[1];
                }
                $pageheight = "29.7cm";
                if (preg_match("/page-height\=\"([^\"]+)\"/", $xslfo, $matches))
                {
                        $pageheight = $matches[1];
                }
                $pagesize = "custom";
                if (((strcmp($pageheight, "29.7cm") == 0) || (strcmp($pageheight, "297mm") == 0)) && ((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)))
                {
                        $pagesize = "a4";
                }
                else if (((strcmp($pagewidth, "29.7cm") == 0) || (strcmp($pagewidth, "297mm") == 0)) && ((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)))
                {
                        $pagesize = "a4landscape";
                }
                else if (((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)) && ((strcmp($pagewidth, "14.8cm") == 0) || (strcmp($pagewidth, "148mm") == 0)))
                {
                        $pagesize = "a5";
                }
                else if (((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)) && ((strcmp($pageheight, "14.8cm") == 0) || (strcmp($pageheight, "148mm") == 0)))
                {
                        $pagesize = "a5landscape";
                }
                else if (((strcmp($pageheight, "11in") == 0)) && ((strcmp($pagewidth, "8.5in") == 0)))
                {
                        $pagesize = "letter";
                }
                else if (((strcmp($pagewidth, "11in") == 0)) && ((strcmp($pageheight, "8.5in") == 0)))
                {
                        $pagesize = "letterlandscape";
                }
                
                /* only needed for upload of xsl-fo to convert existing background image 
                $backgroundimage = "";
                if (preg_match("/background-image\=\"url\([']{0,1}([^\)]+)[']{0,1}\)/", $xslfo, $matches))
                {
                        $backgroundimage = $matches[1];
                        echo $backgroundimage;
                }
                */
                $paddingtop = "0cm";
                if (preg_match("/padding-top\=\"([^\"]+)\"/", $xslfo, $matches))
                {
                        $paddingtop = $matches[1];
                }
                $marginbody_top = "0cm";
                $marginbody_right = "2cm";
                $marginbody_bottom = "0cm";
                $marginbody_left = "2cm";
                if (preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
                {
                        $marginbody = $matches[1];
                        if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
                        {
                                $marginbody_top = $matches[1][0];
                                $marginbody_right = $matches[1][1];
                                $marginbody_bottom = $matches[1][2];
                                $marginbody_left = $matches[1][3];
                        }
                }

                $xsl = file_get_contents("./Modules/Test/xml/fo2xhtml.xsl");
                if ((strlen($xslfo)) && (strlen($xsl)))
                {
                        $args = array( '/_xml' => $xslfo, '/_xsl' => $xsl );
                        $xh = xslt_create();
                        $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
                        xslt_error($xh);
                        xslt_free($xh);
                }

                $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
                // dirty hack: the php xslt processing seems not to recognize the following
                // replacements, so we do it in the code as well
                $output = str_replace("&#xA0;", "<br />", $output);
                $output = str_replace("&#160;", "<br />", $output);
                return array(
                        "pageformat" => $pagesize,
                        "pagewidth" => $pagewidth,
                        "pageheight" => $pageheight,
                        "padding_top" => $paddingtop,
                        "margin_body_top" => $marginbody_top,
                        "margin_body_right" => $marginbody_right,
                        "margin_body_bottom" => $marginbody_bottom,
                        "margin_body_left" => $marginbody_left,
                        "certificate_text" => $output,
                        "certificate_visibility" => $this->object->getCertificateVisibility()
                );
        }

Here is the call graph for this function:

ilTestCertificate::processXHTML2FO ( form_data,
for_export = FALSE 
)

Convert the certificate text to XSL-FO using XSL transformation.

Convert the certificate text to XSL-FO using XSL transformation

Parameters:
array $form_data The form data
Returns:
string XSL-FO code private

Definition at line 450 of file class.ilTestCertificate.php.

References getBackgroundImagePath(), getPageFormats(), hasBackgroundImage(), xslt_create(), xslt_error(), xslt_free(), and xslt_process().

        {
                $content = "<html><body>".$form_data["certificate_text"]."</body></html>";
                $content = str_replace("<p>&nbsp;</p>", "<p><br /></p>", $content);
                $content = str_replace("&nbsp;", " ", $content);
                $xsl = file_get_contents("./Modules/Test/xml/xhtml2fo.xsl");
                $args = array( '/_xml' => $content, '/_xsl' => $xsl );
                $xh = xslt_create();
                if (strcmp($form_data["pageformat"], "custom") == 0)
                {
                        $pageheight = $form_data["pageheight"];
                        $pagewidth = $form_data["pagewidth"];
                }
                else
                {
                        $pageformats = $this->getPageFormats();
                        $pageheight = $pageformats[$form_data["pageformat"]]["height"];
                        $pagewidth = $pageformats[$form_data["pageformat"]]["width"];
                }
                $backgroundimage = $this->hasBackgroundImage() ? $this->getBackgroundImagePath() : "";
                $params = array(
                        "pageheight" => $pageheight, 
                        "pagewidth" => $pagewidth,
                        "backgroundimage" => $backgroundimage,
                        "marginbody" => $form_data["margin_body_top"] . " " . $form_data["margin_body_right"] . " " . $form_data["margin_body_bottom"] . " " . $form_data["margin_body_left"],
                        "paddingtop" => $form_data["padding_top"]
                );
                $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
                xslt_error($xh);
                xslt_free($xh);
                return $output;
        }

Here is the call graph for this function:

ilTestCertificate::saveCertificate ( xslfo,
filename = "" 
)

Saves the XSL-FO code to the ILIAS web directory.

Saves the XSL-FO code to the ILIAS web directory

Parameters:
string $xslfo XSL-FO code private

Definition at line 690 of file class.ilTestCertificate.php.

References $filename, getCertificatePath(), getXSLPath(), and ilUtil::makeDirParents().

Referenced by deliverExportFileXML(), and importCertificate().

        {
                if (!file_exists($this->getCertificatePath()))
                {
                        ilUtil::makeDirParents($this->getCertificatePath());
                }
                if (strlen($filename) == 0)
                {
                        $filename = $this->getXSLPath();
                }
                $fh = fopen($filename, "w");
                fwrite($fh, $xslfo);
                fclose($fh);
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilTestCertificate::saveCertificateVisibility ( a_value  ) 

Saves the visibility settings of the certificate.

Saves the visibility settings of the certificate

Parameters:
integer $a_value The value for the visibility settings (0 = always, 1 = only passed, 2 = never) private

Definition at line 491 of file class.ilTestCertificate.php.

        {
                $this->object->saveCertificateVisibility($a_value);
        }

ilTestCertificate::uploadBackgroundImage ( image_tempfilename  ) 

Uploads a background image for the certificate.

Uploads a background image for the certificate. Creates a new directory for the certificate if needed. Removes an existing certificate image if necessary

Parameters:
string $image_tempfilename Name of the temporary uploaded image file
Returns:
integer An errorcode if the image upload fails, 0 otherwise public

Definition at line 715 of file class.ilTestCertificate.php.

References ilUtil::convertImage(), getBackgroundImageName(), getBackgroundImagePath(), getBackgroundImageTempfilePath(), getBackgroundImageThumbPath(), getCertificatePath(), ilUtil::makeDirParents(), and ilUtil::moveUploadedFile().

        {
                if (!empty($image_tempfilename))
                {
                        $image_filename = "background_upload";
                        $convert_filename = $this->getBackgroundImageName();
                        $imagepath = $this->getCertificatePath();
                        if (!file_exists($imagepath))
                        {
                                ilUtil::makeDirParents($imagepath);
                        }
                        // upload the file
                        if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $this->getBackgroundImageTempfilePath()))
                        {
                                return FALSE;
                        }
                        // convert the uploaded file to JPEG
                        ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImagePath(), "JPEG");
                        ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100);
                        if (!file_exists($this->getBackgroundImagePath()))
                        {
                                // something went wrong converting the file. use the original file and hope, that PDF can work with it
                                if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath()))
                                {
                                        return FALSE;
                                }
                        }
                        unlink($this->getBackgroundImageTempfilePath());
                        if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
                        {
                                return TRUE;
                        }
                }
                return FALSE;
        }

Here is the call graph for this function:


Field Documentation

ilTestCertificate::$ctrl

Definition at line 51 of file class.ilTestCertificate.php.

ilTestCertificate::$ilias

Definition at line 67 of file class.ilTestCertificate.php.

Referenced by ilTestCertificate().

ilTestCertificate::$lng

Definition at line 85 of file class.ilTestCertificate.php.

Referenced by ilTestCertificate().

ilTestCertificate::$object

Definition at line 43 of file class.ilTestCertificate.php.

ilTestCertificate::$tpl

Definition at line 76 of file class.ilTestCertificate.php.

Referenced by ilTestCertificate().

ilTestCertificate::$tree

Definition at line 59 of file class.ilTestCertificate.php.

Referenced by ilTestCertificate().


The documentation for this class was generated from the following file: