Christopher Johnson (WMDE) has submitted this change and it was merged.

Change subject: adds new ProjectCustomField "IsSprint" that replaces special 
character
......................................................................


adds new ProjectCustomField "IsSprint" that replaces special character

changes validation logic for other custom fields to show or not show
removes magic word from all classes
fixes lint warnings
implements SprintValidator for event listeners

Bug:87229
Change-Id: Iefa14e4740939b7e5b7dbe7f86a8cda87eab0f35
---
M .arclint
M src/__phutil_library_map__.php
M src/constants/SprintConstants.php
M src/controller/SprintListController.php
M src/customfield/SprintBeginDateField.php
M src/customfield/SprintEndDateField.php
A src/customfield/SprintIsSprintField.php
M src/customfield/SprintProjectCustomField.php
M src/customfield/SprintTaskStoryPointsField.php
M src/events/BurndownActionMenuEventListener.php
M src/events/SprintUIEventListener.php
D src/query/SprintProjectQuery.php
M src/query/SprintQuery.php
M src/tests/SprintApplicationTest.php
M src/tests/SprintControllerTest.php
M src/util/SprintValidator.php
M src/view/SprintBoardTaskCard.php
M src/view/burndown/TasksTableView.php
18 files changed, 207 insertions(+), 490 deletions(-)

Approvals:
  Christopher Johnson (WMDE): Verified; Looks good to me, approved



diff --git a/.arclint b/.arclint
index 21baaf8..9c27335 100644
--- a/.arclint
+++ b/.arclint
@@ -50,7 +50,7 @@
         "16": "advice",
         "34": "error"
       },
-      "xhpast.php-version": "5.2.3",
+      "xhpast.php-version": "5.3.0",
       "xhpast.php-version.windows": "5.3.0"
     }
   }
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index eaa98ee..aa3d66b 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -49,11 +49,11 @@
     'SprintEndDateField' => 'customfield/SprintEndDateField.php',
     'SprintFactDaemon' => 'fact/SprintFactDaemon.php',
     'SprintFactUpdateIterator' => 'fact/SprintFactUpdateIterator.php',
+    'SprintIsSprintField' => 'customfield/SprintIsSprintField.php',
     'SprintListController' => 'controller/SprintListController.php',
     'SprintPoints' => 'util/SprintPoints.php',
     'SprintProjectCustomField' => 'customfield/SprintProjectCustomField.php',
     'SprintProjectProfileController' => 
'controller/SprintProjectProfileController.php',
-    'SprintProjectQuery' => 'query/SprintProjectQuery.php',
     'SprintProjectViewController' => 
'controller/SprintProjectViewController.php',
     'SprintQuery' => 'query/SprintQuery.php',
     'SprintQueryTest' => 'tests/SprintQueryTest.php',
@@ -102,13 +102,13 @@
     'SprintEndDateField' => 'SprintProjectCustomField',
     'SprintFactDaemon' => 'PhabricatorDaemon',
     'SprintFactUpdateIterator' => 'PhutilBufferedIterator',
+    'SprintIsSprintField' => 'SprintProjectCustomField',
     'SprintListController' => 'SprintController',
     'SprintProjectCustomField' => array(
       'PhabricatorProjectCustomField',
       'PhabricatorStandardCustomFieldInterface',
     ),
     'SprintProjectProfileController' => 'SprintController',
-    'SprintProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
     'SprintProjectViewController' => 'SprintController',
     'SprintQuery' => 'SprintDAO',
     'SprintQueryTest' => 'SprintTestCase',
diff --git a/src/constants/SprintConstants.php 
b/src/constants/SprintConstants.php
index 4a78fd1..1bee05d 100644
--- a/src/constants/SprintConstants.php
+++ b/src/constants/SprintConstants.php
@@ -2,10 +2,11 @@
 
 final class SprintConstants {
 
-  const MAGIC_WORD               = '§';
   const CUSTOMFIELD_TYPE_STATUS  = 'core:customfield';
   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
+  const POINTFIELD_INDEX = 'yERhvoZPNPtM';
+  const SPRINTFIELD_INDEX = 'scsOmkpB9Tqi';
+} 
+
diff --git a/src/controller/SprintListController.php 
b/src/controller/SprintListController.php
index 0b5b54f..99339f8 100644
--- a/src/controller/SprintListController.php
+++ b/src/controller/SprintListController.php
@@ -11,9 +11,9 @@
   public function processRequest() {
     $request = $this->getRequest();
     $viewer = $request->getUser();
-
     $nav = $this->buildNavMenu();
-    $projects = $this->loadAllProjects($viewer);
+    $sprint_phids = $this->getSprintPHIDs();
+    $projects = $this->loadAllSprints($viewer, $sprint_phids);
     $this->view = $nav->selectFilter($this->view, 'list');
 
     $projects_table_view = id(new ProjectsTableView())
@@ -33,9 +33,8 @@
 
     $help = id(new PHUIBoxView())
         ->appendChild(phutil_tag('p', array(),
-            "To have a project show up in this list, make sure its name 
includes"
-            ."\"".SprintConstants::MAGIC_WORD."\" and then edit it to set the 
start and end date."
-        ))
+            'To have a project show up in this list, make sure that the'
+            .'"Is Sprint" box has been checked in Project Edit Details'))
         ->addMargin(PHUI::MARGIN_LARGE);
 
     $nav->appendChild(
@@ -55,11 +54,16 @@
       ));
   }
 
