Beispiel #1
0
		private static QuizAnswerInfo GetOrderingBlockAnswerInfo(IReadOnlyDictionary<string, List<UserQuiz>> answers, OrderingBlock block, int questionIndex)
		{
			IEnumerable<UserQuiz> userAnswers = new List<UserQuiz>();
			UserQuiz firstAnswer = null;
			if (answers.ContainsKey(block.Id))
			{
				userAnswers = answers[block.Id].Where(q => q.ItemId != null);
				firstAnswer = userAnswers.FirstOrDefault();
			}

			var answersPositions = userAnswers.Select(
				userAnswer => block.Items.FindIndex(i => i.GetHash() == userAnswer.ItemId)
			).ToList();

			return new OrderingBlockAnswerInfo
			{
				Id = questionIndex.ToString(),
				AnswersPositions = answersPositions,
				Score = firstAnswer?.QuizBlockScore ?? 0,
				MaxScore = firstAnswer?.QuizBlockMaxScore ?? 0,
			};
		}
public static System.Web.WebPages.HelperResult QuizBlock(OrderingBlock block, BlockRenderContext context)
{
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {


 
	var items = block.ShuffledItems();
	var correctItems = block.Items;
	QuizBlockData model = context.GetBlockData(block) ?? new QuizBlockData(new QuizModel(), 1, QuizState.NotPassed);
	if (model.QuizState != QuizState.NotPassed && model.QuizModel.AnswersToQuizes[block.Id].FirstOrDefault() != null)
	{
		var userAnswers = model.QuizModel.AnswersToQuizes[block.Id].Select(x => x.ItemId).ToList();
		items = items.OrderBy(item => userAnswers.IndexOf(item.GetHash())).ToArray();
	}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t<div class=\"quiz-block-ordering ");


WebViewPage.WriteTo(@__razor_helper_writer, context.CanUserFillQuiz ? "" : "not-movable");

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" id=\'");


                                            WebViewPage.WriteTo(@__razor_helper_writer, block.Id + "_quizBlock");

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\'>\r\n");


 		if (model.QuizState == QuizState.Total && model.ShowCorrectAnswer)
		{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t<div class=\"quiz-block-ordering__correct-description row\">\r\n\t\t\t\t<div class=\"te" +
"xt-success col-sm-5 col-sm-offset-6\">Правильный ответ</div>\r\n\t\t\t</div>\r\n");


		}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t<ul>\r\n");


 			for (var itemIndex = 0; itemIndex < items.Length; itemIndex++)
			{
				var item = items[itemIndex];

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t<li class=\"row\">\r\n\t\t\t\t\t<div class=\"quiz quiz-block-ordering__item col-xs-12 c" +
"ol-sm-5\" data-item-id=\"");


                                       WebViewPage.WriteTo(@__razor_helper_writer, item.GetHash());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n");


 						if (context.CanUserFillQuiz)
						{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t\t<div class=\"quiz-block-ordering__item__icons\">\r\n\t\t\t\t\t\t\t\t<span class=\"glyph" +
"icon glyphicon-arrow-up\"></span>\r\n\t\t\t\t\t\t\t\t<span class=\"glyphicon glyphicon-arrow" +
"-down\"></span>\r\n\t\t\t\t\t\t\t</div>\r\n");


						}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t<input autocomplete=\"off\" id=\'");


WebViewPage.WriteTo(@__razor_helper_writer, block.Id + "quizBlock" + item.GetHash());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\' type=\"hidden\">\r\n\t\t\t\t\t\t<div class=\"text\">");


WebViewPage.WriteTo(@__razor_helper_writer, item.Text.RenderTex());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n\t\t\t\t\t</div>\r\n");


 					if (model.QuizState == QuizState.Total && model.ShowCorrectAnswer)
					{
						var correctItem = correctItems[itemIndex];

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t<div class=\"quiz-block-ordering__item correct col-xs-12 col-sm-offset-1 col" +
"-sm-5\">\r\n\t\t\t\t\t\t\t");


WebViewPage.WriteTo(@__razor_helper_writer, correctItem.Text.RenderTex());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n\t\t\t\t\t\t</div>\r\n");


					}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t</li>\r\n");


			}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t</ul>\r\n\t</div>\r\n");


	if (model.QuizState == QuizState.Total && !string.IsNullOrEmpty(block.Explanation))
	{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t<div class=\"text-muted\">");


WebViewPage.WriteTo(@__razor_helper_writer, block.Explanation);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n");


	}

});

}
Beispiel #3
0
		private IEnumerable<QuizInfoForDb> CreateQuizInfoForDb(OrderingBlock orderingBlock, IGrouping<string, QuizAnswer> answers)
		{
			var ans = answers.Select(x => x.ItemId).ToList()
				.Select(x => new QuizInfoForDb
				{
					QuizId = orderingBlock.Id,
					IsRightAnswer = true,
					ItemId = x,
					Text = null,
					QuizType = typeof(OrderingBlock),
					QuizBlockScore = 0,
					QuizBlockMaxScore = orderingBlock.MaxScore
				}).ToList();

			var isRightQuizBlock = answers.Count() == orderingBlock.Items.Length &&
				answers.Zip(orderingBlock.Items, (answer, item) => answer.ItemId == item.GetHash()).All(x => x);
			var blockScore = isRightQuizBlock ? orderingBlock.MaxScore : 0;
			foreach (var info in ans)
				info.QuizBlockScore = blockScore;

			return ans;
		}