Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php |
— | — | @@ -14,6 +14,24 @@ |
15 | 15 | class EPArticleTable extends EPPager { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * The doBatchLookups method gets all articles relevant to the users that will be displayed |
| 19 | + * and stores them in this field. |
| 20 | + * int userId => array( EPArticle $article0, ... ) |
| 21 | + * |
| 22 | + * @since 0.1 |
| 23 | + * @var array |
| 24 | + */ |
| 25 | + protected $articles = array(); |
| 26 | + |
| 27 | + /** |
| 28 | + * Adittion conditions the articles need to match. |
| 29 | + * By default all articles for the users are obtained, |
| 30 | + * |
| 31 | + * @var array |
| 32 | + */ |
| 33 | + protected $articleConds; |
| 34 | + |
| 35 | + /** |
18 | 36 | * Constructor. |
19 | 37 | * |
20 | 38 | * @param IContextSource $context |
— | — | @@ -55,29 +73,90 @@ |
56 | 74 | return 'TablePager ep-students'; |
57 | 75 | } |
58 | 76 | |
| 77 | + protected $currentArticleKey = 0; |
| 78 | + |
| 79 | + |
59 | 80 | /** |
60 | 81 | * (non-PHPdoc) |
61 | | - * @see EPPager::getFormattedValue() |
| 82 | + * @see TablePager::formatRow() |
62 | 83 | */ |
63 | | - protected function getFormattedValue( $name, $value ) { |
64 | | - switch ( $name ) { |
65 | | - case 'user_id': |
66 | | - $user = User::newFromId( $value ); |
67 | | - $name = $user->getRealName() === '' ? $user->getName() : $user->getRealName(); |
| 84 | + function formatRow( $row ) { |
| 85 | + $this->mCurrentRow = $row; |
| 86 | + $this->currentObject = $this->table->newFromDBResult( $row ); |
68 | 87 | |
69 | | - $value = Linker::userLink( $value, $name ) . Linker::userToolLinks( $value, $name ); |
70 | | - break; |
71 | | - case '_articles': |
72 | | - // TODO |
73 | | - $value = serialize( $this->articles[$this->currentObject->getField( 'user_id' )] ); |
74 | | - break; |
| 88 | + $student = $this->currentObject; |
| 89 | + $articles = $this->articles[$student->getField( 'user_id' )]; |
| 90 | + |
| 91 | + $articleCount = count( $articles ); |
| 92 | + $reviewerCount = array_reduce( $articles, function( /* integer */ $sum, EPArticle $article ) { |
| 93 | + return $sum + count( $article->getField( 'reviewers' ) ); |
| 94 | + }, 0 ); |
| 95 | + |
| 96 | + $html = Html::openElement( 'tr', $this->getRowAttrs( $row ) ); |
| 97 | + |
| 98 | + $html .= $this->getUserCell( $student->getField( 'user_id' ), $reviewerCount ); |
| 99 | + |
| 100 | + $isFirst = true; |
| 101 | + |
| 102 | + foreach ( $articles as /* EPArticle */ $article ) { |
| 103 | + if ( !$isFirst ) { |
| 104 | + $html .= '</tr><tr>'; |
| 105 | + } |
| 106 | + |
| 107 | + $isFirst = false; |
| 108 | + |
| 109 | + $reviewers = $article->getField( 'reviewers' ); |
| 110 | + |
| 111 | + $html .= Html::rawElement( |
| 112 | + 'td', |
| 113 | + array_merge( |
| 114 | + $this->getCellAttrs( 'articles', $article ), |
| 115 | + array( 'rowspan' => max( 1, count( $reviewers ) ) ) |
| 116 | + ), |
| 117 | + serialize( $article ) // TODO |
| 118 | + ); |
| 119 | + |
| 120 | + foreach ( $reviewers as $nr => $userId ) { |
| 121 | + if ( $nr !== 0 ) { |
| 122 | + $html .= '</tr><tr>'; |
| 123 | + } |
| 124 | + |
| 125 | + $html .= Html::rawElement( |
| 126 | + 'td', |
| 127 | + $this->getCellAttrs( 'reviewers', $userId ), |
| 128 | + $userId // TODO |
| 129 | + ); |
| 130 | + } |
75 | 131 | } |
76 | 132 | |
77 | | - return $value; |
| 133 | + $html .= '</tr>'; |
| 134 | + |
| 135 | + return $html; |
78 | 136 | } |
79 | 137 | |
| 138 | + protected function getUserCell( $userId, $rowSpan ) { |
| 139 | + $user = User::newFromId( $userId ); |
| 140 | + $name = $user->getRealName() === '' ? $user->getName() : $user->getRealName(); |
| 141 | + |
| 142 | + return html::rawElement( |
| 143 | + 'td', |
| 144 | + array_merge( |
| 145 | + $this->getCellAttrs( 'user_id', $userId ), |
| 146 | + array( 'rowspan' => $rowSpan ) |
| 147 | + ), |
| 148 | + Linker::userLink( $userId, $name ) . Linker::userToolLinks( $userId, $name ) |
| 149 | + ); |
| 150 | + } |
| 151 | + |
| 152 | + |
80 | 153 | /** |
81 | 154 | * (non-PHPdoc) |
| 155 | + * @see EPPager::getFormattedValue() |
| 156 | + */ |
| 157 | + protected function getFormattedValue( $name, $value ) { /* ... */ } |
| 158 | + |
| 159 | + /** |
| 160 | + * (non-PHPdoc) |
82 | 161 | * @see EPPager::getSortableFields() |
83 | 162 | */ |
84 | 163 | protected function getSortableFields() { |
— | — | @@ -100,15 +179,15 @@ |
101 | 180 | public function getFieldNames() { |
102 | 181 | $fields = parent::getFieldNames(); |
103 | 182 | |
| 183 | + unset( $fields['id'] ); |
| 184 | + |
| 185 | + $fields['user_id'] = 'student'; |
104 | 186 | $fields['_articles'] = 'articles'; |
| 187 | + $fields['_reviewers'] = 'reviewers'; |
105 | 188 | |
106 | 189 | return $fields; |
107 | 190 | } |
108 | 191 | |
109 | | - protected $articles = array(); |
110 | | - |
111 | | - protected $articleConds; |
112 | | - |
113 | 192 | /** |
114 | 193 | * (non-PHPdoc) |
115 | 194 | * @see IndexPager::doBatchLookups() |
— | — | @@ -119,7 +198,10 @@ |
120 | 199 | while( $student = $this->mResult->fetchObject() ) { |
121 | 200 | $field = EPStudents::singleton()->getPrefixedField( 'user_id' ); |
122 | 201 | $userIds[] = $student->$field; |
123 | | - $this->articles[$student->$field] = array(); |
| 202 | + $this->articles[$student->$field] = array( |
| 203 | + EPArticles::singleton()->newFromArray( array( 'page_id' => 1, 'reviewers' => array( 'rev 0', 'rev 1' ) ) ), |
| 204 | + EPArticles::singleton()->newFromArray( array( 'page_id' => 2, 'reviewers' => array( 'rev 2', 'rev 3' ) ) ), |
| 205 | + ); |
124 | 206 | } |
125 | 207 | |
126 | 208 | $conditions = array_merge( array( 'user_id' => $userIds ), $this->articleConds ); |
Index: trunk/extensions/EducationProgram/includes/EPPager.php |
— | — | @@ -65,6 +65,7 @@ |
66 | 66 | * @see TablePager::formatRow() |
67 | 67 | */ |
68 | 68 | function formatRow( $row ) { |
| 69 | + $this->mCurrentRow = $row; |
69 | 70 | $this->currentObject = $this->table->newFromDBResult( $row ); |
70 | 71 | |
71 | 72 | $cells = array(); |
— | — | @@ -322,8 +323,6 @@ |
323 | 324 | $controls = array(); |
324 | 325 | |
325 | 326 | foreach ( $filterOptions as $optionName => $optionData ) { |
326 | | - |
327 | | - |
328 | 327 | switch ( $optionData['type'] ) { |
329 | 328 | case 'select': |
330 | 329 | $select = new XmlSelect( |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -272,7 +272,9 @@ |
273 | 273 | 'epstudentpager-no' => 'No', |
274 | 274 | |
275 | 275 | // Student article pager |
| 276 | + 'epstudentpager-header-student' => 'Student', |
276 | 277 | 'epstudentpager-header-articles' => 'Articles', |
| 278 | + 'epstudentpager-header-reviewers' => 'Reviewers', |
277 | 279 | |
278 | 280 | // Article pager |
279 | 281 | 'ep-articles-noresults' => 'There are no articles to list.', |