Christopher Johnson (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/181886

Change subject: adds SprintPoints
......................................................................

adds SprintPoints

replaces taskpoints ref calls with a new join query to customfields to
retrieve points
removes 'in project' check for transactions to improve performance
refactors SumStatusPoints from TasksTable  into SprintPoints

Change-Id: I660007ccc83323eba98d1415f15c9a9a64ff3a4d
---
M src/__phutil_library_map__.php
M src/constants/SprintConstants.php
M src/customfield/SprintTaskStoryPointsField.php
M src/query/SprintQuery.php
M src/storage/SprintBuildStats.php
D src/storage/SprintTask.php
M src/storage/SprintTransaction.php
A src/util/SprintPoints.php
M src/view/SprintBoardTaskCard.php
R src/view/burndown/EventTableView.php
R src/view/burndown/HistoryTableView.php
R src/view/burndown/SprintDataView.php
R src/view/burndown/SprintTableView.php
R src/view/burndown/TasksTableView.php
R src/view/reports/OpenTasksView.php
R src/view/reports/ProjectOpenTasksView.php
R src/view/reports/SprintReportBurndownView.php
R src/view/reports/SprintReportOpenTasksView.php
R src/view/reports/UserOpenTasksView.php
19 files changed, 215 insertions(+), 500 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint 
refs/changes/86/181886/1

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index 1a07ca8..7b4ed80 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -16,11 +16,11 @@
     'BurndownException' => 'exception/BurndownException.php',
     'CeleritySprintResources' => 'celerity/CeleritySprintResources.php',
     'DateIterator' => 'tests/DateIterator.php',
-    'EventTableView' => 'view/EventTableView.php',
-    'HistoryTableView' => 'view/HistoryTableView.php',
-    'OpenTasksView' => 'view/OpenTasksView.php',
+    'EventTableView' => 'view/burndown/EventTableView.php',
+    'HistoryTableView' => 'view/burndown/HistoryTableView.php',
+    'OpenTasksView' => 'view/reports/OpenTasksView.php',
     'PhabricatorFactSprintEngine' => 'fact/PhabricatorFactSprintEngine.php',
-    'ProjectOpenTasksView' => 'view/ProjectOpenTasksView.php',
+    'ProjectOpenTasksView' => 'view/reports/ProjectOpenTasksView.php',
     'SprintApplication' => 'application/SprintApplication.php',
     'SprintApplicationTest' => 'tests/SprintApplicationTest.php',
     'SprintBeginDateField' => 'customfield/SprintBeginDateField.php',
@@ -39,23 +39,23 @@
     'SprintConstants' => 'constants/SprintConstants.php',
     'SprintController' => 'controller/SprintController.php',
     'SprintControllerTest' => 'tests/SprintControllerTest.php',
-    'SprintCustomDateFieldTest' => 'tests/SprintCustomFieldTest.php',
+    'SprintCustomFieldTest' => 'tests/SprintCustomFieldTest.php',
     'SprintDAO' => 'storage/SprintDAO.php',
-    'SprintDataView' => 'view/SprintDataView.php',
+    'SprintDataView' => 'view/burndown/SprintDataView.php',
     'SprintDataViewController' => 'controller/SprintDataViewController.php',
     'SprintDefaultViewCapability' => 
'capability/SprintDefaultViewCapability.php',
     'SprintEndDateField' => 'customfield/SprintEndDateField.php',
     'SprintFactDaemon' => 'fact/SprintFactDaemon.php',
     'SprintFactUpdateIterator' => 'fact/SprintFactUpdateIterator.php',
     'SprintListController' => 'controller/SprintListController.php',
+    'SprintPoints' => 'util/SprintPoints.php',
     'SprintProjectCustomField' => 'customfield/SprintProjectCustomField.php',
     'SprintQuery' => 'query/SprintQuery.php',
     'SprintQueryTest' => 'tests/SprintQueryTest.php',
-    'SprintReportBurndownView' => 'view/SprintReportBurndownView.php',
+    'SprintReportBurndownView' => 'view/reports/SprintReportBurndownView.php',
     'SprintReportController' => 'controller/SprintReportController.php',
-    'SprintReportOpenTasksView' => 'view/SprintReportOpenTasksView.php',
-    'SprintTableView' => 'view/SprintTableView.php',
-    'SprintTask' => 'storage/SprintTask.php',
+    'SprintReportOpenTasksView' => 
'view/reports/SprintReportOpenTasksView.php',
+    'SprintTableView' => 'view/burndown/SprintTableView.php',
     'SprintTaskStoryPointsField' => 
'customfield/SprintTaskStoryPointsField.php',
     'SprintTestCase' => 'tests/SprintTestCase.php',
     'SprintTransaction' => 'storage/SprintTransaction.php',
@@ -63,8 +63,8 @@
     'SprintUIInterface' => 'controller/SprintUIInterface.php',
     'SprintValidator' => 'util/SprintValidator.php',
     'SprintView' => 'view/SprintView.php',
-    'TasksTableView' => 'view/TasksTableView.php',
-    'UserOpenTasksView' => 'view/UserOpenTasksView.php',
+    'TasksTableView' => 'view/burndown/TasksTableView.php',
+    'UserOpenTasksView' => 'view/reports/UserOpenTasksView.php',
     'ViewController' => 'controller/ViewController.php',
   ),
   'function' => array(),
