示例#1
0
shared_ptr<PsiScale> CTestManager::LoadPsiScale(const CString& file_path)
{
	CXml xml;
	if (!xml.Load(file_path))
		return shared_ptr<PsiScale>();

	auto scale = shared_ptr<PsiScale>(new PsiScale);

	scale->SetId(xml.GetIntegerAttrib(XML_ID));
	scale->SetName(xml.GetAttrib(XML_NAME));
	scale->SetDescription(xml.GetAttrib(XML_DESCRIPTION));

	auto prologue_element = xml.GetElement(XML_PROLOGUE);
	if (prologue_element == nullptr)
		return shared_ptr<PsiScale>();

	scale->SetPrologue(prologue_element->GetAttrib(XML_TEXT));

	auto groups_element = xml.GetElement(XML_GROUPS);
	if (groups_element == nullptr)
		return shared_ptr<PsiScale>();

	auto& group_items = groups_element->GetChildElements();
	for (auto item : group_items)
	{
		PsiScaleGroup group;
		group.id = item->GetIntegerAttrib(XML_ID);
		group.description = item->GetAttrib(XML_DESCRIPTION);
		scale->AddGroup(group);
	}

	bool same_choices = xml.GetBoolAttrib(XML_SAME_CHOICES);
	if (same_choices)
	{
		auto choices_element = xml.GetElement(XML_CHOICES);
		if (choices_element == nullptr)
			return shared_ptr<PsiScale>();

		for (auto item : choices_element->GetChildElements())
		{
			QuestionChoice choice;
			choice.id = item->GetIntegerAttrib(XML_ID);
			choice.text = item->GetAttrib(XML_TEXT);
			scale->Choices().push_back(choice);
		}
	}

	auto questions_element = xml.GetElement(XML_QUESTIONS);
	if (questions_element == nullptr)
		return shared_ptr<PsiScale>();

	auto& question_items = questions_element->GetChildElements();
	for (auto item : question_items)
	{
		PsiScaleQuestion question(item->GetIntegerAttrib(XML_ID), 
			item->GetAttrib(XML_TEXT), 
			item->GetBoolAttrib(XML_REVERSE_SCORE),
			item->GetIntegerAttrib(XML_GROUP_ID));

		scale->AddQuestion(question);
	}

	return scale;
}
示例#2
0
bool CPsiScale::Load(const CString& file_path)
{
	CXml xml;
	if (!xml.Load(file_path))
		return false;

	Reset();

	_id = xml.GetIntegerAttrib(XML_ID);
	_name = xml.GetAttrib(XML_NAME);
	_description = xml.GetAttrib(XML_DESCRIPTION);
	_prologue = xml.GetElementData(XML_PROLOGUE);

	auto groups_element = xml.GetElement(XML_GROUPS);
	if (groups_element == nullptr)
		return false;

	auto& group_items = groups_element->GetChildElements();
	for (auto item : group_items)
	{
		_groups.push_back(item->GetData());
	}

	_same_choice = xml.GetBoolAttrib(XML_SAME_CHOICES);
	if (_same_choice)
	{
		auto choices_element = xml.GetElement(XML_CHOICES);
		if (choices_element == nullptr)
			return false;

		for (auto item : choices_element->GetChildElements())
		{
			CQuestionChoice choice;
			choice.id = item->GetIntegerAttrib(XML_ID);
			choice.text = item->GetData();
			_choices.push_back(choice);
		}
	}

	auto questions_element = xml.GetElement(XML_QUESTIONS);
	if (questions_element == nullptr)
		return false;

	for (auto question_item : questions_element->GetChildElements())
	{
		if (_same_choice)
		{
			CPsiScaleQuestion question(question_item->GetIntegerAttrib(XML_ID),
				question_item->GetData(),
				question_item->GetBoolAttrib(XML_REVERSE_SCORE),
				question_item->GetAttrib(XML_SUB_SCALE));
			_questions.push_back(question);
		}
		else
		{
			CPsiScaleQuestion question(question_item->GetIntegerAttrib(XML_ID),
				question_item->GetElementData(XML_TEXT),
				question_item->GetBoolAttrib(XML_REVERSE_SCORE),
				question_item->GetAttrib(XML_SUB_SCALE));

			auto choices_element = question_item->GetElement(XML_CHOICES);
			if (choices_element == nullptr)
				return false;

			for (auto choice_item : choices_element->GetChildElements())
			{
				CQuestionChoice choice;
				choice.id = choice_item->GetIntegerAttrib(XML_ID);
				choice.text = choice_item->GetData();
				question.Choices().push_back(choice);
			}

			_questions.push_back(question);
		}

	}

	return true;
}