-  // Load all projects with "§" in the name.
-  private function loadAllProjects($viewer) {
-    $projects = id(new SprintProjectQuery())
+  private function getSprintPHIDs() {
+    $query = id(new SprintQuery());
+    $sprint_phids = $query->getSprintPHIDs();
+    return $sprint_phids;
+  }
+
+  private function loadAllSprints($viewer, $sprints) {
+    $projects = id(new PhabricatorProjectQuery())
       ->setViewer($viewer)
-      ->withDatasourceQuery(SprintConstants::MAGIC_WORD)
+      ->withPHIDS($sprints)
       ->execute();
     return $projects;
   }
diff --git a/src/customfield/SprintBeginDateField.php 
b/src/customfield/SprintBeginDateField.php
index ef606ee..b4c0bcf 100644
--- a/src/customfield/SprintBeginDateField.php
+++ b/src/customfield/SprintBeginDateField.php
@@ -6,10 +6,11 @@
 
 final class SprintBeginDateField extends SprintProjectCustomField {
 
-  private $date_proxy;
+  private $dateproxy;
 
   public function __construct() {
-    $this->date_proxy = $this->getDateFieldProxy($this, $this->getFieldName(), 
$this->getFieldDescription());
+    $this->dateproxy = $this->getDateFieldProxy($this, $this->getFieldName(),
+        $this->getFieldDescription());
   }
 
   // == General field identity stuff
@@ -26,11 +27,12 @@
   }
 
   public function renderPropertyViewValue(array $handles) {
-    return $this->renderDateProxyPropertyViewValue($this->date_proxy, 
$handles);
+    return $this->renderDateProxyPropertyViewValue($this->dateproxy, $handles);
   }
 
   public function renderEditControl(array $handles) {
-    return 
$this->renderDateProxyEditControl($this->date_proxy,'start-of-business');
+    return $this->renderDateProxyEditControl($this->dateproxy,
+        'start-of-business');
   }
 
   // == Search
diff --git a/src/customfield/SprintEndDateField.php 
b/src/customfield/SprintEndDateField.php
index 4677513..b870489 100644
--- a/src/customfield/SprintEndDateField.php
+++ b/src/customfield/SprintEndDateField.php
@@ -6,10 +6,11 @@
 
 final class SprintEndDateField extends SprintProjectCustomField {
 
-  private $date_proxy;
+  private $dateproxy;
 
   public function __construct() {
-    $this->date_proxy = $this->getDateFieldProxy($this, $this->getFieldName(), 
$this->getFieldDescription());
+    $this->dateproxy = $this->getDateFieldProxy($this, $this->getFieldName(),
+        $this->getFieldDescription());
   }
 
   // == General field identity stuff
@@ -26,11 +27,12 @@
   }
 
   public function renderPropertyViewValue(array $handles) {
-    return $this->renderDateProxyPropertyViewValue($this->date_proxy, 
$handles);
+    return $this->renderDateProxyPropertyViewValue($this->dateproxy, $handles);
   }
 
   public function renderEditControl(array $handles) {
-    return 
$this->renderDateProxyEditControl($this->date_proxy,'end-of-business');
+    return $this->renderDateProxyEditControl($this->dateproxy,
+        'end-of-business');
   }
 
   // == Search
diff --git a/src/customfield/SprintIsSprintField.php 
b/src/customfield/SprintIsSprintField.php
new file mode 100644
index 0000000..045b99d
--- /dev/null
+++ b/src/customfield/SprintIsSprintField.php
@@ -0,0 +1,38 @@
+<?php
+
+final class SprintIsSprintField extends SprintProjectCustomField {
+
+  private $fieldproxy;
+
+  public function __construct() {
+    $this->fieldproxy = $this->getBoolFieldProxy($this, $this->getFieldName(),
+        $this->getFieldDescription());
+  }
+
+  // == General field identity stuff
+  public function getFieldKey() {
+    return 'isdc:sprint:issprint';
+  }
+
+  public function getFieldName() {
+    return 'Is Sprint';
+  }
+
+  public function getFieldDescription() {
+    return 'Project Is Sprint';
+  }
+
+  public function renderPropertyViewValue(array $handles) {
+    return $this->renderBoolProxyPropertyViewValue($this->fieldproxy,
+        $handles);
+  }
+
+  public function renderEditControl(array $handles) {
+    return $this->fieldproxy->renderEditControl($handles);
+  }
+
+  // == Search
+  public function shouldAppearInApplicationSearch() {
+    return true;
+  }
+}
diff --git a/src/customfield/SprintProjectCustomField.php 
b/src/customfield/SprintProjectCustomField.php
index 8654ea7..12e2831 100644
--- a/src/customfield/SprintProjectCustomField.php
+++ b/src/customfield/SprintProjectCustomField.php
@@ -10,9 +10,9 @@
 
   protected function isSprint() {
     $validator = new SprintValidator;
-    $is_sprint = call_user_func(array($validator, 'checkForSprint'),
-        array($validator, 'shouldShowSprintFields'), $this->getObject());
-    return $is_sprint;
+    $issprint = call_user_func(array($validator, 'checkForSprint'),
+        array($validator, 'isSprint'), $this->getObject()->getPHID());
+    return $issprint;
   }
 
   /**
@@ -26,24 +26,45 @@
    * @param string $name
    * @param string $description
    */
-  public function getDateFieldProxy($date_field, $name, $description) {
-    $obj = clone $date_field;
-    $date_proxy = id(new PhabricatorStandardCustomFieldDate())
+  public function getDateFieldProxy($datefield, $name, $description) {
+    $obj = clone $datefield;
+    $dateproxy = id(new PhabricatorStandardCustomFieldDate())
         ->setFieldKey($this->getFieldKey())
         ->setApplicationField($obj)
         ->setFieldConfig(array(
             'name' => $name,
             'description' => $description
         ));
-    $this->setProxy($date_proxy);
-    return $date_proxy;
+    $this->setProxy($dateproxy);
+    return $dateproxy;
   }
 
-  public function renderDateProxyPropertyViewValue($date_proxy, $handles) {
-    $is_sprint = $this->isSprint();
+  /**
+   * @param string $name
+   * @param string $description
+   */
+  public function getBoolFieldProxy($field, $name, $description) {
+    $obj = clone $field;
+    $fieldproxy = id(new PhabricatorStandardCustomFieldBool())
+        ->setFieldKey($this->getFieldKey())
+        ->setApplicationField($obj)
+        ->setFieldConfig(array(
+            'name' => $name,
+            'description' => $description,
+        ));
+    $this->setProxy($fieldproxy);
+    return $fieldproxy;
+  }
 
-    if ($is_sprint && ($date_proxy->getFieldValue())) {
-        return $date_proxy->renderPropertyViewValue($handles);
+  public function renderBoolProxyPropertyViewValue($boolproxy, $handles) {
+      return $boolproxy->renderPropertyViewValue($handles);
+  }
+
+  public function renderDateProxyPropertyViewValue($dateproxy, $handles) {
+    $issprint = $this->isSprint();
+
+    if ($issprint && ($dateproxy->getFieldValue())) {
+        return $dateproxy->renderPropertyViewValue($handles);
     } else {
        return null;
     }
@@ -52,11 +73,11 @@
   /**
    * @param string $time
    */
-  public function renderDateProxyEditControl($date_proxy, $time) {
-    $is_sprint = $this->isSprint();
+  public function renderDateProxyEditControl($dateproxy, $time) {
+    $issprint = $this->isSprint();
 
-    if ($is_sprint && $date_proxy) {
-        return $this->newDateControl($date_proxy, $time);
+    if ($issprint && $dateproxy) {
+        return $this->newDateControl($dateproxy, $time);
     } else {
       return null;
     }
diff --git a/src/customfield/SprintTaskStoryPointsField.php 
b/src/customfield/SprintTaskStoryPointsField.php
index e1cc69f..c0f81bf 100644
--- a/src/customfield/SprintTaskStoryPointsField.php
+++ b/src/customfield/SprintTaskStoryPointsField.php
@@ -9,18 +9,18 @@
     PhabricatorStandardCustomFieldInterface {
 
   private $obj;
-  private $text_proxy;
+  private $textproxy;
 
   public function __construct() {
     $this->obj = clone $this;
-    $this->text_proxy = id(new PhabricatorStandardCustomFieldText())
+    $this->textproxy = id(new PhabricatorStandardCustomFieldText())
       ->setFieldKey($this->getFieldKey())
       ->setApplicationField($this->obj)
       ->setFieldConfig(array(
         'name' => $this->getFieldName(),
         'description' => $this->getFieldDescription(),
       ));
-    $this->setProxy($this->text_proxy);
+    $this->setProxy($this->textproxy);
   }
 
   public function canSetProxy() {
@@ -58,25 +58,19 @@
              ->withIds(array($id))
              ->needProjectPHIDs(true)
              ->executeOne();
-          $project_phids = $task->getProjectPHIDs();
+          $projectphids = $task->getProjectPHIDs();
        }
      }
 
-      if (empty($project_phids)) {
+      if (empty($projectphids)) {
         return $show = false;
       }
-      // Fetch the names from all the Projects associated with this task
-      $projects = id(new PhabricatorProject())
-        ->loadAllWhere(
-        'phid IN (%Ls)',
-        $project_phids);
-      $names = mpull($projects, 'getName');
 
-      // Set show to true if one of the Projects contains "Sprint"
       $show = false;
-      foreach($names as $name) {
-        if (strpos($name, SprintConstants::MAGIC_WORD) !== false) {
+      foreach ($projectphids as $projectphid) {
+        if ($this->isSprint($projectphid)) {
           $show = true;
+          break;
         }
       }
     }
@@ -84,25 +78,21 @@
   }
 
   public function renderPropertyViewLabel() {
-    if (!$this->showField()) {
-      return null;
+    if ($this->showField() === true) {
+      if ($this->textproxy) {
+        return $this->textproxy->renderPropertyViewLabel();
+      }
+      return $this->getFieldName();
     }
-
-    if ($this->text_proxy) {
-      return $this->text_proxy->renderPropertyViewLabel();
-    }
-    return $this->getFieldName();
   }
 
   public function renderPropertyViewValue(array $handles) {
-    if (!$this->showField()) {
-      return null;
+    if ($this->showField() === true) {
+      if ($this->textproxy) {
+        return $this->textproxy->renderPropertyViewValue($handles);
+      }
+      throw new PhabricatorCustomFieldImplementationIncompleteException($this);
     }
-
-    if ($this->text_proxy) {
-      return $this->text_proxy->renderPropertyViewValue($handles);
-    }
-    throw new PhabricatorCustomFieldImplementationIncompleteException($this);
   }
 
   public function shouldAppearInEditView() {
@@ -110,20 +100,24 @@
   }
 
   public function renderEditControl(array $handles) {
-    if (!$this->showField()) {
-      return null;
+    if ($this->showField() === true) {
+      if ($this->textproxy) {
+        return $this->textproxy->renderEditControl($handles);
+      }
+      throw new PhabricatorCustomFieldImplementationIncompleteException($this);
     }
-
-    if ($this->text_proxy) {
-      return $this->text_proxy->renderEditControl($handles);
-    }
-    throw new PhabricatorCustomFieldImplementationIncompleteException($this);
   }
 
   // == Search
-  public function shouldAppearInApplicationSearch()
-  {
+  public function shouldAppearInApplicationSearch() {
     return true;
   }
 
+  protected function isSprint($projectphid) {
+    $validator = new SprintValidator();
+    $issprint = call_user_func(array($validator, 'checkForSprint'),
+        array($validator, 'isSprint'), $projectphid);
+    return $issprint;
+  }
+
 }
diff --git a/src/events/BurndownActionMenuEventListener.php 
b/src/events/BurndownActionMenuEventListener.php
index 9dafd37..b9e7f79 100644
--- a/src/events/BurndownActionMenuEventListener.php
+++ b/src/events/BurndownActionMenuEventListener.php
@@ -23,13 +23,20 @@
 
     $actions = null;
     if ($object instanceof PhabricatorProject &&
-      stripos($object->getName(), SprintConstants::MAGIC_WORD) !== false) {
+      $this->isSprint($object) !== false) {
       $actions = $this->renderUserItems($event);
     }
 
     $this->addActionMenuItems($event, $actions);
   }
 
+  protected function isSprint($object) {
+    $validator = new SprintValidator();
+    $issprint = call_user_func(array($validator, 'checkForSprint'),
+        array($validator, 'isSprint'), $object->getPHID());
+    return $issprint;
+  }
+
   private function renderUserItems(PhutilEvent $event) {
     if (!$this->canUseApplication($event->getUser())) {
       return null;
diff --git a/src/events/SprintUIEventListener.php 
b/src/events/SprintUIEventListener.php
index e796b0a..f67c9c4 100644
--- a/src/events/SprintUIEventListener.php
+++ b/src/events/SprintUIEventListener.php
@@ -15,17 +15,24 @@
     }
   }
 
-  private function filterSprints ($phandles, $value){
+  private function filterSprints ($phandles) {
     $handles = array();
-    if(is_array($phandles) && count($phandles)>0)
-    {
+    if (is_array($phandles) && count($phandles) > 0) {
       foreach($phandles as $handle) {
-        if (stripos($handle->getName(), $value) !== false) {
+        $phid = $handle->getPHID();
+        if ($this->isSprint($phid) == true) {
             $handles[$handle->getPHID()] = $phandles[$handle->getPHID()];
         }
       }
     }
     return $handles;
+  }
+
+  protected function isSprint($phid) {
+    $validator = new SprintValidator();
+    $issprint = call_user_func(array($validator, 'checkForSprint'),
+        array($validator, 'isSprint'), $phid);
+    return $issprint;
   }
 
   private function handlePropertyEvent($event)
@@ -53,7 +60,7 @@
           ->setViewer($user)
           ->withPHIDs($project_phids)
           ->execute();
-      $handles = $this->filterSprints($phandles, SprintConstants::MAGIC_WORD);
+      $handles = $this->filterSprints($phandles);
     }
 
     // If this object can appear on boards, build the workboard annotations.
diff --git a/src/query/SprintProjectQuery.php b/src/query/SprintProjectQuery.php
deleted file mode 100644
index c4338f8..0000000
--- a/src/query/SprintProjectQuery.php
+++ /dev/null
@@ -1,392 +0,0 @@
-<?php
-
-final class SprintProjectQuery
-    extends PhabricatorCursorPagedPolicyAwareQuery {
-
-  private $ids;
-  private $phids;
-  private $memberPHIDs;
-  private $slugs;
-  private $phrictionSlugs;
-  private $names;
-  private $datasourceQuery;
-  private $icons;
-  private $colors;
-
-  private $status       = 'status-any';
-  const STATUS_ANY      = 'status-any';
-  const STATUS_OPEN     = 'status-open';
-  const STATUS_CLOSED   = 'status-closed';
-  const STATUS_ACTIVE   = 'status-active';
-  const STATUS_ARCHIVED = 'status-archived';
-
-  private $needSlugs;
-  private $needMembers;
-  private $needWatchers;
-  private $needImages;
-
-  public function withIDs(array $ids) {
-    $this->ids = $ids;
-    return $this;
-  }
-
-  public function withPHIDs(array $phids) {
-    $this->phids = $phids;
-    return $this;
-  }
-
-  public function withStatus($status) {
-    $this->status = $status;
-    return $this;
-  }
-
-  public function withMemberPHIDs(array $member_phids) {
-    $this->memberPHIDs = $member_phids;
-    return $this;
-  }
-
-  public function withSlugs(array $slugs) {
-    $this->slugs = $slugs;
-    return $this;
-  }
-
-  public function withPhrictionSlugs(array $slugs) {
-    $this->phrictionSlugs = $slugs;
-    return $this;
-  }
-
-  public function withNames(array $names) {
-    $this->names = $names;
-    return $this;
-  }
-
-  public function withDatasourceQuery($string) {
-    $this->datasourceQuery = $string;
-    return $this;
-  }
-
-  public function withIcons(array $icons) {
-    $this->icons = $icons;
-    return $this;
-  }
-
-  public function withColors(array $colors) {
-    $this->colors = $colors;
-    return $this;
-  }
-
-  public function needMembers($need_members) {
-    $this->needMembers = $need_members;
-    return $this;
-  }
-
-  public function needWatchers($need_watchers) {
-    $this->needWatchers = $need_watchers;
-    return $this;
-  }
-
-  public function needImages($need_images) {
-    $this->needImages = $need_images;
-    return $this;
-  }
-
-  public function needSlugs($need_slugs) {
-    $this->needSlugs = $need_slugs;
-    return $this;
-  }
-
-  protected function getPagingColumn() {
-    return 'name';
-  }
-
-  protected function getPagingValue($result) {
-    return $result->getName();
-  }
-
-  protected function getReversePaging() {
-    return true;
-  }
-
-  protected function loadPage() {
-    $table = new PhabricatorProject();
-    $conn_r = $table->establishConnection('r');
-
-    // NOTE: Because visibility checks for projects depend on whether or not
-    // the user is a project member, we always load their membership. If we're
-    // loading all members anyway we can piggyback on that; otherwise we
-    // do an explicit join.
-
-    $select_clause = '';
-    if (!$this->needMembers) {
-      $select_clause = ', vm.dst viewerIsMember';
-    }
-
-    $data = queryfx_all(
-        $conn_r,
-        'SELECT p.* %Q FROM %T p %Q %Q %Q %Q %Q',
-        $select_clause,
-        $table->getTableName(),
-        $this->buildJoinClause($conn_r),
-        $this->buildWhereClause($conn_r),
-        $this->buildGroupClause($conn_r),
-        $this->buildOrderClause($conn_r),
-        $this->buildLimitClause($conn_r));
-
-    $projects = $table->loadAllFromArray($data);
-
-    if ($projects) {
-      $viewer_phid = $this->getViewer()->getPHID();
-      $project_phids = mpull($projects, 'getPHID');
-
-      $member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
-      $watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
-
-      $need_edge_types = array();
-      if ($this->needMembers) {
-        $need_edge_types[] = $member_type;
-      } else {
-        foreach ($data as $row) {
-          $projects[$row['id']]->setIsUserMember(
-              $viewer_phid,
-              ($row['viewerIsMember'] !== null));
-        }
-      }
-
-      if ($this->needWatchers) {
-        $need_edge_types[] = $watcher_type;
-      }
-
-      if ($need_edge_types) {
-        $edges = id(new PhabricatorEdgeQuery())
-            ->withSourcePHIDs($project_phids)
-            ->withEdgeTypes($need_edge_types)
-            ->execute();
-
-        if ($this->needMembers) {
-          foreach ($projects as $project) {
-            $phid = $project->getPHID();
-            $project->attachMemberPHIDs(
-                array_keys($edges[$phid][$member_type]));
-            $project->setIsUserMember(
-                $viewer_phid,
-                isset($edges[$phid][$member_type][$viewer_phid]));
-          }
-        }
-
-        if ($this->needWatchers) {
-          foreach ($projects as $project) {
-            $phid = $project->getPHID();
-            $project->attachWatcherPHIDs(
-                array_keys($edges[$phid][$watcher_type]));
-            $project->setIsUserWatcher(
-                $viewer_phid,
-                isset($edges[$phid][$watcher_type][$viewer_phid]));
-          }
-        }
-      }
-    }
-
-    return $projects;
-  }
-
-  protected function didFilterPage(array $projects) {
-    if ($this->needImages) {
-      $default = null;
-
-      $file_phids = mpull($projects, 'getProfileImagePHID');
-      $files = id(new PhabricatorFileQuery())
-          ->setParentQuery($this)
-          ->setViewer($this->getViewer())
-          ->withPHIDs($file_phids)
-          ->execute();
-      $files = mpull($files, null, 'getPHID');
-      foreach ($projects as $project) {
-        $file = idx($files, $project->getProfileImagePHID());
-        if (!$file) {
-          if (!$default) {
-            $default = PhabricatorFile::loadBuiltin(
-                $this->getViewer(),
-                'project.png');
-          }
-          $file = $default;
-        }
-        $project->attachProfileImageFile($file);
-      }
-    }
-
-    if ($this->needSlugs) {
-      $slugs = id(new PhabricatorProjectSlug())
-          ->loadAllWhere(
-              'projectPHID IN (%Ls)',
-              mpull($projects, 'getPHID'));
-      $slugs = mgroup($slugs, 'getProjectPHID');
-      foreach ($projects as $project) {
-        $project_slugs = idx($slugs, $project->getPHID(), array());
-        $project->attachSlugs($project_slugs);
-      }
-    }
-
-    return $projects;
-  }
-
-  private function buildWhereClause($conn_r) {
-    $where = array();
-
-    if ($this->status != self::STATUS_ANY) {
-      switch ($this->status) {
-        case self::STATUS_OPEN:
-        case self::STATUS_ACTIVE:
-          $filter = array(
-              PhabricatorProjectStatus::STATUS_ACTIVE,
-          );
-          break;
-        case self::STATUS_CLOSED:
-        case self::STATUS_ARCHIVED:
-          $filter = array(
-              PhabricatorProjectStatus::STATUS_ARCHIVED,
-          );
-          break;
-        default:
-          throw new Exception(
-              "Unknown project status '{$this->status}'!");
-      }
-      $where[] = qsprintf(
-          $conn_r,
-          'status IN (%Ld)',
-          $filter);
-    }
-
-    if ($this->ids !== null) {
-      $where[] = qsprintf(
-          $conn_r,
-          'id IN (%Ld)',
-          $this->ids);
-    }
-
-    if ($this->phids !== null) {
-      $where[] = qsprintf(
-          $conn_r,
-          'phid IN (%Ls)',
-          $this->phids);
-    }
-
-    if ($this->memberPHIDs !== null) {
-      $where[] = qsprintf(
-          $conn_r,
-          'e.dst IN (%Ls)',
-          $this->memberPHIDs);
-    }
-
-    if ($this->slugs !== null) {
-      $slugs = array();
-      foreach ($this->slugs as $slug) {
-        $slugs[] = rtrim(PhabricatorSlug::normalize($slug), '/');
-      }
-
-      $where[] = qsprintf(
-          $conn_r,
-          'slug.slug IN (%Ls)',
-          $slugs);
-    }
-
-    if ($this->phrictionSlugs !== null) {
-      $where[] = qsprintf(
-          $conn_r,
-          'phrictionSlug IN (%Ls)',
-          $this->phrictionSlugs);
-    }
-
-    if ($this->names !== null) {
-      $where[] = qsprintf(
-          $conn_r,
-          'name IN (%Ls)',
-          $this->names);
-    }
-
-    if ($this->icons !== null) {
-      $where[] = qsprintf(
-          $conn_r,
-          'icon IN (%Ls)',
-          $this->icons);
-    }
-
-    if ($this->colors !== null) {
-      $where[] = qsprintf(
-          $conn_r,
-          'color IN (%Ls)',
-          $this->colors);
-    }
-
-    $where[] = $this->buildPagingClause($conn_r);
-
-    return $this->formatWhereClause($where);
-  }
-
-  private function buildGroupClause($conn_r) {
-    if ($this->memberPHIDs || $this->datasourceQuery) {
-      return 'GROUP BY p.id';
-    } else {
-      return $this->buildApplicationSearchGroupClause($conn_r);
-    }
-  }
-
-  private function buildJoinClause($conn_r) {
-    $joins = array();
-
-    if (!$this->needMembers !== null) {
-      $joins[] = qsprintf(
-          $conn_r,
-          'LEFT JOIN %T vm ON vm.src = p.phid AND vm.type = %d AND vm.dst = 
%s',
-          PhabricatorEdgeConfig::TABLE_NAME_EDGE,
-          PhabricatorProjectProjectHasMemberEdgeType::EDGECONST,
-          $this->getViewer()->getPHID());
-    }
-
-    if ($this->memberPHIDs !== null) {
-      $joins[] = qsprintf(
-          $conn_r,
-          'JOIN %T e ON e.src = p.phid AND e.type = %d',
-          PhabricatorEdgeConfig::TABLE_NAME_EDGE,
-          PhabricatorProjectProjectHasMemberEdgeType::EDGECONST);
-    }
-
-    if ($this->slugs !== null) {
-      $joins[] = qsprintf(
-          $conn_r,
-          'JOIN %T slug on slug.projectPHID = p.phid',
-          id(new PhabricatorProjectSlug())->getTableName());
-    }
-
-    if ($this->datasourceQuery !== null) {
-      $tokens = PhabricatorTypeaheadDatasource::tokenizeString(
-          $this->datasourceQuery);
-      if (!$tokens) {
-        throw new PhabricatorEmptyQueryException();
-      }
-
-      $likes = array();
-      foreach ($tokens as $token) {
-        $likes[] = qsprintf($conn_r, 'token.token LIKE %~', $token);
-      }
-
-      $joins[] = qsprintf(
-          $conn_r,
-          'JOIN %T token ON token.projectID = p.id AND (%Q)',
-          PhabricatorProject::TABLE_DATASOURCE_TOKEN,
-          '('.implode(') OR (', $likes).')');
-    }
-
-    $joins[] = $this->buildApplicationSearchJoinClause($conn_r);
-
-    return implode(' ', $joins);
-  }
-
-  public function getQueryApplicationClass() {
-    return 'PhabricatorProjectApplication';
-  }
-
-  protected function getApplicationSearchObjectPHIDColumn() {
-    return 'p.phid';
-  }
-
-}
diff --git a/src/query/SprintQuery.php b/src/query/SprintQuery.php
index e627eab..71392a4 100644
--- a/src/query/SprintQuery.php
+++ b/src/query/SprintQuery.php
@@ -67,7 +67,7 @@
     $points = null;
     $object = new ManiphestCustomFieldStorage();
     $corecustomfield = $object->loadRawDataWhere('objectPHID= %s AND
-    fieldIndex=%s', $task_phid, SprintConstants::CUSTOMFIELD_INDEX);
+    fieldIndex=%s', $task_phid, SprintConstants::POINTFIELD_INDEX);
     if (!empty($corecustomfield)) {
       foreach ($corecustomfield as $array) {
         $points = idx($array, 'fieldValue');
@@ -76,6 +76,32 @@
       $points = 0;
     }
     return $points;
+  }
+
+  public function getIsSprint() {
+    $object = new PhabricatorProjectCustomFieldStorage();
+    $boolfield = $object->loadRawDataWhere('objectPHID= %s AND
+    fieldIndex=%s', $this->project_phid, SprintConstants::SPRINTFIELD_INDEX);
+    if (!empty($boolfield)) {
+      foreach ($boolfield as $array) {
+        $issprint = idx($array, 'fieldValue');
+      }
+    } else {
+      $issprint = null;
+    }
+    return $issprint;
+  }
+
+  public function getSprintPHIDs() {
+    $sprint_phids = array();
+    $object = new PhabricatorProjectCustomFieldStorage();
+    $data = $object->loadRawDataWhere('fieldValue= %s AND
+    fieldIndex=%s', true, SprintConstants::SPRINTFIELD_INDEX);
+    $sprintfields = $object->loadAllFromArray($data);
+    foreach ($sprintfields as $key => $value) {
+        $sprint_phids[] = $value->getObjectPHID();
+      }
+    return $sprint_phids;
   }
 
   public function getXactions($tasks) {
@@ -88,11 +114,9 @@
   }
 
   public function checkNull($start, $end, $tasks) {
-    $mword = SprintConstants::MAGIC_WORD;
     if (!$start OR !$end) {
       throw new BurndownException("This project is not set up for Sprints.  "
-          . "Check that it has a start date and end date.  And has an "
-          . "'{$mword}' in the name.");
+          .'Check that it has a start date and end date.');
     }
     if (!$tasks) {
       throw new BurndownException("This project has no tasks.");
@@ -171,7 +195,7 @@
         WHERE fieldIndex = %s',
         $this->getCustomFieldObj()->getTableName(),
         $this->getCustomFieldJoins(),
-        SprintConstants::CUSTOMFIELD_INDEX);
+        SprintConstants::POINTFIELD_INDEX);
 
     $task_data = $task_dao->loadAllFromArray($data);
     return $task_data;
diff --git a/src/tests/SprintApplicationTest.php 
b/src/tests/SprintApplicationTest.php
index 47161e9..780376e 100644
--- a/src/tests/SprintApplicationTest.php
+++ b/src/tests/SprintApplicationTest.php
@@ -9,8 +9,8 @@
 
   public function testBaseURI () {
     $burndown_application = new SprintApplication;
-    $baseURI = $burndown_application->getBaseURI();
-    $this->assertEquals('/project/sprint/', $baseURI);
+    $baseuri = $burndown_application->getBaseURI();
+    $this->assertEquals('/project/sprint/', $baseuri);
   }
 
   public function testgetIconName() {
diff --git a/src/tests/SprintControllerTest.php 
b/src/tests/SprintControllerTest.php
index 2d9e91e..605ae1e 100644
--- a/src/tests/SprintControllerTest.php
+++ b/src/tests/SprintControllerTest.php
@@ -49,6 +49,7 @@
     $sprint = new SprintApplication();
     $dvcontroller->setCurrentApplication($sprint);
     $request = new AphrontRequest('phab.wmde.de', '/project/sprint/view/18');
+    $data = array();
     $data['id'] =  3;
     $request->setRequestdata($data);
     $viewer = $this->generateNewTestUser();
diff --git a/src/util/SprintValidator.php b/src/util/SprintValidator.php
index 1ac0fc4..863a671 100644
--- a/src/util/SprintValidator.php
+++ b/src/util/SprintValidator.php
@@ -2,16 +2,19 @@
 
 final class SprintValidator {
 
-  public function checkForSprint($showfields, $project) {
-    $show = $showfields($project);
-    if ($show === false) {
+  public function checkForSprint($showfields, $project_phid) {
+    $show = $showfields($project_phid);
+    if ($show == false) {
       return false;
     } else {
       return true;
     }
   }
 
-  public function shouldShowSprintFields($project) {
-    return (stripos($project->getName(), SprintConstants::MAGIC_WORD));
+  public function isSprint($project_phid) {
+    $query = id(new SprintQuery())
+        ->setPHID($project_phid);
+    $issprint = $query->getIsSprint();
+    return $issprint;
   }
-}
\ No newline at end of file
+}
diff --git a/src/view/SprintBoardTaskCard.php b/src/view/SprintBoardTaskCard.php
index f62ee78..59ec215 100644
--- a/src/view/SprintBoardTaskCard.php
+++ b/src/view/SprintBoardTaskCard.php
@@ -134,7 +134,8 @@
                 ->setName(pht('Edit'))
                 ->setIcon('fa-pencil')
                 ->addSigil('edit-project-card')
-                
->setHref('/project/sprint/board/task/edit/'.$task->getID().'/'))
+                ->setHref('/project/sprint/board/task/edit/'.$task->getID()
+                    .'/'))
       ->setBarColor($bar_color);
 
      $card->addAttribute($this->getPointList());
diff --git a/src/view/burndown/TasksTableView.php 
b/src/view/burndown/TasksTableView.php
index 6ad2b8f..89b27c3 100644
--- a/src/view/burndown/TasksTableView.php
+++ b/src/view/burndown/TasksTableView.php
@@ -9,6 +9,7 @@
   private $taskpoints;
   private $query;
 
+
   public function setProject ($project) {
     $this->project = $project;
     return $this;
@@ -164,7 +165,9 @@
     if ($reverse) {
       $rows = array_reverse($rows);
     }
-    $rows = array_map( function( $a ) { return $a['0']; }, $rows );
+
+    $a = array();
+    $rows = array_map(function($a) { return $a['0']; }, $rows);
     return $rows;
   }
 
@@ -287,7 +290,8 @@
                         ? 'phui-tag-core-closed'
                         : '',
                 ),
-                array ($this->buildTaskLink($task), $blockericon, 
$blockedicon))),
+                array ($this->buildTaskLink($task), $blockericon,
+                    $blockedicon,))),
         $cdate,
         $date_created,
         $udate,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iefa14e4740939b7e5b7dbe7f86a8cda87eab0f35
Gerrit-PatchSet: 2
Gerrit-Project: phabricator/extensions/Sprint
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>
Gerrit-Reviewer: Christopher Johnson (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to