@@ -91,7 +91,7 @@
     'SprintBuildStatsTest' => 'SprintTestCase',
     'SprintController' => 'PhabricatorController',
     'SprintControllerTest' => 'SprintTestCase',
-    'SprintCustomDateFieldTest' => 'SprintTestCase',
+    'SprintCustomFieldTest' => 'SprintTestCase',
     'SprintDAO' => 'PhabricatorLiskDAO',
     'SprintDataView' => 'SprintView',
     'SprintDataViewController' => 'SprintController',
@@ -109,19 +109,6 @@
     'SprintReportBurndownView' => 'SprintView',
     'SprintReportController' => 'SprintController',
     'SprintReportOpenTasksView' => 'SprintView',
-    'SprintTask' => array(
-      'SprintDAO',
-      'PhabricatorMarkupInterface',
-      'PhabricatorPolicyInterface',
-      'PhabricatorTokenReceiverInterface',
-      'PhabricatorFlaggableInterface',
-      'PhabricatorMentionableInterface',
-      'PhrequentTrackableInterface',
-      'PhabricatorCustomFieldInterface',
-      'PhabricatorDestructibleInterface',
-      'PhabricatorApplicationTransactionInterface',
-      'PhabricatorProjectInterface',
-    ),
     'SprintTaskStoryPointsField' => array(
       'ManiphestCustomField',
       'PhabricatorStandardCustomFieldInterface',
diff --git a/src/constants/SprintConstants.php 
b/src/constants/SprintConstants.php
index f9e2714..4a78fd1 100644
--- a/src/constants/SprintConstants.php
+++ b/src/constants/SprintConstants.php
@@ -7,4 +7,5 @@
   const PHABRICATOR_ROOT_DIR = 'vendor/phabricator/phabricator';
   const LIBPHUTIL_ROOT_DIR = 'vendor/libphutil/libphutil';
   const ROOT_DIR = '/srv/phab';
+  const CUSTOMFIELD_INDEX = 'yERhvoZPNPtM';
 } 
\ No newline at end of file
diff --git a/src/customfield/SprintTaskStoryPointsField.php 
b/src/customfield/SprintTaskStoryPointsField.php
index 123c204..e1cc69f 100644
--- a/src/customfield/SprintTaskStoryPointsField.php
+++ b/src/customfield/SprintTaskStoryPointsField.php
@@ -5,7 +5,8 @@
  */
 
 final class SprintTaskStoryPointsField extends ManiphestCustomField
-  implements PhabricatorStandardCustomFieldInterface {
+  implements
+    PhabricatorStandardCustomFieldInterface {
 
   private $obj;
   private $text_proxy;
diff --git a/src/query/SprintQuery.php b/src/query/SprintQuery.php
index ba493c4..dfd6c13 100644
--- a/src/query/SprintQuery.php
+++ b/src/query/SprintQuery.php
@@ -71,6 +71,20 @@
      return $points;
   }
 
+  private function getTaskPoints($task_phid) {
+    $taskpoints = mpull($this->taskpoints, null, 'getObjectPHID');
+    if (!empty($taskpoints)) {
+      foreach ($taskpoints as $key=>$value) {
+        if ($key == $task_phid) {
+          $points = $value->getfieldValue();
+        }
+      }
+      if (!isset($points)) {
+        $points = '0';
+      }
+    }
+    return $points;
+  }
 
   public function getXactions($tasks) {
     $task_phids = mpull($tasks, 'getPHID');
@@ -103,6 +117,16 @@
     return $conn;
   }
 
+  public function getCustomFieldObj () {
+    $table = new ManiphestCustomFieldStorage();
+    return $table;
+  }
+
+  public function getCustomFieldConn () {
+    $conn = $this->getCustomFieldObj()->establishConnection('r');
+    return $conn;
+  }
+
   public function getJoins() {
 
     $joins = '';
@@ -110,6 +134,22 @@
       $joins = qsprintf(
           $this->getXactionConn(),
           'JOIN %T t ON x.objectPHID = t.phid
+          JOIN %T p ON p.src = t.phid AND p.type = %d AND p.dst = %s',
+          id(new ManiphestTask())->getTableName(),
+          PhabricatorEdgeConfig::TABLE_NAME_EDGE,
+          PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
+          $this->project_phid);
+    }
+    return $joins;
+  }
+
+  public function getCustomFieldJoins() {
+
+    $joins = '';
+    if ($this->project_phid) {
+      $joins = qsprintf(
+          $this->getCustomFieldConn(),
+          'JOIN %T t ON f.objectPHID = t.phid
           JOIN %T p ON p.src = t.phid AND p.type = %d AND p.dst = %s',
           id(new ManiphestTask())->getTableName(),
           PhabricatorEdgeConfig::TABLE_NAME_EDGE,
@@ -131,6 +171,18 @@
     return $data;
  }
 
+  public function getTaskData($where) {
+    $task_dao = new ManiphestCustomFieldStorage();
+    $data = queryfx_all(
+        $this->getCustomFieldConn(),
+        'SELECT f.* FROM %T f %Q',
+        $this->getCustomFieldObj()->getTableName(),
+        $this->getCustomFieldJoins());
+
+    $task_data = $task_dao->loadAllFromArray($data);
+    return $task_data;
+  }
+
   public function getEdges ($tasks) {
     // Load all edges of depends and depended on tasks
     $edges = id(new PhabricatorEdgeQuery())
diff --git a/src/storage/SprintBuildStats.php b/src/storage/SprintBuildStats.php
index 5603f0a..7ecfc2f 100644
--- a/src/storage/SprintBuildStats.php
+++ b/src/storage/SprintBuildStats.php
@@ -235,14 +235,4 @@
     }
     return $data;
   }
-
-  public function setTaskOpenStatusSum ($task_open_status_sum, $points) {
-    $task_open_status_sum += $points;
-    return $task_open_status_sum;
-  }
-
-  public function setTaskClosedStatusSum ($task_closed_status_sum, $points) {
-    $task_closed_status_sum += $points;
-    return $task_closed_status_sum;
-  }
 }
