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

assessment/classes/class.ilObjQuestionPool.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00035 require_once "./classes/class.ilObjectGUI.php";
00036 require_once "./classes/class.ilMetaData.php";
00037 require_once "./assessment/classes/class.assQuestion.php";
00038 require_once "./assessment/classes/class.assClozeTestGUI.php";
00039 require_once "./assessment/classes/class.assImagemapQuestionGUI.php";
00040 require_once "./assessment/classes/class.assJavaAppletGUI.php";
00041 require_once "./assessment/classes/class.assMatchingQuestionGUI.php";
00042 require_once "./assessment/classes/class.assMultipleChoiceGUI.php";
00043 require_once "./assessment/classes/class.assOrderingQuestionGUI.php";
00044 
00045 class ilObjQuestionPool extends ilObject
00046 {
00053         function ilObjQuestionPool($a_id = 0,$a_call_by_reference = true)
00054         {
00055                 $this->type = "qpl";
00056                 $this->ilObject($a_id,$a_call_by_reference);
00057                 if ($a_id == 0)
00058                 {
00059                         $new_meta =& new ilMetaData();
00060                         $this->assignMetaData($new_meta);
00061                 }
00062         }
00063 
00067         function create($a_upload = false)
00068         {
00069                 parent::create();
00070                 if (!$a_upload)
00071                 {
00072                         $this->meta_data->setId($this->getId());
00073                         $this->meta_data->setType($this->getType());
00074                         $this->meta_data->setTitle($this->getTitle());
00075                         $this->meta_data->setDescription($this->getDescription());
00076                         $this->meta_data->setObject($this);
00077                         $this->meta_data->create();
00078                 }
00079         }
00080 
00087         function update()
00088         {
00089                 if (!parent::update())
00090                 {
00091                         return false;
00092                 }
00093 
00094                 // put here object specific stuff
00095 
00096                 return true;
00097         }
00098 
00104         function read($a_force_db = false)
00105         {
00106                 parent::read($a_force_db);
00107                 $this->meta_data =& new ilMetaData($this->getType(), $this->getId());
00108         }
00109 
00117         function ilClone($a_parent_ref)
00118         {
00119                 global $rbacadmin;
00120 
00121                 // always call parent ilClone function first!!
00122                 $new_ref_id = parent::ilClone($a_parent_ref);
00123 
00124                 // get object instance of ilCloned object
00125                 //$newObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00126 
00127                 // create a local role folder & default roles
00128                 //$roles = $newObj->initDefaultRoles();
00129 
00130                 // ...finally assign role to creator of object
00131                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "n");
00132 
00133                 // always destroy objects in ilClone method because ilClone() is recursive and creates instances for each object in subtree!
00134                 //unset($newObj);
00135 
00136                 // ... and finally always return new reference ID!!
00137                 return $new_ref_id;
00138         }
00139 
00146         function delete()
00147         {
00148                 // always call parent delete function first!!
00149                 if (!parent::delete())
00150                 {
00151                         return false;
00152                 }
00153 
00154                 //put here your module specific stuff
00155                 $this->deleteQuestionpool();
00156 
00157                 return true;
00158         }
00159 
00160         function deleteQuestionpool()
00161         {
00162                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND original_id IS NULL",
00163                         $this->ilias->db->quote($this->getId()));
00164 
00165                 $result = $this->ilias->db->query($query);
00166                 $questions = array();
00167 
00168                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00169                 {
00170                         array_push($questions, $row["question_id"]);
00171                 }
00172 
00173                 if (count($questions))
00174                 {
00175                         foreach ($questions as $question_id)
00176                         {
00177                                 $this->deleteQuestion($question_id);
00178                         }
00179                 }
00180 
00181                 // delete export files
00182                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00183                 $directory = $qpl_data_dir."/qpl_".$this->getId();
00184                 if (is_dir($directory))
00185                 {
00186                         $directory = escapeshellarg($directory);
00187                         exec("rm -rf $directory");
00188                 }
00189         }
00190 
00200         function initDefaultRoles()
00201         {
00202                 global $rbacadmin;
00203 
00204                 // create a local role folder
00205                 //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
00206 
00207                 // create moderator role and assign role to rolefolder...
00208                 //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
00209                 //$roles[] = $roleObj->getId();
00210 
00211                 //unset($rfoldObj);
00212                 //unset($roleObj);
00213 
00214                 return $roles ? $roles : array();
00215         }
00216 
00230         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00231         {
00232                 global $tree;
00233 
00234                 switch ($a_event)
00235                 {
00236                         case "link":
00237 
00238                                 //var_dump("<pre>",$a_params,"</pre>");
00239                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00240                                 //exit;
00241                                 break;
00242 
00243                         case "cut":
00244 
00245                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00246                                 //exit;
00247                                 break;
00248 
00249                         case "copy":
00250 
00251                                 //var_dump("<pre>",$a_params,"</pre>");
00252                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00253                                 //exit;
00254                                 break;
00255 
00256                         case "paste":
00257 
00258                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00259                                 //exit;
00260                                 break;
00261 
00262                         case "new":
00263 
00264                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00265                                 //exit;
00266                                 break;
00267                 }
00268 
00269                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00270                 if ($a_node_id==$_GET["ref_id"])
00271                 {
00272                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00273                         $parent_type = $parent_obj->getType();
00274                         if($parent_type == $this->getType())
00275                         {
00276                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00277                         }
00278                 }
00279 
00280                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00281         }
00282 
00291         function deleteQuestion($question_id)
00292         {
00293                 $question = new ASS_Question();
00294                 $question->delete($question_id);
00295         }
00296 
00306         function getQuestiontype($question_id)
00307         {
00308                 if ($question_id < 1)
00309                 {
00310                         return;
00311                 }
00312 
00313                 $query = sprintf("SELECT qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id AND qpl_questions.question_id = %s",
00314                         $this->ilias->db->quote($question_id));
00315 
00316                 $result = $this->ilias->db->query($query);
00317                 if ($result->numRows() == 1)
00318                 {
00319                         $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00320                         return $data->type_tag;
00321                 }
00322                 else
00323                 {
00324                         return;
00325                 }
00326         }
00327 
00328         /* moved to ASS_Question
00329         function get_total_answers($question_id)
00330         {
00331                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s",
00332                         $this->ilias->db->quote($question_id));
00333 
00334                 $result = $this->ilias->db->query($query);
00335 
00336                 if ($result->numRows() == 0)
00337                 {
00338                         return 0;
00339                 }
00340                 $found_id = array();
00341                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00342                 {
00343                         array_push($found_id, $row->question_id);
00344                 }
00345 
00346                 $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi IN (%s) GROUP BY CONCAT(user_fi,test_fi)",
00347                         join($found_id, ","));
00348 
00349                 $result = $this->ilias->db->query($query);
00350                 return $result->numRows();
00351         }*/
00352 
00353         /* moved to ASS_Question
00354         function get_total_right_answers($question_id)
00355         {
00356                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s",
00357                         $this->ilias->db->quote($question_id));
00358 
00359                 $result = $this->ilias->db->query($query);
00360                 if ($result->numRows() == 0)
00361                 {
00362                         return 0;
00363                 }
00364                 $found_id = array();
00365                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00366                 {
00367                         array_push($found_id, $row->question_id);
00368                 }
00369                 $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi IN (%s) GROUP BY CONCAT(user_fi,test_fi)",
00370                         join($found_id, ","));
00371 
00372                 $result = $this->ilias->db->query($query);
00373                 $answers = array();
00374                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00375                 {
00376                 $question =& $this->createQuestion("", $row->question_fi);
00377                         $reached = $question->object->getReachedPoints($row->user_fi, $row->test_fi);
00378                         $max = $question->object->getMaximumPoints();
00379                         array_push($answers, array("reached" => $reached, "max" => $max));
00380                 }
00381                 $max = 0.0;
00382                 $reached = 0.0;
00383                 foreach ($answers as $key => $value)
00384                 {
00385                         $max += $value["max"];
00386                         $reached += $value["reached"];
00387                 }
00388                 return $reached / $max;
00389         }*/
00390 
00396         function getDescription()
00397         {
00398                 return parent::getDescription();
00399                 //return $this->meta_data->getDescription();
00400         }
00401 
00405         function setDescription($a_description)
00406         {
00407                 parent::setDescription($a_description);
00408                 $this->meta_data->setDescription($a_description);
00409         }
00410 
00416         function getTitle()
00417         {
00418                 return parent::getTitle();
00419         }
00420 
00424         function setTitle($a_title)
00425         {
00426                 parent::setTitle($a_title);
00427                 $this->meta_data->setTitle($a_title);
00428         }
00429 
00435         function assignMetaData(&$a_meta_data)
00436         {
00437                 $this->meta_data =& $a_meta_data;
00438         }
00439 
00445         function &getMetaData()
00446         {
00447                 return $this->meta_data;
00448         }
00449 
00453         function initMeta()
00454         {
00455                 if (!is_object($this->meta_data))
00456                 {
00457                         if ($this->getId())
00458                         {
00459                                 $new_meta =& new ilMetaData($this->getType(), $this->getId());
00460                         }       
00461                         else
00462                         {
00463                                 $new_meta =& new ilMetaData();
00464                         }
00465                         $this->assignMetaData($new_meta);
00466                 }
00467         }
00468 
00472         function updateMetaData()
00473         {
00474                 $this->initMeta();
00475                 $this->meta_data->update();
00476                 if ($this->meta_data->section != "General")
00477                 {
00478                         $meta = $this->meta_data->getElement("Title", "General");
00479                         $this->meta_data->setTitle($meta[0]["value"]);
00480                         $meta = $this->meta_data->getElement("Description", "General");
00481                         $this->meta_data->setDescription($meta[0]["value"]);
00482                 }
00483                 else
00484                 {
00485                         $this->setTitle($this->meta_data->getTitle());
00486                         $this->setDescription($this->meta_data->getDescription());
00487                 }
00488                 parent::update();
00489         }
00490 
00491 
00501         function isInUse($question_id)
00502         {
00503                 $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00504                         $this->ilias->db->quote("$question_id"));
00505 
00506                 $result = $this->ilias->db->query($query);
00507                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00508 
00509                 return $row->solution_count;
00510         }
00511 
00512         function &createQuestion($question_type, $question_id = -1)
00513         {
00514                 if ((!$question_type) and ($question_id > 0))
00515                 {
00516                         $question_type = $this->getQuestiontype($question_id);
00517                 }
00518 
00519                 switch ($question_type)
00520                 {
00521                         case "qt_multiple_choice_sr":
00522                                 $question =& new ASS_MultipleChoiceGUI();
00523                                 $question->object->set_response(RESPONSE_SINGLE);
00524                                 break;
00525 
00526                         case "qt_multiple_choice_mr":
00527                                 $question =& new ASS_MultipleChoiceGUI();
00528                                 $question->object->set_response(RESPONSE_MULTIPLE);
00529                                 break;
00530 
00531                         case "qt_cloze":
00532                                 $question =& new ASS_ClozeTestGUI();
00533                                 break;
00534 
00535                         case "qt_matching":
00536                                 $question =& new ASS_MatchingQuestionGUI();
00537                                 break;
00538 
00539                         case "qt_ordering":
00540                                 $question =& new ASS_OrderingQuestionGUI();
00541                                 break;
00542 
00543                         case "qt_imagemap":
00544                                 $question =& new ASS_ImagemapQuestionGUI();
00545                                 break;
00546 
00547                         case "qt_javaapplet":
00548                                 $question =& new ASS_JavaAppletGUI();
00549                                 break;
00550 
00551                         case "qt_text":
00552                                 $question =& new ASS_TextQuestionGUI();
00553                                 break;
00554                 }
00555 
00556                 if ($question_id > 0)
00557                 {
00558                         $question->object->loadFromDb($question_id);
00559                 }
00560 
00561                 return $question;
00562         }
00563 
00572         function duplicateQuestion($question_id)
00573         {
00574                 global $ilUser;
00575 
00576                 $question =& $this->createQuestion("", $question_id);
00577                 $counter = 2;
00578                 while ($question->object->questionTitleExists($question->object->getTitle() . " ($counter)"))
00579                 {
00580                         $counter++;
00581                 }
00582 
00583                 $question->object->duplicate(false, $question->object->getTitle() . " ($counter)", $ilUser->fullname, $ilUser->id);
00584         }
00585 
00593         function getQuestionsTable($sortoptions, $filter_text, $sel_filter_type, $startrow = 0)
00594         {
00595                 global $ilUser;
00596                 $where = "";
00597                 if (strlen($filter_text) > 0)
00598                 {
00599                         switch($sel_filter_type)
00600                         {
00601                                 case "title":
00602                                         $where = " AND qpl_questions.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00603                                         break;
00604 
00605                                 case "comment":
00606                                         $where = " AND qpl_questions.comment LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00607                                         break;
00608 
00609                                 case "author":
00610                                         $where = " AND qpl_questions.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00611                                         break;
00612                         }
00613                 }
00614 
00615             // build sort order for sql query
00616                 $order = "";
00617                 $images = array();
00618                 if (count($sortoptions))
00619                 {
00620                         foreach ($sortoptions as $key => $value)
00621                         {
00622                                 switch($key)
00623                                 {
00624                                         case "title":
00625                                                 $order = " ORDER BY title $value";
00626                                                 $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00627                                                 break;
00628                                         case "comment":
00629                                                 $order = " ORDER BY comment $value";
00630                                                 $images["comment"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00631                                                 break;
00632                                         case "type":
00633                                                 $order = " ORDER BY question_type_id $value";
00634                                                 $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00635                                                 break;
00636                                         case "author":
00637                                                 $order = " ORDER BY author $value";
00638                                                 $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00639                                                 break;
00640                                         case "created":
00641                                                 $order = " ORDER BY created $value";
00642                                                 $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00643                                                 break;
00644                                         case "updated":
00645                                                 $order = " ORDER BY TIMESTAMP14 $value";
00646                                                 $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00647                                                 break;
00648                                 }
00649                         }
00650                 }
00651                 $maxentries = $ilUser->prefs["hits_per_page"];
00652                 if ($maxentries < 1)
00653                 {
00654                         $maxentries = 9999;
00655                 }
00656                 $query = "SELECT qpl_questions.question_id, qpl_questions.TIMESTAMP + 0 AS TIMESTAMP14 FROM qpl_questions, qpl_question_type WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.question_type_fi = qpl_question_type.question_type_id AND qpl_questions.obj_fi = " . $this->getId() . " $where$order$limit";
00657                 $query_result = $this->ilias->db->query($query);
00658                 $max = $query_result->numRows();
00659                 if ($startrow > $max -1)
00660                 {
00661                         $startrow = $max - ($max % $maxentries);
00662                 }
00663                 else if ($startrow < 0)
00664                 {
00665                         $startrow = 0;
00666                 }
00667                 $limit = " LIMIT $startrow, $maxentries";
00668                 $query = "SELECT qpl_questions.*, qpl_questions.TIMESTAMP + 0 AS TIMESTAMP14, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE ISNULL(qpl_questions.original_id) AND qpl_questions.question_type_fi = qpl_question_type.question_type_id AND qpl_questions.obj_fi = " . $this->getId() . " $where$order$limit";
00669                 $query_result = $this->ilias->db->query($query);
00670                 $rows = array();
00671                 if ($query_result->numRows())
00672                 {
00673                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00674                         {
00675                                 array_push($rows, $row);
00676                         }
00677                 }
00678                 $nextrow = $startrow + $maxentries;
00679                 if ($nextrow > $max - 1)
00680                 {
00681                         $nextrow = $startrow;
00682                 }
00683                 $prevrow = $startrow - $maxentries;
00684                 if ($prevrow < 0)
00685                 {
00686                         $prevrow = 0;
00687                 }
00688                 return array(
00689                         "rows" => $rows,
00690                         "images" => $images,
00691                         "startrow" => $startrow,
00692                         "nextrow" => $nextrow,
00693                         "prevrow" => $prevrow,
00694                         "step" => $maxentries,
00695                         "rowcount" => $max
00696                 );
00697         }
00698 
00705         function exportPagesXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog, $questions)
00706         {
00707                 global $ilBench;
00708                 
00709                 $this->mob_ids = array();
00710                 $this->file_ids = array();
00711 
00712                 $attrs = array();
00713                 $attrs["Type"] = "Questionpool_Test";
00714                 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00715 
00716                 // MetaData
00717                 $this->exportXMLMetaData($a_xml_writer);
00718 
00719                 // PageObjects
00720                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
00721                 $ilBench->start("ContentObjectExport", "exportPageObjects");
00722                 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog, $questions);
00723                 $ilBench->stop("ContentObjectExport", "exportPageObjects");
00724                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
00725 
00726                 // MediaObjects
00727                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00728                 $ilBench->start("ContentObjectExport", "exportMediaObjects");
00729                 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00730                 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
00731                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00732 
00733                 // FileItems
00734                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00735                 $ilBench->start("ContentObjectExport", "exportFileItems");
00736                 $this->exportFileItems($a_target_dir, $expLog);
00737                 $ilBench->stop("ContentObjectExport", "exportFileItems");
00738                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00739 
00740                 $a_xml_writer->xmlEndTag("ContentObject");
00741         }
00742 
00749         function exportXMLMetaData(&$a_xml_writer)
00750         {
00751                 $nested = new ilNestedSetXML();
00752                 $nested->setParameterModifier($this, "modifyExportIdentifier");
00753                 $a_xml_writer->appendXML($nested->export($this->getId(),
00754                         $this->getType()));
00755         }
00756 
00757         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00758         {
00759                 if ($a_tag == "Identifier" && $a_param == "Entry")
00760                 {
00761                         $a_value = ilUtil::insertInstIntoID($a_value);
00762                 }
00763 
00764                 return $a_value;
00765         }
00766 
00767 
00774         function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog, $questions)
00775         {
00776                 global $ilBench;
00777 
00778                 include_once "./content/classes/class.ilLMPageObject.php";
00779 
00780                 foreach ($questions as $question_id)
00781                 {
00782                         $ilBench->start("ContentObjectExport", "exportPageObject");
00783                         $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$question_id);
00784 
00785                         $attrs = array();
00786                         $a_xml_writer->xmlStartTag("PageObject", $attrs);
00787 
00788                         
00789                         // export xml to writer object
00790                         $ilBench->start("ContentObjectExport", "exportPageObject_XML");
00791                         $page_object = new ilPageObject("qpl", $question_id);
00792                         $page_object->buildDom();
00793                         $page_object->insertInstIntoIDs($a_inst);
00794                         $mob_ids = $page_object->collectMediaObjects(false);
00795                         $file_ids = $page_object->collectFileItems();
00796                         $xml = $page_object->getXMLFromDom(false, false, false, "", true);
00797                         $xml = str_replace("&","&amp;", $xml);
00798                         $a_xml_writer->appendXML($xml);
00799                         $page_object->freeDom();
00800                         unset ($page_object);
00801                         
00802                         $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
00803 
00804                         // collect media objects
00805                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
00806                         //$mob_ids = $page_obj->getMediaObjectIDs();
00807                         foreach($mob_ids as $mob_id)
00808                         {
00809                                 $this->mob_ids[$mob_id] = $mob_id;
00810                         }
00811                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
00812 
00813                         // collect all file items
00814                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
00815                         //$file_ids = $page_obj->getFileItemIds();
00816                         foreach($file_ids as $file_id)
00817                         {
00818                                 $this->file_ids[$file_id] = $file_id;
00819                         }
00820                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
00821                         
00822                         $a_xml_writer->xmlEndTag("PageObject");
00823                         //unset($page_obj);
00824 
00825                         $ilBench->stop("ContentObjectExport", "exportPageObject");
00826                         
00827 
00828                 }
00829         }
00830 
00837         function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00838         {
00839                 include_once("content/classes/Media/class.ilObjMediaObject.php");
00840 
00841                 foreach ($this->mob_ids as $mob_id)
00842                 {
00843                         $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00844                         $media_obj = new ilObjMediaObject($mob_id);
00845                         $media_obj->exportXML($a_xml_writer, $a_inst);
00846                         $media_obj->exportFiles($a_target_dir);
00847                         unset($media_obj);
00848                 }
00849         }
00850 
00855         function exportFileItems($a_target_dir, &$expLog)
00856         {
00857                 include_once("classes/class.ilObjFile.php");
00858 
00859                 foreach ($this->file_ids as $file_id)
00860                 {
00861                         $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00862                         $file_obj = new ilObjFile($file_id, false);
00863                         $file_obj->export($a_target_dir);
00864                         unset($file_obj);
00865                 }
00866         }       
00867 
00873         function createExportDirectory()
00874         {
00875                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00876                 ilUtil::makeDir($qpl_data_dir);
00877                 if(!is_writable($qpl_data_dir))
00878                 {
00879                         $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00880                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00881                 }
00882                 
00883                 // create learning module directory (data_dir/lm_data/lm_<id>)
00884                 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00885                 ilUtil::makeDir($qpl_dir);
00886                 if(!@is_dir($qpl_dir))
00887                 {
00888                         $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00889                 }
00890                 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
00891                 $export_dir = $qpl_dir."/export";
00892                 ilUtil::makeDir($export_dir);
00893                 if(!@is_dir($export_dir))
00894                 {
00895                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00896                 }
00897         }
00898 
00902         function getExportDirectory()
00903         {
00904                 $export_dir = ilUtil::getDataDir()."/qpl_data"."/qpl_".$this->getId()."/export";
00905 
00906                 return $export_dir;
00907         }
00908         
00912         function getExportFiles($dir)
00913         {
00914                 // quit if import dir not available
00915                 if (!@is_dir($dir) or
00916                         !is_writeable($dir))
00917                 {
00918                         return array();
00919                 }
00920                 // open directory
00921                 $dir = dir($dir);
00922 
00923                 // initialize array
00924                 $file = array();
00925 
00926                 // get files and save the in the array
00927                 while ($entry = $dir->read())
00928                 {
00929                         if ($entry != "." and
00930                                 $entry != ".." and
00931                                 substr($entry, -4) == ".zip" and
00932                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(qpl__)*[0-9]+\.zip\$", $entry))
00933                         {
00934                                 $file[] = $entry;
00935                         }
00936                 }
00937 
00938                 // close import directory
00939                 $dir->close();
00940 
00941                 // sort files
00942                 sort ($file);
00943                 reset ($file);
00944                 return $file;
00945         }
00946 
00952         function createImportDirectory()
00953         {
00954                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00955                 ilUtil::makeDir($qpl_data_dir);
00956                 
00957                 if(!is_writable($qpl_data_dir))
00958                 {
00959                         $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00960                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00961                 }
00962 
00963                 // create questionpool directory (data_dir/qpl_data/qpl_<id>)
00964                 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00965                 ilUtil::makeDir($qpl_dir);
00966                 if(!@is_dir($qpl_dir))
00967                 {
00968                         $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00969                 }
00970 
00971                 // create import subdirectory (data_dir/qpl_data/qpl_<id>/import)
00972                 $import_dir = $qpl_dir."/import";
00973                 ilUtil::makeDir($import_dir);
00974                 if(!@is_dir($import_dir))
00975                 {
00976                         $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
00977                 }
00978         }
00979 
00983         function getImportDirectory()
00984         {
00985                 $import_dir = ilUtil::getDataDir()."/qpl_data".
00986                         "/qpl_".$this->getId()."/import";
00987                 if(@is_dir($import_dir))
00988                 {
00989                         return $import_dir;
00990                 }
00991                 else
00992                 {
00993                         return false;
00994                 }
00995         }
00996         
00997         function &getAllQuestionIds()
00998         {
00999                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE ISNULL(original_id) AND obj_fi = %s",
01000                         $this->ilias->db->quote($this->getId())
01001                 );
01002                 $query_result = $this->ilias->db->query($query);
01003                 $questions = array();
01004                 if ($query_result->numRows())
01005                 {
01006                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01007                         {
01008                                 array_push($questions, $row["question_id"]);
01009                         }
01010                 }
01011                 return $questions;
01012         }
01013         
01018         function getImportMapping()
01019         {
01020                 if (!is_array($this->import_mapping))
01021                 {
01022                         return array();
01023                 }
01024                 else
01025                 {
01026                         return $this->import_mapping;
01027                 }
01028         }
01029         
01039         function to_xml($questions)
01040         {
01041                 $xml = "";
01042                 // export button was pressed
01043                 if (count($questions) > 0)
01044                 {
01045                         foreach ($questions as $key => $value)
01046                         {
01047                                 $question =& $this->createQuestion("", $value);
01048                                 $xml .= $question->object->to_xml();
01049                         }
01050                         if (count($questions) > 1)
01051                         {
01052                                 $xml = preg_replace("/<\/questestinterop>\s*<.xml.*?>\s*<questestinterop>/", "", $xml);
01053                         }
01054                 }
01055                 return $xml;
01056         }
01057         
01058         function importObject($source)
01059         {
01060                 $this->import_mapping = array();
01061                 if (is_file($source))
01062                 {
01063                         // import file into questionpool
01064                         $fh = fopen($source, "r") or die("");
01065                         $xml = fread($fh, filesize($source));
01066                         fclose($fh) or die("");
01067                         if (preg_match_all("/(<item[^>]*>.*?<\/item>)/si", $xml, $matches))
01068                         {
01069                                 foreach ($matches[1] as $index => $item)
01070                                 {
01071                                         // get identifier
01072                                         if (preg_match("/(<item[^>]*>)/is", $item, $start_tag))
01073                                         {
01074                                                 if (preg_match("/(ident=\"([^\"]*)\")/is", $start_tag[1], $ident))
01075                                                 {
01076                                                         $ident = $ident[2];
01077                                                 }
01078                                         }
01079                                         $question = "";
01080                                         $qt = "";
01081                                         if (preg_match("/<fieldlabel>QUESTIONTYPE<\/fieldlabel>\s*<fieldentry>(.*?)<\/fieldentry>/is", $item, $questiontype))
01082                                         {
01083                                                 $qt = $questiontype[1];
01084                                         }
01085                                         if (preg_match("/<qticomment>Questiontype\=(.*?)<\/qticomment>/is", $item, $questiontype))
01086                                         {
01087                                                 $qt = $questiontype[1];
01088                                         }
01089                                         if (strlen($qt))
01090                                         {
01091                                                 switch ($qt)
01092                                                 {
01093                                                         case CLOZE_TEST_IDENTIFIER:
01094                                                                 $question = new ASS_ClozeTest();
01095                                                                 break;
01096                                                         case IMAGEMAP_QUESTION_IDENTIFIER:
01097                                                                 $question = new ASS_ImagemapQuestion();
01098                                                                 break;
01099                                                         case MATCHING_QUESTION_IDENTIFIER:
01100                                                                 $question = new ASS_MatchingQuestion();
01101                                                                 break;
01102                                                         case MULTIPLE_CHOICE_QUESTION_IDENTIFIER:
01103                                                                 $question = new ASS_MultipleChoice();
01104                                                                 break;
01105                                                         case ORDERING_QUESTION_IDENTIFIER:
01106                                                                 $question = new ASS_OrderingQuestion();
01107                                                                 break;
01108                                                         case JAVAAPPLET_QUESTION_IDENTIFIER:
01109                                                                 $question = new ASS_JavaApplet();
01110                                                                 break;
01111                                                         case TEXT_QUESTION_IDENTIFIER:
01112                                                                 $question = new ASS_TextQuestion();
01113                                                                 break;
01114                                                 }
01115                                                 if ($question)
01116                                                 {
01117                                                         $question->setObjId($this->getId());
01118                                                         if ($question->from_xml("<questestinterop>$item</questestinterop>"))
01119                                                         {
01120                                                                 $question->saveToDb();
01121                                                                 $this->import_mapping[$ident] = array(
01122                                                                         "pool" => $question->getId(), "test" => 0);
01123                                                         }
01124                                                         else
01125                                                         {
01126                                                                 $this->ilias->raiseError($this->lng->txt("error_importing_question"), $this->ilias->error_obj->MESSAGE);
01127                                                         }
01128                                                 }
01129                                         }
01130                                 }
01131                         }
01132                 }
01133         }
01134         
01145         function _getQuestionCount($questionpool_id, $complete_questions_only = FALSE)
01146         {
01147                 global $ilDB;
01148                 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE obj_fi = %s AND ISNULL(original_id)",
01149                         $ilDB->quote($questionpool_id . "")
01150                 );
01151                 if ($complete_questions_only)
01152                 {
01153                         $query .= " AND complete = '1'";
01154                 }
01155                 $result = $ilDB->query($query);
01156                 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01157                 return $row["question_count"];
01158         }
01159         
01160 } // END class.ilObjQuestionPool
01161 ?>

Generated on Fri Dec 13 2013 09:06:33 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1