ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilPCQuestion Class Reference

Class ilPCQuestion. More...

+ Inheritance diagram for ilPCQuestion:
+ Collaboration diagram for ilPCQuestion:

Public Member Functions

 init ()
 Init page content component.
 setNode (&$a_node)
 Set node.
 setQuestionReference ($a_questionreference)
 Set Question Reference.
 getQuestionReference ()
 Get Question Reference.
 create (&$a_pg_obj, $a_hier_id)
 Create Question Element.
 copyPoolQuestionIntoPage ($a_q_id, $a_hier_id)
 Copy question from pool into page.
 _getPageForQuestionId ($a_q_id, $a_parent_type="")
 Get page for question id.
 modifyPageContentPostXsl ($a_output, $a_mode)
 Modify page content after xsl.
 getJavascriptFiles ($a_mode)
 Get Javascript files.
 getCssFiles ($a_mode)
 Get css files.
 getOnloadCode ($a_mode)
 Get on load code.
 getQuestionJsOfPage ($a_no_interaction, $a_mode)
 Get question js.
- Public Member Functions inherited from ilPageContent
 __construct ($a_pg_obj)
 Constructor.
 setPage ($a_val)
 Set page.
 getPage ()
 Get page.
 getType ()
 Get type of page content.
getNode ()
 Get xml node of page content.
 getJavascriptFiles ()
 Get Javascript files.
 getCssFiles ()
 Get css files.
 getOnloadCode ()
 Get on load code.
 setHierId ($a_hier_id)
 Set hierarchical ID in xml structure.
 getHierId ()
 Get hierarchical id.
 lookupHierId ()
 Get hierarchical id from dom.
 readHierId ()
 Read PC Id.
 setPcId ($a_pcid)
 Set PC Id.
 getPCId ()
 Get PC Id.
 readPCId ()
 Read PC Id.
 writePCId ($a_pc_id)
 Write pc id.
 isGreaterHierId ($a, $b)
 Check whether Hier ID $a is greater than Hier ID $b.
 setEnabled ($value)
 Set Enabled value for page content component.
 enable ()
 Enable page content.
 disable ()
 Disable page content.
 isEnabled ()
 Check whether page content is enabled.
 createPageContentNode ($a_set_this_node=true)
 Create page content node (always use this method first when adding a new element)

Static Public Member Functions

static getLangVars ()
 Get lang vars needed for editing.
