r111813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111812‎ | r111813 | r111814 >
Date:02:46, 18 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on article table
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticle.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticleTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php
@@ -83,16 +83,31 @@
8484
8585 $student = $this->currentObject;
8686 $articles = $this->articles[$student->getField( 'user_id' )];
 87+ $user = $this->getUser();
8788
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;
9197 }, 0 );
9298
9399 $html = Html::openElement( 'tr', $this->getRowAttrs( $row ) );
94100
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'] );
96105
 106+ if ( $showArticleAdittion ) {
 107+ $rowCount++;
 108+ }
 109+
 110+ $html .= $this->getUserCell( $student->getField( 'user_id' ), $rowCount );
 111+
97112 $isFirst = true;
98113
99114 foreach ( $articles as /* EPArticle */ $article ) {
@@ -104,8 +119,16 @@
105120
106121 $reviewers = $article->getField( 'reviewers' );
107122
108 - $html .= $this->getArticleCell( $article, max( 1, count( $reviewers ) ) );
 123+ $articleRowCount = count( $reviewers );
109124
 125+ if ( $article->canBecomeReviewer( $user ) ) {
 126+ $articleRowCount++;
 127+ }
 128+
 129+ $articleRowCount = max( 1, $articleRowCount );
 130+
 131+ $html .= $this->getArticleCell( $article, $articleRowCount );
 132+
110133 foreach ( $reviewers as $nr => $userId ) {
111134 if ( $nr !== 0 ) {
112135 $html .= '</tr><tr>';
@@ -114,11 +137,23 @@
115138 $html .= $this->getReviewerCell( $article, $userId );
116139 }
117140
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+ }
119148 }
120149
121 - // TODO: add article adittion control for student
 150+ if ( $showArticleAdittion ) {
 151+ if ( !$isFirst ) {
 152+ $html .= '</tr><tr>';
 153+ }
122154
 155+ $html .= $this->getArticleAdittionControl( $this->articleConds['course_id'] );
 156+ }
 157+
123158 $html .= '</tr>';
124159
125160 return $html;
@@ -269,20 +304,51 @@
270305 );
271306 }
272307
273 - protected function addArticleRemovalControl() {
 308+ protected function getArticleAdittionControl( $courseId ) {
 309+ $html = '';
274310
275 - }
 311+ $html .= Html::openElement(
 312+ 'form',
 313+ array(
 314+ 'method' => 'post',
 315+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'addarticle' ) ),
 316+ )
 317+ );
276318
277 - protected function addReviwerRemovalControl() {
 319+ $html .= Xml::inputLabel(
 320+ wfMsg( 'ep-artciles-addarticle-text' ),
 321+ 'addarticlename',
 322+ 'addarticlename'
 323+ );
278324
279 - }
 325+ $html .= '&#160;' . Html::input(
 326+ 'addarticle',
 327+ wfMsg( 'ep-artciles-addarticle-button' ),
 328+ 'submit',
 329+ array(
 330+ 'class' => 'ep-addarticle',
 331+ )
 332+ );
280333
281 - protected function addArticleAdittionControl() {
 334+ $html .= Html::hidden( 'addArticleToken', $this->getUser()->getEditToken( 'addarticle' . $courseId ) );
282335
 336+ $html .= '</form>';
 337+
 338+ return '<td colspan="2">' . $html . '</td>';
283339 }
284340
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+ );
286351
 352+ return '<td>' . $html . '</td>';
287353 }
288354
289355 /**
Index: trunk/extensions/EducationProgram/includes/EPArticle.php
@@ -86,4 +86,17 @@
8787 return $this->title;
8888 }
8989
 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+
90103 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -279,6 +279,9 @@
280280 'ep-artciles-remreviewer-self' => 'Remove myself as reviewer',
281281 'ep-artciles-remreviewer' => 'remove as reviewer',
282282 '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',
283286
284287 // Article pager
285288 'ep-articles-noresults' => 'There are no articles to list.',

Status & tagging log