• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Exercise/classes/class.ilExerciseXMLWriter.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004     +-----------------------------------------------------------------------------+
00005     | ILIAS open source                                                           |
00006         +-----------------------------------------------------------------------------+
00007     | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00008     |                                                                             |
00009     | This program is free software; you can redistribute it and/or               |
00010     | modify it under the terms of the GNU General Public License                 |
00011     | as published by the Free Software Foundation; either version 2              |
00012     | of the License, or (at your option) any later version.                      |
00013     |                                                                             |
00014     | This program is distributed in the hope that it will be useful,             |
00015     | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00016     | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00017     | GNU General Public License for more details.                                |
00018     |                                                                             |
00019     | You should have received a copy of the GNU General Public License           |
00020     | along with this program; if not, write to the Free Software                 |
00021     | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00022     +-----------------------------------------------------------------------------+
00023 */
00024 
00040 include_once "./classes/class.ilXmlWriter.php";
00041 
00042 class ilExerciseXMLWriter extends ilXmlWriter
00043 {
00044 
00045     static $CONTENT_ATTACH_NO = 0;
00046     static $CONTENT_ATTACH_ENCODED = 1;
00047     static $CONTENT_ATTACH_ZLIB_ENCODED = 2;
00048     static $CONTENT_ATTACH_GZIP_ENCODED = 3;
00054     var $attachFileContents;
00055 
00061         var $exercise;
00062 
00070         function ilExerciseXMLWriter()
00071         {
00072                 parent::ilXmlWriter();
00073                 $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
00074         }
00075 
00076 
00077         function setExercise(&  $exercise)
00078         {
00079                 $this->exercise = & $exercise;
00080         }
00081 
00088         function setAttachFileContents($attachFileContents)
00089         {
00090              if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode"))
00091                  {
00092                       throw new ilExerciseException("Inflating with gzip is not supported",  ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
00093          }
00094          if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress"))
00095          {
00096             throw new ilExerciseException("Inflating with zlib (compress/uncompress) is not supported",  ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
00097          }
00098 
00099                 $this->attachFileContents = $attachFileContents;
00100         }
00101 
00102 
00103         function start()
00104         {
00105                 $this->__buildHeader();
00106 
00107                 $attribs =array ("obj_id" => "il_".IL_INST_ID."_exc_".$this->exercise->getId());
00108 
00109                 if ($this->exercise->getOwner())
00110             $attribs["owner"] = "il_".IL_INST_ID."_usr_".$this->exercise->getOwner();
00111 
00112         $this->xmlStartTag("Exercise", $attribs);
00113 
00114         $this->xmlElement("Title", null,$this->exercise->getTitle());
00115         $this->xmlElement("Description",  null,$this->exercise->getDescription());
00116         $this->xmlElement("Instruction",  null,$this->exercise->getInstruction());
00117         $this->xmlElement("DueDate",  null,$this->exercise->getTimestamp());
00118         $this->xmlStartTag("Files");
00119 
00123         $exerciseFileData = $this->exercise->file_obj;
00124         $files = $exerciseFileData->getFiles();
00125         if (count($files))
00126         {
00127             foreach ($files as $file)
00128             {
00129                 $this->xmlStartTag("File", array ("size" => $file["size"] ));
00130                 $this->xmlElement("Filename", null, $file["name"]);
00131                 if ($this->attachFileContents)
00132                 {
00133                     $filename = $file["fullpath"];
00134                     if (@is_file($filename))
00135                     {
00136                         $content = @file_get_contents($filename);
00137                         $attribs = array ("mode"=>"PLAIN");
00138                         if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED)
00139                         {
00140                             $attribs = array ("mode"=>"ZLIB");
00141                             $content = gzcompress($content, 9);
00142                         }
00143                          elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED)
00144                         {
00145                             $attribs = array ("mode"=>"GZIP");
00146                             $content = gzencode($content, 9);
00147                         }
00148                         $content = base64_encode($content);
00149                         $this->xmlElement("Content",$attribs, $content);
00150                     }
00151                 }
00152                 $this->xmlEndTag("File");
00153             }
00154         }
00155         $this->xmlEndTag("Files");
00156 
00157         $this->xmlStartTag("Members");
00158         $members = $this->exercise->getMemberListData();
00159         if (count($members))
00160         {
00161             foreach ($members as $member)
00162             {
00163                 $this->xmlElement("Member", array ("usr_id" => "il_".IL_INST_ID."_usr_".$member["usr_id"]));
00164             }
00165         }
00166         $this->xmlEndTag("Members");
00167 
00168 
00169         $this->xmlEndTag("Exercise");
00170                 $this->__buildFooter();
00171 
00172                 return true;
00173         }
00174 
00175         function getXML()
00176         {
00177                 return $this->xmlDumpMem(FALSE);
00178         }
00179 
00180 
00181         function __buildHeader()
00182         {
00183                 $this->xmlSetDtdDef("<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_exercise_3_8.dtd\">");
00184                 $this->xmlSetGenCmt("Exercise Object");
00185                 $this->xmlHeader();
00186 
00187                 return true;
00188         }
00189 
00190         function __buildFooter()
00191         {
00192 
00193         }
00194 
00195 }
00196 
00197 
00198 ?>

Generated on Fri Dec 13 2013 17:56:50 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1