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

assessment/classes/class.assClozeTestGUI.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 
00024 require_once "./assessment/classes/class.assQuestionGUI.php";
00025 require_once "./assessment/classes/class.assClozeTest.php";
00026 
00038 class ASS_ClozeTestGUI extends ASS_QuestionGUI
00039 {
00048         function ASS_ClozeTestGUI(
00049                         $id = -1
00050         )
00051         {
00052                 $this->ASS_QuestionGUI();
00053 //echo "<br>assClozeTestGUI_constructor";
00054                 $this->object = new ASS_ClozeTest();
00055                 if ($id >= 0)
00056                 {
00057                         $this->object->loadFromDb($id);
00058                 }
00059         }
00060 
00069         function getQuestionType()
00070         {
00071                 return "qt_cloze";
00072         }
00073 
00074 
00075         function getCommand($cmd)
00076         {
00077                 if (substr($cmd, 0, 6) == "delete")
00078                 {
00079                         $cmd = "delete";
00080                 }
00081                 if (substr($cmd, 0, 10) == "addTextGap")
00082                 {
00083                         $cmd = "addTextGap";
00084                 }
00085                 if (substr($cmd, 0, 12) == "addSelectGap")
00086                 {
00087                         $cmd = "addSelectGap";
00088                 }
00089                 if (substr($cmd, 0, 20) == "addSuggestedSolution")
00090                 {
00091                         $cmd = "addSuggestedSolution";
00092                 }
00093                 if (substr($cmd, 0, 23) == "removeSuggestedSolution")
00094                 {
00095                         $cmd = "removeSuggestedSolution";
00096                 }
00097 
00098                 return $cmd;
00099         }
00100 
00101 
00109         function editQuestion()
00110         {
00111                 $internallinks = array(
00112                         "lm" => $this->lng->txt("obj_lm"),
00113                         "st" => $this->lng->txt("obj_st"),
00114                         "pg" => $this->lng->txt("obj_pg"),
00115                         "glo" => $this->lng->txt("glossary_term")
00116                 );
00117                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00118                 $this->getQuestionTemplate("qt_cloze");
00119                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_cloze_question.html", true);
00120                 for ($i = 0; $i < $this->object->get_gap_count(); $i++)
00121                 {
00122                         $gap = $this->object->get_gap($i);
00123                         if ($gap[0]->get_cloze_type() == CLOZE_TEXT)
00124                         {
00125                                 $this->tpl->setCurrentBlock("textgap_value");
00126                                 foreach ($gap    as $key => $value)
00127                                 {
00128                                         $this->tpl->setVariable("VALUE_TEXT_GAP", htmlspecialchars($value->get_answertext()));
00129                                         $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value"));
00130                                         $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key");
00131                                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00132                                         $this->tpl->parseCurrentBlock();
00133                                 }
00134 
00135                                 foreach ($internallinks as $key => $value)
00136                                 {
00137                                         $this->tpl->setCurrentBlock("textgap_internallink");
00138                                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00139                                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00140                                         $this->tpl->parseCurrentBlock();
00141                                 }
00142 
00143                                 $this->tpl->setCurrentBlock("textgap_suggested_solution");
00144                                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00145                                 if (array_key_exists($i, $this->object->suggested_solutions))
00146                                 {
00147                                         $solution_array = $this->object->getSuggestedSolution($i);
00148                                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00149                                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00150                                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00151                                         $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i);
00152                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00153                                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00154                                 }
00155                                 else
00156                                 {
00157                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00158                                 }
00159                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00160                                 $this->tpl->parseCurrentBlock();
00161                                 $this->tpl->setCurrentBlock("textgap");
00162                                 $answer_array = $this->object->get_gap($i);
00163                                 $answer_points = $answer_array[0]->get_points();
00164                                 $this->tpl->setVariable("VALUE_TEXT_GAP_POINTS", sprintf("%d", $answer_points));
00165                                 $this->tpl->setVariable("ADD_TEXT_GAP", $this->lng->txt("add_gap"));
00166                                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00167                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00168                                 $this->tpl->parseCurrentBlock();
00169                                 
00170                         }
00171                         elseif ($gap[0]->get_cloze_type() == CLOZE_SELECT)
00172                         {
00173                                 $this->tpl->setCurrentBlock("selectgap_value");
00174                                 foreach ($gap as $key => $value)
00175                                 {
00176                                         $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value"));
00177                                         $this->tpl->setVariable("VALUE_SELECT_GAP", htmlspecialchars($value->get_answertext()));
00178                                         $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key");
00179                                         $this->tpl->setVariable("VALUE_GAP", $i);
00180                                         $this->tpl->setVariable("VALUE_INDEX", $key);
00181                                         $this->tpl->setVariable("TEXT_TRUE", $this->lng->txt("true"));
00182                                         $this->tpl->setVariable("VALUE_STATUS_COUNTER", $key);
00183                                         $this->tpl->setVariable("VALUE_GAP", $i);
00184                                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00185                                         $this->tpl->setVariable("VALUE_SELECT_GAP_POINTS", sprintf("%d", $value->get_points()));
00186                                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00187                                         $this->tpl->parseCurrentBlock();
00188                                 }
00189 
00190                                 foreach ($internallinks as $key => $value)
00191                                 {
00192                                         $this->tpl->setCurrentBlock("selectgap_internallink");
00193                                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00194                                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00195                                         $this->tpl->parseCurrentBlock();
00196                                 }
00197 
00198                                 $this->tpl->setCurrentBlock("selectgap_suggested_solution");
00199                                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00200                                 if (array_key_exists($i, $this->object->suggested_solutions))
00201                                 {
00202                                         $solution_array = $this->object->getSuggestedSolution($i);
00203                                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00204                                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00205                                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00206                                         $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i);
00207                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00208                                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00209                                 }
00210                                 else
00211                                 {
00212                                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00213                                 }
00214                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00215                                 $this->tpl->parseCurrentBlock();
00216                                 $this->tpl->setCurrentBlock("selectgap");
00217                                 $this->tpl->setVariable("ADD_SELECT_GAP", $this->lng->txt("add_gap"));
00218                                 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00219                                 $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i");
00220                                 if ($gap[0]->get_shuffle())
00221                                 {
00222                                         $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00223                                 }
00224                                 else
00225                                 {
00226                                         $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00227                                 }
00228                                 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00229                                 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00230                                 $this->tpl->parseCurrentBlock();
00231                         }
00232                         $this->tpl->setCurrentBlock("answer_row");
00233                         $name = $gap[0]->get_name();
00234                         if (!$name)
00235                         {
00236                                 $name = $this->lng->txt("gap") . " " . ($i+1);
00237                         }
00238                         $this->tpl->setVariable("TEXT_GAP_NAME", $name);
00239                         $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00240                         if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
00241                         {
00242                                 $this->tpl->setVariable("SELECTED_SELECT_GAP", " selected=\"selected\"");
00243                         }
00244                         else
00245                         {
00246                                 $this->tpl->setVariable("SELECTED_TEXT_GAP", " selected=\"selected\"");
00247                         }
00248                         $this->tpl->setVariable("TEXT_TEXT_GAP", $this->lng->txt("text_gap"));
00249                         $this->tpl->setVariable("TEXT_SELECT_GAP", $this->lng->txt("select_gap"));
00250                         $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00251                         $this->tpl->parseCurrentBlock();
00252                 }
00253 
00254                 // call to other question data i.e. estimated working time block
00255                 $this->outOtherQuestionData();
00256 
00257                 $this->tpl->setCurrentBlock("HeadContent");
00258                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00259                 if (preg_match("/addTextGap_(\d+)/", $this->ctrl->getCmd(), $matches))
00260                 {
00261                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.textgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".focus(); document.frm_cloze_test.textgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".scrollIntoView(\"true\");"));
00262                 }
00263                 else if (preg_match("/addSelectGap_(\d+)/", $this->ctrl->getCmd(), $matches))
00264                 {
00265                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.selectgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".focus(); document.frm_cloze_test.selectgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".scrollIntoView(\"true\");"));
00266                 }
00267                 else
00268                 {
00269                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.title.focus();"));
00270                 }
00271                 $this->tpl->parseCurrentBlock();
00272                 $this->tpl->setCurrentBlock("question_data");
00273                 $this->tpl->setVariable("VALUE_CLOZE_TITLE", htmlspecialchars($this->object->getTitle()));
00274                 $this->tpl->setVariable("VALUE_CLOZE_COMMENT", htmlspecialchars($this->object->getComment()));
00275                 $this->tpl->setVariable("VALUE_CLOZE_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00276                 $cloze_text = $this->object->get_cloze_text();
00277                 $cloze_text = preg_replace("/<br \/>/", "\n", $cloze_text);
00278                 $this->tpl->setVariable("VALUE_CLOZE_TEXT", $cloze_text);
00279                 $this->tpl->setVariable("TEXT_CREATE_GAPS", $this->lng->txt("create_gaps"));
00280                 $this->tpl->setVariable("CLOZE_ID", $this->object->getId());
00281 
00282                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00283                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00284                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00285                 $this->tpl->setVariable("TEXT_CLOZE_TEXT", $this->lng->txt("cloze_text"));
00286                 $this->tpl->setVariable("TEXT_CLOSE_HINT", htmlspecialchars($this->lng->txt("close_text_hint")));
00287                 $this->tpl->setVariable("TEXT_GAP_DEFINITION", $this->lng->txt("gap_definition"));
00288                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00289                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00290                 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00291                 $this->ctrl->setParameter($this, "sel_question_types", "qt_cloze");
00292                 $this->tpl->setVariable("ACTION_CLOZE_TEST", $this->ctrl->getFormAction($this));
00293                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00294                 $this->tpl->parseCurrentBlock();
00295 
00296                 $this->tpl->setCurrentBlock("adm_content");
00297                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00298                 $this->tpl->parseCurrentBlock();
00299         }
00300 
00308         function outOtherQuestionData()
00309         {
00310                 $colspan = " colspan=\"4\"";
00311 
00312                 $this->tpl->setCurrentBlock("other_question_data");
00313                 $est_working_time = $this->object->getEstimatedWorkingTime();
00314                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00315                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00316                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00317                 $this->tpl->parseCurrentBlock();
00318         }
00319 
00328         function writePostData()
00329         {
00330                 $result = 0;
00331                 $saved = false;
00332 
00333                 // Delete all existing gaps and create new gaps from the form data
00334                 $this->object->flush_gaps();
00335 
00336                 if (!$this->checkInput())
00337                 {
00338                         $result = 1;
00339                 }
00340 
00341                 if (($result) and ($_POST["cmd"]["add"]))
00342                 {
00343                         // You cannot create gaps before you enter the required data
00344                         sendInfo($this->lng->txt("fill_out_all_required_fields_create_gaps"));
00345                         $_POST["cmd"]["add"] = "";
00346                 }
00347 
00348                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00349                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00350                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00351                 $cloze_text = ilUtil::stripSlashes($_POST["clozetext"], true, "<strong><em><code><cite><gap>");
00352                 $cloze_text = preg_replace("/\n/", "<br />", $cloze_text);
00353                 $this->object->set_cloze_text($cloze_text);
00354                 // adding estimated working time
00355                 $saved = $saved | $this->writeOtherPostData($result);
00356                 $this->object->suggested_solutions = array();
00357                 foreach ($_POST as $key => $value)
00358                 {
00359                         if (preg_match("/^solution_hint_(\d+)/", $key, $matches))
00360                         {
00361                                 if ($value)
00362                                 {
00363                                         $this->object->setSuggestedSolution($value, $matches[1]);
00364                                 }
00365                         }
00366                 }
00367                 
00368                 if ($this->ctrl->getCmd() != "createGaps")
00369                 {
00370                         $this->setGapValues();
00371                         $this->setGapPoints();
00372                         $this->setShuffleState();
00373 
00374                         foreach ($_POST as $key => $value)
00375                         {
00376                                 // Set the cloze type of the gap
00377                                 if (preg_match("/clozetype_(\d+)/", $key, $matches))
00378                                 {
00379                                         $this->object->set_cloze_type($matches[1], $value);
00380                                 }
00381                         }
00382                 }
00383 
00384                 $this->object->update_all_gap_params();
00385                 if ($saved)
00386                 {
00387                         // If the question was saved automatically before an upload, we have to make
00388                         // sure, that the state after the upload is saved. Otherwise the user could be
00389                         // irritated, if he presses cancel, because he only has the question state before
00390                         // the upload process.
00391                         $this->object->saveToDb();
00392                         $_GET["q_id"] = $this->object->getId();
00393                 }
00394                 return $result;
00395         }
00396 
00400         function delete()
00401         {
00402                 $this->writePostData();
00403                 foreach ($_POST["cmd"] as $key => $value)
00404                 {
00405                         // Check, if one of the gap values was deleted
00406                         if (preg_match("/delete_(\d+)_(\d+)/", $key, $matches))
00407                         {
00408                                 $selectgap = "selectgap_" . $matches[1] . "_" . $matches[2];
00409                                 $this->object->delete_answertext_by_index($matches[1], $matches[2]);
00410                         }
00411                 }
00412                 $this->editQuestion();
00413         }
00414 
00415         function addSelectGap()
00416         {
00417                 $this->writePostData();
00418 
00419                 $len = strlen("addSelectGap_");
00420                 $i = substr($this->ctrl->getCmd(), $len);
00421                 $this->object->set_answertext(
00422                         ilUtil::stripSlashes($i),
00423                         ilUtil::stripSlashes($this->object->get_gap_text_count($i)),
00424                         "",
00425                         1
00426                 );
00427 
00428                 $this->editQuestion();
00429         }
00430 
00431         function addTextGap()
00432         {
00433                 $this->writePostData();
00434 
00435                 $len = strlen("addTextGap_");
00436                 $i = substr($this->ctrl->getCmd(), $len);
00437                 $this->object->set_answertext(
00438                         ilUtil::stripSlashes($i),
00439                         ilUtil::stripSlashes($this->object->get_gap_text_count($i)),
00440                         "",
00441                         1
00442                 );
00443 
00444                 $this->editQuestion();
00445         }
00446 
00447         function setGapValues($a_apply_text = true)
00448         {
00449 //echo "<br>SETGapValues:$a_apply_text:";
00450                 foreach ($_POST as $key => $value)
00451                 {
00452                         // Set gap values
00453                         if ($a_apply_text)
00454                         {
00455                                 if (preg_match("/textgap_(\d+)_(\d+)/", $key, $matches))
00456                                 {
00457                                         $answer_array = $this->object->get_gap($matches[1]);
00458                                         if (strlen($value) > 0)
00459                                         {
00460                                                 // Only change gap values <> empty string
00461                                                 if (array_key_exists($matches[2], $answer_array))
00462                                                 {
00463                                                         if (strcmp($value, $answer_array[$matches[2]]->get_answertext()) != 0)
00464                                                         {
00465                                                                 $this->object->set_answertext(
00466                                                                         ilUtil::stripSlashes($matches[1]),
00467                                                                         ilUtil::stripSlashes($matches[2]),
00468                                                                         ilUtil::stripSlashes($value)
00469                                                                 );
00470                                                         }
00471                                                 }
00472                                         }
00473                                         else
00474                                         {
00475                                                 // Display errormessage: You've tried to set an gap value to an empty string!
00476                                         }
00477                                 }
00478                         }
00479 
00480                         if (preg_match("/selectgap_(\d+)_(\d+)/", $key, $matches))
00481                         {
00482                                 $answer_array = $this->object->get_gap($matches[1]);
00483                                 if (strlen($value) > 0)
00484                                 {
00485                                         // Only change gap values <> empty string
00486                                         if (array_key_exists($matches[2], $answer_array))
00487                                         {
00488                                                 if (strcmp($value, $answer_array[$matches[2]]->get_answertext()) != 0)
00489                                                 {
00490                                                         if ($a_apply_text)
00491                                                         {
00492                                                                 $this->object->set_answertext(
00493                                                                         ilUtil::stripSlashes($matches[1]),
00494                                                                         ilUtil::stripSlashes($matches[2]),
00495                                                                         ilUtil::stripSlashes($value)
00496                                                                 );
00497                                                         }
00498                                                 }
00499                                                 if (preg_match("/\d+/", $_POST["points_$matches[1]_$matches[2]"]))
00500                                                 {
00501                                                         $points = $_POST["points_$matches[1]_$matches[2]"];
00502                                                         if ($points < 0)
00503                                                         {
00504                                                                 $points = 0.0;
00505                                                                 sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00506                                                         }
00507                                                 }
00508                                                 else
00509                                                 {
00510                                                         $points = 0.0;
00511                                                 }
00512                                                 $this->object->set_single_answer_points($matches[1], $matches[2], $points);
00513                                                 $this->object->set_single_answer_state($matches[1], $matches[2], 1);
00514                                         }
00515                                 }
00516                                 else
00517                                 {
00518                                         // Display errormessage: You've tried to set an gap value to an empty string!
00519                                 }
00520                         }
00521                 }
00522         }
00523 
00524         function setGapPoints()
00525         {
00526                 foreach ($_POST as $key => $value)
00527                 {
00528                         // Set text gap points
00529                         if (preg_match("/^points_(\d+)$/", $key, $matches))
00530                         {
00531                                 if (preg_match("/\d+/", $value))
00532                                 {
00533                                         $points = $value;
00534                                         if ($points < 0)
00535                                         {
00536                                                 $points = 0.0;
00537                                                 sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00538                                         }
00539                                 }
00540                                 else
00541                                 {
00542                                         $points = 0.0;
00543                                 }
00544                                 $this->object->set_gap_points($matches[1], $points);
00545                         }
00546                 }
00547         }
00548 
00549         function setShuffleState()
00550         {
00551                 foreach ($_POST as $key => $value)
00552                 {
00553                         // Set select gap shuffle state
00554                         if (preg_match("/^shuffle_(\d+)$/", $key, $matches))
00555                         {
00556                                 $this->object->set_gap_shuffle($matches[1], $value);
00557                         }
00558                 }
00559         }
00560 
00564         function createGaps()
00565         {
00566                 $this->writePostData();
00567 
00568                 $this->setGapValues(false);
00569                 $this->setGapPoints();
00570                 $this->setShuffleState();
00571                 $this->object->update_all_gap_params();
00572                 $this->editQuestion();
00573         }
00574 
00575 
00583         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0)
00584         {
00585                 global $ilUser;
00586                 
00587                 $output = $this->outQuestionPage("CLOZE_TEST", $is_postponed);
00588                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00589                 $solutionoutput = preg_replace("/\"tgap/", "\"solution_tgap", $solutionoutput);
00590                 $solutionoutput = preg_replace("/\"sgap/", "\"solution_sgap", $solutionoutput);
00591                 $solutionoutput = preg_replace("/name=\"gap/", "name=\"solution_gap", $solutionoutput);
00592 
00593                 // set solutions
00594                 if ($test_id)
00595                 {
00596                         $solutions =& $this->object->getSolutionValues($test_id);
00597                         foreach ($solutions as $idx => $solution_value)
00598                         {
00599                                 $repl_str = "dummy=\"tgap_".$solution_value->value1."\"";
00600                                 $output = str_replace($repl_str, $repl_str." value=\"".ilUtil::prepareFormOutput($solution_value->value2)."\"", $output);
00601                                 $repl_str = "dummy=\"sgap_".$solution_value->value1."_".$solution_value->value2."\"";
00602                                 $output = str_replace($repl_str, $repl_str." selected=\"selected\"", $output);
00603 //echo "<br>".$repl_str;
00604                         }
00605                 }
00606 
00607                 foreach ($this->object->gaps as $idx => $gap)
00608                 {
00609                         $solution_value = "";
00610                         foreach ($solutions as $solidx => $solvalue)
00611                         {
00612                                 if ($solvalue->value1 == $idx)
00613                                 {
00614                                         $solution_value = $solvalue->value2;
00615                                 }
00616                         }
00617                         if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
00618                         {
00619                                 $maxpoints = 0;
00620                                 $maxindex = -1;
00621                                 foreach ($gap as $answeridx => $answer)
00622                                 {
00623                                         if ($answer->get_points() > $maxpoints)
00624                                         {
00625                                                 $maxpoints = $answer->get_points();
00626                                                 $maxindex = $answeridx;
00627                                         }
00628                                 }
00629                                 if ($maxindex > -1)
00630                                 {
00631                                         $repl_str = "dummy=\"solution_sgap_$idx" . "_$maxindex\"";
00632                                         $solutionoutput = str_replace($repl_str, $repl_str." selected=\"selected\"", $solutionoutput);
00633                                 }
00634                                 $solutionoutput = preg_replace("/(<select name\=\"solution_gap_$idx((?:(?!<select).)*)<\/select>)/is", "\\1" . " <em>(" . $maxpoints . " " . $this->lng->txt("points") . ")</em> " , $solutionoutput);
00635                                 if ($this->object->suggested_solutions[$idx])
00636                                 {
00637                                         if ($showsolution)
00638                                         {
00639                                                 $href = $this->object->_getInternalLinkHref($this->object->suggested_solutions[$idx]["internal_link"]);
00640                                                 $output = preg_replace("/(<select name\=\"gap_$idx((?:(?!<select).)*)<\/select>)/is", "\\1" . " [<a href=\"$href\" target=\"_blank\">".$this->lng->txt("solution_hint")."</a>] " , $output);
00641                                         }
00642                                 }
00643                         }
00644                         else
00645                         {
00646                                 $repl_str = "dummy=\"solution_tgap_$idx\"";
00647                                 $pvals = array();
00648                                 foreach ($gap as $answeridx => $answer)
00649                                 {
00650                                         array_push($pvals, $answer->get_answertext());
00651                                 }
00652                                 $possible_values = join($pvals, " " . $this->lng->txt("or") . " ");
00653                                 $solutionoutput = str_replace($repl_str, $repl_str." value=\"".ilUtil::prepareFormOutput($possible_values)."\"", $solutionoutput);
00654                                 $solutionoutput = preg_replace("/(<input[^<]*?dummy\=\"solution_tgap_$idx" . "[^>]*?>)/is", "\\1" . " <em>(" . $gap[0]->get_points() . " " . $this->lng->txt("points") . ")</em> ", $solutionoutput);
00655                                 if ($this->object->suggested_solutions[$idx])
00656                                 {
00657                                         if ($showsolution)
00658                                         {
00659                                                 $href = $this->object->_getInternalLinkHref($this->object->suggested_solutions[$idx]["internal_link"]);
00660                                                 $output = preg_replace("/(<input[^<]*?dummy\=\"tgap_$idx" . "[^>]*?>)/is", "\\1" . " [<a href=\"$href\" target=\"_blank\">".$this->lng->txt("solution_hint")."</a>] " , $output);
00661                                         }
00662                                 }
00663                         }
00664                 }
00665 
00666                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00667                 if ($test_id) 
00668                 {
00669                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
00670                 }
00671                 if (!$showsolution)
00672                 {
00673                         $solutionoutput = "";
00674                         $received_points = "";
00675                 }
00676 
00677                 $this->tpl->setVariable("CLOZE_TEST", $output.$solutionoutput.$received_points);
00678                 return;
00679         }
00680 
00688         function outUserSolution($user_id, $test_id)
00689         {
00690                 $results = $this->object->getReachedInformation($user_id, $test_id);
00691                 foreach ($this->object->gaps as $key => $gap)
00692                 {
00693                         $this->tpl->setCurrentBlock("tablerow");
00694                         if ($gap[0]->get_cloze_type() == CLOZE_SELECT)
00695                         {
00696                                 if ($gap[$results[$key]["value"]]->isStateChecked())
00697                                 {
00698                                         $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("right.png", true));
00699                                         $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_right"));
00700                                 }
00701                                 else
00702                                 {
00703                                         $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("wrong.png", true));
00704                                         $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_wrong"));
00705                                 }
00706                                 $this->tpl->setVariable("ANSWER_DESCRIPTION", $this->lng->txt("gap") . " " . ($key+1) . ": " . "&quot;<em>" . $gap[$results[$key]["value"]]->get_answertext() . "</em>&quot;");
00707                         }
00708                         else
00709                         {
00710                                 $right = 0;
00711                                 foreach ($gap as $gapkey => $answer)
00712                                 {
00713                                         if (strcmp(strtolower($results[$key]["value"]), strtolower($answer->get_answertext())) == 0)
00714                                         {
00715                                                 $right = 1;
00716                                         }
00717                                 }
00718                                 if ($right)
00719                                 {
00720                                         $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("right.png", true));
00721                                         $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_right"));
00722                                 }
00723                                 else
00724                                 {
00725                                         $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("wrong.png", true));
00726                                         $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_wrong"));
00727                                 }
00728                                 $this->tpl->setVariable("ANSWER_DESCRIPTION", $this->lng->txt("gap") . " " . ($key+1) . ": " . "&quot;<em>" . $results[$key]["value"] . "</em>&quot;");
00729                         }
00730                         $this->tpl->parseCurrentBlock();
00731                 }
00732         }
00733 
00737         function checkInput()
00738         {
00739                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["clozetext"]))
00740                 {
00741                         return false;
00742                 }
00743                 return true;
00744         }
00745 
00746 
00747         function addSuggestedSolution()
00748         {
00749                 $addForGap = -1;
00750                 if (array_key_exists("cmd", $_POST))
00751                 {
00752                         foreach ($_POST["cmd"] as $key => $value)
00753                         {
00754                                 if (preg_match("/addSuggestedSolution_(\d+)/", $key, $matches))
00755                                 {
00756                                         $addForGap = $matches[1];
00757                                 }
00758                         }
00759                 }
00760                 if ($addForGap > -1)
00761                 {
00762                         $this->writePostData();
00763                         if (!$this->checkInput())
00764                         {
00765                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00766                                 $this->editQuestion();
00767                                 return;
00768                         }
00769                         $_POST["internalLinkType"] = $_POST["internalLinkType_$addForGap"];
00770                         $_SESSION["subquestion_index"] = $addForGap;
00771                 }
00772                 $this->object->saveToDb();
00773                 $_GET["q_id"] = $this->object->getId();
00774                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00775                 $this->getQuestionTemplate("qt_cloze");
00776                 parent::addSuggestedSolution();
00777         }
00778 
00779         function removeSuggestedSolution()
00780         {
00781                 $removeFromGap = -1;
00782                 foreach ($_POST["cmd"] as $key => $value)
00783                 {
00784                         if (preg_match("/removeSuggestedSolution_(\d+)/", $key, $matches))
00785                         {
00786                                 $removeFromGap = $matches[1];
00787                         }
00788                 }
00789                 if ($removeFromGap > -1)
00790                 {
00791                         unset($this->object->suggested_solutions[$removeFromGap]);
00792                 }
00793         $this->object->saveToDb();
00794         $this->editQuestion();
00795         }
00796         
00797 }
00798 ?>

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