@@ -74,6 +74,8 @@ public function aggregatedScores( array $params ) {
7474 $ params ['sort ' ] : $ defaults ['sort ' ];
7575 $ order = $ params ['order ' ] === 'desc ' ? 'DESC ' : 'ASC ' ;
7676
77+ $ crit = array ();
78+
7779 if ( $ params ['items ' ] == 'all ' ) {
7880 $ limit = '' ;
7981 $ offset = '' ;
@@ -112,4 +114,73 @@ public function aggregatedScores( array $params ) {
112114 );
113115 return $ this ->fetchAllWithFound ( $ sql , $ crit );
114116 }
117+
118+ public function export () {
119+ $ sql = self ::concat (
120+ 'SELECT p.id, p.title, ' ,
121+ 'r.impact, ' ,
122+ 'r.innovation, ' ,
123+ 'r.ability, ' ,
124+ 'r.engagement, ' ,
125+ 'r.recommend, ' ,
126+ 'IF(r.conditional >0, \'* \', \'\') AS conditional, ' ,
127+ 'r.cnt AS rcnt, ' ,
128+ 'ROUND((r.recommend / r.cnt) * 100, 2) AS pcnt ' ,
129+ 'FROM proposals p ' ,
130+ 'INNER JOIN ( ' ,
131+ 'SELECT COUNT(*) AS cnt, ' ,
132+ 'AVG(impact) AS impact, ' ,
133+ 'AVG(innovation) AS innovation, ' ,
134+ 'AVG(ability) AS ability, ' ,
135+ 'AVG(engagement) AS engagement, ' ,
136+ 'SUM(IF(recommendation > 0, 1, 0)) AS recommend, ' ,
137+ 'SUM(IF(recommendation = 1, 1, 0)) AS conditional, ' ,
138+ 'proposal ' ,
139+ 'FROM reviews ' ,
140+ 'GROUP BY proposal ' ,
141+ ') r ON p.id = r.proposal ' ,
142+ "ORDER BY pcnt DESC, id DESC "
143+ );
144+ $ results = $ this ->fetchAllWithFound ( $ sql );
145+
146+ $ commentsSql = self ::concat (
147+ 'SELECT proposal, ' ,
148+ 'impact_note, ' ,
149+ 'innovation_note, ' ,
150+ 'ability_note, ' ,
151+ 'engagement_note, ' ,
152+ 'comments ' ,
153+ 'FROM reviews '
154+ );
155+
156+ $ comments = array ();
157+ foreach ( $ this ->fetchAll ( $ commentsSql ) as $ row ) {
158+ if ( !isset ( $ comments [ $ row ['proposal ' ] ] ) ) {
159+ $ comments [ $ row ['proposal ' ] ] = array ();
160+ }
161+ if ( $ row ['impact_note ' ] ) {
162+ $ comments [$ row ['proposal ' ]][] = $ row ['impact_note ' ];
163+ }
164+ if ( $ row ['innovation_note ' ] ) {
165+ $ comments [$ row ['proposal ' ]][] = $ row ['innovation_note ' ];
166+ }
167+ if ( $ row ['ability_note ' ] ) {
168+ $ comments [$ row ['proposal ' ]][] = $ row ['ability_note ' ];
169+ }
170+ if ( $ row ['engagement_note ' ] ) {
171+ $ comments [$ row ['proposal ' ]][] = $ row ['engagement_note ' ];
172+ }
173+ if ( $ row ['comments ' ] ) {
174+ $ comments [$ row ['proposal ' ]][] = $ row ['comments ' ];
175+ }
176+ }
177+
178+ foreach ( $ results ->rows as &$ row ) {
179+ if ( isset ( $ comments [$ row ['id ' ]] ) ) {
180+ $ row ['comments ' ] = $ comments [$ row ['id ' ]];
181+ }
182+ }
183+
184+ return $ results ;
185+ }
115186}
0 commit comments