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

Modules/SurveyQuestionPool/classes/class.SurveyTextQuestionGUI.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 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
00025 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00026 
00038 class SurveyTextQuestionGUI extends SurveyQuestionGUI 
00039 {
00040 
00049   function SurveyTextQuestionGUI(
00050                 $id = -1
00051   )
00052 
00053   {
00054                 $this->SurveyQuestionGUI();
00055                 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyTextQuestion.php";
00056                 $this->object = new SurveyTextQuestion();
00057                 if ($id >= 0)
00058                 {
00059                         $this->object->loadFromDb($id);
00060                 }
00061         }
00062 
00070   function editQuestion() 
00071         {
00072                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_text.html", "Modules/SurveyQuestionPool");
00073           $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
00074 
00075                 $internallinks = array(
00076                         "lm" => $this->lng->txt("obj_lm"),
00077                         "st" => $this->lng->txt("obj_st"),
00078                         "pg" => $this->lng->txt("obj_pg"),
00079                         "glo" => $this->lng->txt("glossary_term")
00080                 );
00081                 foreach ($internallinks as $key => $value)
00082                 {
00083                         $this->tpl->setCurrentBlock("internallink");
00084                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00085                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00086                         $this->tpl->parseCurrentBlock();
00087                 }
00088                 
00089                 $this->tpl->setCurrentBlock("adm_content");
00090                 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
00091                 if (count($this->object->material))
00092                 {
00093                         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00094                         $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00095                         $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
00096                         $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
00097                         $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
00098                         $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
00099                         $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
00100                         $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00101                 }
00102                 else
00103                 {
00104                         $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
00105                 }
00106                 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00107                 $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
00108                 $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
00109                 $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
00110                 if ($this->object->getMaxChars() > 0)
00111                 {
00112                         $this->tpl->setVariable("VALUE_MAXCHARS", $this->object->getMaxChars());
00113                 }
00114                 $questiontext = $this->object->getQuestiontext();
00115                 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00116                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00117                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00118                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00119                 $this->tpl->setVariable("TEXT_MAXCHARS", $this->lng->txt("maxchars"));
00120                 $this->tpl->setVariable("TEXT_WIDTH", $this->lng->txt("width"));
00121                 $this->tpl->setVariable("TEXT_HEIGHT", $this->lng->txt("height"));
00122                 $this->tpl->setVariable("DESCRIPTION_TEXTWIDTH", $this->lng->txt("survey_text_textwidth_desc"));
00123                 $this->tpl->setVariable("DESCRIPTION_TEXTHEIGHT", $this->lng->txt("survey_text_textheight_desc"));
00124                 if ($this->object->getTextWidth())
00125                 {
00126                         $this->tpl->setVariable("VALUE_TEXTWIDTH", " value=\"" . $this->object->getTextWidth() . "\"");
00127                 }
00128                 if ($this->object->getTextHeight())
00129                 {
00130                         $this->tpl->setVariable("VALUE_TEXTHEIGHT", " value=\"" . $this->object->getTextHeight() . "\"");
00131                 }
00132                 $this->tpl->setVariable("DESCRIPTION_MAXCHARS", $this->lng->txt("description_maxchars"));
00133                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00134                 $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
00135                 if ($this->object->getObligatory())
00136                 {
00137                         $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
00138                 }
00139                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00140                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00141                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00142                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
00143                 $this->tpl->parseCurrentBlock();
00144                 include_once "./Services/RTE/classes/class.ilRTE.php";
00145                 $rtestring = ilRTE::_getRTEClassname();
00146                 include_once "./Services/RTE/classes/class.$rtestring.php";
00147                 $rte = new $rtestring();
00148                 $rte->addPlugin("latex");
00149                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00150                 $rte->removePlugin("ibrowser");
00151                 include_once "./classes/class.ilObject.php";
00152                 $obj_id = $_GET["q_id"];
00153                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00154                 $rte->addRTESupport($obj_id, $obj_type, "survey");
00155   }
00156 
00164         function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "")
00165         {
00166                 $template = new ilTemplate("tpl.il_svy_out_text.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00167                 if (count($this->object->material))
00168                 {
00169                         $template->setCurrentBlock("material_text");
00170                         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00171                         $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00172                         $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
00173                         $template->parseCurrentBlock();
00174                 }
00175 
00176                 if ($this->object->getTextHeight() == 1)
00177                 {
00178                         $template->setCurrentBlock("textinput");
00179                         if (is_array($working_data))
00180                         {
00181                                 if (strlen($working_data[0]["textanswer"]))
00182                                 {
00183                                         $template->setVariable("VALUE_ANSWER", " value=\"" . $this->object->prepareTextareaOutput($working_data[0]["textanswer"], TRUE) . "\"");
00184                                 }
00185                         }
00186                         $template->setVariable("QUESTION_ID", $this->object->getId());
00187                         $template->setVariable("WIDTH", $this->object->getTextWidth());
00188                         if ($this->object->getMaxChars())
00189                         {
00190                                 $template->setVariable("MAXLENGTH", " maxlength=\"" . $this->object->getMaxChars() . "\"");
00191                         }
00192                         $template->parseCurrentBlock();
00193                 }
00194                 else
00195                 {
00196                         $template->setCurrentBlock("textarea");
00197                         if (is_array($working_data))
00198                         {
00199                                 $template->setVariable("VALUE_ANSWER", $working_data[0]["textanswer"]);
00200                         }
00201                         $template->setVariable("QUESTION_ID", $this->object->getId());
00202                         $template->setVariable("WIDTH", $this->object->getTextWidth());
00203                         $template->setVariable("HEIGHT", $this->object->getTextHeight());
00204                         $template->parseCurrentBlock();
00205                 }
00206                 $template->setCurrentBlock("question_data_text");
00207                 if ($show_questiontext)
00208                 {
00209                         $questiontext = $this->object->getQuestiontext();
00210                         $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00211                 }
00212                 if (! $this->object->getObligatory())
00213                 {
00214                         $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00215                 }
00216                 if ($question_title)
00217                 {
00218                         $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00219                 }
00220                 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00221                 $template->setVariable("LABEL_QUESTION_ID", $this->object->getId());
00222                 if (strcmp($error_message, "") != 0)
00223                 {
00224                         $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
00225                 }
00226                 if ($this->object->getMaxChars())
00227                 {
00228                         $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
00229                 }
00230                 $template->parseCurrentBlock();
00231                 return $template->get();
00232         }
00233 
00241         function getPrintView($question_title = 1, $show_questiontext = 1)
00242         {
00243                 $template = new ilTemplate("tpl.il_svy_qpl_text_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00244                 if ($show_questiontext)
00245                 {
00246                         $questiontext = $this->object->getQuestiontext();
00247                         $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00248                 }
00249                 if (! $this->object->getObligatory())
00250                 {
00251                         $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00252                 }
00253                 if ($question_title)
00254                 {
00255                         $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00256                 }
00257                 $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00258                 $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
00259                 $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
00260                 $template->setVariable("TEXTBOX_WIDTH", $this->object->getTextWidth()*16);
00261                 $template->setVariable("TEXTBOX_HEIGHT", $this->object->getTextHeight()*16);
00262                 $template->setVariable("QUESTION_ID", $this->object->getId());
00263                 if ($this->object->getMaxChars())
00264                 {
00265                         $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
00266                 }
00267                 return $template->get();
00268         }
00269         
00277         function preview()
00278         {
00279                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
00280                 $question_output = $this->getWorkingForm();
00281                 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
00282                 $this->tpl->parseCurrentBlock();
00283         }
00284 
00293   function writePostData() 
00294         {
00295     $result = 0;
00296     if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00297       $result = 1;
00298 
00299     // Set the question id from a hidden form parameter
00300     if ($_POST["id"] > 0)
00301       $this->object->setId($_POST["id"]);
00302                 include_once "./Services/Utilities/classes/class.ilUtil.php";
00303     $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00304     $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00305     $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00306                 $this->object->setMaxChars(ilUtil::stripSlashes($_POST["maxchars"]));
00307                 $this->object->setTextWidth(ilUtil::stripSlashes($_POST["textwidth"]));
00308                 $this->object->setTextHeight(ilUtil::stripSlashes($_POST["textheight"]));
00309                 if (strlen($_POST["material"]))
00310                 {
00311                         $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
00312                 }
00313                 include_once "./classes/class.ilObjAdvancedEditing.php";
00314                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
00315                 $this->object->setQuestiontext($questiontext);
00316                 if ($_POST["obligatory"])
00317                 {
00318                         $this->object->setObligatory(1);
00319                 }
00320                 else
00321                 {
00322                         $this->object->setObligatory(0);
00323                 }
00324 
00325                 if ($saved) 
00326                 {
00327                         // If the question was saved automatically before an upload, we have to make
00328                         // sure, that the state after the upload is saved. Otherwise the user could be
00329                         // irritated, if he presses cancel, because he only has the question state before
00330                         // the upload process.
00331                         $this->object->saveToDb();
00332                 }
00333     return $result;
00334   }
00335 
00336         function setQuestionTabs()
00337         {
00338                 $this->setQuestionTabsForClass("surveytextquestiongui");
00339         }
00340 
00349         function getCumulatedResultRow($counter, $css_class, $survey_id)
00350         {
00351                 include_once "./classes/class.ilTemplate.php";
00352                 if (count($this->cumulated) == 0)
00353                 {
00354                         include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00355                         $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00356                         $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
00357                 }
00358                 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
00359                 $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
00360                 $maxlen = 37;
00361                 $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
00362                 if (strlen($questiontext) > $maxlen + 3)
00363                 {
00364                         $questiontext = substr($questiontext, 0, $maxlen) . "...";
00365                 }
00366                 $template->setVariable("QUESTION_TEXT", $questiontext);
00367                 $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
00368                 $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
00369                 $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
00370                 $template->setVariable("MODE", $this->cumulated["MODE"]);
00371                 $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
00372                 $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
00373                 $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
00374                 $template->setVariable("COLOR_CLASS", $css_class);
00375                 return $template->get();
00376         }
00377 
00388         function getCumulatedResultsDetails($survey_id, $counter)
00389         {
00390                 if (count($this->cumulated) == 0)
00391                 {
00392                         include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00393                         $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00394                         $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
00395                 }
00396                 
00397                 $output = "";
00398                 include_once "./classes/class.ilTemplate.php";
00399                 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
00400 
00401                 $template->setCurrentBlock("detail_row");
00402                 $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
00403                 $questiontext = $this->object->getQuestiontext();
00404                 $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
00405                 $template->parseCurrentBlock();
00406                 $template->setCurrentBlock("detail_row");
00407                 $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
00408                 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
00409                 $template->parseCurrentBlock();
00410                 $template->setCurrentBlock("detail_row");
00411                 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
00412                 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
00413                 $template->parseCurrentBlock();
00414                 $template->setCurrentBlock("detail_row");
00415                 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
00416                 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
00417                 $template->parseCurrentBlock();
00418                 
00419                 $template->setCurrentBlock("detail_row");
00420                 $template->setVariable("TEXT_OPTION", $this->lng->txt("given_answers"));
00421                 $textvalues = "";
00422                 if (is_array($this->cumulated["textvalues"]))
00423                 {
00424                         foreach ($this->cumulated["textvalues"] as $textvalue)
00425                         {
00426                                 $textvalues .= "<li>" . preg_replace("/\n/", "<br>", $textvalue) . "</li>";
00427                         }
00428                 }
00429                 $textvalues = "<ul>$textvalues</ul>";
00430                 $template->setVariable("TEXT_OPTION_VALUE", $textvalues);
00431                 $template->parseCurrentBlock();
00432 
00433                 $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
00434                 return $template->get();
00435         }
00436 }
00437 ?>

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