Ejemplo n.º 1
0
void CommentableObjectViewer::renderPosts(shared_ptr<XMLPortalExporter> exporter)
{
	if(getObject() == nullptr || getObject()->allowChild(portalObjectTypePost) == false)
		return;

	// Calcola il numero totale di posts
	uint32 total_posts = getEntity()->getChildsCount(getDatabase(), portalObjectTypePost);
	if(total_posts == 0)
		return;

	// Numero di posts da visualizzare per pagina
	uint32 posts_to_show = getSkin()->getPagerItems();
	// Inizializza l'offset di estrazione
	uint32 offset = conversions::from_utf16<uint32>(getRequest()->getUrlParam(OS_URL_PARAM_OFFSET));

	// Corregge l'offset se necessario
	adjustOffset(total_posts, posts_to_show, offset);

	objects_posts_list posts;
	// Estrae le risposte nell'intervallo richiesto
	shared_ptr<EntitiesEntities> post_childs = getEntity()->getChilds(getDatabase(), portalObjectTypePost, RangeUint32(offset, posts_to_show));
	for(EntitiesEntities::iterator i = post_childs->begin(); i != post_childs->end(); ++i)
	{
		// Carica la riposta corrente
		shared_ptr<EntitiesEntity> post_entity = post_childs->get(getDatabase(), *i);
		if(post_entity != nullptr)
		{
			// Calcola la revisione corrente della risposta
			shared_ptr<ObjectsPost> current_post = objects_post_cast(post_entity->getCurrent());
			if(current_post != nullptr)
				posts.push_back(current_post);
		}
	}

	if(posts.empty() == false)
	{
		shared_ptr<XMLNode> posts_node = exporter->getNode(OS_PORTAL_OBJECT_POST_GROUPNAME);
		for(objects_posts_list::const_iterator i = posts.begin(); i != posts.end(); ++i)
		{
			shared_ptr<XMLPortalExporter> postExporter(OS_NEW XMLPortalExporter(posts_node->addChild(OS_PORTAL_OBJECT_POST_TYPENAME), exporter->getPage(), exporter->getMode()));
			renderPost(postExporter, *i);
		}
	}

	createPager(getSkin(), exporter->getRoot(), total_posts, posts_to_show, offset);
}
Ejemplo n.º 2
0
void IdeMailBox::renderFolder(MessageFolder folder, shared_ptr<XMLNode> node)
{
	getPortal()->getMessenger()->markNewMessagesAsUnread(getPage()->getDatabase(), getSessionAccount());

	node->setAttributeString(_S("name"), DataLocalMessage::toString(folder));

	// Calcola il numero totale di messaggi nel folder
	uint32 total_messages = getPortal()->getMessenger()->getMessagesCount(getPage()->getDatabase(), getSessionAccount(), folder);
	// Calcola il numero di messaggi da mostrare
	uint32 messages_to_show = getSkin()->getPagerItems();
	// Crea il pager dei messaggi se necessario
	createPager(getSkin(), node, total_messages, messages_to_show, getOffset());

	shared_ptr<XMLNode> node_messages;

	DataLocalMessage::DataLocalMessageList messages;

	RangeUint32 range(m_offset, messages_to_show);
	// Estrae i messaggi nel folder corrente
	if(getPortal()->getMessenger()->getMessages(getPage()->getDatabase(), getSessionAccount(), messages, folder, range))
	{
		for(DataLocalMessage::DataLocalMessageList::const_iterator i = messages.begin(); i != messages.end(); ++i)
		{
			shared_ptr<DataLocalMessage> local_message = *i;
			shared_ptr<ObjectsMessage> message = local_message->decode(getSessionAccount()->getPrivateKey());
			if(message != nullptr)
			{
				if(node_messages == nullptr)
					node_messages = node->addChild(_S("messages"));

				shared_ptr<XMLPortalExporter> messageExporter(OS_NEW XMLPortalExporter(node_messages->addChild(_S("message")), getPage(), XMLPortalExporter::emLite));
				local_message->exportXML(messageExporter, message->subject, String::EMPTY, false);
			}
		}
	}

	shared_ptr<XMLNode> node_actions = node->addChild(_S("actions"));
	switch(folder)
	{
	case messageFolderInbox:		{
										shared_ptr<XMLNode> actionReadAll = node_actions->addChild(_S("action"));
										actionReadAll->setAttributeString(_S("name"), _S("readAllMessages"));
										actionReadAll->setAttributeString(_S("href"), getEventCommand(EVENT_ONREADALLMESSAGES, conversions::to_utf16(folder)));
									}

									break;

	case messageFolderTrash:		{
										shared_ptr<XMLNode> actionDeleteAll = node_actions->addChild(_S("action"));
										actionDeleteAll->setAttributeString(_S("name"), _S("deleteAllMessages"));
										actionDeleteAll->setAttributeString(_S("href"), getEventCommand(EVENT_ONDELETEALLMESSAGES, conversions::to_utf16(folder)));
									}

									break;

	case messageFolderSentItems:
									break;

	default:						OS_ASSERTFALSE();
									break;
	}
}