mirror of
https://github.com/znc/znc.git
synced 2026-05-09 23:04:47 +02:00
Added the ability to sort template loop data based on a key.
e.g. <? LOOP name SORTASC=key ?> or <? LOOP name SORTDESC=key ?> Patch by BrianC, thanks again. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1948 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "Template.h"
|
||||
#include "FileUtils.h"
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
using std::stringstream;
|
||||
|
||||
@@ -201,6 +202,15 @@ bool CTemplate::SetFile(const CString& sFileName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
class CLoopSorter {
|
||||
CString m_sType;
|
||||
public:
|
||||
CLoopSorter(const CString& sType) : m_sType(sType) {}
|
||||
bool operator()(CTemplate* pTemplate1, CTemplate* pTemplate2) {
|
||||
return (pTemplate1->GetValue(m_sType, false) < pTemplate2->GetValue(m_sType, false));
|
||||
}
|
||||
};
|
||||
|
||||
CTemplate& CTemplate::AddRow(const CString& sName) {
|
||||
CTemplate* pTmpl = new CTemplate(m_spOptions, this);
|
||||
m_mvLoops[sName].push_back(pTmpl);
|
||||
@@ -429,8 +439,24 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) {
|
||||
|
||||
CString sLoopName = sArgs.Token(0);
|
||||
bool bReverse = (sArgs.Token(1).Equals("REVERSE"));
|
||||
bool bSort = (sArgs.Token(1).Left(4).Equals("SORT"));
|
||||
vector<CTemplate*>* pvLoop = GetLoop(sLoopName);
|
||||
|
||||
if (bSort) {
|
||||
CString sKey;
|
||||
|
||||
if(sArgs.Token(1).TrimPrefix_n("SORT").Left(4).Equals("ASC=")) {
|
||||
sKey = sArgs.Token(1).TrimPrefix_n("SORTASC=");
|
||||
} else if(sArgs.Token(1).TrimPrefix_n("SORT").Left(5).Equals("DESC=")) {
|
||||
sKey = sArgs.Token(1).TrimPrefix_n("SORTDESC=");
|
||||
bReverse = true;
|
||||
}
|
||||
|
||||
if (!sKey.empty()) {
|
||||
std::sort(pvLoop->begin(), pvLoop->end(), CLoopSorter(sKey));
|
||||
}
|
||||
}
|
||||
|
||||
if (pvLoop) {
|
||||
// If we found data for this loop, add it to our context vector
|
||||
//unsigned long uBeforeLoopTag = uCurPos - iPos2 - 4;
|
||||
|
||||
Reference in New Issue
Block a user