00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 class assQuestionTypeTemplate extends assQuestion
00035 {
00043 var $question;
00044
00058 function assQuestionTypeTemplate(
00059 $title = "",
00060 $comment = "",
00061 $author = "",
00062 $owner = -1,
00063 $question = ""
00064 )
00065 {
00066 $this->assQuestion($title, $comment, $author, $owner);
00067
00068
00069 $this->question = $question;
00070 }
00071
00080 function isComplete()
00081 {
00082
00083
00084
00085
00086 if ((strlen($this->getTitle())) and (strlen($this->getAuthor())) and (strlen($this->getQuestion())) and ($this->getMaximumPoints() > 0))
00087 {
00088 return TRUE;
00089 }
00090 else
00091 {
00092 return FALSE;
00093 }
00094 }
00095
00109 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
00110 {
00111
00112 }
00113
00123 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
00124 {
00125
00126 }
00127
00136 function saveToDb($original_id = "")
00137 {
00138
00139
00140
00141
00142 global $ilDB;
00143
00144 $complete = 0;
00145 if ($this->isComplete())
00146 {
00147 $complete = 1;
00148 }
00149
00150 $estw_time = $this->getEstimatedWorkingTime();
00151 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00152
00153 if ($original_id)
00154 {
00155 $original_id = $ilDB->quote($original_id);
00156 }
00157 else
00158 {
00159 $original_id = "NULL";
00160 }
00161
00162 if ($this->getId() == -1)
00163 {
00164
00165 $now = getdate();
00166 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00167 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, points, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00168 $ilDB->quote("1"),
00169 $ilDB->quote($this->obj_id),
00170 $ilDB->quote($this->title),
00171 $ilDB->quote($this->comment),
00172 $ilDB->quote($this->author),
00173 $ilDB->quote($this->owner),
00174 $ilDB->quote($this->question),
00175 $ilDB->quote($this->getMaximumPoints() . ""),
00176 $ilDB->quote($estw_time),
00177 $ilDB->quote("$complete"),
00178 $ilDB->quote($created),
00179 $original_id
00180 );
00181 $result = $ilDB->query($query);
00182
00183 if ($result == DB_OK)
00184 {
00185
00186
00187
00188
00189 $this->setId($ilDB->getLastInsertId());
00190 $query = sprintf("INSERT INTO qpl_question_mytype (question_fi, myattribute) VALUES (%s, %s)",
00191 $ilDB->quote($this->getId() . ""),
00192 $ilDB->quote($this->getMyAttribute())
00193 );
00194 $ilDB->query($query);
00195
00196
00197 $this->createPageObject();
00198
00199
00200 if ($this->getTestId() > 0)
00201 {
00202 $this->insertIntoTest($this->getTestId());
00203 }
00204 }
00205 }
00206 else
00207 {
00208
00209 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
00210 $ilDB->quote($this->obj_id. ""),
00211 $ilDB->quote($this->title),
00212 $ilDB->quote($this->comment),
00213 $ilDB->quote($this->author),
00214 $ilDB->quote($this->question),
00215 $ilDB->quote($this->getMaximumPoints() . ""),
00216 $ilDB->quote($estw_time),
00217 $ilDB->quote("$complete"),
00218 $ilDB->quote($this->getId())
00219 );
00220 $result = $ilDB->query($query);
00221
00222
00223
00224
00225 $query = sprintf("UPDATE qpl_question_mytype SET myattribute = %s WHERE question_fi = %s",
00226 $ilDB->quote($this->getMyAttribute()),
00227 $ilDB->quote($this->getId() . "")
00228 );
00229 $result = $ilDB->query($query);
00230 }
00231
00232
00233
00234 parent::saveToDb($original_id);
00235 }
00236
00245 function loadFromDb($question_id)
00246 {
00247
00248
00249
00250
00251 global $ilDB;
00252
00253 $hasimages = 0;
00254 $query = sprintf("SELECT qpl_questions.*, qpl_question_mytype.* FROM qpl_questions, qpl_question_mytype WHERE question_id = %s AND qpl_questions.question_id = qpl_question_mytype.question_fi",
00255 $ilDB->quote($question_id)
00256 );
00257 $result = $ilDB->query($query);
00258 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00259 {
00260 if ($result->numRows() == 1)
00261 {
00262 $data = $result->fetchRow(DB_FETCHMODE_ASSOC);
00263 $this->setId($question_id);
00264 $this->setTitle($data["title"]);
00265 $this->setComment($data["comment"]);
00266
00267 }
00268 }
00269
00270
00271 parent::loadFromDb($question_id);
00272 }
00273
00281 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00282 {
00283 if ($this->id <= 0)
00284 {
00285
00286 return;
00287 }
00288
00289 $clone = $this;
00290 include_once ("./assessment/classes/class.assQuestion.php");
00291 $original_id = assQuestion::_getOriginalId($this->id);
00292 $clone->id = -1;
00293 if ($title)
00294 {
00295 $clone->setTitle($title);
00296 }
00297
00298 if ($author)
00299 {
00300 $clone->setAuthor($author);
00301 }
00302 if ($owner)
00303 {
00304 $clone->setOwner($owner);
00305 }
00306
00307 if ($for_test)
00308 {
00309 $clone->saveToDb($original_id);
00310 }
00311 else
00312 {
00313 $clone->saveToDb();
00314 }
00315
00316
00317 $clone->copyPageOfQuestion($original_id);
00318
00319
00320
00321
00322 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00323
00324 $clone->duplicateImages($original_id);
00325
00326 return $clone->id;
00327 }
00328
00338 function copyObject($target_questionpool, $title = "")
00339 {
00340 if ($this->getId() <= 0)
00341 {
00342
00343 return;
00344 }
00345
00346 $clone = $this;
00347 include_once ("./assessment/classes/class.assQuestion.php");
00348 $original_id = assQuestion::_getOriginalId($this->id);
00349 $clone->id = -1;
00350 $source_questionpool = $this->getObjId();
00351 $clone->setObjId($target_questionpool);
00352 if ($title)
00353 {
00354 $clone->setTitle($title);
00355 }
00356 $clone->saveToDb();
00357
00358
00359 $clone->copyPageOfQuestion($original_id);
00360
00361
00362
00363
00364 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00365
00366 $clone->copyImages($original_id, $source_questionpool);
00367
00368 return $clone->id;
00369 }
00370
00380 function getQuestion()
00381 {
00382
00383
00384 return $this->question;
00385 }
00386
00396 function setQuestion($question = "")
00397 {
00398
00399
00400 $this->question = $question;
00401 }
00402
00411 function getMaximumPoints()
00412 {
00413
00414
00415
00416
00417 $points = 3;
00418 return $points;
00419 }
00420
00432 function calculateReachedPoints($active_id, $pass = NULL)
00433 {
00434
00435
00436
00437
00438
00439
00440 global $ilDB;
00441
00442 $found_values = array();
00443 if (is_null($pass))
00444 {
00445 $pass = $this->getSolutionMaxPass($active_id);
00446 }
00447 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00448 $ilDB->quote($active_id . ""),
00449 $ilDB->quote($this->getId() . ""),
00450 $ilDB->quote($pass . "")
00451 );
00452 $result = $ilDB->query($query);
00453
00454
00455
00456 $points = .... some calculations
00457
00458
00459
00460 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
00461 return $points;
00462 }
00463
00473 function saveWorkingData($active_id, $pass = NULL)
00474 {
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486 global $ilDB;
00487 global $ilUser;
00488
00489 include_once "./assessment/classes/class.ilObjTest.php";
00490 $activepass = ilObjTest::_getPass($active_id);
00491 $entered_values = 0;
00492
00493 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00494 $ilDB->quote($active_id . ""),
00495 $ilDB->quote($this->getId() . ""),
00496 $ilDB->quote($activepass . "")
00497 );
00498 $result = $ilDB->query($query);
00499 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00500 $update = $row->solution_id;
00501 if ($update)
00502 {
00503
00504 }
00505 else
00506 {
00507
00508
00509 }
00510
00511
00512
00513
00514
00515 parent::saveWorkingData($active_id, $pass);
00516
00517 return TRUE;
00518 }
00519
00527 function syncWithOriginal()
00528 {
00529
00530
00531
00532
00533
00534 global $ilDB;
00535
00536 if ($this->original_id)
00537 {
00538 $complete = 0;
00539 if ($this->isComplete())
00540 {
00541 $complete = 1;
00542 }
00543 $estw_time = $this->getEstimatedWorkingTime();
00544 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00545
00546 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
00547 $ilDB->quote($this->obj_id. ""),
00548 $ilDB->quote($this->title. ""),
00549 $ilDB->quote($this->comment. ""),
00550 $ilDB->quote($this->author. ""),
00551 $ilDB->quote($this->question. ""),
00552 $ilDB->quote($this->getMaximumPoints() . ""),
00553 $ilDB->quote($estw_time. ""),
00554 $ilDB->quote($complete. ""),
00555 $ilDB->quote($this->original_id. "")
00556 );
00557 $result = $ilDB->query($query);
00558
00559
00560 $query = sprintf("UPDATE qpl_question_mytype SET myattribute = %s WHERE question_fi = %s",
00561 $ilDB->quote($this->getMyAttribute()),
00562 $ilDB->quote($this->original_id . "")
00563 );
00564 $result = $ilDB->query($query);
00565
00566
00567 parent::syncWithOriginal();
00568 }
00569 }
00570
00580 function getQuestionType()
00581 {
00582 $question_type = 13;
00583 return $question_type;
00584 }
00585
00594 function getAdditionalTableName()
00595 {
00596 return "qpl_question_mytype";
00597 }
00598
00607 function getAnswerTableName()
00608 {
00609 return "qpl_answer_mytype";
00610 }
00611
00612 }
00613
00614 ?>