~ubuntu-branches/ubuntu/wily/phabricator/wily-proposed

« back to all changes in this revision

Viewing changes to phabricator/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2015-08-03 23:28:35 UTC
  • mfrom: (0.39.1) (0.38.1) (0.27.3) (2.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20150803232835-qnomusa964oxnywb
Tags: 0~git20150803-1
* New snapshot release (closes: #789760)
* renamed arcanist bash-completion file (closes: #791632)
* depends on same version for libphutil (closes: #794462)
* added php5-mysqlnd alternative depends (closes: #792136)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
final class PhabricatorSlowvoteVoteController
4
4
  extends PhabricatorSlowvoteController {
5
5
 
6
 
  private $id;
7
 
 
8
 
  public function willProcessRequest(array $data) {
9
 
    $this->id = $data['id'];
10
 
  }
11
 
 
12
 
  public function processRequest() {
13
 
    $request = $this->getRequest();
14
 
    $user = $request->getUser();
 
6
  public function handleRequest(AphrontRequest $request) {
 
7
    $viewer = $request->getViewer();
 
8
    $id = $request->getURIData('id');
15
9
 
16
10
    $poll = id(new PhabricatorSlowvoteQuery())
17
 
      ->setViewer($user)
18
 
      ->withIDs(array($this->id))
 
11
      ->setViewer($viewer)
 
12
      ->withIDs(array($id))
19
13
      ->needOptions(true)
20
14
      ->needViewerChoices(true)
21
15
      ->executeOne();
27
21
    }
28
22
 
29
23
    $options = $poll->getOptions();
30
 
    $user_choices = $poll->getViewerChoices($user);
 
24
    $viewer_choices = $poll->getViewerChoices($viewer);
31
25
 
32
 
    $old_votes = mpull($user_choices, null, 'getOptionID');
 
26
    $old_votes = mpull($viewer_choices, null, 'getOptionID');
33
27
 
34
28
    if ($request->isAjax()) {
35
29
      $vote = $request->getInt('vote');
50
44
        }
51
45
      }
52
46
 
53
 
      $this->updateVotes($user, $poll, $old_votes, $votes);
 
47
      $this->updateVotes($viewer, $poll, $old_votes, $votes);
54
48
 
55
49
      $updated_choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
56
50
        'pollID = %d AND authorPHID = %s',
57
51
        $poll->getID(),
58
 
        $user->getPHID());
 
52
        $viewer->getPHID());
59
53
 
60
54
      $embed = id(new SlowvoteEmbedView())
61
55
        ->setPoll($poll)
76
70
    $votes = $request->getArr('vote');
77
71
    $votes = array_fuse($votes, $votes);
78
72
 
79
 
    $this->updateVotes($user, $poll, $old_votes, $votes);
 
73
    $this->updateVotes($viewer, $poll, $old_votes, $votes);
80
74
 
81
75
    return id(new AphrontRedirectResponse())->setURI('/V'.$poll->getID());
82
76
  }
83
77
 
84
 
  private function updateVotes($user, $poll, $old_votes, $votes) {
 
78
  private function updateVotes($viewer, $poll, $old_votes, $votes) {
85
79
    if (!empty($votes) && count($votes) > 1 &&
86
80
        $poll->getMethod() == PhabricatorSlowvotePoll::METHOD_PLURALITY) {
87
81
      return id(new Aphront400Response());
99
93
      }
100
94
 
101
95
      id(new PhabricatorSlowvoteChoice())
102
 
        ->setAuthorPHID($user->getPHID())
 
96
        ->setAuthorPHID($viewer->getPHID())
103
97
        ->setPollID($poll->getID())
104
98
        ->setOptionID($vote)
105
99
        ->save();