Change saved quiz filename to quiz-now().jpg see #1771

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent cf59aa819d
commit 6dc440ad77
  1. 6
      main/exercise/hotspot.class.php
  2. 10
      main/exercise/hotspot_actionscript.as.php
  3. 7
      main/exercise/hotspot_actionscript_admin.as.php
  4. 5
      main/exercise/hotspot_admin.inc.php
  5. 15
      main/exercise/hotspot_answers.as.php
  6. 99
      main/exercise/question.class.php
  7. 18
      main/inc/lib/exercise.lib.php

@ -86,11 +86,11 @@ class HotSpot extends Question
if (!empty($file_info['tmp_name'])) {
$this->uploadPicture($file_info['tmp_name'], $file_info['name']);
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
// fixed width ang height
if (file_exists($picturePath.'/'.$this->picture)) {
if (file_exists($picturePath.'/'.$this->getPictureFilename())) {
$this->resizePicture('width', 800);
$this->save();
} else {

@ -23,8 +23,8 @@ $answer_type = $objQuestion->selectType(); //very important
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
$pictureName = $objQuestion->selectPicture();
$pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
$pictureName = $objQuestion->getPictureFilename();
$pictureSize = getimagesize($picturePath.'/'.$pictureName);
$pictureWidth = $pictureSize[0];
$pictureHeight = $pictureSize[1];
$course_id = api_get_course_int_id();
@ -35,14 +35,14 @@ if ($answer_type == HOT_SPOT_DELINEATION) {
FROM $TBL_ANSWERS
WHERE
c_id = $course_id AND
question_id = ".$questionId." AND
question_id = $questionId AND
hotspot_type = 'delineation'
ORDER BY iid";
} else {
$sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation
FROM $TBL_ANSWERS
WHERE c_id = $course_id AND question_id = ".$questionId."
ORDER BY iid";
WHERE c_id = $course_id AND question_id = $questionId
ORDER BY position";
}
$result = Database::query($sql);

@ -21,12 +21,11 @@ if (!$isAllowedToEdit) {
$questionId = intval($_GET['modifyAnswers']);
$objQuestion = Question::read($questionId);
$_course = api_get_course_info();
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
$pictureName = $objQuestion->selectPicture();
$pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
$pictureName = $objQuestion->getPictureFilename();
$pictureSize = getimagesize($picturePath.'/'.$pictureName);
$pictureWidth = $pictureSize[0];
$pictureHeight = $pictureSize[1];

@ -18,7 +18,8 @@ if (!is_object($objQuestion)) {
$questionName = $objQuestion->selectTitle();
$answerType = $objQuestion->selectType();
$pictureName = $objQuestion->selectPicture();
$pictureName = $objQuestion->getPictureFilename();
$debug = 0; // debug variable to get where we are
$okPicture = empty($pictureName) ? false : true;
@ -636,7 +637,7 @@ if ($modifyAnswers) {
$isSelected = false;
foreach ($flat_list as $id => $details) {
$selected = '';
if ($id == $lp[$i]) {
if (isset($lp[$i]) && $id == $lp[$i]) {
$isSelected = true;
$selected = 'selected="selected"';
}

@ -23,8 +23,8 @@ $objExercise->read($trackExerciseInfo['exe_exo_id']);
$em = Database::getManager();
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath . '/images';
$pictureName = $objQuestion->selectPicture();
$pictureSize = getimagesize($picturePath . '/' . $objQuestion->selectPicture());
$pictureName = $objQuestion->getPictureFilename();
$pictureSize = getimagesize($picturePath . '/' . $pictureName);
$pictureWidth = $pictureSize[0];
$pictureHeight = $pictureSize[1];
$course_id = api_get_course_int_id();
@ -103,17 +103,16 @@ if (!$hideExpectedAnswer) {
$qb
->where($qb->expr()->eq('a.cId', $course_id))
->andWhere($qb->expr()->eq('a.questionId', intval($questionId)))
->andWhere($qb->expr()->neq('a.hotspotType', 'noerror'));
->andWhere($qb->expr()->neq('a.hotspotType', 'noerror'))
->orderBy('a.id', 'ASC');
} else {
$qb
->where($qb->expr()->eq('a.cId', $course_id))
->andWhere($qb->expr()->eq('a.questionId', intval($questionId)));
->andWhere($qb->expr()->eq('a.questionId', intval($questionId)))
->orderBy('a.position', 'ASC');
}
$result = $qb
->orderBy('a.id', 'ASC')
->getQuery()
->getResult();
$result = $qb->getQuery()->getResult();
/** @var CQuizAnswer $hotSpotAnswer */
foreach ($result as $hotSpotAnswer) {

@ -261,17 +261,74 @@ abstract class Question
}
/**
* @return string|false
* @return string
*/
public function selectPicturePath()
{
if (!empty($this->picture)) {
return api_get_path(WEB_COURSE_PATH) . $this->course['path'] . '/document/images/' . $this->picture;
return api_get_path(WEB_COURSE_PATH).$this->course['path'].'/document/images/'.$this->getPictureFilename();
}
return '';
}
/**
* @return int|string
*/
public function getPictureId()
{
// for backward compatibility
// when in field picture we had the filename not the document id
if (preg_match("/quiz-.*/", $this->picture)) {
return DocumentManager::get_document_id(
$this->course,
$this->selectPicturePath(),
api_get_session_id()
);
}
return $this->picture;
}
/**
* @param int $courseId
* @param int $sessionId
* @return string
*/
public function getPictureFilename($courseId = 0, $sessionId = 0)
{
$courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId;
$sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId;
if (empty($courseId)) {
return '';
}
// for backward compatibility
// when in field picture we had the filename not the document id
if (preg_match("/quiz-.*/", $this->picture)) {
return $this->picture;
}
$pictureId = $this->getPictureId();
$courseInfo = $this->course;
$documentInfo = DocumentManager::get_document_data_by_id(
$pictureId,
$courseInfo['code'],
false,
$sessionId
);
$documentFilename = '';
if ($documentInfo) {
// document in document/images folder
$documentFilename = pathinfo(
$documentInfo['path'],
PATHINFO_BASENAME
);
}
return $documentFilename;
}
/**
* returns the array with the exercise ID list
*
@ -539,10 +596,16 @@ abstract class Question
if (!file_exists($picturePath)) {
if (mkdir($picturePath, api_get_permissions_for_new_directories())) {
// document path
$documentPath = api_get_path(SYS_COURSE_PATH) . $this->course['path'] . "/document";
$documentPath = api_get_path(SYS_COURSE_PATH).$this->course['path'].'/document';
$path = str_replace($documentPath, '', $picturePath);
$title_path = basename($picturePath);
$doc_id = add_document($this->course, $path, 'folder', 0, $title_path);
$doc_id = add_document(
$this->course,
$path,
'folder',
0,
$title_path
);
api_item_property_update(
$this->course,
TOOL_DOCUMENT,
@ -555,16 +618,18 @@ abstract class Question
// if the question has got an ID
if ($this->id) {
$this->picture = 'quiz-' . $this->id . '.jpg';
$o_img = new Image($Picture);
$o_img->send_image($picturePath . '/' . $this->picture, -1, 'jpg');
$pictureFilename = self::generatePictureName();
$img = new Image($Picture);
$img->send_image($picturePath.'/'.$pictureFilename, -1, 'jpg');
$document_id = add_document(
$this->course,
'/images/' . $this->picture,
'/images/'.$pictureFilename,
'file',
filesize($picturePath . '/' . $this->picture),
$this->picture
filesize($picturePath.'/'.$pictureFilename),
$pictureFilename
);
$this->picture = $document_id;
if ($document_id) {
return api_item_property_update(
$this->course,
@ -579,6 +644,20 @@ abstract class Question
return false;
}
/**
* return the name for image use in hotspot question
* to be unique, name is quiz-[utc unix timestamp].jpg
* @param string $prefix
* @param string $extension
* @return string
*/
public function generatePictureName($prefix = 'quiz-', $extension = 'jpg')
{
// image name is quiz-xxx.jpg in folder images/
$utcTime = time();
return $prefix.$utcTime.'.'.$extension;
}
/**
* Resizes a picture || Warning!: can only be called after uploadPicture,
* or if picture is already available in object.

@ -56,7 +56,7 @@ class ExerciseLib
}
$answerType = $objQuestionTmp->selectType();
$pictureName = $objQuestionTmp->selectPicture();
$pictureName = $objQuestionTmp->getPictureFilename();
$s = '';
if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION && $answerType != ANNOTATION) {
@ -1130,10 +1130,7 @@ HTML;
// Question is a HOT_SPOT
//checking document/images visibility
if (api_is_platform_admin() || api_is_course_admin()) {
$doc_id = DocumentManager::get_document_id(
$course,
'/images/' . $pictureName
);
$doc_id = $objQuestionTmp->getPictureId();
if (is_numeric($doc_id)) {
$images_folder_visibility = api_get_item_visibility(
$course,
@ -1186,6 +1183,7 @@ HTML;
}
$answerList = '';
$hotspotColor = 0;
if ($answerType != HOT_SPOT_DELINEATION) {
$answerList = '
<div class="well well-sm">
@ -1197,8 +1195,14 @@ HTML;
Session::write("hotspot_ordered$questionId", array_keys($answers_hotspot));
$countAnswers = 1;
foreach ($answers_hotspot as $value) {
$answerList .= "<li><p>{$countAnswers} - {$value}</p></li>";
$countAnswers++;
$answerList .= "<p>";
if ($freeze) {
$answerList .= "&nbsp<span class='hotspot-color hotspot-color-$hotspotColor'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
}
$answerList .= "&nbsp{$countAnswers}.&nbsp;";
$answerList .= $value;
$answerList .= "</p>";
$hotspotColor++;
}
}

Loading…
Cancel
Save