Niharika29 has uploaded a new change for review. https://gerrit.wikimedia.org/r/196288
Change subject: [WIP] Update reviews system ...................................................................... [WIP] Update reviews system Bug: T92442 Change-Id: I22d88b957a7040031ca79827077861a994594aef --- M data/templates/proposals/view_review_edit.html M src/App.php M src/Controllers/Proposals/Review.php M src/Controllers/Proposals/View.php M src/Dao/Reviews.php 5 files changed, 70 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/iegreview refs/changes/88/196288/1 diff --git a/data/templates/proposals/view_review_edit.html b/data/templates/proposals/view_review_edit.html index 6355390..5748d16 100644 --- a/data/templates/proposals/view_review_edit.html +++ b/data/templates/proposals/view_review_edit.html @@ -3,17 +3,21 @@ {% import _self as local %} {% set ctx = _context %} -{% macro criteria( review, name, ctx ) %} +{% macro criteria( review, ques, name, ctx ) %} {% set msgprefix = "review-#{name}" %} {% set opts = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] %} {% set r = review[name] %} <section class="panel panel-default"> <div class="panel-heading"> - <h4 class="panel-title"><a href="//meta.wikimedia.org/wiki/Grants:IEG/Committee/Workroom#review-rubric" target="_blank">{{ msgprefix|message }}</a></h4> + <h4 class="panel-title"> +<!-- <a href="//meta.wikimedia.org/wiki/Grants:IEG/Committee/Workroom#review-rubric" target="_blank">--> +{{ msgprefix|message }} +<!-- </a>--> + </h4> </div> <div class="panel-body"> - {{ "#{msgprefix}-instructions"|message|raw|wikitext }} - {{ ctx.forms.radioList( ctx, "#{msgprefix}-rank", name, { + {{ ques.question }} + {{ ctx.forms.radioList( ctx, "#{msgprefix}-rank", "points[#{ques.id}]", { 1:'review-rank-1', 2:'review-rank-2', 3:'review-rank-3', @@ -27,7 +31,8 @@ }, { 'required':true, 'value':r } ) }} <div class="form-group"> <label for="{{ "#{name}_note" }}" class="control-label">{{ "#{msgprefix}-note"|message }}</label> - <textarea name="{{ "#{name}_note" }}" class="form-control">{{ review["#{name}_note"] }}</textarea> +<!-- <textarea name="{{ "#{name}_note" }}" class="form-control">{{ review["#{name}_note"] }}</textarea>--> + <textarea name="notes[{{ ques.id }}]" class="form-control">{{ review["#{name}_note"] }}</textarea> </div> </div> </section> @@ -47,10 +52,11 @@ <form method="post" action="{{ urlFor( 'proposals_review_post', { 'id': proposal.id } ) }}"> <input type="hidden" name="{{ csrf_param }}" value="{{ csrf_token }}" /> <input type="hidden" name="proposal" value="{{ proposal.id }}" /> - {{ local.criteria( myreview, 'impact', ctx ) }} - {{ local.criteria( myreview, 'innovation', ctx ) }} - {{ local.criteria( myreview, 'ability', ctx ) }} - {{ local.criteria( myreview, 'engagement', ctx ) }} + + {% for q in questions %} + {{ local.criteria( myreview, q, 'impact', ctx ) }} + {% endfor %} + <section class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title">{{ 'review-recommendation'|message }}</h4> diff --git a/src/App.php b/src/App.php index 472e19a..78ed08f 100644 --- a/src/App.php +++ b/src/App.php @@ -494,6 +494,7 @@ $page = new Controllers\Proposals\View( $slim ); $page->setDao( $slim->proposalsDao ); $page->setReviewsDao( $slim->reviewsDao ); + $page->setCampaignsDao( $slim->campaignsDao ); $page( $id ); } )->name( 'proposals_view' ); } diff --git a/src/Controllers/Proposals/Review.php b/src/Controllers/Proposals/Review.php index a5e8d87..aad39ac 100644 --- a/src/Controllers/Proposals/Review.php +++ b/src/Controllers/Proposals/Review.php @@ -35,33 +35,21 @@ protected function handlePost( $id ) { $this->form->requireInt( 'proposal' ); - $this->form->requireInt( 'impact' ); - $this->form->expectString( 'impact_note' ); - $this->form->requireInt( 'innovation' ); - $this->form->expectString( 'innovation_note' ); - $this->form->requireInt( 'ability' ); - $this->form->expectString( 'ability_note' ); - $this->form->requireInt( 'engagement' ); - $this->form->expectString( 'engagement_note' ); + $this->form->expectIntArray( 'points' ); + $this->form->expectStringArray( 'notes' ); $this->form->requireInt( 'recommendation' ); $this->form->expectString( 'comments' ); if ( $this->form->validate() ) { $review = array( 'proposal' => $this->form->get( 'proposal' ), - 'impact' => $this->form->get( 'impact' ), - 'impact_note' => $this->form->get( 'impact_note' ), - 'innovation' => $this->form->get( 'innovation' ), - 'innovation_note' => $this->form->get( 'innovation_note' ), - 'ability' => $this->form->get( 'ability' ), - 'ability_note' => $this->form->get( 'ability_note' ), - 'engagement' => $this->form->get( 'engagement' ), - 'engagement_note' => $this->form->get( 'engagement_note' ), + 'points' => $this->form->get( 'points' ), + 'notes' => $this->form->get( 'notes' ), 'recommendation' => $this->form->get( 'recommendation' ), 'comments' => $this->form->get( 'comments' ), ); - $ok = $this->dao->saveReview( $review ); + $ok = $this->dao->insertOrUpdateReview( $review ); if ( $ok ) { $this->flash( 'info', $this->msg( 'review-edit-save' ) ); diff --git a/src/Controllers/Proposals/View.php b/src/Controllers/Proposals/View.php index a610fc3..15cfdd8 100644 --- a/src/Controllers/Proposals/View.php +++ b/src/Controllers/Proposals/View.php @@ -38,13 +38,25 @@ */ protected $reviewsDao; + + /** + * @var \Wikimedia\IEGReview\Dao\AbstractDao $dao + */ + protected $campaignsDao; + public function setReviewsDao( $dao ) { $this->reviewsDao = $dao; } + public function setCampaignsDao( $dao ) { + $this->campaignsDao = $dao; + } + protected function handleGet( $id ) { $proposal = $this->dao->getProposal( $id ); + $questions = $this->campaignsDao->getQuestions( $this->activeCampaign ); $this->view->setData( 'proposal', $proposal ); + $this->view->setData( 'questions', $questions ); if ( $this->authManager->isReviewer() ) { $myReview = $this->reviewsDao->reviewByUser( $id ); diff --git a/src/Dao/Reviews.php b/src/Dao/Reviews.php index 7d196a1..b0dd5a0 100644 --- a/src/Dao/Reviews.php +++ b/src/Dao/Reviews.php @@ -51,6 +51,7 @@ $this->userId = $uid; } + public function saveReview( array $data ) { $review = $this->reviewByUser( $data['proposal'] ); if ( $review ) { @@ -58,6 +59,34 @@ } else { return $this->createReview( $data ); } + } + + public function insertOrUpdateReview( array $data ) { + $comments = $data['notes']; + $points = $data['points']; + $reviewer = $this->userId; + $cols = array( 'proposal', 'question', 'reviewer', 'points', 'comments' ); + $params = self::makeBindParams( $cols ); + + foreach( $comments as $id => $value ) { + $sql = self::concat( + 'INSERT INTO review_answers(', + implode( ', ', $cols ), + ') VALUES (', + implode( ', ', $params ), + ') ON DUPLICATE KEY UPDATE', + 'points = :points, comments = :comments' + ); + $values = array( + 'points' => $points[$id], + 'comments' => $value, + 'proposal' => $data['proposal'], + 'question' => $id, + 'reviewer' => $reviewer + ); + $this->insert( $sql, $values ); + } + return true; } /** @@ -69,7 +98,7 @@ public function reviewByUser( $proposal ) { $sql = self::concat( 'SELECT *', - 'FROM reviews', + 'FROM review_answers', 'WHERE proposal = :proposal', 'AND reviewer = :reviewer' ); @@ -123,6 +152,13 @@ return $this->update( $sql, $data ); } + /* + public function insertOrUpdateReview( array $data ) { + $sql = self::concat( + 'INSERT INTO review_answers', + '' + }*/ + public function getReview( $id ) { return $this->fetch( 'SELECT * FROM reviews WHERE id = ?', -- To view, visit https://gerrit.wikimedia.org/r/196288 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I22d88b957a7040031ca79827077861a994594aef Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/iegreview Gerrit-Branch: master Gerrit-Owner: Niharika29 <niharikakohl...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits