Changeset 3957

Show
Ignore:
Timestamp:
Sat Oct 8 17:22:38 2005
Author:
mugur
Message:

fixed ticket:1448 - Implement "List subtopics"

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/campsite/implementation/parser/parser/parser.cpp

    r3956 r3957  
    56 56 ", " ST_LIST " " ST_ISSUE ", " ST_LIST " " ST_SECTION ", " ST_LIST " " ST_ARTICLE \  
    57 57 ", " ST_LIST " " ST_SEARCHRESULT ", " ST_LIST " " ST_SUBTITLE ", " ST_LIST " " ST_ARTICLETOPIC \  
    58   ", " ST_URLPARAMETERS ", " ST_URI ", " ST_URIPATH ", " ST_FORMPARAMETERS ", " ST_PRINT \  
    59   ", " ST_DATE ", " ST_SUBSCRIPTION ", " ST_EDIT ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
      58 ", " ST_LIST " " ST_SUBTOPIC ", " ST_URLPARAMETERS ", " ST_URI ", " ST_URIPATH \  
      59 ", " ST_FORMPARAMETERS ", " ST_PRINT ", " ST_DATE ", " ST_SUBSCRIPTION ", " ST_EDIT \  
      60 ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
    60 61  
    61 62 #define LISSUE_STATEMENTS ST_SECTION ", " ST_ARTICLE ", " ST_TOPIC ", " ST_INCLUDE ", " ST_IF \  
    62 63 ", " ST_LOCAL ", " ST_WITH ", " ST_LIST " " ST_SECTION ", " ST_LIST " " ST_ARTICLE \  
    63 64 ", " ST_LIST " " ST_SEARCHRESULT ", " ST_LIST " " ST_SUBTITLE ", " ST_LIST " " ST_ARTICLETOPIC \  
    64   ", " ST_URLPARAMETERS ", " ST_URI ", " ST_URIPATH ", " ST_FORMPARAMETERS ", " ST_PRINT \  
    65   ", " ST_DATE ", " ST_SUBSCRIPTION ", " ST_EDIT ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
      65 ", " ST_LIST " " ST_SUBTOPIC ", " ST_URLPARAMETERS ", " ST_URI ", " ST_URIPATH \  
      66 ", " ST_FORMPARAMETERS ", " ST_PRINT ", " ST_DATE ", " ST_SUBSCRIPTION ", " ST_EDIT \  
      67 ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
    66 68  
    67 69 #define LSECTION_STATEMENTS ST_ARTICLE ", " ST_TOPIC ", " ST_INCLUDE ", " ST_IF ", " ST_LOCAL \  
    68 70 ", " ST_WITH ", " ST_LIST " " ST_ARTICLE ", " ST_LIST " " ST_SEARCHRESULT \  
    69   ", " ST_LIST " " ST_SUBTITLE ", " ST_LIST " " ST_ARTICLETOPIC ", " ST_URLPARAMETERS \  
    70   ", " ST_URI ", " ST_URIPATH ", " ST_FORMPARAMETERS ", " ST_PRINT ", " ST_DATE \  
    71   ", " ST_SUBSCRIPTION ", " ST_EDIT ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
      71 ", " ST_LIST " " ST_SUBTITLE ", " ST_LIST " " ST_ARTICLETOPIC ", " ST_LIST " " ST_SUBTOPIC \  
      72 ", " ST_URLPARAMETERS ", " ST_URI ", " ST_URIPATH ", " ST_FORMPARAMETERS ", " ST_PRINT \  
      73 ", " ST_DATE ", " ST_SUBSCRIPTION ", " ST_EDIT ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
    72 74  
    73 75 #define LARTICLE_STATEMENTS ST_TOPIC ", " ST_INCLUDE ", " ST_IF ", " ST_LOCAL ", " ST_WITH \  
    74   ", " ST_LIST " " ST_ARTICLETOPIC ", " ST_URLPARAMETERS ", " ST_URI ", " ST_URIPATH \  
    75   ", " ST_FORMPARAMETERS ", " ST_PRINT ", " ST_DATE ", " ST_SUBSCRIPTION ", " ST_EDIT \  
    76   ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
      76 ", " ST_LIST " " ST_ARTICLETOPIC ", " ST_LIST " " ST_SUBTOPIC ", " ST_URLPARAMETERS \  
      77 ", " ST_URI ", " ST_URIPATH ", " ST_FORMPARAMETERS ", " ST_PRINT ", " ST_DATE \  
      78 ", " ST_SUBSCRIPTION ", " ST_EDIT ", " ST_SELECT ", " ST_USER ", " ST_SEARCH  
    77 79  
    78 80 #define LV_ROOT 1  
     
    101 103 #define SUBLV_IFLANGUAGE 65536  
    102 104 #define SUBLV_IFTOPIC 131072  
      105 #define SUBLV_ARTICLETOPIC 262144  
      106 #define SUBLV_SUBTOPIC 524288  
    103 107  
    104 108  
     
    1086 1090     // check for modifier (Issue, Section, Article, SearchResult, Subtitle, ArticleTopic)  
    1087 1091     st = (const CStatement*)l->atom();  
    1088       if (level >= LV_LARTICLE && st->id() != CMS_ST_ARTICLETOPIC)  
      1092     if (level >= LV_LARTICLE && st->id() != CMS_ST_ARTICLETOPIC && st->id() != CMS_ST_SUBTOPIC)  
    1088 1092         FatalPError(parse_err, PERR_WRONG_STATEMENT, MODE_PARSE,  
    1089 1093                     LARTICLE_STATEMENTS, lex.prevLine(), lex.prevColumn());  
     
    1116 1120     DEBUGLexem("hlist1", l);  
    1117 1121     while (mod != CMS_ST_SEARCHRESULT && mod != CMS_ST_SUBTITLE && mod != CMS_ST_ARTICLETOPIC  
    1118              && (l->res() == CMS_LEX_IDENTIFIER || (IsTopicStatement(l) && mod == CMS_ST_ARTICLE)))  
      1122               && mod != CMS_ST_SUBTOPIC  
      1123               && (l->res() == CMS_LEX_IDENTIFIER || (IsTopicStatement(l) && mod == CMS_ST_ARTICLE)))  
    1119 1124     {  
    1120 1125         StringSet ah;  
     
    1245 1250     if (mod == CMS_ST_SEARCHRESULT)  
    1246 1251         sublevel |= SUBLV_SEARCHRESULT;  
      1252     if (mod == CMS_ST_ARTICLETOPIC)  
      1253         sublevel |= SUBLV_ARTICLETOPIC;  
      1254     if (mod == CMS_ST_SUBTOPIC)  
      1255         sublevel |= SUBLV_SUBTOPIC;  
    1247 1256     int tmp_level = LMod2Level(mod);  
    1248 1257     if (tmp_level == 0)  
    1406 1415     {  
    1407 1416         if ((sublv & SUBLV_EMPTYLIST)  
    1408                   || (lv == LV_ROOT && (sublv & SUBLV_SEARCHRESULT) == 0))  
      1417                    || (lv == LV_ROOT  
      1418                    && (sublv & (SUBLV_SEARCHRESULT | SUBLV_ARTICLETOPIC | SUBLV_SUBTOPIC)) == 0))  
    1409 1419         {  
    1410 1420             FatalPError(parse_err, PERR_WRONG_STATEMENT, MODE_PARSE,  
  • trunk/campsite/implementation/parser/parser/lex.cpp

    r3956 r3957  
    798 798     this->insert(pcoSt);  
    799 799  
      800     // Subtopic statement  
      801     pcoSt = new CStatement(CMS_ST_SUBTOPIC, ST_SUBTOPIC);  
      802  
      803     pcoCtx = new CStatementContext(CMS_CT_LIST);  
      804     pcoSt->insertCtx(pcoCtx);  
      805  
      806     this->insert(pcoSt);  
      807  
    800 808     CLOSE_TRY  
    801 809     CATCH(InvalidValue &rcoEx)  
  • trunk/campsite/implementation/parser/parser/actions.cpp

    r3956 r3957  
    582 582     insert(CMS_ST_SUBTITLE);  
    583 583     insert(CMS_ST_ARTICLETOPIC);  
      584     insert(CMS_ST_SUBTOPIC);  
    584 585 }  
    585 586  
     
    827 828 {  
    828 829     CParameterList::iterator pl_i;  
    829       if (modifier != CMS_ST_SEARCHRESULT && modifier != CMS_ST_ARTICLETOPIC)  
      830     if (modifier != CMS_ST_SEARCHRESULT && modifier != CMS_ST_ARTICLETOPIC  
      831            && modifier != CMS_ST_SUBTOPIC)  
    830 832     {  
    831 833         string table;  
     
    847 849             s += string(", Articles.ArticleOrder asc");  
    848 850     }  
      851     if (modifier == CMS_ST_SUBTOPIC)  
      852     {  
      853         s = " order by Id asc";  
      854     }  
    849 855     if (modifier == CMS_ST_SEARCHRESULT)  
    850 856     {  
     
    938 944     {  
    939 945         string where, order, limit, fields, prefix, table, having;  
    940           if (modifier == CMS_ST_ARTICLE)  
    941           {  
    942               WriteArtParam(where, lc, table);  
    943               prefix = "Articles.";  
    944           }  
    945           if (modifier == CMS_ST_SEARCHRESULT)  
    946           {  
    947               WriteSrcParam(where, lc, table);  
    948               if (where == "")  
    949               {  
    950                   runActions(second_block, c, fs);  
    951                   return RES_OK;  
    952               }  
    953           }  
    954           if (modifier == CMS_ST_ISSUE || modifier == CMS_ST_SECTION)  
    955           {  
    956               WriteModParam(where, lc, table);  
    957           }  
    958           if (modifier == CMS_ST_ARTICLETOPIC)  
    959           {  
    960               stringstream buf;  
    961               buf << " where NrArticle = " << lc.Article();  
    962               where = buf.str();  
    963               table = "ArticleTopics";  
    964           }  
    965           if (modifier == CMS_ST_SEARCHRESULT && lc.SearchAnd())  
    966           {  
    967               stringstream buf;  
    968               buf << " having count(NrArticle) = " << lc.KeywordsNr();  
    969               having = buf.str();  
      946         stringstream buf;  
      947         switch (modifier) {  
      948             case CMS_ST_ISSUE:  
      949             case CMS_ST_SECTION:  
      950                 WriteModParam(where, lc, table);  
      951                 break;  
      952             case CMS_ST_ARTICLE:  
      953                 WriteArtParam(where, lc, table);  
      954                 prefix = "Articles.";  
      955                 break;  
      956             case CMS_ST_SEARCHRESULT:  
      957                 WriteSrcParam(where, lc, table);  
      958                 if (where == "")  
      959                 {  
      960                     runActions(second_block, c, fs);  
      961                     return RES_OK;  
      962                 }  
      963                 if (lc.SearchAnd())  
      964                 {  
      965                     buf << " having count(NrArticle) = " << lc.KeywordsNr();  
      966                     having = buf.str();  
      967                 }  
      968                 break;  
      969             case CMS_ST_ARTICLETOPIC:  
      970                 buf << " where NrArticle = " << lc.Article();  
      971                 where = buf.str();  
      972                 table = "ArticleTopics";  
      973                 break;  
      974             case CMS_ST_SUBTOPIC:  
      975                 id_type nTopic = lc.Topic() >= 0 ? lc.Topic() : 0;  
      976                 buf << " where ParentId = " << nTopic;  
      977                 where = buf.str();  
      978                 table = "Topics";  
      979                 break;  
    970 980         }  
    971 981         WriteOrdParam(order);  
    972 982         WriteLimit(limit, lc);  
    973 983          
    974           if (modifier == CMS_ST_SEARCHRESULT)  
    975               fields = "select NrArticle, MAX(Articles.IdLanguage), Articles.IdPublication";  
    976           if (modifier == CMS_ST_ARTICLE)  
    977               fields = "select Number, MAX(Articles.IdLanguage), IdPublication";  
    978           if (modifier == CMS_ST_ISSUE || modifier == CMS_ST_SECTION || modifier == CMS_ST_SUBTITLE)  
    979               fields = "select Number, MAX(IdLanguage), IdPublication";  
    980           if (modifier == CMS_ST_ARTICLETOPIC)  
    981               fields = "select TopicId";  
      984         switch (modifier) {  
      985             case CMS_ST_ISSUE:  
      986             case CMS_ST_SECTION:  
      987                 fields = "select Number, MAX(IdLanguage), IdPublication";  
      988                 if (modifier == CMS_ST_SECTION)  
      989                     fields += ", NrIssue";  
      990                 break;  
      991             case CMS_ST_ARTICLE:  
      992                 fields = "select Number, MAX(Articles.IdLanguage), IdPublication"  
      993                         ", Articles.NrIssue, Articles.NrSection";  
      994                 break;  
      995             case CMS_ST_SEARCHRESULT:  
      996                 fields = "select NrArticle, MAX(Articles.IdLanguage), Articles.IdPublication"  
      997                         ", Articles.NrIssue, Articles.NrSection";  
      998                 break;  
      999             case CMS_ST_ARTICLETOPIC:  
      1000                 fields = "select TopicId";  
      1001                 break;  
      1002             case CMS_ST_SUBTOPIC:  
      1003                 fields = "select distinct Id";  
      1004                 break;  
      1005         }  
    982 1006          
    983           if (modifier == CMS_ST_ARTICLE || modifier == CMS_ST_SEARCHRESULT)  
    984               fields += ", Articles.NrIssue, Articles.NrSection";  
    985           if (modifier == CMS_ST_SECTION)  
    986               fields += ", NrIssue";  
    987 1007         string group;  
    988           if (modifier == CMS_ST_SEARCHRESULT)  
    989           {  
    990               group = " group by NrArticle";  
    991           }  
    992 1008         if (modifier == CMS_ST_ISSUE || modifier == CMS_ST_SECTION || modifier == CMS_ST_ARTICLE)  
    993 1009         {  
    994 1010             group = " group by Number";  
    995 1011         }  
      1012         if (modifier == CMS_ST_SEARCHRESULT)  
      1013         {  
      1014             group = " group by NrArticle";  
      1015         }  
    996 1016         string coQuery = fields + " from " + table + where + group + having + order + limit;  
    997 1017         DEBUGAct("takeAction()", coQuery.c_str(), fs);  
    1031 1051             if ((row = mysql_fetch_row(*res)) == NULL)  
    1032 1052                 break;  
    1033               if (modifier != CMS_ST_ARTICLETOPIC)  
      1053             if (modifier != CMS_ST_ARTICLETOPIC && modifier != CMS_ST_SUBTOPIC)  
    1033 1053             {  
    1034 1054                 lc.SetLanguage(strtol(row[1], 0, 10));  
  • trunk/campsite/implementation/parser/parser/lex.h

    r3956 r3957  
    90 90 #define CMS_ST_URI 43  
    91 91 #define CMS_ST_ARTICLETOPIC 44  
      92 #define CMS_ST_SUBTOPIC 45  
    92 93  
    93 94 // statement names  
    136 137 #define ST_URI "URI"  
    137 138 #define ST_ARTICLETOPIC "ArticleTopic"  
      139 #define ST_SUBTOPIC "Subtopic"  
    138 140  
    139 141 // The lexem returned by lex class