static afterPageUpdate ($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
 After page has been updated (or created)
static beforePageDelete ($a_page)
 Before page is being deleted.
static _getQuestionIdsForPage ($a_parent_type, $a_page_id, $a_lang="-")
 Get all questions of a page.
static resetInitialState ()
 Reset initial state (for exports)
static getJSTextInitCode ($a_lang)
 Get js txt init code.
- Static Public Member Functions inherited from ilPageContent
static incEdId ($ed_id)
 Increases an hierarchical editing id at lowest level (last number)
static decEdId ($ed_id)
 Decreases an hierarchical editing id at lowest level (last number)
static haveSameContainer ($ed_id1, $ed_id2)
 Check, if two ids are in same container.
static sortHierIds ($a_array)
 Sort an array of Hier IDS in ascending order.
static handleCopiedContent (DOMDocument $a_domdoc, $a_self_ass=true, $a_clone_mobs=false)
 Handle copied content.
static afterPageHistoryEntry ($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
 After page history entry has been created.

Data Fields

 $dom
 $q_node
- Data Fields inherited from ilPageContent
 $hier_id
 $node
 $dom

Static Protected Attributes

static $initial_done

Additional Inherited Members

- Protected Member Functions inherited from ilPageContent
 setType ($a_type)
 Set Type.

Detailed Description

Class ilPCQuestion.

Assessment Question of ilPageObject

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id:
class.ilPCQuestion.php 60875 2015-09-25 12:11:15Z gitmgr

Definition at line 18 of file class.ilPCQuestion.php.

Member Function Documentation

ilPCQuestion::_getPageForQuestionId (   $a_q_id,
  $a_parent_type = "" 
)

Get page for question id.

Parameters
@returnarray

Definition at line 237 of file class.ilPCQuestion.php.

References $ilDB.

Referenced by ilObjMediaObject\getParentObjectIdForUsage().

{
global $ilDB;
$set = $ilDB->query("SELECT * FROM page_question ".
" WHERE question_id = ".$ilDB->quote($a_q_id, "integer")
);
while ($rec = $ilDB->fetchAssoc($set))
{
if ($a_parent_type == "" || $rec["page_parent_type"] == $a_parent_type)
{
return array("page_id" => $rec["page_id"], "parent_type" => $rec["page_parent_type"]);
}
}
return false;
}

+ Here is the caller graph for this function:

static ilPCQuestion::_getQuestionIdsForPage (   $a_parent_type,
  $a_page_id,
  $a_lang = "-" 
)
static

Get all questions of a page.

Definition at line 214 of file class.ilPCQuestion.php.

References $ilDB, and $res.

Referenced by ilSCORM2004Asset\exportHTMLPageObjects(), ilObjContentObject\exportHTMLPages(), ilSCORM2004Asset\exportPDFPrepareXmlNFiles(), ilSCORM2004Asset\exportXMLPageObjects(), ilObjectivesAlignmentTableGUI\fillRow(), ilLMPageObject\getQuestionIds(), and ilSCORM2004ScoGUI\sahs_questions().

{
global $ilDB;
$res = $ilDB->queryF("SELECT * FROM page_question WHERE page_parent_type = %s ".
" AND page_id = %s AND page_lang = %s",
array("text", "integer", "text"),
array($a_parent_type, $a_page_id, $a_lang));
$q_ids = array();
while ($rec = $ilDB->fetchAssoc($res))
{
$q_ids[] = $rec["question_id"];
}
return $q_ids;
}

+ Here is the caller graph for this function:

static ilPCQuestion::afterPageUpdate (   $a_page,
DOMDocument  $a_domdoc,
  $a_xml,
  $a_creation 
)
static

After page has been updated (or created)

Parameters
objectpage object
DOMDocument$a_domdocdom document
stringxml
booltrue on creation, otherwise false

Reimplemented from ilPageContent.

Definition at line 160 of file class.ilPCQuestion.php.

References $ilDB, ilPageContent\$node, ilInternalLink\_extractInstOfTarget(), and ilInternalLink\_extractObjIdOfTarget().

{
global $ilDB;
include_once("./Services/Link/classes/class.ilInternalLink.php");
$ilDB->manipulateF("DELETE FROM page_question WHERE page_parent_type = %s ".
" AND page_id = %s AND page_lang = %s", array("text", "integer", "text"),
array($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage()));
$xpath = new DOMXPath($a_domdoc);
$nodes = $xpath->query('//Question');
$q_ids = array();
foreach ($nodes as $node)
{
$q_ref = $node->getAttribute("QRef");
if (!($inst_id > 0))
{
if ($q_id > 0)
{
$q_ids[$q_id] = $q_id;
}
}
}
foreach($q_ids as $qid)
{
$ilDB->manipulateF("INSERT INTO page_question (page_parent_type, page_id, page_lang, question_id)".
" VALUES (%s,%s,%s,%s)",
array("text", "integer", "text", "integer"),
array($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage(), $qid));
}
}

+ Here is the call graph for this function:

static ilPCQuestion::beforePageDelete (   $a_page)
static

Before page is being deleted.

Parameters
objectpage object

Reimplemented from ilPageContent.

Definition at line 202 of file class.ilPCQuestion.php.

References $ilDB.

{
global $ilDB;
$ilDB->manipulateF("DELETE FROM page_question WHERE page_parent_type = %s ".
" AND page_id = %s AND page_lang = %s", array("text", "integer", "text"),
array($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage()));
}
ilPCQuestion::copyPoolQuestionIntoPage (   $a_q_id,
  $a_hier_id 
)

Copy question from pool into page.

Parameters
@return

Definition at line 87 of file class.ilPCQuestion.php.

References $t, assQuestion\_instanciateQuestion(), assQuestionGUI\getSelfAssessmentTags(), and ilUtil\secureString().

{
include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
$question = assQuestion::_instanciateQuestion($a_q_id);
$duplicate_id = $question->copyObject(0, $question->getTitle());
$duplicate = assQuestion::_instanciateQuestion($duplicate_id);
$duplicate->setObjId(0);
// we remove everything not supported by the non-tiny self
// assessment question editor
$q = $duplicate->getQuestion();
// we try to save all latex tags
$try = true;
$ls = '<span class="latex">';
$le = '</span>';
while ($try)
{
// search position of start tag
$pos1 = strpos($q, $ls);
if (is_int($pos1))
{
$pos2 = strpos($q, $le, $pos1);
if (is_int($pos2))
{
// both found: replace end tag
$q = substr($q, 0, $pos2)."[/tex]".substr($q, $pos2+7);
$q = substr($q, 0, $pos1)."[tex]".substr($q, $pos1+20);
}
else
{
$try = false;
}
}
else
{
$try = false;
}
}
$tstr = "";
foreach ($tags as $t)
{
$tstr.="<".$t.">";
}
$q = ilUtil::secureString($q, true, $tstr);
// self assessment uses nl2br, not p
$duplicate->setQuestion($q);
$duplicate->saveQuestionDataToDb();
$this->q_node->set_attribute("QRef", "il__qst_".$duplicate_id);
}

+ Here is the call graph for this function:

ilPCQuestion::create ( $a_pg_obj,
  $a_hier_id 
)

Create Question Element.

Definition at line 72 of file class.ilPCQuestion.php.

References ilPageContent\createPageContentNode(), and IL_INSERT_AFTER.

{
$a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER);
$this->q_node = $this->dom->create_element("Question");
$this->q_node = $this->node->append_child($this->q_node);
$this->q_node->set_attribute("QRef", "");
}

+ Here is the call graph for this function:

ilPCQuestion::getCssFiles (   $a_mode)

Get css files.

Definition at line 346 of file class.ilPCQuestion.php.

References ilPageContent\getPage().

{
if ($this->getPage()->getPageConfig()->getEnableSelfAssessment())
{
return array("./Modules/Scorm2004/templates/default/question_handling.css",
"Modules/TestQuestionPool/templates/default/test_javascript.css");
}
return array();
}

+ Here is the call graph for this function:

ilPCQuestion::getJavascriptFiles (   $a_mode)

Get Javascript files.

Definition at line 323 of file class.ilPCQuestion.php.

References ilPageContent\getPage(), and IL_PAGE_PREVIEW.

{
$js_files = array();
if ($this->getPage()->getPageConfig()->getEnableSelfAssessment())
{
$js_files[] = "./Modules/Scorm2004/scripts/questions/pure.js";
$js_files[] = "./Modules/Scorm2004/scripts/questions/question_handling.js";
$js_files[] = "Modules/TestQuestionPool/js/ilMatchingQuestion.js";
}
if (!$this->getPage()->getPageConfig()->getEnableSelfAssessmentScorm() && $a_mode != IL_PAGE_PREVIEW
&& $a_mode != "offline")
{
$js_files[] = "./Services/COPage/js/ilCOPageQuestionHandler.js";
}
return $js_files;
}

+ Here is the call graph for this function:

static ilPCQuestion::getJSTextInitCode (   $a_lang)
static

Get js txt init code.

Parameters
@return

Definition at line 406 of file class.ilPCQuestion.php.

References $ilUser, and $lng.

Referenced by ilSCORM2004Asset\exportHTMLPageObjects(), and getOnloadCode().

{
global $lng, $ilUser;
if ($a_lang == "")
{
$a_lang = $ilUser->getLanguage();
}
return
'
ilias.questions.txt.wrong_answers = "'.$lng->txtlng("content", "cont_wrong_answers", $a_lang).'";
ilias.questions.txt.wrong_answers_single = "'.$lng->txtlng("content", "cont_wrong_answers_single", $a_lang).'";
ilias.questions.txt.tries_remaining = "'.$lng->txtlng("content", "cont_tries_remaining", $a_lang).'";
ilias.questions.txt.please_try_again = "'.$lng->txtlng("content", "cont_please_try_again", $a_lang).'";
ilias.questions.txt.all_answers_correct = "'.$lng->txtlng("content", "cont_all_answers_correct", $a_lang).'";
ilias.questions.txt.enough_answers_correct = "'.$lng->txtlng("content", "cont_enough_answers_correct", $a_lang).'";
ilias.questions.txt.nr_of_tries_exceeded = "'.$lng->txtlng("content", "cont_nr_of_tries_exceeded", $a_lang).'";
ilias.questions.txt.correct_answers_shown = "'.$lng->txtlng("content", "cont_correct_answers_shown", $a_lang).'";
ilias.questions.txt.correct_answers_also = "'.$lng->txtlng("content", "cont_correct_answers_also", $a_lang).'";
ilias.questions.txt.correct_answer_also = "'.$lng->txtlng("content", "cont_correct_answer_also", $a_lang).'";
ilias.questions.txt.ov_all_correct = "'.$lng->txtlng("content", "cont_ov_all_correct", $a_lang).'";
ilias.questions.txt.ov_some_correct = "'.$lng->txtlng("content", "cont_ov_some_correct", $a_lang).'";
ilias.questions.txt.ov_wrong_answered = "'.$lng->txtlng("content", "cont_ov_wrong_answered", $a_lang).'";
ilias.questions.txt.please_select = "'.$lng->txtlng("content", "cont_please_select", $a_lang).'";
ilias.questions.refresh_lang();
';
}

+ Here is the caller graph for this function:

static ilPCQuestion::getLangVars ( )
static

Get lang vars needed for editing.

Returns
array array of lang var keys

Reimplemented from ilPageContent.

Definition at line 147 of file class.ilPCQuestion.php.

{
return array("ed_insert_pcqst", "empty_question", "pc_qst");
}
ilPCQuestion::getOnloadCode (   $a_mode)

Get on load code.

Definition at line 359 of file class.ilPCQuestion.php.

References $ilCtrl, $ilUser, ilPageQuestionProcessor\getAnswerStatus(), getJSTextInitCode(), ilPageContent\getPage(), and IL_PAGE_PREVIEW.

{
global $ilCtrl, $ilUser;
$code = array();
if ($this->getPage()->getPageConfig()->getEnableSelfAssessment())
{
if (!$this->getPage()->getPageConfig()->getEnableSelfAssessmentScorm() && $a_mode != IL_PAGE_PREVIEW
&& $a_mode != "offline")
{
$ilCtrl->setParameterByClass(strtolower(get_class($this->getPage()))."gui", "page_id", $this->getPage()->getId());
$url = $ilCtrl->getLinkTargetByClass(strtolower(get_class($this->getPage()))."gui", "processAnswer", "", true, false);
$code[] = "ilCOPageQuestionHandler.initCallback('".$url."');";
}
if ($this->getPage()->getPageConfig()->getDisableDefaultQuestionFeedback())
{
$code[] = "ilias.questions.default_feedback = false;";
}
$code[] = self::getJSTextInitCode($this->getPage()->getPageConfig()->getLocalizationLanguage()).' il.COPagePres.updateQuestionOverviews();';
}
$get_stored_tries = $this->getPage()->getPageConfig()->getUseStoredQuestionTries();
if ($get_stored_tries)
{
$q_ids = $this->getPage()->getQuestionIds();
if (count($q_ids) > 0)
{
foreach ($q_ids as $q_id)
{
include_once("./Services/COPage/classes/class.ilPageQuestionProcessor.php");
$as = ilPageQuestionProcessor::getAnswerStatus($q_id, $ilUser->getId());
$code[] = "ilias.questions.initAnswer(".$q_id.", ".(int) $as["try"].", ".($as["passed"] ? "true" : "null").");";
}
}
}
return $code;
}

+ Here is the call graph for this function:

ilPCQuestion::getQuestionJsOfPage (   $a_no_interaction,
  $a_mode 
)

Get question js.

Definition at line 439 of file class.ilPCQuestion.php.

References ilPageContent\getPage().

Referenced by modifyPageContentPostXsl().

{
require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
$q_ids = $this->getPage()->getQuestionIds();
$js = array();
if (count($q_ids) > 0)
{
foreach ($q_ids as $q_id)
{
$q_exporter = new ilQuestionExporter($a_no_interaction);
$image_path = null;
if ($a_mode == "offline")
{
if ($this->getPage()->getParentType() == "sahs")
{
$image_path = "./objects/";
}
if ($this->getPage()->getParentType() == "lm")
{
$image_path = "./assessment/0/".$q_id."/images/";
}
}
$js[$q_id] = $q_exporter->exportQuestion($q_id, $image_path, $a_mode);
}
}
return $js;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPCQuestion::getQuestionReference ( )

Get Question Reference.

Returns
string Question Reference

Definition at line 60 of file class.ilPCQuestion.php.

{
if (is_object($this->q_node))
{
return $this->q_node->get_attribute("QRef", $a_questionreference);
}
return false;
}
ilPCQuestion::init ( )

Init page content component.

Reimplemented from ilPageContent.

Definition at line 28 of file class.ilPCQuestion.php.

References ilPageContent\setType().

{
$this->setType("pcqst");
}

+ Here is the call graph for this function:

ilPCQuestion::modifyPageContentPostXsl (   $a_output,
  $a_mode 
)

Modify page content after xsl.

Parameters
string$a_output
Returns
string

Reimplemented from ilPageContent.

Definition at line 260 of file class.ilPCQuestion.php.

References $lng, assQuestionGUI\_getQuestionGUI(), ilPageContent\getPage(), and getQuestionJsOfPage().

{
global $lng;
if ($this->getPage()->getPageConfig()->getEnableSelfAssessment())
{
// #14154
$q_ids = $this->getPage()->getQuestionIds();
if(sizeof($q_ids))
{
include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
foreach($q_ids as $q_id)
{
$q_gui = assQuestionGUI::_getQuestionGUI("", $q_id);
// object check due to #16557
if(is_object($q_gui->object) && !$q_gui->object->isComplete())
{
$a_output = str_replace("{{{{{Question;il__qst_".$q_id."}}}}}",
"<i>".$lng->txt("cont_empty_question")."</i>",
$a_output);
}
}
// this exports the questions which is needed below
$qhtml = $this->getQuestionJsOfPage(($a_mode == "edit") ? true : false, $a_mode);
require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
$a_output = "<script>".ilQuestionExporter::questionsJS($q_ids)."</script>".$a_output;
if(!self::$initial_done)
{
$a_output = "<script>var ScormApi=null; var questions = new Array();</script>".$a_output;
self::$initial_done = true;
}
}
}
else
{
// set by T&A components
$qhtml = $this->getPage()->getPageConfig()->getQuestionHTML();
}
if (is_array($qhtml))
{
foreach ($qhtml as $k => $h)
{
$a_output = str_replace("{{{{{Question;il__qst_$k"."}}}}}", " ".$h, $a_output);
}
}
return $a_output;
}

+ Here is the call graph for this function:

static ilPCQuestion::resetInitialState ( )
static

Reset initial state (for exports)

Definition at line 315 of file class.ilPCQuestion.php.

Referenced by ilObjContentObject\exportPageHTML().

{
self::$initial_done = false;
}

+ Here is the caller graph for this function:

ilPCQuestion::setNode ( $a_node)

Set node.

Reimplemented from ilPageContent.

Definition at line 36 of file class.ilPCQuestion.php.

{
parent::setNode($a_node); // this is the PageContent node
$this->q_node =& $a_node->first_child(); //... and this the Question
}
ilPCQuestion::setQuestionReference (   $a_questionreference)

Set Question Reference.

Parameters
string$a_questionreferenceQuestion Reference

Definition at line 47 of file class.ilPCQuestion.php.

{
if (is_object($this->q_node))
{
$this->q_node->set_attribute("QRef", $a_questionreference);
}
}

Field Documentation

ilPCQuestion::$dom

Definition at line 20 of file class.ilPCQuestion.php.

ilPCQuestion::$initial_done
staticprotected

Definition at line 23 of file class.ilPCQuestion.php.

ilPCQuestion::$q_node

Definition at line 21 of file class.ilPCQuestion.php.


The documentation for this class was generated from the following file: