Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions src/_score/score_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,43 @@ class Score_Modules_Wordguess extends Score_Module
{
public function check_answer($log)
{
if (isset($this->questions[$log->item_id])) return 100;
return 0;
// if (isset($this->questions[$log->item_id])) return 100;
if (isset($this->inst->qset->data['options']) && isset($this->inst->qset->data['options']['enableScoring']) )
{
// trace("A LOG IS: " . print_r($log, true));
$questionID = $log->item_id;
$playerAnswer = trim($log->text);

if (isset($this->questions[$questionID]))
{
$correctAnswers = $this->questions[$questionID]->answers;
foreach ($correctAnswers as $answer)
{
// check if the answer and user input match
// should work regardless of capitalization or spaces
if (strcasecmp($playerAnswer, trim($answer['text'])) === 0)
{
// trace("Correct answer for question $questionID: $playerAnswer");
return 100; // return full score
}
}
trace("Incorrect answer for question $questionID: $playerAnswer");
return 0;
}

trace("Question ID $questionID not found.");
return 0;
}
// else the option for scoring is not enabled, give them a 100
return 100;
}

// use the question feedback area to display all guesses for the given word by all students
// hide the option when qset.data.options.showAllOtherAnswersBoolean is false(default)
protected function get_feedback($log, $answers)
{
$all_words = [];
$final_words = [];
if (strlen($log->text)) $all_words[$log->text] = 1;

$where = [
Expand All @@ -35,7 +64,13 @@ protected function get_feedback($log, $answers)
}
}

$final_words = [];
//If options boolean is false it will show no feedback for other recorded responses
if ( isset($this->inst->qset->data['options']) &&
isset($this->inst->qset->data['options']['showAllOtherAnswersBoolean']) &&
$this->inst->qset->data['options']['showAllOtherAnswersBoolean'] === false)
{
return;
}
if ( ! empty($all_words))
{
//second loop - condense words and their counts into single strings
Expand Down
18 changes: 11 additions & 7 deletions src/creator-UI.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ Namespace('Wordguess').CreatorUI = do ->
noParagraph.opacity = 0.6
, 10

showFirstMenu = (paragraphTextarea, resetButton) ->
showFirstMenu = (paragraphTextarea, resetButton, nextButton) ->
paragraphTextarea.style.display = 'block'
resetButton.style.display = 'block'
resetButton.style.display = 'inline-block'
resetButton.style.opacity = 1
nextButton.style.opacity = 1
nextButton.style.display = 'inline-block'

return this

hideFirstMenu = (paragraphTextarea, resetButton) ->
hideFirstMenu = (paragraphTextarea, resetButton, nextButton) ->
paragraphTextarea.style.display = 'none'
resetButton.style.opacity = 0
nextButton.style.opacity = 0
setTimeout ->
resetButton.style.display = 'none'
nextButton.style.display = 'none'
, 300

return this
Expand All @@ -77,17 +81,17 @@ Namespace('Wordguess').CreatorUI = do ->
editable.className = 'edit-areas ease-out-quart'

return this

showWarningText = (warningText) ->
warningText.style.display = 'block'

return this

hideWarningText = (warningText) ->
warningText.style.display = 'none'

return this


animateInSecondMenu = (editRegion, hiddenWords, options) ->
optionsH3 = options.children[0].style
Expand Down Expand Up @@ -197,4 +201,4 @@ Namespace('Wordguess').CreatorUI = do ->
showHiddenWords : showHiddenWords
highlightWords : highlightWords
hideWarningText : hideWarningText
showWarningText : showWarningText
showWarningText : showWarningText
37 changes: 25 additions & 12 deletions src/creator-events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Namespace('Wordguess').CreatorEvents = do ->
nextButton = null
backButton = null
resetButton = null
enableScoringDiv = null
enableScoringInput = null
enableScoringLabel = null
autoHide = null
manHide = null

Expand Down Expand Up @@ -56,6 +59,9 @@ Namespace('Wordguess').CreatorEvents = do ->
numDown = document.getElementById('num-down')
numWordsToSkip = document.getElementById('num-words-to-skip')
nextButton = document.getElementById('next')
enableScoringDiv = document.getElementById('enableScoringDiv')
enableScoringInput = document.getElementById('enableScoringInput')
enableScoringLabel = document.getElementById('enableScoringLabel')
backButton = document.getElementById('back')
resetButton = document.getElementById('reset')
autoHide = document.getElementById('auto-hide')
Expand Down Expand Up @@ -91,7 +97,7 @@ Namespace('Wordguess').CreatorEvents = do ->
.setWordsToSkip(wordsToSkip)

return this

onNextClick = (previousMode) ->


Expand Down Expand Up @@ -123,13 +129,13 @@ Namespace('Wordguess').CreatorEvents = do ->


Wordguess.CreatorUI
.hideFirstMenu(paragraphTextarea, resetButton)
.hideFirstMenu(paragraphTextarea, resetButton, nextButton)
.showSecondMenu(title, backButton, editable)
.hideWarningText(warningText)
.animateInSecondMenu(editRegion.style, hiddenWords.style, options)
.showHiddenWords(hiddenWordsBox)
.highlightWords(numWordsToSkip, paragraphTextarea.value, editable)

# set mode to previous mode
if previousMode is 'manual'
Wordguess.CreatorEvents
Expand Down Expand Up @@ -176,7 +182,7 @@ Namespace('Wordguess').CreatorEvents = do ->
setTimeout ->
document.addEventListener 'click', removeManHideBox
, 1

onAutoHideClick = ->
# if im already on automatic mode, dont do anything
if mode is 'automatic'
Expand All @@ -187,7 +193,7 @@ Namespace('Wordguess').CreatorEvents = do ->

autoHide.classList.add 'selected'
manHide.classList.remove 'selected'

mode = 'automatic'
manuallyHide = off
Wordguess.CreatorLogic
Expand Down Expand Up @@ -235,8 +241,6 @@ Namespace('Wordguess').CreatorEvents = do ->
# or clear the manually selected words on the second.
resetButton.addEventListener 'click', ->
if menu is 1
title.value = ''
paragraphTitle.value = ''
paragraphTextarea.value = ''
editable.innerHTML = ''
hiddenWordsBox.innerHTML = ''
Expand All @@ -248,16 +252,25 @@ Namespace('Wordguess').CreatorEvents = do ->
.setUpManualHiding(paragraph, editable)
.showHiddenWords(hiddenWordsBox)


enableScoringDiv.addEventListener 'click', ->
enableScoringInput.checked = !enableScoringInput.checked
if enableScoringInput.checked
enableScoringDiv.style.backgroundColor = '#004f00' #dark green
enableScoringLabel.textContent = 'Enable Scoring:On'
else
enableScoringDiv.style.backgroundColor = '#2E2E2E' #default grey color
enableScoringLabel.textContent = 'Enable Scoring:Off'

nextButton.addEventListener 'click', ->
previousMode = mode

# default mode is automatic
mode = 'automatic'
onNextClick(previousMode)


return this


setSecondMenuEventListeners = ->
numUp.addEventListener 'click', ->
Wordguess.CreatorLogic
Expand All @@ -281,7 +294,7 @@ Namespace('Wordguess').CreatorEvents = do ->
autoHide.addEventListener 'click', ->
onAutoHideClick()


backButton.addEventListener 'click', ->
if not animating
animating = true
Expand All @@ -292,7 +305,7 @@ Namespace('Wordguess').CreatorEvents = do ->
menu = 1

Wordguess.CreatorUI
.showFirstMenu(paragraphTextarea, resetButton)
.showFirstMenu(paragraphTextarea, resetButton, nextButton)
.hideSecondMenu(title, backButton, editable)
.showWarningText(warningText)
.animateOutSecondMenu(editRegion.style, hiddenWords.style, options)
Expand Down Expand Up @@ -400,4 +413,4 @@ Namespace('Wordguess').CreatorEvents = do ->
onManHideClick : onManHideClick
onAutoHideClick : onAutoHideClick
storeHiddenWords : storeHiddenWords
initializeWordsToSkip : initializeWordsToSkip
initializeWordsToSkip : initializeWordsToSkip
24 changes: 13 additions & 11 deletions src/creator-logic.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ Namespace('Wordguess').CreatorLogic = do ->
questionsAnswers = []
j = 1

# we have to sort the array based on their data index or else will be out of alignment
#TS is SO DUMB cause doing myArray.sort() puts 11 before 2 cause strings >:(
manualSkippingIndices.sort (a, b) -> a - b

if manuallyHide is on
for i in [0..manualSkippingIndices.length - 1]
questionsAnswers.push
Expand All @@ -142,22 +146,18 @@ Namespace('Wordguess').CreatorLogic = do ->

return questionsAnswers

buildSaveData = (titleValue) ->
buildSaveData = (enableScoring) ->

if manuallyHide is on and hiddenWordsIndices.size is 0
saveWarningText = document.getElementById('save-warning-text')
Wordguess.CreatorUI.showWarningText(saveWarningText)
return null


manualSkippingIndices = Array.from(hiddenWordsIndices)

previousWordsToSkip = wordsToSkip

if manuallyHide is on
wordsToSkip = -1


paragraph = cleanParagraph(document.getElementById('paragraph').value)
questionsAnswers = buildQuestionsAnswers(paragraph)

Expand All @@ -166,8 +166,10 @@ Namespace('Wordguess').CreatorLogic = do ->
'questions_answers' : questionsAnswers
'title' : replaceTags(document.getElementById('title').value)
'paragraph' : replaceTags(paragraph.join ' ')
'wordsToSkip' : wordsToSkip
'wordsToSkip' : if manuallyHide is on then -1 else wordsToSkip
'manualSkippingIndices' : manualSkippingIndices
'options':
'enableScoring' : enableScoring
'previousWordsToSkip' : previousWordsToSkip

analyzeParagraph = (paragraph) ->
Expand All @@ -178,7 +180,7 @@ Namespace('Wordguess').CreatorLogic = do ->
# prepares hidden words for automatic hiding
for i in [wordsToSkip..paragraph.length - 1] by (wordsToSkip + 1)
hiddenWords.push paragraph[i]

updateHiddenWords = (paragraph, previousHiddenWords) ->
paragraph = cleanParagraph(paragraph)

Expand All @@ -191,9 +193,9 @@ Namespace('Wordguess').CreatorLogic = do ->
newHiddenWords.push(paragraph[index])
else
hiddenWordsIndices.delete(index)

previousHiddenWords = newHiddenWords

initializeHiddenWords = (manualSkippingIndices, paragraph) ->
hiddenWordsIndices = new Set(manualSkippingIndices)

Expand Down Expand Up @@ -228,4 +230,4 @@ Namespace('Wordguess').CreatorLogic = do ->
resetHiddenWordsIndices : resetHiddenWordsIndices
initializeHiddenWords : initializeHiddenWords
updateHiddenWords : updateHiddenWords
setWordsToSkip : setWordsToSkip
setWordsToSkip : setWordsToSkip
22 changes: 19 additions & 3 deletions src/creator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,25 @@ Namespace('Wordguess').Creator = do ->
.initializeWordsToSkip(wordsToSkip)
Wordguess.CreatorUI
.setInputValues(title, qset.paragraph, wordsToSkip)
# update the toggle buttons based on qset
if qset.options
enableScoringInput = document.getElementById('enableScoringInput')
enableScoringDiv = document.getElementById('enableScoringDiv')
enableScoringLabel = document.getElementById('enableScoringLabel')

if qset?.options?.enableScoring

enableScoringInput.checked = true
enableScoringDiv.style.backgroundColor = '#004f00' # dark green
enableScoringLabel.textContent = 'Enable Scoring:On'
else
enableScoringInput.checked = false
enableScoringDiv.style.backgroundColor = '#2E2E2E' # default grey
enableScoringLabel.textContent = 'Enable Scoring:Off'

Wordguess.CreatorLogic
.initializeHiddenWords(manualSkippingIndices, qset.paragraph)

Wordguess.CreatorEvents
.storeHiddenWords()

Expand All @@ -55,11 +70,12 @@ Namespace('Wordguess').Creator = do ->
.onNextClick(previousMode)

onSaveClicked = (mode = 'save') ->
enableScoringBoolean = document.getElementById('enableScoringInput').checked
titleValue = document.getElementById('title').value
if titleValue then widgetTitle = Wordguess.CreatorLogic.replaceTags(titleValue)
else widgetTitle = 'New Wordguess Widget'

_qset = Wordguess.CreatorLogic.buildSaveData()
_qset = Wordguess.CreatorLogic.buildSaveData(enableScoringBoolean)

if _qset == null then return false

Expand All @@ -71,4 +87,4 @@ Namespace('Wordguess').Creator = do ->
initNewWidget : initNewWidget
initExistingWidget : initExistingWidget
onSaveClicked : onSaveClicked
onSaveComplete : onSaveComplete
onSaveComplete : onSaveComplete
Loading