ForumCommentWidget::ForumCommentWidget(const CommentPtr& comment) {
    dbo::Transaction t(tApp->session());
    if (comment->type() != Comment::FORUM_COMMENT) {
        return;
    }
    new Header(tr("tc.forum.Comment"), this);
    Wt::WText* text = new Wt::WText(forum_comment_text(comment), this);
    text->addStyleClass("thechess-forum-comments");
    UserPtr user = comment->init();
    if (user) {
        new Wt::WBreak(this);
        user_anchor(user, this);
    }
    CommentPtr post_text = comment->root();
    CommentPtr post = post_text->parent();
    new Wt::WBreak(this);
    Wt::WAnchor* a = new Wt::WAnchor(this);
    a->setLink(tApp->path().post()->get_link(post.id()));
    a->setText(tr("tc.forum.post_header")
               .arg(post.id()).arg(post->text_or_removed(tApp->user())));
    CommentPtr parent = comment->parent();
    if (parent->type() == Comment::FORUM_COMMENT) {
        new Wt::WBreak(this);
        Wt::WAnchor* g = new Wt::WAnchor(this);
        g->setLink(tApp->path().post_comment()->get_link(parent.id()));
        g->setText(tr("tc.forum.Goto_parent").arg(parent.id()));
    }
    if (comment->can_edit(tApp->user())) {
        new Wt::WBreak(this);
        Wt::WAnchor* e = new Wt::WAnchor(this);
        e->setLink(tApp->path().forum_edit()->get_link(comment.id()));
        e->setText(tr("tc.forum.Edit"));
    }
    Wt::WTextEdit* edit = new Wt::WTextEdit(this);
    patch_text_edit(edit);
    new Wt::WBreak(this);
    if (Comment::can_create(tApp->user(), Comment::FORUM_COMMENT, comment)) {
        Wt::WPushButton* add = new Wt::WPushButton(tr("tc.comment.Add"), this);
        add->clicked().connect(boost::bind(add_comment, comment, edit, this));
    }
    add_remover_buttons(comment, this);
}
void AlunoList::setTable(){

	Wt::Dbo::Transaction transaction(_dbSession);
	_table->clear();
	_table->setHeaderCount(1);
	_table->setStyleClass("table table-striped table-hover");
	_table->setWidth(500);

		Wt::Dbo::ptr<SiconfModel::Turma> turma = _disciplina->turma();

		Wt::Dbo::collection<Wt::Dbo::ptr<SiconfModel::Aluno>> alunos = turma->alunos();

		new Wt::WText("Nome", _table->elementAt(0,0));
		new Wt::WText("Frequencia", _table->elementAt(0,1));

		Wt::Dbo::collection<Wt::Dbo::ptr<SiconfModel::Avaliacao>> avaliacoes = _disciplina->avaliacoes();

		for(unsigned i = 1; i < (avaliacoes.size() + 1) ; i++){
			new Wt::WText("Av. " + std::to_string(i), _table->elementAt(0, _table->columnCount()));
		}

		new Wt::WText("Media", _table->elementAt(0, _table->columnCount()));

		for(auto aluno : alunos){
			int row = _table->rowCount();
			new Wt::WText(aluno->usuario()->nome(), _table->elementAt(row, 0));
			float presencas = 0.0;
			float total = 0.0;

			try{

				std::vector<Wt::Dbo::ptr<SiconfModel::Frequencia>> frequencias;

				total = _disciplina->aulas().size();

				Wt::Dbo::collection<Wt::Dbo::ptr<SiconfModel::Frequencia>> collFrequ = _dbSession.find<SiconfModel::Frequencia>("where frequencias_aluno_id = ?").bind(aluno.id());

				for(auto i : collFrequ){

					if(i->aula()->disciplina().id() == _disciplina.id()){
						if(i->presenca()){
							presencas +=1;
						}
					}
				}

				if(total > 0){
					for(auto i : frequencias){
						if(i->presenca()) presencas +=1;
					}
					presencas = ((presencas/total)* 100);
				}

			}catch(Wt::Dbo::Exception& e){
				std::cout << "AlunoList::setTable: " << e.what() << std::endl;
			}

			std::stringstream strPresencas;
			strPresencas << std::fixed << std::setprecision(1) << presencas;

			new Wt::WText(strPresencas.str() + " %", _table->elementAt(row, 1));
			unsigned col = 2;

			int qtdAvaliacoes = avaliacoes.size();
			float media = 0;

			for(auto avaliacao : avaliacoes){
				Wt::Dbo::ptr<SiconfModel::Nota> nota = _dbSession.find<SiconfModel::Nota>("where notas_avaliacao_id = ? and notas_aluno_id = ?").bind(avaliacao.id()).bind(aluno.id());
				if(nota){
					media+=nota->nota();
					std::stringstream strNotas;
					strNotas << std::fixed << std::setprecision(1) << nota->nota();
					Wt::WText* text = new Wt::WText(strNotas.str(), _table->elementAt(row, col));
					if(nota->nota() < 5){
						text->addStyleClass("text-red");
					}
				}
				col++;
			}


			if(qtdAvaliacoes == 0){
				media = 0;
			}else{
				media /= qtdAvaliacoes;
			}


			std::stringstream strMedia;
			strMedia << std::fixed << std::setprecision(1) << media;
			Wt::WText* text = new Wt::WText(strMedia.str(), _table->elementAt(row, _table->columnCount() -1));
			if(media < 5){
				text->addStyleClass("text-red");
			}
		}
}