Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -321,7 +321,7 @@ |
322 | 322 | /** |
323 | 323 | * Return an array of records given type and other criteria |
324 | 324 | */ |
325 | | - function getRecords( $type, $posted, $operator, $wpTitle = '', $invert = false, $orderby = 'created desc' ) { |
| 325 | + function getRecords( $type, $posted, $operator, $wpTitle = '', $invert = false, $orderby = 'created desc', $groupby = false, $format = false ) { |
326 | 326 | global $wgRequest; |
327 | 327 | |
328 | 328 | # If the page is already rendered, don't run this query |
— | — | @@ -357,14 +357,7 @@ |
358 | 358 | if ( $v && !( $i && $this->cmpCallback( $r[$k], $v, $operator[$k] ) ) ) $match = false; |
359 | 359 | } |
360 | 360 | if ( $invert ) $match = !$match; |
361 | | - if ( $match ) { |
362 | | - if ( $group ) { |
363 | | - $records[] = $r; |
364 | | - } |
365 | | - else { |
366 | | - $records[] = $r; |
367 | | - } |
368 | | - } |
| 361 | + if ( $match ) $records[] = $r; |
369 | 362 | } |
370 | 363 | } |
371 | 364 | $dbr->freeResult( $res ); |
— | — | @@ -396,6 +389,24 @@ |
397 | 390 | if ( $this->desc = eregi( ' +desc *$', $orderby ) ) $orderby = eregi_replace( ' +desc *$', '', $orderby ); |
398 | 391 | $this->orderBy = $orderby; |
399 | 392 | usort( $records, array( $this, 'sortCallback' ) ); |
| 393 | + |
| 394 | + # Group the records according to the "groupby" parameter |
| 395 | + if ( $groupby ) { |
| 396 | + if ( !is_array( $groupby ) ) $groupby = split( '/\s*,\s*/', $groupby ); |
| 397 | + $tmp = array(); |
| 398 | + foreach ( $records as $r ) { |
| 399 | + $v0 = $r[$groupby[0]]; |
| 400 | + if ( $groupby[1] ) { |
| 401 | + $v1 = $r[$groupby[1]]; |
| 402 | + if ( !in_array( $tmp[$v0] ) ) $tmp[$v0] = array(); |
| 403 | + $tmp[$v0][$v1] = $r; |
| 404 | + } else $tmp[$v0] = $r; |
| 405 | + } |
| 406 | + $records = $tmp; |
| 407 | + } |
| 408 | + $this->groupBy = $groupby; |
| 409 | + $this->format = $format; |
| 410 | + |
400 | 411 | return $records; |
401 | 412 | } |
402 | 413 | |
— | — | @@ -883,6 +894,8 @@ |
884 | 895 | elseif ( $k == 'name' ) $name = $v; |
885 | 896 | elseif ( $k == 'invert' ) $invert = $v; |
886 | 897 | elseif ( $k == 'orderby' ) $orderby = $v; |
| 898 | + elseif ( $k == 'groupby' ) $groupby = $v; |
| 899 | + elseif ( $k == 'format' ) $format = $v; |
887 | 900 | elseif ( $k == 'cols' ) $cols = preg_split( '/\s*,\s*/', $v ); |
888 | 901 | elseif ( $k == 'sortable' ) $sortable = eregi( '1|yes|true|on', $v ); |
889 | 902 | elseif ( $k == 'template' ) $template = $v; |
— | — | @@ -898,7 +911,7 @@ |
899 | 912 | $tmp = $this->type; |
900 | 913 | $this->preProcessForm( $type ); |
901 | 914 | $this->examineForm(); |
902 | | - $records = $this->getRecords( $type, $filter, $op, $title, $invert, $orderby ); |
| 915 | + $records = $this->getRecords( $type, $filter, $op, $title, $invert, $orderby, $groupby, $format ); |
903 | 916 | if ( $count ) while ( count( $records ) > $count ) array_pop( $records ); |
904 | 917 | $table = $this->renderRecords( $records, $cols, $sortable, $template, $name, $export ); |
905 | 918 | $this->type = $tmp; |
— | — | @@ -946,7 +959,7 @@ |
947 | 960 | "rev_id=page_latest AND old_id=rev_text_id AND tl_from=page_id AND tl_title='$type' $regexp", |
948 | 961 | __METHOD__ |
949 | 962 | ); |
950 | | - if ($row) return Title::newFromId( $row->page_id )->getPrefixedText(); |
| 963 | + if ( $row ) return Title::newFromId( $row->page_id )->getPrefixedText(); |
951 | 964 | } |
952 | 965 | |
953 | 966 | return ''; |
Index: trunk/extensions/RecordAdmin/RecordAdmin.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU General Public Licence 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -define( 'RECORDADMIN_VERSION', '0.9.9, 2010-01-05' ); |
| 15 | +define( 'RECORDADMIN_VERSION', '0.9.10, 2010-01-18' ); |
16 | 16 | |
17 | 17 | $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type |
18 | 18 | $wgRecordAdminCategory = 'Records'; # Category containing record types |