r111707 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111706‎ | r111707 | r111708 >
Date:01:03, 17 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on student article table
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticleTable.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php
@@ -14,6 +14,24 @@
1515 class EPArticleTable extends EPPager {
1616
1717 /**
 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+ /**
1836 * Constructor.
1937 *
2038 * @param IContextSource $context
@@ -55,29 +73,90 @@
5674 return 'TablePager ep-students';
5775 }
5876
 77+ protected $currentArticleKey = 0;
 78+
 79+
5980 /**
6081 * (non-PHPdoc)
61 - * @see EPPager::getFormattedValue()
 82+ * @see TablePager::formatRow()
6283 */
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 );
6887
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+ }
75131 }
76132
77 - return $value;
 133+ $html .= '</tr>';
 134+
 135+ return $html;
78136 }
79137
 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+
80153 /**
81154 * (non-PHPdoc)
 155+ * @see EPPager::getFormattedValue()
 156+ */
 157+ protected function getFormattedValue( $name, $value ) { /* ... */ }
 158+
 159+ /**
 160+ * (non-PHPdoc)
82161 * @see EPPager::getSortableFields()
83162 */
84163 protected function getSortableFields() {
@@ -100,15 +179,15 @@
101180 public function getFieldNames() {
102181 $fields = parent::getFieldNames();
103182
 183+ unset( $fields['id'] );
 184+
 185+ $fields['user_id'] = 'student';
104186 $fields['_articles'] = 'articles';
 187+ $fields['_reviewers'] = 'reviewers';
105188
106189 return $fields;
107190 }
108191
109 - protected $articles = array();
110 -
111 - protected $articleConds;
112 -
113192 /**
114193 * (non-PHPdoc)
115194 * @see IndexPager::doBatchLookups()
@@ -119,7 +198,10 @@
120199 while( $student = $this->mResult->fetchObject() ) {
121200 $field = EPStudents::singleton()->getPrefixedField( 'user_id' );
122201 $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+ );
124206 }
125207
126208 $conditions = array_merge( array( 'user_id' => $userIds ), $this->articleConds );
Index: trunk/extensions/EducationProgram/includes/EPPager.php
@@ -65,6 +65,7 @@
6666 * @see TablePager::formatRow()
6767 */
6868 function formatRow( $row ) {
 69+ $this->mCurrentRow = $row;
6970 $this->currentObject = $this->table->newFromDBResult( $row );
7071
7172 $cells = array();
@@ -322,8 +323,6 @@
323324 $controls = array();
324325
325326 foreach ( $filterOptions as $optionName => $optionData ) {
326 -
327 -
328327 switch ( $optionData['type'] ) {
329328 case 'select':
330329 $select = new XmlSelect(
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -272,7 +272,9 @@
273273 'epstudentpager-no' => 'No',
274274
275275 // Student article pager
 276+ 'epstudentpager-header-student' => 'Student',
276277 'epstudentpager-header-articles' => 'Articles',
 278+ 'epstudentpager-header-reviewers' => 'Reviewers',
277279
278280 // Article pager
279281 'ep-articles-noresults' => 'There are no articles to list.',

Status & tagging log