https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111851

Revision: 111851
Author:   jeroendedauw
Date:     2012-02-19 01:36:17 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
work on article table

Modified Paths:
--------------
    trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
    trunk/extensions/EducationProgram/includes/EPArticleTable.php

Modified: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPAddArticleAction.php    
2012-02-19 01:08:32 UTC (rev 111850)
+++ trunk/extensions/EducationProgram/actions/EPAddArticleAction.php    
2012-02-19 01:36:17 UTC (rev 111851)
@@ -32,21 +32,27 @@
                $user = $this->getUser();
 
                $salt = 'addarticle' . $req->getInt( 'course-id' );
+               $title = Title::newFromText( $req->getText( 'addarticlename' ) 
);
 
-               if ( $user->matchEditToken( $req->getText( 'token' ), $salt )
-                       && $user->isAllowed( 'ep-student' ) ) {
-
-                       $articleData = array(
-                               'user_id' => $user->getId(),
-                               'course_id' => $req->getInt( 'course-id' ),
-                               'page_id' => '',
+               if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) 
&& !is_null( $title ) && $title->getArticleID() !== 0 ) {
+                       $course = EPCourses::singleton()->selectRow(
+                               array( 'students' ),
+                               array( 'id' => $req->getInt( 'course-id' ) )
                        );
 
-                       if ( !EPArticles::singleton()->has( $articleData ) ) {
-                               $article = 
EPArticles::singleton()->newFromArray( $articleData, true );
+                       if ( $course !== false && in_array( $user->getId(), 
$course->getField( 'students' ) ) ) {
+                               $articleData = array(
+                                       'user_id' => $user->getId(),
+                                       'course_id' => $req->getInt( 
'course-id' ),
+                                       'page_id' => $title->getArticleID(),
+                               );
 
-                               if ( $article->save() ) {
-                                       // TODO: log
+                               if ( !EPArticles::singleton()->has( 
$articleData ) ) {
+                                       $article = 
EPArticles::singleton()->newFromArray( $articleData, true );
+
+                                       if ( $article->save() ) {
+                                               // TODO: log
+                                       }
                                }
                        }
                }

Modified: trunk/extensions/EducationProgram/includes/EPArticleTable.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticleTable.php       
2012-02-19 01:08:32 UTC (rev 111850)
+++ trunk/extensions/EducationProgram/includes/EPArticleTable.php       
2012-02-19 01:36:17 UTC (rev 111851)
@@ -99,7 +99,7 @@
                $user = $this->getUser();
 
                $rowCount = array_reduce( $articles, function( /* integer */ 
$sum, EPArticle $article ) use ( $user ) {
-                       $sum += count( $article->getField( 'reviewers' ) );
+                       $sum += max( count( $article->getField( 'reviewers' ) 
), 1 );
 
                        if ( $article->canBecomeReviewer( $user ) ) {
                                $sum++;
@@ -111,7 +111,7 @@
                $html = Html::openElement( 'tr', $this->getRowAttrs( $row ) );
 
                $showArticleAdittion =
-                       $this->getUser()->getId() === $student->getField( 
'user_id' )
+                       $user->getId() === $student->getField( 'user_id' )
                        && array_key_exists( 'course_id', $this->articleConds )
                        && is_integer( $this->articleConds['course_id'] );
 
@@ -174,6 +174,9 @@
 
                                $html .= $this->getReviewerAdittionControl( 
$article );
                        }
+                       else if ( count( $reviewers ) === 0 ) {
+                               $html .= '<td></td>';
+                       }
                }
 
                if ( $showArticleAdittion ) {
@@ -377,38 +380,34 @@
        protected function getArticleAdittionControl( $courseId ) {
                $html = '';
 
-               if ( $this->getUser()->isAllowed( 'ep-student' )
-                       && $this->getUser()->getId() === 
$this->currentObject->getField( 'user_id' ) ) {
+               $html .= Html::openElement(
+                       'form',
+                       array(
+                               'method' => 'post',
+                               'action' => $this->getTitle()->getLocalURL( 
array( 'action' => 'epaddarticle' ) ),
+                       )
+               );
 
-                       $html .= Html::openElement(
-                               'form',
-                               array(
-                                       'method' => 'post',
-                                       'action' => 
$this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ),
-                               )
-                       );
+               $html .=  Xml::inputLabel(
+                       wfMsg( 'ep-artciles-addarticle-text' ),
+                       'addarticlename',
+                       'addarticlename'
+               );
 
-                       $html .=  Xml::inputLabel(
-                               wfMsg( 'ep-artciles-addarticle-text' ),
-                               'addarticlename',
-                               'addarticlename'
-                       );
+               $html .= '&#160;' . Html::input(
+                       'addarticle',
+                       wfMsg( 'ep-artciles-addarticle-button' ),
+                       'submit',
+                       array(
+                               'class' => 'ep-addarticle',
+                       )
+               );
 
-                       $html .= '&#160;' . Html::input(
-                               'addarticle',
-                               wfMsg( 'ep-artciles-addarticle-button' ),
-                               'submit',
-                               array(
-                                       'class' => 'ep-addarticle',
-                               )
-                       );
+               $html .= Html::hidden( 'course-id', $courseId );
+               $html .= Html::hidden( 'token', $this->getUser()->getEditToken( 
'addarticle' . $courseId ) );
 
-                       $html .= Html::hidden( 'token', 
$this->getUser()->getEditToken( 'addarticle' . $courseId ) );
+               $html .= '</form>';
 
-                       $html .= '</form>';
-               }
-
-
                return '<td colspan="2">' . $html . '</td>';
        }
 
@@ -487,10 +486,7 @@
                while( $student = $this->mResult->fetchObject() ) {
                        $field = EPStudents::singleton()->getPrefixedField( 
'user_id' );
                        $userIds[] = $student->$field;
-                       $this->articles[$student->$field] = array( // TODO
-                               EPArticles::singleton()->newFromArray( array( 
'page_id' => 1, 'user_id' => 1, 'reviewers' => array( 1, 1 ) ) ),
-                               EPArticles::singleton()->newFromArray( array( 
'page_id' => 2, 'user_id' => 1, 'reviewers' => array( 1, 1 ) ) ),
-                       );
+                       $this->articles[$student->$field] = array();
                }
 
                $conditions = array_merge( array( 'user_id' => $userIds ), 
$this->articleConds );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to