/*
Copyright (c) 2007 Matt Williams matt@milliams.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License or (at
your option) version 3 or, at the discretion of KDE e.V. (which shall
act as a proxy as in section 14 of the GPLv3), any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "kqtiassessmentsection.h"

#include "kqtiassessmentitemref.h"

KQtiAssessmentSection::KQtiAssessmentSection(const QString& identifier, const QString& title) : 
        mTitle(title)
{
    setIdentifier(identifier);
}

KQtiAssessmentSection::KQtiAssessmentSection(const QDomElement& element)
{
    mTitle = element.attribute("title");
    mIdentifier = element.attribute("identifier");
    
    for(int i=0; i<element.elementsByTagName("assessmentItemRef").size(); i++)
    {
        QDomElement assessmentItemRef = element.elementsByTagName("assessmentItemRef").item(i).toElement();
        KQtiAssessmentItemRef* itemRef = new KQtiAssessmentItemRef(assessmentItemRef);
        addSectionPart(itemRef);
    }
    
    for(int i=0; i<element.elementsByTagName("assessmentSection").size(); i++)
    {
        QDomNode assessmentSection = element.elementsByTagName("assessmentSection").item(i);
        //TODO implement this
    }
}


KQtiAssessmentSection::~KQtiAssessmentSection()
{
}

void KQtiAssessmentSection::addSectionPart(KQtiSectionPart* sectionPart)
{
    mSectionParts.append(sectionPart);
}

QDomElement KQtiAssessmentSection::element() const
{
    QDomDocument doc;
    
    QDomElement assessmentSectionElement = doc.createElement("assessmentSection");
    assessmentSectionElement.setAttribute("identifier", mIdentifier);
    assessmentSectionElement.setAttribute("title", mTitle);
    
    foreach(KQtiSectionPart* sectionPart, mSectionParts)
    {
        assessmentSectionElement.appendChild(sectionPart->element());
    }
    
    return assessmentSectionElement;
}
