PhabricatorProjectsCurtainExtension.php 2.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php

final class PhabricatorProjectsCurtainExtension
  extends PHUICurtainExtension {

  const EXTENSIONKEY = 'projects.projects';

  public function shouldEnableForObject($object) {
    return ($object instanceof PhabricatorProjectInterface);
  }

  public function getExtensionApplication() {
    return new PhabricatorProjectApplication();
  }

  public function buildCurtainPanel($object) {
    $viewer = $this->getViewer();

    $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
      $object->getPHID(),
      PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);

    $has_projects = (bool)$project_phids;
    $project_phids = array_reverse($project_phids);
    $handles = $viewer->loadHandles($project_phids);
26 27 28 29 30 31 32 33 34 35
    $handles = iterator_to_array($handles);
    foreach ($handles as $key => $handle) {
      if ($handle->getPolicyFiltered()) {
        unset($handles[$key]);
      }
    }

    if (empty($handles)) {
      $has_projects = false;
    }
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

    // If this object can appear on boards, build the workboard annotations.
    // Some day, this might be a generic interface. For now, only tasks can
    // appear on boards.
    $can_appear_on_boards = ($object instanceof ManiphestTask);

    $annotations = array();
    if ($has_projects && $can_appear_on_boards) {
      $engine = id(new PhabricatorBoardLayoutEngine())
        ->setViewer($viewer)
        ->setBoardPHIDs($project_phids)
        ->setObjectPHIDs(array($object->getPHID()))
        ->executeLayout();

      // TDOO: Generalize this UI and move it out of Maniphest.
      require_celerity_resource('maniphest-task-summary-css');

53
      foreach ($handles as $project_phid => $handle) {
54 55 56 57 58 59 60 61 62 63 64 65
        $columns = $engine->getObjectColumns(
          $project_phid,
          $object->getPHID());

        $annotation = array();
        foreach ($columns as $column) {
          $project_id = $column->getProject()->getID();

          $column_name = pht('(%s)', $column->getDisplayName());
          $column_link = phutil_tag(
            'a',
            array(
66
              'href' => $column->getWorkboardURI(),
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
              'class' => 'maniphest-board-link',
            ),
            $column_name);

          $annotation[] = $column_link;
        }

        if ($annotation) {
          $annotations[$project_phid] = array(
            ' ',
            phutil_implode_html(', ', $annotation),
          );
        }
      }

    }

    if ($has_projects) {
      $list = id(new PHUIHandleTagListView())
        ->setHandles($handles)
        ->setAnnotations($annotations)
        ->setShowHovercards(true);
    } else {
      $list = phutil_tag('em', array(), pht('None'));
    }

    return $this->newPanel()
94
      ->setHeaderText(pht('Tags'))
95 96 97 98 99
      ->setOrder(10000)
      ->appendChild($list);
  }

}