Index: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php |
— | — | @@ -32,21 +32,27 @@ |
33 | 33 | $user = $this->getUser(); |
34 | 34 | |
35 | 35 | $salt = 'addarticle' . $req->getInt( 'course-id' ); |
| 36 | + $title = Title::newFromText( $req->getText( 'addarticlename' ) ); |
36 | 37 | |
37 | | - if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) |
38 | | - && $user->isAllowed( 'ep-student' ) ) { |
39 | | - |
40 | | - $articleData = array( |
41 | | - 'user_id' => $user->getId(), |
42 | | - 'course_id' => $req->getInt( 'course-id' ), |
43 | | - 'page_id' => '', |
| 38 | + if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) && !is_null( $title ) && $title->getArticleID() !== 0 ) { |
| 39 | + $course = EPCourses::singleton()->selectRow( |
| 40 | + array( 'students' ), |
| 41 | + array( 'id' => $req->getInt( 'course-id' ) ) |
44 | 42 | ); |
45 | 43 | |
46 | | - if ( !EPArticles::singleton()->has( $articleData ) ) { |
47 | | - $article = EPArticles::singleton()->newFromArray( $articleData, true ); |
| 44 | + if ( $course !== false && in_array( $user->getId(), $course->getField( 'students' ) ) ) { |
| 45 | + $articleData = array( |
| 46 | + 'user_id' => $user->getId(), |
| 47 | + 'course_id' => $req->getInt( 'course-id' ), |
| 48 | + 'page_id' => $title->getArticleID(), |
| 49 | + ); |
48 | 50 | |
49 | | - if ( $article->save() ) { |
50 | | - // TODO: log |
| 51 | + if ( !EPArticles::singleton()->has( $articleData ) ) { |
| 52 | + $article = EPArticles::singleton()->newFromArray( $articleData, true ); |
| 53 | + |
| 54 | + if ( $article->save() ) { |
| 55 | + // TODO: log |
| 56 | + } |
51 | 57 | } |
52 | 58 | } |
53 | 59 | } |
Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | $user = $this->getUser(); |
101 | 101 | |
102 | 102 | $rowCount = array_reduce( $articles, function( /* integer */ $sum, EPArticle $article ) use ( $user ) { |
103 | | - $sum += count( $article->getField( 'reviewers' ) ); |
| 103 | + $sum += max( count( $article->getField( 'reviewers' ) ), 1 ); |
104 | 104 | |
105 | 105 | if ( $article->canBecomeReviewer( $user ) ) { |
106 | 106 | $sum++; |
— | — | @@ -111,7 +111,7 @@ |
112 | 112 | $html = Html::openElement( 'tr', $this->getRowAttrs( $row ) ); |
113 | 113 | |
114 | 114 | $showArticleAdittion = |
115 | | - $this->getUser()->getId() === $student->getField( 'user_id' ) |
| 115 | + $user->getId() === $student->getField( 'user_id' ) |
116 | 116 | && array_key_exists( 'course_id', $this->articleConds ) |
117 | 117 | && is_integer( $this->articleConds['course_id'] ); |
118 | 118 | |
— | — | @@ -174,6 +174,9 @@ |
175 | 175 | |
176 | 176 | $html .= $this->getReviewerAdittionControl( $article ); |
177 | 177 | } |
| 178 | + else if ( count( $reviewers ) === 0 ) { |
| 179 | + $html .= '<td></td>'; |
| 180 | + } |
178 | 181 | } |
179 | 182 | |
180 | 183 | if ( $showArticleAdittion ) { |
— | — | @@ -377,38 +380,34 @@ |
378 | 381 | protected function getArticleAdittionControl( $courseId ) { |
379 | 382 | $html = ''; |
380 | 383 | |
381 | | - if ( $this->getUser()->isAllowed( 'ep-student' ) |
382 | | - && $this->getUser()->getId() === $this->currentObject->getField( 'user_id' ) ) { |
| 384 | + $html .= Html::openElement( |
| 385 | + 'form', |
| 386 | + array( |
| 387 | + 'method' => 'post', |
| 388 | + 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ), |
| 389 | + ) |
| 390 | + ); |
383 | 391 | |
384 | | - $html .= Html::openElement( |
385 | | - 'form', |
386 | | - array( |
387 | | - 'method' => 'post', |
388 | | - 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ), |
389 | | - ) |
390 | | - ); |
| 392 | + $html .= Xml::inputLabel( |
| 393 | + wfMsg( 'ep-artciles-addarticle-text' ), |
| 394 | + 'addarticlename', |
| 395 | + 'addarticlename' |
| 396 | + ); |
391 | 397 | |
392 | | - $html .= Xml::inputLabel( |
393 | | - wfMsg( 'ep-artciles-addarticle-text' ), |
394 | | - 'addarticlename', |
395 | | - 'addarticlename' |
396 | | - ); |
| 398 | + $html .= ' ' . Html::input( |
| 399 | + 'addarticle', |
| 400 | + wfMsg( 'ep-artciles-addarticle-button' ), |
| 401 | + 'submit', |
| 402 | + array( |
| 403 | + 'class' => 'ep-addarticle', |
| 404 | + ) |
| 405 | + ); |
397 | 406 | |
398 | | - $html .= ' ' . Html::input( |
399 | | - 'addarticle', |
400 | | - wfMsg( 'ep-artciles-addarticle-button' ), |
401 | | - 'submit', |
402 | | - array( |
403 | | - 'class' => 'ep-addarticle', |
404 | | - ) |
405 | | - ); |
| 407 | + $html .= Html::hidden( 'course-id', $courseId ); |
| 408 | + $html .= Html::hidden( 'token', $this->getUser()->getEditToken( 'addarticle' . $courseId ) ); |
406 | 409 | |
407 | | - $html .= Html::hidden( 'token', $this->getUser()->getEditToken( 'addarticle' . $courseId ) ); |
| 410 | + $html .= '</form>'; |
408 | 411 | |
409 | | - $html .= '</form>'; |
410 | | - } |
411 | | - |
412 | | - |
413 | 412 | return '<td colspan="2">' . $html . '</td>'; |
414 | 413 | } |
415 | 414 | |
— | — | @@ -487,10 +486,7 @@ |
488 | 487 | while( $student = $this->mResult->fetchObject() ) { |
489 | 488 | $field = EPStudents::singleton()->getPrefixedField( 'user_id' ); |
490 | 489 | $userIds[] = $student->$field; |
491 | | - $this->articles[$student->$field] = array( // TODO |
492 | | - EPArticles::singleton()->newFromArray( array( 'page_id' => 1, 'user_id' => 1, 'reviewers' => array( 1, 1 ) ) ), |
493 | | - EPArticles::singleton()->newFromArray( array( 'page_id' => 2, 'user_id' => 1, 'reviewers' => array( 1, 1 ) ) ), |
494 | | - ); |
| 490 | + $this->articles[$student->$field] = array(); |
495 | 491 | } |
496 | 492 | |
497 | 493 | $conditions = array_merge( array( 'user_id' => $userIds ), $this->articleConds ); |