diff --git a/src/storage/SprintTask.php b/src/storage/SprintTask.php
deleted file mode 100644
index 2bfa73b..0000000
--- a/src/storage/SprintTask.php
+++ /dev/null
@@ -1,385 +0,0 @@
-<?php
-
-final class SprintTask extends SprintDAO
-    implements
-    PhabricatorMarkupInterface,
-    PhabricatorPolicyInterface,
-    PhabricatorTokenReceiverInterface,
-    PhabricatorFlaggableInterface,
-    PhabricatorMentionableInterface,
-    PhrequentTrackableInterface,
-    PhabricatorCustomFieldInterface,
-    PhabricatorDestructibleInterface,
-    PhabricatorApplicationTransactionInterface,
-    PhabricatorProjectInterface {
-
-  const MARKUP_FIELD_DESCRIPTION = 'markup:desc';
-
-  protected $authorPHID;
-  protected $ownerPHID;
-  protected $ccPHIDs = array();
-
-  protected $status;
-
-  protected $priority;
-  protected $subpriority = 0;
-
-  protected $title = '';
-  protected $originalTitle = '';
-  protected $description = '';
-  protected $originalEmailSource;
-  protected $mailKey;
-  protected $viewPolicy = PhabricatorPolicies::POLICY_USER;
-  protected $editPolicy = PhabricatorPolicies::POLICY_USER;
-
-  protected $attached = array();
-  protected $projectPHIDs = array();
-  private $subscribersNeedUpdate;
-
-  protected $ownerOrdering;
-
-  private $groupByProjectPHID = self::ATTACHABLE;
-  private $customFields = self::ATTACHABLE;
-  private $edgeProjectPHIDs = self::ATTACHABLE;
-
-  public static function initializeNewTask(PhabricatorUser $actor) {
-    $app = id(new PhabricatorApplicationQuery())
-        ->setViewer($actor)
-        ->withClasses(array('PhabricatorManiphestApplication'))
-        ->executeOne();
-
-    $view_policy = $app->getPolicy(ManiphestDefaultViewCapability::CAPABILITY);
-    $edit_policy = $app->getPolicy(ManiphestDefaultEditCapability::CAPABILITY);
-
-    return id(new ManiphestTask())
-        ->setStatus(ManiphestTaskStatus::getDefaultStatus())
-        ->setPriority(ManiphestTaskPriority::getDefaultPriority())
-        ->setAuthorPHID($actor->getPHID())
-        ->setViewPolicy($view_policy)
-        ->setEditPolicy($edit_policy)
-        ->attachProjectPHIDs(array());
-  }
-
-  public function getConfiguration() {
-    return array(
-        self::CONFIG_AUX_PHID => true,
-        self::CONFIG_SERIALIZATION => array(
-            'ccPHIDs' => self::SERIALIZATION_JSON,
-            'attached' => self::SERIALIZATION_JSON,
-            'projectPHIDs' => self::SERIALIZATION_JSON,
-        ),
-        self::CONFIG_COLUMN_SCHEMA => array(
-            'ownerPHID' => 'phid?',
-            'status' => 'text12',
-            'priority' => 'uint32',
-            'title' => 'sort',
-            'originalTitle' => 'text',
-            'description' => 'text',
-            'mailKey' => 'bytes20',
-            'ownerOrdering' => 'text64?',
-            'originalEmailSource' => 'text255?',
-            'subpriority' => 'double',
-
-          // T6203/NULLABILITY
-          // This should not be nullable. It's going away soon anyway.
-            'ccPHIDs' => 'text?',
-
-        ),
-        self::CONFIG_KEY_SCHEMA => array(
-            'key_phid' => null,
-            'phid' => array(
-                'columns' => array('phid'),
-                'unique' => true,
-            ),
-            'priority' => array(
-                'columns' => array('priority', 'status'),
-            ),
-            'status' => array(
-                'columns' => array('status'),
-            ),
-            'ownerPHID' => array(
-                'columns' => array('ownerPHID', 'status'),
-            ),
-            'authorPHID' => array(
-                'columns' => array('authorPHID', 'status'),
-            ),
-            'ownerOrdering' => array(
-                'columns' => array('ownerOrdering'),
-            ),
-            'priority_2' => array(
-                'columns' => array('priority', 'subpriority'),
-            ),
-            'key_dateCreated' => array(
-                'columns' => array('dateCreated'),
-            ),
-            'key_dateModified' => array(
-                'columns' => array('dateModified'),
-            ),
-            'key_title' => array(
-                'columns' => array('title(64)'),
-            ),
-        ),
-    ) + parent::getConfiguration();
-  }
-
-  public function loadDependsOnTaskPHIDs() {
-    return PhabricatorEdgeQuery::loadDestinationPHIDs(
-        $this->getPHID(),
-        PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK);
-  }
-
-  public function loadDependedOnByTaskPHIDs() {
-    return PhabricatorEdgeQuery::loadDestinationPHIDs(
-        $this->getPHID(),
-        PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK);
-  }
-
-  public function getAttachedPHIDs($type) {
-    return array_keys(idx($this->attached, $type, array()));
-  }
-
-  public function generatePHID() {
-    return PhabricatorPHID::generateNewPHID(ManiphestTaskPHIDType::TYPECONST);
-  }
-
-  public function getCCPHIDs() {
-    return array_values(nonempty($this->ccPHIDs, array()));
-  }
-
-  public function getProjectPHIDs() {
-    return $this->assertAttached($this->edgeProjectPHIDs);
-  }
-
-  public function attachProjectPHIDs(array $phids) {
-    $this->edgeProjectPHIDs = $phids;
-    return $this;
-  }
-
-  public function setCCPHIDs(array $phids) {
-    $this->ccPHIDs = array_values($phids);
-    $this->subscribersNeedUpdate = true;
-    return $this;
-  }
-
-  public function setOwnerPHID($phid) {
-    $this->ownerPHID = nonempty($phid, null);
-    $this->subscribersNeedUpdate = true;
-    return $this;
-  }
-
-  public function setTitle($title) {
-    $this->title = $title;
-    if (!$this->getID()) {
-      $this->originalTitle = $title;
-    }
-    return $this;
-  }
-
-  public function getMonogram() {
-    return 'T'.$this->getID();
-  }
-
-  public function attachGroupByProjectPHID($phid) {
-    $this->groupByProjectPHID = $phid;
-    return $this;
-  }
-
-  public function getGroupByProjectPHID() {
-    return $this->assertAttached($this->groupByProjectPHID);
-  }
-
-  public function save() {
-    if (!$this->mailKey) {
-      $this->mailKey = Filesystem::readRandomCharacters(20);
-    }
-
-    $result = parent::save();
-
-    if ($this->subscribersNeedUpdate) {
-      // If we've changed the subscriber PHIDs for this task, update the link
-      // table.
-      ManiphestTaskSubscriber::updateTaskSubscribers($this);
-      $this->subscribersNeedUpdate = false;
-    }
-
-    return $result;
-  }
-
-  public function isClosed() {
-    return ManiphestTaskStatus::isClosedStatus($this->getStatus());
-  }
-
-  public function getPrioritySortVector() {
-    return array(
-        $this->getPriority(),
-        -$this->getSubpriority(),
-        $this->getID(),
-    );
-  }
-
-
-  /* -(  Markup Interface  
)--------------------------------------------------- */
-
-
-  /**
-   * @task markup
-   */
-  public function getMarkupFieldKey($field) {
-    $hash = PhabricatorHash::digest($this->getMarkupText($field));
-    $id = $this->getID();
-    return "maniphest:T{$id}:{$field}:{$hash}";
-  }
-
-
-  /**
-   * @task markup
-   */
-  public function getMarkupText($field) {
-    return $this->getDescription();
-  }
-
-
-  /**
-   * @task markup
-   */
-  public function newMarkupEngine($field) {
-    return PhabricatorMarkupEngine::newManiphestMarkupEngine();
-  }
-
-
-  /**
-   * @task markup
-   */
-  public function didMarkupText(
-      $field,
-      $output,
-      PhutilMarkupEngine $engine) {
-    return $output;
-  }
-
-
-  /**
-   * @task markup
-   */
-  public function shouldUseMarkupCache($field) {
-    return (bool)$this->getID();
-  }
-
-
-  /* -(  Policy Interface  
)--------------------------------------------------- */
-
-
-  public function getCapabilities() {
-    return array(
-        PhabricatorPolicyCapability::CAN_VIEW,
-        PhabricatorPolicyCapability::CAN_EDIT,
-    );
-  }
-
-  public function getPolicy($capability) {
-    switch ($capability) {
-      case PhabricatorPolicyCapability::CAN_VIEW:
-        return $this->getViewPolicy();
-      case PhabricatorPolicyCapability::CAN_EDIT:
-        return $this->getEditPolicy();
-    }
-  }
-
-  public function hasAutomaticCapability($capability, PhabricatorUser $user) {
-    // The owner of a task can always view and edit it.
-    $owner_phid = $this->getOwnerPHID();
-    if ($owner_phid) {
-      $user_phid = $user->getPHID();
-      if ($user_phid == $owner_phid) {
-        return true;
-      }
-    }
-
-    return false;
-  }
-
-  public function describeAutomaticCapability($capability) {
-    return pht('The owner of a task can always view and edit it.');
-  }
-
-
-  /* -(  PhabricatorTokenReceiverInterface  
)---------------------------------- */
-
-
-  public function getUsersToNotifyOfTokenGiven() {
-    // Sort of ambiguous who this was intended for; just let them both know.
-    return array_filter(
-        array_unique(
-            array(
-                $this->getAuthorPHID(),
-                $this->getOwnerPHID(),
-            )));
-  }
-
-
-  /* -(  PhabricatorCustomFieldInterface  
)------------------------------------ */
-
-
-  public function getCustomFieldSpecificationForRole($role) {
-    return PhabricatorEnv::getEnvConfig('maniphest.fields');
-  }
-
-  public function getCustomFieldBaseClass() {
-    return 'ManiphestCustomField';
-  }
-
-  public function getCustomFields() {
-    return $this->assertAttached($this->customFields);
-  }
-
-  public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) 
{
-    $this->customFields = $fields;
-    return $this;
-  }
-
-
-  /* -(  PhabricatorDestructibleInterface  
)----------------------------------- */
-
-
-  public function destroyObjectPermanently(
-      PhabricatorDestructionEngine $engine) {
-
-    $this->openTransaction();
-
-    // TODO: Once this implements PhabricatorTransactionInterface, this
-    // will be handled automatically and can be removed.
-    $xactions = id(new ManiphestTransaction())->loadAllWhere(
-        'objectPHID = %s',
-        $this->getPHID());
-    foreach ($xactions as $xaction) {
-      $engine->destroyObject($xaction);
-    }
-
-    $this->delete();
-    $this->saveTransaction();
-  }
-
-
-  /* -(  PhabricatorApplicationTransactionInterface  
)------------------------- */
-
-
-  public function getApplicationTransactionEditor() {
-    return new ManiphestTransactionEditor();
-  }
-
-  public function getApplicationTransactionObject() {
-    return $this;
-  }
-
-  public function getApplicationTransactionTemplate() {
-    return new ManiphestTransaction();
-  }
-
-  public function willRenderTimeline(
-      PhabricatorApplicationTransactionView $timeline,
-      AphrontRequest $request) {
-
-    return $timeline;
-  }
-
-}
diff --git a/src/storage/SprintTransaction.php 
b/src/storage/SprintTransaction.php
index 91bb187..2603013 100644
--- a/src/storage/SprintTransaction.php
+++ b/src/storage/SprintTransaction.php
@@ -4,6 +4,7 @@
 
   private $viewer;
   private $task_points = array();
