Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php |
— | — | @@ -83,16 +83,31 @@ |
84 | 84 | |
85 | 85 | $student = $this->currentObject; |
86 | 86 | $articles = $this->articles[$student->getField( 'user_id' )]; |
| 87 | + $user = $this->getUser(); |
87 | 88 | |
88 | | - $articleCount = count( $articles ); |
89 | | - $reviewerCount = array_reduce( $articles, function( /* integer */ $sum, EPArticle $article ) { |
90 | | - return $sum + count( $article->getField( 'reviewers' ) ); |
| 89 | + $rowCount = array_reduce( $articles, function( /* integer */ $sum, EPArticle $article ) use ( $user ) { |
| 90 | + $sum += count( $article->getField( 'reviewers' ) ); |
| 91 | + |
| 92 | + if ( $article->canBecomeReviewer( $user ) ) { |
| 93 | + $sum++; |
| 94 | + } |
| 95 | + |
| 96 | + return $sum; |
91 | 97 | }, 0 ); |
92 | 98 | |
93 | 99 | $html = Html::openElement( 'tr', $this->getRowAttrs( $row ) ); |
94 | 100 | |
95 | | - $html .= $this->getUserCell( $student->getField( 'user_id' ), $reviewerCount ); |
| 101 | + $showArticleAdittion = |
| 102 | + $this->getUser()->getId() === $student->getField( 'user_id' ) |
| 103 | + && array_key_exists( 'course_id', $this->articleConds ) |
| 104 | + && is_integer( $this->articleConds['course_id'] ); |
96 | 105 | |
| 106 | + if ( $showArticleAdittion ) { |
| 107 | + $rowCount++; |
| 108 | + } |
| 109 | + |
| 110 | + $html .= $this->getUserCell( $student->getField( 'user_id' ), $rowCount ); |
| 111 | + |
97 | 112 | $isFirst = true; |
98 | 113 | |
99 | 114 | foreach ( $articles as /* EPArticle */ $article ) { |
— | — | @@ -104,8 +119,16 @@ |
105 | 120 | |
106 | 121 | $reviewers = $article->getField( 'reviewers' ); |
107 | 122 | |
108 | | - $html .= $this->getArticleCell( $article, max( 1, count( $reviewers ) ) ); |
| 123 | + $articleRowCount = count( $reviewers ); |
109 | 124 | |
| 125 | + if ( $article->canBecomeReviewer( $user ) ) { |
| 126 | + $articleRowCount++; |
| 127 | + } |
| 128 | + |
| 129 | + $articleRowCount = max( 1, $articleRowCount ); |
| 130 | + |
| 131 | + $html .= $this->getArticleCell( $article, $articleRowCount ); |
| 132 | + |
110 | 133 | foreach ( $reviewers as $nr => $userId ) { |
111 | 134 | if ( $nr !== 0 ) { |
112 | 135 | $html .= '</tr><tr>'; |
— | — | @@ -114,11 +137,23 @@ |
115 | 138 | $html .= $this->getReviewerCell( $article, $userId ); |
116 | 139 | } |
117 | 140 | |
118 | | - // TODO: add reviewer adittion control for reviewers |
| 141 | + if ( $article->canBecomeReviewer( $user ) ) { |
| 142 | + if ( count( $reviewers ) !== 0 ) { |
| 143 | + $html .= '</tr><tr>'; |
| 144 | + } |
| 145 | + |
| 146 | + $html .= $this->getReviewerAdittionControl( $article ); |
| 147 | + } |
119 | 148 | } |
120 | 149 | |
121 | | - // TODO: add article adittion control for student |
| 150 | + if ( $showArticleAdittion ) { |
| 151 | + if ( !$isFirst ) { |
| 152 | + $html .= '</tr><tr>'; |
| 153 | + } |
122 | 154 | |
| 155 | + $html .= $this->getArticleAdittionControl( $this->articleConds['course_id'] ); |
| 156 | + } |
| 157 | + |
123 | 158 | $html .= '</tr>'; |
124 | 159 | |
125 | 160 | return $html; |
— | — | @@ -269,20 +304,51 @@ |
270 | 305 | ); |
271 | 306 | } |
272 | 307 | |
273 | | - protected function addArticleRemovalControl() { |
| 308 | + protected function getArticleAdittionControl( $courseId ) { |
| 309 | + $html = ''; |
274 | 310 | |
275 | | - } |
| 311 | + $html .= Html::openElement( |
| 312 | + 'form', |
| 313 | + array( |
| 314 | + 'method' => 'post', |
| 315 | + 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'addarticle' ) ), |
| 316 | + ) |
| 317 | + ); |
276 | 318 | |
277 | | - protected function addReviwerRemovalControl() { |
| 319 | + $html .= Xml::inputLabel( |
| 320 | + wfMsg( 'ep-artciles-addarticle-text' ), |
| 321 | + 'addarticlename', |
| 322 | + 'addarticlename' |
| 323 | + ); |
278 | 324 | |
279 | | - } |
| 325 | + $html .= ' ' . Html::input( |
| 326 | + 'addarticle', |
| 327 | + wfMsg( 'ep-artciles-addarticle-button' ), |
| 328 | + 'submit', |
| 329 | + array( |
| 330 | + 'class' => 'ep-addarticle', |
| 331 | + ) |
| 332 | + ); |
280 | 333 | |
281 | | - protected function addArticleAdittionControl() { |
| 334 | + $html .= Html::hidden( 'addArticleToken', $this->getUser()->getEditToken( 'addarticle' . $courseId ) ); |
282 | 335 | |
| 336 | + $html .= '</form>'; |
| 337 | + |
| 338 | + return '<td colspan="2">' . $html . '</td>'; |
283 | 339 | } |
284 | 340 | |
285 | | - protected function addReviewerAdittionControl() { |
| 341 | + protected function getReviewerAdittionControl( EPArticle $article ) { |
| 342 | + $html = Html::element( |
| 343 | + 'button', |
| 344 | + array( |
| 345 | + 'class' => 'ep-become-reviewer', |
| 346 | + //'disabled' => 'disabled', |
| 347 | + 'data-article-id' => $article->getId(), |
| 348 | + ), |
| 349 | + wfMsg( 'ep-artciles-becomereviewer' ) |
| 350 | + ); |
286 | 351 | |
| 352 | + return '<td>' . $html . '</td>'; |
287 | 353 | } |
288 | 354 | |
289 | 355 | /** |
Index: trunk/extensions/EducationProgram/includes/EPArticle.php |
— | — | @@ -86,4 +86,17 @@ |
87 | 87 | return $this->title; |
88 | 88 | } |
89 | 89 | |
| 90 | + protected $canBecomeReviwer = array(); |
| 91 | + |
| 92 | + public function canBecomeReviewer( User $user ) { |
| 93 | + if ( !array_key_exists( $user->getId(), $this->canBecomeReviwer ) ) { |
| 94 | + $this->canBecomeReviwer[$user->getId()] = $this->getUser()->isAllowed( 'ep-bereviewer' ) |
| 95 | + //&& $this->getUser()->getId() !== $student->getField( 'user_id' ) |
| 96 | + //&& !in_array( $this->getUser()->getId(), $article->getField( 'reviewers' ) ) |
| 97 | + ; |
| 98 | + } |
| 99 | + |
| 100 | + return $this->canBecomeReviwer[$user->getId()]; |
| 101 | + } |
| 102 | + |
90 | 103 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -279,6 +279,9 @@ |
280 | 280 | 'ep-artciles-remreviewer-self' => 'Remove myself as reviewer', |
281 | 281 | 'ep-artciles-remreviewer' => 'remove as reviewer', |
282 | 282 | 'ep-artciles-remarticle' => 'remove article', |
| 283 | + 'ep-artciles-addarticle-text' => 'Add an article:', |
| 284 | + 'ep-artciles-addarticle-button' => 'Add article', |
| 285 | + 'ep-artciles-becomereviewer' => 'Add myself as reviewer', |
283 | 286 | |
284 | 287 | // Article pager |
285 | 288 | 'ep-articles-noresults' => 'There are no articles to list.', |