• 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 /*
00058                 if ($a_id == 0)
00059                 {
00060                         $new_meta =& new ilMetaData();
00061                         $this->assignMetaData($new_meta);
00062                 }
00063 */
00064         }
00065 
00069         function create($a_upload = false)
00070         {
00071                 parent::create();
00072                 
00073                 // meta data will be created by
00074                 // import parser
00075                 if (!$a_upload)
00076                 {
00077                         $this->createMetaData();
00078                 }
00079         }
00080 
00087         function update()
00088         {
00089                 $this->updateMetaData();
00090                 if (!parent::update())
00091                 {
00092                         return false;
00093                 }
00094 
00095                 // put here object specific stuff
00096 
00097                 return true;
00098         }
00099 
00105         function read($a_force_db = false)
00106         {
00107                 parent::read($a_force_db);
00108 //              $this->meta_data =& new ilMetaData($this->getType(), $this->getId());
00109         }
00110 
00118         function ilClone($a_parent_ref)
00119         {
00120                 global $rbacadmin;
00121 
00122                 // always call parent ilClone function first!!
00123                 $new_ref_id = parent::ilClone($a_parent_ref);
00124 
00125                 // get object instance of ilCloned object
00126                 //$newObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00127 
00128                 // create a local role folder & default roles
00129                 //$roles = $newObj->initDefaultRoles();
00130 
00131                 // ...finally assign role to creator of object
00132                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "n");
00133 
00134                 // always destroy objects in ilClone method because ilClone() is recursive and creates instances for each object in subtree!
00135                 //unset($newObj);
00136 
00137                 // ... and finally always return new reference ID!!
00138                 return $new_ref_id;
00139         }
00140 
00147         function delete()
00148         {
00149                 // always call parent delete function first!!
00150                 if (!parent::delete())
00151                 {
00152                         return false;
00153                 }
00154 
00155                 // delete meta data
00156                 $this->deleteMetaData();
00157 
00158                 //put here your module specific stuff
00159                 $this->deleteQuestionpool();
00160 
00161                 return true;
00162         }
00163 
00164         function deleteQuestionpool()
00165         {
00166                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND original_id IS NULL",
00167                         $this->ilias->db->quote($this->getId()));
00168 
00169                 $result = $this->ilias->db->query($query);
00170                 $questions = array();
00171 
00172                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00173                 {
00174                         array_push($questions, $row["question_id"]);
00175                 }
00176 
00177                 if (count($questions))
00178                 {
00179                         foreach ($questions as $question_id)
00180                         {
00181                                 $this->deleteQuestion($question_id);
00182                         }
00183                 }
00184 
00185                 // delete export files
00186                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00187                 $directory = $qpl_data_dir."/qpl_".$this->getId();
00188                 if (is_dir($directory))
00189                 {
00190                         $directory = escapeshellarg($directory);
00191                         exec("rm -rf $directory");
00192                 }
00193         }
00194 
00204         function initDefaultRoles()
00205         {
00206                 global $rbacadmin;
00207 
00208                 // create a local role folder
00209                 //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
00210 
00211                 // create moderator role and assign role to rolefolder...
00212                 //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
00213                 //$roles[] = $roleObj->getId();
00214 
00215                 //unset($rfoldObj);
00216                 //unset($roleObj);
00217 
00218                 return $roles ? $roles : array();
00219         }
00220 
00234         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00235         {
00236                 global $tree;
00237 
00238                 switch ($a_event)
00239                 {
00240                         case "link":
00241 
00242                                 //var_dump("<pre>",$a_params,"</pre>");
00243                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00244                                 //exit;
00245                                 break;
00246 
00247                         case "cut":
00248 
00249                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00250                                 //exit;
00251                                 break;
00252 
00253                         case "copy":
00254 
00255                                 //var_dump("<pre>",$a_params,"</pre>");
00256                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00257                                 //exit;
00258                                 break;
00259 
00260                         case "paste":
00261 
00262                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00263                                 //exit;
00264                                 break;
00265 
00266                         case "new":
00267 
00268                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00269                                 //exit;
00270                                 break;
00271                 }
00272 
00273                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00274                 if ($a_node_id==$_GET["ref_id"])
00275                 {
00276                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00277                         $parent_type = $parent_obj->getType();
00278                         if($parent_type == $this->getType())
00279                         {
00280                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00281                         }
00282                 }
00283 
00284                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00285         }
00286 
00295         function deleteQuestion($question_id)
00296         {
00297                 $question = new ASS_Question();
00298                 $question->delete($question_id);
00299         }
00300 
00310         function getQuestiontype($question_id)
00311         {
00312                 if ($question_id < 1)
00313                 {
00314                         return;
00315                 }
00316 
00317                 $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",
00318                         $this->ilias->db->quote($question_id));
00319 
00320                 $result = $this->ilias->db->query($query);
00321                 if ($result->numRows() == 1)
00322                 {
00323                         $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00324                         return $data->type_tag;
00325                 }
00326                 else
00327                 {
00328                         return;
00329                 }
00330         }
00331 
00337         function getDescription()
00338         {
00339                 return parent::getDescription();
00340                 //return $this->meta_data->getDescription();
00341         }
00342 
00346         function setDescription($a_description)
00347         {
00348                 parent::setDescription($a_description);
00349 //              $this->meta_data->setDescription($a_description);
00350         }
00351 
00357         function getTitle()
00358         {
00359                 return parent::getTitle();
00360         }
00361 
00365         function setTitle($a_title)
00366         {
00367                 parent::setTitle($a_title);
00368 //              $this->meta_data->setTitle($a_title);
00369         }
00370 
00376 /*
00377         function assignMetaData(&$a_meta_data)
00378         {
00379                 $this->meta_data =& $a_meta_data;
00380         }
00381 */
00382 
00388 /*
00389         function &getMetaData()
00390         {
00391                 return $this->meta_data;
00392         }
00393 */
00394 
00398 /*
00399         function initMeta()
00400         {
00401                 if (!is_object($this->meta_data))
00402                 {
00403                         if ($this->getId())
00404                         {
00405                                 $new_meta =& new ilMetaData($this->getType(), $this->getId());
00406                         }
00407                         else
00408                         {
00409                                 $new_meta =& new ilMetaData();
00410                         }
00411                         $this->assignMetaData($new_meta);
00412                 }
00413         }
00414 */
00415 
00419 /*
00420         function updateMetaData()
00421         {
00422                 $this->initMeta();
00423                 $this->meta_data->update();
00424                 if ($this->meta_data->section != "General")
00425                 {
00426                         $meta = $this->meta_data->getElement("Title", "General");
00427                         $this->meta_data->setTitle($meta[0]["value"]);
00428                         $meta = $this->meta_data->getElement("Description", "General");
00429                         $this->meta_data->setDescription($meta[0]["value"]);
00430                 }
00431                 else
00432                 {
00433                         $this->setTitle($this->meta_data->getTitle());
00434                         $this->setDescription($this->meta_data->getDescription());
00435                 }
00436                 parent::update();
00437         }
00438 */
00439 
00449         function isInUse($question_id)
00450         {
00451                 $query = sprintf("SELECT COUNT(solution_id) AS solution_count FROM tst_solutions WHERE question_fi = %s",
00452                         $this->ilias->db->quote("$question_id"));
00453 
00454                 $result = $this->ilias->db->query($query);
00455                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00456 
00457                 return $row->solution_count;
00458         }
00459 
00460         function &createQuestion($question_type, $question_id = -1)
00461         {
00462                 if ((!$question_type) and ($question_id > 0))
00463                 {
00464                         $question_type = $this->getQuestiontype($question_id);
00465                 }
00466 
00467                 switch ($question_type)
00468                 {
00469                         case "qt_multiple_choice_sr":
00470                                 $question =& new ASS_MultipleChoiceGUI();
00471                                 $question->object->set_response(RESPONSE_SINGLE);
00472                                 break;
00473 
00474                         case "qt_multiple_choice_mr":
00475                                 $question =& new ASS_MultipleChoiceGUI();
00476                                 $question->object->set_response(RESPONSE_MULTIPLE);
00477                                 break;
00478 
00479                         case "qt_cloze":
00480                                 $question =& new ASS_ClozeTestGUI();
00481                                 break;
00482 
00483                         case "qt_matching":
00484                                 $question =& new ASS_MatchingQuestionGUI();
00485                                 break;
00486 
00487                         case "qt_ordering":
00488                                 $question =& new ASS_OrderingQuestionGUI();
00489                                 break;
00490 
00491                         case "qt_imagemap":
00492                                 $question =& new ASS_ImagemapQuestionGUI();
00493                                 break;
00494 
00495                         case "qt_javaapplet":
00496                                 $question =& new ASS_JavaAppletGUI();
00497                                 break;
00498 
00499                         case "qt_text":
00500                                 $question =& new ASS_TextQuestionGUI();
00501                                 break;
00502                 }
00503 
00504                 if ($question_id > 0)
00505                 {
00506                         $question->object->loadFromDb($question_id);
00507                 }
00508 
00509                 return $question;
00510         }
00511 
00520         function duplicateQuestion($question_id)
00521         {
00522                 global $ilUser;
00523 
00524                 $question =& $this->createQuestion("", $question_id);
00525                 $counter = 2;
00526                 while ($question->object->questionTitleExists($question->object->getTitle() . " ($counter)"))
00527                 {
00528                         $counter++;
00529                 }
00530 
00531                 $question->object->duplicate(false, $question->object->getTitle() . " ($counter)", $ilUser->fullname, $ilUser->id);
00532         }
00533 
00541         function getQuestionsTable($sortoptions, $filter_text, $sel_filter_type, $startrow = 0)
00542         {
00543                 global $ilUser;
00544                 $where = "";
00545                 if (strlen($filter_text) > 0)
00546                 {
00547                         switch($sel_filter_type)
00548                         {
00549                                 case "title":
00550                                         $where = " AND qpl_questions.title LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00551                                         break;
00552 
00553                                 case "comment":
00554                                         $where = " AND qpl_questions.comment LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00555                                         break;
00556 
00557                                 case "author":
00558                                         $where = " AND qpl_questions.author LIKE " . $this->ilias->db->quote("%" . $filter_text . "%");
00559                                         break;
00560                         }
00561                 }
00562 
00563             // build sort order for sql query
00564                 $order = "";
00565                 $images = array();
00566                 if (count($sortoptions))
00567                 {
00568                         foreach ($sortoptions as $key => $value)
00569                         {
00570                                 switch($key)
00571                                 {
00572                                         case "title":
00573                                                 $order = " ORDER BY title $value";
00574                                                 $images["title"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00575                                                 break;
00576                                         case "comment":
00577                                                 $order = " ORDER BY comment $value";
00578                                                 $images["comment"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00579                                                 break;
00580                                         case "type":
00581                                                 $order = " ORDER BY question_type_id $value";
00582                                                 $images["type"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00583                                                 break;
00584                                         case "author":
00585                                                 $order = " ORDER BY author $value";
00586                                                 $images["author"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00587                                                 break;
00588                                         case "created":
00589                                                 $order = " ORDER BY created $value";
00590                                                 $images["created"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00591                                                 break;
00592                                         case "updated":
00593                                                 $order = " ORDER BY TIMESTAMP14 $value";
00594                                                 $images["updated"] = " <img src=\"" . ilUtil::getImagePath(strtolower($value) . "_order.png", true) . "\" alt=\"" . strtolower($value) . "ending order\" />";
00595                                                 break;
00596                                 }
00597                         }
00598                 }
00599                 $maxentries = $ilUser->prefs["hits_per_page"];
00600                 if ($maxentries < 1)
00601                 {
00602                         $maxentries = 9999;
00603                 }
00604                 $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";
00605                 $query_result = $this->ilias->db->query($query);
00606                 $max = $query_result->numRows();
00607                 if ($startrow > $max -1)
00608                 {
00609                         $startrow = $max - ($max % $maxentries);
00610                 }
00611                 else if ($startrow < 0)
00612                 {
00613                         $startrow = 0;
00614                 }
00615                 $limit = " LIMIT $startrow, $maxentries";
00616                 $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";
00617                 $query_result = $this->ilias->db->query($query);
00618                 $rows = array();
00619                 if ($query_result->numRows())
00620                 {
00621                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00622                         {
00623                                 array_push($rows, $row);
00624                         }
00625                 }
00626                 $nextrow = $startrow + $maxentries;
00627                 if ($nextrow > $max - 1)
00628                 {
00629                         $nextrow = $startrow;
00630                 }
00631                 $prevrow = $startrow - $maxentries;
00632                 if ($prevrow < 0)
00633                 {
00634                         $prevrow = 0;
00635                 }
00636                 return array(
00637                         "rows" => $rows,
00638                         "images" => $images,
00639                         "startrow" => $startrow,
00640                         "nextrow" => $nextrow,
00641                         "prevrow" => $prevrow,
00642                         "step" => $maxentries,
00643                         "rowcount" => $max
00644                 );
00645         }
00646 
00653         function exportPagesXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog, $questions)
00654         {
00655                 global $ilBench;
00656                 
00657                 $this->mob_ids = array();
00658                 $this->file_ids = array();
00659 
00660                 $attrs = array();
00661                 $attrs["Type"] = "Questionpool_Test";
00662                 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00663 
00664                 // MetaData
00665                 $this->exportXMLMetaData($a_xml_writer);
00666 
00667                 // PageObjects
00668                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
00669                 $ilBench->start("ContentObjectExport", "exportPageObjects");
00670                 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog, $questions);
00671                 $ilBench->stop("ContentObjectExport", "exportPageObjects");
00672                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
00673 
00674                 // MediaObjects
00675                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00676                 $ilBench->start("ContentObjectExport", "exportMediaObjects");
00677                 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00678                 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
00679                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00680 
00681                 // FileItems
00682                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00683                 $ilBench->start("ContentObjectExport", "exportFileItems");
00684                 $this->exportFileItems($a_target_dir, $expLog);
00685                 $ilBench->stop("ContentObjectExport", "exportFileItems");
00686                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00687 
00688                 $a_xml_writer->xmlEndTag("ContentObject");
00689         }
00690 
00697         function exportXMLMetaData(&$a_xml_writer)
00698         {
00699                 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00700                 $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
00701                 $md2xml->setExportMode(true);
00702                 $md2xml->startExport();
00703                 $a_xml_writer->appendXML($md2xml->getXML());
00704         }
00705 
00706         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00707         {
00708                 if ($a_tag == "Identifier" && $a_param == "Entry")
00709                 {
00710                         $a_value = ilUtil::insertInstIntoID($a_value);
00711                 }
00712 
00713                 return $a_value;
00714         }
00715 
00716 
00723         function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog, $questions)
00724         {
00725                 global $ilBench;
00726 
00727                 include_once "./content/classes/class.ilLMPageObject.php";
00728 
00729                 foreach ($questions as $question_id)
00730                 {
00731                         $ilBench->start("ContentObjectExport", "exportPageObject");
00732                         $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$question_id);
00733 
00734                         $attrs = array();
00735                         $a_xml_writer->xmlStartTag("PageObject", $attrs);
00736 
00737                         
00738                         // export xml to writer object
00739                         $ilBench->start("ContentObjectExport", "exportPageObject_XML");
00740                         $page_object = new ilPageObject("qpl", $question_id);
00741                         $page_object->buildDom();
00742                         $page_object->insertInstIntoIDs($a_inst);
00743                         $mob_ids = $page_object->collectMediaObjects(false);
00744                         $file_ids = $page_object->collectFileItems();
00745                         $xml = $page_object->getXMLFromDom(false, false, false, "", true);
00746                         $xml = str_replace("&","&amp;", $xml);
00747                         $a_xml_writer->appendXML($xml);
00748                         $page_object->freeDom();
00749                         unset ($page_object);
00750                         
00751                         $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
00752 
00753                         // collect media objects
00754                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
00755                         //$mob_ids = $page_obj->getMediaObjectIDs();
00756                         foreach($mob_ids as $mob_id)
00757                         {
00758                                 $this->mob_ids[$mob_id] = $mob_id;
00759                         }
00760                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
00761 
00762                         // collect all file items
00763                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
00764                         //$file_ids = $page_obj->getFileItemIds();
00765                         foreach($file_ids as $file_id)
00766                         {
00767                                 $this->file_ids[$file_id] = $file_id;
00768                         }
00769                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
00770                         
00771                         $a_xml_writer->xmlEndTag("PageObject");
00772                         //unset($page_obj);
00773 
00774                         $ilBench->stop("ContentObjectExport", "exportPageObject");
00775                         
00776 
00777                 }
00778         }
00779 
00786         function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00787         {
00788                 include_once("content/classes/Media/class.ilObjMediaObject.php");
00789 
00790                 foreach ($this->mob_ids as $mob_id)
00791                 {
00792                         $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00793                         $media_obj = new ilObjMediaObject($mob_id);
00794                         $media_obj->exportXML($a_xml_writer, $a_inst);
00795                         $media_obj->exportFiles($a_target_dir);
00796                         unset($media_obj);
00797                 }
00798         }
00799 
00804         function exportFileItems($a_target_dir, &$expLog)
00805         {
00806                 include_once("classes/class.ilObjFile.php");
00807 
00808                 foreach ($this->file_ids as $file_id)
00809                 {
00810                         $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00811                         $file_obj = new ilObjFile($file_id, false);
00812                         $file_obj->export($a_target_dir);
00813                         unset($file_obj);
00814                 }
00815         }       
00816 
00822         function createExportDirectory()
00823         {
00824                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00825                 ilUtil::makeDir($qpl_data_dir);
00826                 if(!is_writable($qpl_data_dir))
00827                 {
00828                         $this->ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00829                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00830                 }
00831                 
00832                 // create learning module directory (data_dir/lm_data/lm_<id>)
00833                 $qpl_dir = $qpl_data_dir."/qpl_".$this->getId();
00834                 ilUtil::makeDir($qpl_dir);
00835                 if(!@is_dir($qpl_dir))
00836                 {
00837                         $this->ilias->raiseError("Creation of Questionpool Directory failed.",$this->ilias->error_obj->FATAL);
00838                 }
00839                 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
00840                 $export_dir = $qpl_dir."/export";
00841                 ilUtil::makeDir($export_dir);
00842                 if(!@is_dir($export_dir))
00843                 {
00844                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00845                 }
00846         }
00847 
00851         function getExportDirectory()
00852         {
00853                 $export_dir = ilUtil::getDataDir()."/qpl_data"."/qpl_".$this->getId()."/export";
00854 
00855                 return $export_dir;
00856         }
00857         
00861         function getExportFiles($dir)
00862         {
00863                 // quit if import dir not available
00864                 if (!@is_dir($dir) or
00865                         !is_writeable($dir))
00866                 {
00867                         return array();
00868                 }
00869                 // open directory
00870                 $dir = dir($dir);
00871 
00872                 // initialize array
00873                 $file = array();
00874 
00875                 // get files and save the in the array
00876                 while ($entry = $dir->read())
00877                 {
00878                         if ($entry != "." and
00879                                 $entry != ".." and
00880                                 substr($entry, -4) == ".zip" and
00881                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(qpl__)*[0-9]+\.zip\$", $entry))
00882                         {
00883                                 $file[] = $entry;
00884                         }
00885                 }
00886 
00887                 // close import directory
00888                 $dir->close();
00889 
00890                 // sort files
00891                 sort ($file);
00892                 reset ($file);
00893                 return $file;
00894         }
00895 
00901         function _createImportDirectory()
00902         {
00903                 global $ilias;
00904                 
00905                 $qpl_data_dir = ilUtil::getDataDir()."/qpl_data";
00906                 ilUtil::makeDir($qpl_data_dir);
00907                 
00908                 if(!is_writable($qpl_data_dir))
00909                 {
00910                         $ilias->raiseError("Questionpool Data Directory (".$qpl_data_dir
00911                                 .") not writeable.",$ilias->error_obj->FATAL);
00912                 }
00913 
00914                 // create questionpool directory (data_dir/qpl_data/qpl_import)
00915                 $qpl_dir = $qpl_data_dir."/qpl_import";
00916                 ilUtil::makeDir($qpl_dir);
00917                 if(!@is_dir($qpl_dir))
00918                 {
00919                         $ilias->raiseError("Creation of Questionpool Directory failed.",$ilias->error_obj->FATAL);
00920                 }
00921         }
00922 
00926         function _getImportDirectory()
00927         {
00928                 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
00929                 if(@is_dir($import_dir))
00930                 {
00931                         return $import_dir;
00932                 }
00933                 else
00934                 {
00935                         return false;
00936                 }
00937         }
00938 
00942         function getImportDirectory()
00943         {
00944                 $import_dir = ilUtil::getDataDir()."/qpl_data/qpl_import";
00945                 if(@is_dir($import_dir))
00946                 {
00947                         return $import_dir;
00948                 }
00949                 else
00950                 {
00951                         return false;
00952                 }
00953         }
00954         
00955         function &getAllQuestionIds()
00956         {
00957                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE ISNULL(original_id) AND obj_fi = %s AND complete = %s",
00958                         $this->ilias->db->quote($this->getId()),
00959                         $this->ilias->db->quote("1")
00960                 );
00961                 $query_result = $this->ilias->db->query($query);
00962                 $questions = array();
00963                 if ($query_result->numRows())
00964                 {
00965                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
00966                         {
00967                                 array_push($questions, $row["question_id"]);
00968                         }
00969                 }
00970                 return $questions;
00971         }
00972         
00977         function getImportMapping()
00978         {
00979                 if (!is_array($this->import_mapping))
00980                 {
00981                         return array();
00982                 }
00983                 else
00984                 {
00985                         return $this->import_mapping;
00986                 }
00987         }
00988         
00998         function to_xml($questions)
00999         {
01000                 $xml = "";
01001                 // export button was pressed
01002                 if (count($questions) > 0)
01003                 {
01004                         foreach ($questions as $key => $value)
01005                         {
01006                                 $question =& $this->createQuestion("", $value);
01007                                 $xml .= $question->object->to_xml();
01008                         }
01009                         if (count($questions) > 1)
01010                         {
01011                                 $xml = preg_replace("/<\/questestinterop>\s*<.xml.*?>\s*<questestinterop>/", "", $xml);
01012                         }
01013                 }
01014                 return $xml;
01015         }
01016         
01017         function importObject($source)
01018         {
01019                 $this->import_mapping = array();
01020                 if (is_file($source))
01021                 {
01022                         // import file into questionpool
01023                         $fh = fopen($source, "r") or die("");
01024                         $xml = fread($fh, filesize($source));
01025                         fclose($fh) or die("");
01026 
01027                         if (preg_match_all("/(<item[^>]*>.*?<\/item>)/si", $xml, $matches))
01028                         {
01029                                 foreach ($matches[1] as $index => $item)
01030                                 {
01031                                         // get identifier
01032                                         if (preg_match("/(<item[^>]*>)/is", $item, $start_tag))
01033                                         {
01034                                                 if (preg_match("/(ident=\"([^\"]*)\")/is", $start_tag[1], $ident))
01035                                                 {
01036                                                         $ident = $ident[2];
01037                                                 }
01038                                         }
01039                                         $question = "";
01040                                         $qt = "";
01041                                         if (preg_match("/<fieldlabel>QUESTIONTYPE<\/fieldlabel>\s*<fieldentry>(.*?)<\/fieldentry>/is", $item, $questiontype))
01042                                         {
01043                                                 $qt = $questiontype[1];
01044                                         }
01045                                         if (preg_match("/<qticomment>Questiontype\=(.*?)<\/qticomment>/is", $item, $questiontype))
01046                                         {
01047                                                 $qt = $questiontype[1];
01048                                         }
01049                                         if (strlen($qt))
01050                                         {
01051                                                 switch ($qt)
01052                                                 {
01053                                                         case CLOZE_TEST_IDENTIFIER:
01054                                                                 $question = new ASS_ClozeTest();
01055                                                                 break;
01056                                                         case IMAGEMAP_QUESTION_IDENTIFIER:
01057                                                                 $question = new ASS_ImagemapQuestion();
01058                                                                 break;
01059                                                         case MATCHING_QUESTION_IDENTIFIER:
01060                                                                 $question = new ASS_MatchingQuestion();
01061                                                                 break;
01062                                                         case MULTIPLE_CHOICE_QUESTION_IDENTIFIER:
01063                                                                 $question = new ASS_MultipleChoice();
01064                                                                 break;
01065                                                         case ORDERING_QUESTION_IDENTIFIER:
01066                                                                 $question = new ASS_OrderingQuestion();
01067                                                                 break;
01068                                                         case JAVAAPPLET_QUESTION_IDENTIFIER:
01069                                                                 $question = new ASS_JavaApplet();
01070                                                                 break;
01071                                                         case TEXT_QUESTION_IDENTIFIER:
01072                                                                 $question = new ASS_TextQuestion();
01073                                                                 break;
01074                                                 }
01075                                                 if ($question)
01076                                                 {
01077                                                         $question->setObjId($this->getId());
01078                                                         if ($question->from_xml("<questestinterop>$item</questestinterop>"))
01079                                                         {
01080                                                                 $question->saveToDb();
01081                                                                 $this->import_mapping[$ident] = array(
01082                                                                         "pool" => $question->getId(), "test" => 0);
01083                                                         }
01084                                                         else
01085                                                         {
01086                                                                 $this->ilias->raiseError($this->lng->txt("error_importing_question"), $this->ilias->error_obj->MESSAGE);
01087                                                         }
01088                                                 }
01089                                         }
01090                                 }
01091                         }
01092                 }
01093                 else
01094                 {
01095                         return FALSE;
01096                 }
01097                 return TRUE;
01098         }
01099         
01110         function _getQuestionCount($questionpool_id, $complete_questions_only = FALSE)
01111         {
01112                 global $ilDB;
01113                 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE obj_fi = %s AND ISNULL(original_id)",
01114                         $ilDB->quote($questionpool_id . "")
01115                 );
01116                 if ($complete_questions_only)
01117                 {
01118                         $query .= " AND complete = '1'";
01119                 }
01120                 $result = $ilDB->query($query);
01121                 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01122                 return $row["question_count"];
01123         }
01124 
01134         function _isWriteable($object_id, $user_id)
01135         {
01136                 global $rbacsystem;
01137                 global $ilDB;
01138                 
01139                 $result_array = array();
01140                 $query = sprintf("SELECT object_data.*, object_data.obj_id, object_reference.ref_id FROM object_data, object_reference WHERE object_data.obj_id = object_reference.obj_id AND object_data.obj_id = %s",
01141                         $ilDB->quote($object_id . "")
01142                 );
01143                 $result = $ilDB->query($query);
01144                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01145                 {               
01146                         include_once "./classes/class.ilObject.php";
01147                         if ($rbacsystem->checkAccess("write", $row["ref_id"]) && (ilObject::_hasUntrashedReference($row["obj_id"])))
01148                         {
01149                                 return true;
01150                         }
01151                 }
01152                 return false;
01153         }
01154         
01164         function &getQuestionDetails($question_ids)
01165         {
01166                 global $ilDB;
01167                 
01168                 $result = array();
01169                 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01170                 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01171                 $query = "SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id$whereclause ORDER BY qpl_questions.title";
01172                 $query_result = $ilDB->query($query);
01173                 if ($query_result->numRows())
01174                 {
01175                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01176                         {
01177                                 array_push($result, $row);
01178                         }
01179                 }
01180                 return $result;
01181         }
01182 
01194         function &getDeleteableQuestionDetails($question_ids)
01195         {
01196                 global $ilDB;
01197                 
01198                 $result = array();
01199                 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01200                 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01201                 $query = "SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id$whereclause ORDER BY qpl_questions.title";
01202                 $query_result = $ilDB->query($query);
01203                 if ($query_result->numRows())
01204                 {
01205                         include_once "./assessment/classes/class.assQuestion.php";
01206                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01207                         {
01208                                 if (!ASS_Question::_isUsedInRandomTest($row["question_id"]))
01209                                 {
01210                                         array_push($result, $row);
01211                                 }
01212                         }
01213                 }
01214                 return $result;
01215         }
01216 
01228         function &getUsedQuestionDetails($question_ids)
01229         {
01230                 global $ilDB;
01231                 
01232                 $result = array();
01233                 $whereclause = join($question_ids, " OR qpl_questions.question_id = ");
01234                 $whereclause = " AND (qpl_questions.question_id = " . $whereclause . ")";
01235                 $query = "SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id$whereclause ORDER BY qpl_questions.title";
01236                 $query_result = $ilDB->query($query);
01237                 if ($query_result->numRows())
01238                 {
01239                         include_once "./assessment/classes/class.assQuestion.php";
01240                         while ($row = $query_result->fetchRow(DB_FETCHMODE_ASSOC))
01241                         {
01242                                 if (ASS_Question::_isUsedInRandomTest($row["question_id"]))
01243                                 {
01244                                         array_push($result, $row);
01245                                 }
01246                         }
01247                 }
01248                 return $result;
01249         }
01250 
01251 } // END class.ilObjQuestionPool
01252 ?>

Generated on Fri Dec 13 2013 10:18:26 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1