+  private $tasks;
   private $task_statuses = array();
   private $task_in_sprint = array();
 
@@ -12,30 +13,30 @@
     return $this;
   }
 
-  public function buildDailyData($events, $before, $start, $end, $dates, 
$xactions, $project) {
+  public function setTasks ($tasks) {
+    $this->tasks = $tasks;
+    return $this;
+  }
 
-    $query = id(new SprintQuery());
+  public function setTaskPoints ($taskpoints) {
+    $this->taskpoints = $taskpoints;
+    return $this;
+  }
+
+  public function buildDailyData($events, $before, $start, $end, $dates, 
$xactions) {
+
+    $sprintpoints = id(new SprintPoints())
+        ->setTaskPoints($this->taskpoints);
 
     foreach ($events as $event) {
       $date = null;
       $xaction = $xactions[$event['transactionPHID']];
       $xaction_date = $xaction->getDateCreated();
       $task_phid = $xaction->getObjectPHID();
-      $project_phid = $project->getPHID();
 
-      $task = id(new ManiphestTaskQuery())
-          ->setViewer($this->viewer)
-          ->withPHIDs(array($task_phid))
-          ->needProjectPHIDs(true)
-          ->executeOne();
-      $project_phids = $task->getProjectPHIDs();
-
-      if (in_array($project_phid, $project_phids)) {
-        $points = $query->getStoryPointsForTask($task_phid);
+      $points = $sprintpoints->getTaskPoints($task_phid);
 
         $date = phabricator_format_local_time($xaction_date, $this->viewer, 'D 
M j');
-
-
 
         if ($xaction_date < $start) {
 
@@ -102,12 +103,11 @@
           }
         }
       }
-    }
   return $dates;
 }
 
-  public function buildStatArrays($tasks) {
-    foreach ($tasks as $task) {
+  public function buildStatArrays() {
+    foreach ($this->tasks as $task) {
       $this->task_points[$task->getPHID()] = 0;
       $this->task_statuses[$task->getPHID()] = null;
       $this->task_in_sprint[$task->getPHID()] = 0;
diff --git a/src/util/SprintPoints.php b/src/util/SprintPoints.php
new file mode 100644
index 0000000..3b4bad2
--- /dev/null
+++ b/src/util/SprintPoints.php
@@ -0,0 +1,84 @@
+<?php
+
+final class SprintPoints {
+
+private $taskpoints;
+private $task_open_status_sum;
+private $task_closed_status_sum;
+private $tasks;
+
+  public function setTaskPoints ($taskpoints) {
+    $this->taskpoints = $taskpoints;
+    return $this;
+  }
+
+  public function setTasks ($tasks) {
+    $this->tasks = $tasks;
+    return $this;
+  }
+
+  public function getTaskPoints($task_phid) {
+    $taskpoints = mpull($this->taskpoints, null, 'getObjectPHID');
+    if (!empty($taskpoints)) {
+      foreach ($taskpoints as $key=>$value) {
+        if ($key == $task_phid) {
+          $points = $value->getfieldValue();
+        }
+      }
+      if (!isset($points)) {
+        $points = '0';
+      }
+    }
+    return $points;
+  }
+
+  public function getTaskStatus($task) {
+    $status = $task->getStatus();
+    return $status;
+  }
+
+  private function sumPointsbyStatus ($task) {
+    $status = $this->getTaskStatus($task);
+
+    $points = $this->getTaskPoints($task->getPHID());
+
+    if ($status == 'open') {
+      $this->task_open_status_sum = 
$this->setTaskOpenStatusSum($this->task_open_status_sum, $points);
+    } elseif ($status == 'resolved') {
+      $this->task_closed_status_sum = 
$this->setTaskClosedStatusSum($this->task_closed_status_sum, $points);
+    }
+    return;
+  }
+
+  public function setTaskOpenStatusSum ($task_open_status_sum, $points) {
+    $task_open_status_sum += $points;
+    return $task_open_status_sum;
+  }
+
+  public function setTaskClosedStatusSum ($task_closed_status_sum, $points) {
+    $task_closed_status_sum += $points;
+    return $task_closed_status_sum;
+  }
+
+  public function setStatusPoints () {
+    foreach ($this->tasks as $task) {
+      $this->sumPointsbyStatus($task);
+    }
+    return $this;
+  }
+
+  public function getStatusSums() {
+    $this->setStatusPoints();
+    $opensum = $this->getOpenStatusSum();
+    $closedsum = $this->getClosedStatusSum();
+    return array ($opensum, $closedsum);
+  }
+
+  public function getOpenStatusSum() {
+    return $this->task_open_status_sum;
+  }
+
+  public function getClosedStatusSum() {
+    return $this->task_closed_status_sum;
+  }
+}
\ No newline at end of file
diff --git a/src/view/SprintBoardTaskCard.php b/src/view/SprintBoardTaskCard.php
index 8a655ab..00b77dc 100644
--- a/src/view/SprintBoardTaskCard.php
+++ b/src/view/SprintBoardTaskCard.php
@@ -62,8 +62,9 @@
     $task = $this->getTask();
     $task_phid = $task->getPHID();
     $owner = $this->getOwner();
+
     $points = $query->getStoryPointsForTask($task_phid);
-     $can_edit = $this->getCanEdit();
+    $can_edit = $this->getCanEdit();
 
     $color_map = ManiphestTaskPriority::getColorMap();
     $bar_color = idx($color_map, $task->getPriority(), 'grey');
diff --git a/src/view/EventTableView.php b/src/view/burndown/EventTableView.php
similarity index 100%
rename from src/view/EventTableView.php
rename to src/view/burndown/EventTableView.php
diff --git a/src/view/HistoryTableView.php 
b/src/view/burndown/HistoryTableView.php
similarity index 100%
rename from src/view/HistoryTableView.php
rename to src/view/burndown/HistoryTableView.php
diff --git a/src/view/SprintDataView.php b/src/view/burndown/SprintDataView.php
similarity index 84%
rename from src/view/SprintDataView.php
rename to src/view/burndown/SprintDataView.php
index 77b879a..c1a0c72 100644
--- a/src/view/SprintDataView.php
+++ b/src/view/burndown/SprintDataView.php
@@ -13,6 +13,7 @@
   private $project;
   private $viewer;
   private $tasks;
+  private $taskpoints;
   private $events;
   private $xactions;
   private $start;
@@ -37,31 +38,39 @@
   public function render() {
     $query = id(new SprintQuery())
         ->setProject($this->project)
-        ->setViewer($this->viewer);
+        ->setViewer($this->viewer)
+        ->setPHID($this->project->getPHID());
+
+    $this->taskpoints = 
$query->getTaskData(SprintConstants::CUSTOMFIELD_INDEX);
     $tasks = $query->getTasks();
     $this->tasks = mpull($tasks, null, 'getPHID');
 
     $chart = $this->buildC3Chart($query);
+
     $tasks_table_view = id(new TasksTableView())
         ->setProject($this->project)
         ->setViewer($this->viewer)
         ->setRequest($this->request)
         ->setTasks($this->tasks)
+        ->setTaskPoints($this->taskpoints)
         ->setQuery($query);
 
     $tasks_table = $tasks_table_view->buildTasksTable();
-    $pie = $this->buildC3Pie($tasks_table_view);
+    $pie = $this->buildC3Pie();
     $history_table_view = new HistoryTableView();
     $history_table = $history_table_view->buildHistoryTable($this->before);
     $sprint_table_view = new SprintTableView();
-    $sprint_table = $sprint_table_view->buildSprintTable($this->sprint_data, 
$this->before);
+    $sprint_table = $sprint_table_view->buildSprintTable($this->sprint_data,
+        $this->before);
     $event_table_view = id(new EventTableView())
         ->setProject($this->project)
         ->setViewer($this->viewer)
         ->setRequest($this->request);
-    $event_table = $event_table_view->buildEventTable($this->events, 
$this->xactions,
+    $event_table = $event_table_view->buildEventTable($this->events,
+        $this->xactions,
         $this->tasks, $this->start, $this->end);
-    return array($chart, $tasks_table, $pie, $history_table, $sprint_table, 
$event_table);
+    return array($chart, $tasks_table, $pie, $history_table, $sprint_table,
+        $event_table);
   }
 
   private function buildChartDataSet($query) {
@@ -84,9 +93,14 @@
     $this->xactions = mpull($xactions, null, 'getPHID');
 
     $sprint_xaction = id(new SprintTransaction())
-        ->setViewer($this->viewer);
-    $sprint_xaction->buildStatArrays($this->tasks);
-    $dates = $sprint_xaction->buildDailyData($this->events, $this->before, 
$this->start, $this->end, $dates, $this->xactions, $this->project);
+        ->setViewer($this->viewer)
+        ->setTasks($this->tasks)
+        ->setTaskPoints($this->taskpoints);
+
+    $sprint_xaction->buildStatArrays();
+
+    $dates = $sprint_xaction->buildDailyData($this->events, $this->before,
+        $this->start, $this->end, $dates, $this->xactions, $this->project);
 
     $this->sprint_data = $stats->setSprintData($dates, $this->before);
     $data = $stats->buildDataSet($this->sprint_data);
@@ -143,10 +157,13 @@
     return $chart;
   }
 
-  private function buildC3Pie($tasks_table) {
-    $tasks_table->setStatusPoints();
-    $task_open_status_sum = $tasks_table->getOpenStatusSum();
-    $task_closed_status_sum = $tasks_table->getClosedStatusSum();
+  private function buildC3Pie() {
+    $sprintpoints = id(new SprintPoints())
+        ->setTaskPoints($this->taskpoints)
+        ->setTasks($this->tasks);
+
+    list($task_open_status_sum, $task_closed_status_sum) = $sprintpoints
+        ->getStatusSums();
 
     require_celerity_resource('d3', 'sprint');
     require_celerity_resource('c3-css', 'sprint');
diff --git a/src/view/SprintTableView.php 
b/src/view/burndown/SprintTableView.php
similarity index 100%
rename from src/view/SprintTableView.php
rename to src/view/burndown/SprintTableView.php
diff --git a/src/view/TasksTableView.php b/src/view/burndown/TasksTableView.php
similarity index 84%
rename from src/view/TasksTableView.php
rename to src/view/burndown/TasksTableView.php
index 3b3382d..322ade3 100644
--- a/src/view/TasksTableView.php
+++ b/src/view/burndown/TasksTableView.php
@@ -6,8 +6,7 @@
   private $viewer;
   private $request;
   private $tasks;
-  private $task_open_status_sum;
-  private $task_closed_status_sum;
+  private $taskpoints;
   private $query;
 
   public function setProject ($project) {
@@ -21,17 +20,22 @@
   }
 
   public function setRequest ($request) {
-    $this->request =  $request;
+    $this->request = $request;
     return $this;
   }
 
   public function setTasks ($tasks) {
-    $this->tasks =  $tasks;
+    $this->tasks = $tasks;
+    return $this;
+  }
+
+  public function setTaskPoints ($taskpoints) {
+    $this->taskpoints = $taskpoints;
     return $this;
   }
 
   public function setQuery ($query) {
-    $this->query =  $query;
+    $this->query = $query;
     return $this;
   }
 
@@ -117,6 +121,8 @@
   private function buildTasksTree($order, $reverse) {
     $edges = $this->query->getEdges($this->tasks);
     $map = $this->buildTaskMap($edges, $this->tasks);
+    $sprintpoints = id(new SprintPoints())
+        ->setTaskPoints($this->taskpoints);
 
         // We also collect the phids we need to fetch owner information
     $handle_phids = array();
@@ -126,7 +132,6 @@
     }
     $handles = $this->query->getViewerHandles($this->request, $handle_phids);
 
-    // Now we loop through the tasks, and add them to the output
     $output = array();
     $rows = array();
     foreach ($this->tasks as $task) {
@@ -138,7 +143,8 @@
         $blocked = true;
       }
 
-      $points = $this->getTaskPoints($task);
+      $points = $sprintpoints->getTaskPoints($task->getPHID());
+
       $row = $this->addTaskToTree($output, $blocked, $task, $handles, $points);
       list ($task, $cdate, $date_created, $udate, $last_update, $owner_link, 
$numpriority, $priority, $points, $status) = $row[0];
       $row['sort'] = $this->setSortOrder($row, $order, $task, $cdate, $udate, 
$owner_link, $numpriority, $points, $status);
@@ -226,14 +232,6 @@
     return $owner_link;
   }
 
-  private function getTaskPoints($task) {
-    $query = id(new SprintQuery())
-        ->setProject($this->project)
-        ->setViewer($this->viewer);
-    $points = $query->getStoryPointsForTask($task->getPHID());
-    return $points;
-  }
-
   private function getTaskCreatedDate($task) {
     $date_created = $task->getDateCreated();
     return $date_created;
@@ -259,8 +257,8 @@
     $date_created = phabricator_datetime($cdate, $this->viewer);
     $udate = $this->getTaskModifiedDate($task);
     $last_updated = phabricator_datetime($udate, $this->viewer);
-
-    $status = $this->setTaskStatus($task);
+    $sprintpoints = id(new SprintPoints());
+    $status = $sprintpoints->getTaskStatus($task);
 
     $owner_link = $this->setOwnerLink($handles, $task);
     $priority = $this->getPriority($task);
@@ -291,35 +289,4 @@
     return $output;
   }
 
-  private function setTaskStatus($task) {
-    $status = $task->getStatus();
-    return $status;
-  }
-
-  private function sumPointsbyStatus ($task) {
-    $stats = id(new SprintBuildStats());
-    $status = $this->setTaskStatus($task);
-    $points = $this->getTaskPoints($task);
-    if ($status == 'open') {
-      $this->task_open_status_sum = 
$stats->setTaskOpenStatusSum($this->task_open_status_sum, $points);
-    } elseif ($status == 'resolved') {
-      $this->task_closed_status_sum = 
$stats->setTaskClosedStatusSum($this->task_closed_status_sum, $points);
-    }
-    return;
-  }
-
-  public function setStatusPoints () {
-    foreach ($this->tasks as $task) {
-      $this->sumPointsbyStatus($task);
-    }
-   return;
-  }
-
-  public function getOpenStatusSum() {
-    return $this->task_open_status_sum;
-  }
-
-  public function getClosedStatusSum() {
-    return $this->task_closed_status_sum;
-  }
 }
\ No newline at end of file
diff --git a/src/view/OpenTasksView.php b/src/view/reports/OpenTasksView.php
similarity index 100%
rename from src/view/OpenTasksView.php
rename to src/view/reports/OpenTasksView.php
diff --git a/src/view/ProjectOpenTasksView.php 
b/src/view/reports/ProjectOpenTasksView.php
similarity index 100%
rename from src/view/ProjectOpenTasksView.php
rename to src/view/reports/ProjectOpenTasksView.php
diff --git a/src/view/SprintReportBurndownView.php 
b/src/view/reports/SprintReportBurndownView.php
similarity index 100%
rename from src/view/SprintReportBurndownView.php
rename to src/view/reports/SprintReportBurndownView.php
diff --git a/src/view/SprintReportOpenTasksView.php 
b/src/view/reports/SprintReportOpenTasksView.php
similarity index 100%
rename from src/view/SprintReportOpenTasksView.php
rename to src/view/reports/SprintReportOpenTasksView.php
diff --git a/src/view/UserOpenTasksView.php 
b/src/view/reports/UserOpenTasksView.php
similarity index 100%
rename from src/view/UserOpenTasksView.php
rename to src/view/reports/UserOpenTasksView.php

-- 
To view, visit https://gerrit.wikimedia.org/r/181886
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I660007ccc83323eba98d1415f15c9a9a64ff3a4d
Gerrit-PatchSet: 1
Gerrit-Project: phabricator/extensions/Sprint
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>

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

Reply via email to