~ubuntu-branches/ubuntu/vivid/phabricator/vivid-proposed

« back to all changes in this revision

Viewing changes to phabricator/src/applications/maniphest/phid/ManiphestTaskPHIDType.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-10-23 20:49:26 UTC
  • Revision ID: package-import@ubuntu.com-20141023204926-ar20vnfjqwxysrce
Tags: upstream-0~git20141023
ImportĀ upstreamĀ versionĀ 0~git20141023

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
final class ManiphestTaskPHIDType extends PhabricatorPHIDType {
 
4
 
 
5
  const TYPECONST = 'TASK';
 
6
 
 
7
  public function getTypeName() {
 
8
    return pht('Task');
 
9
  }
 
10
 
 
11
  public function getPHIDTypeApplicationClass() {
 
12
    return 'PhabricatorManiphestApplication';
 
13
  }
 
14
 
 
15
  public function newObject() {
 
16
    return new ManiphestTask();
 
17
  }
 
18
 
 
19
  protected function buildQueryForObjects(
 
20
    PhabricatorObjectQuery $query,
 
21
    array $phids) {
 
22
 
 
23
    return id(new ManiphestTaskQuery())
 
24
      ->withPHIDs($phids);
 
25
  }
 
26
 
 
27
  public function loadHandles(
 
28
    PhabricatorHandleQuery $query,
 
29
    array $handles,
 
30
    array $objects) {
 
31
 
 
32
    foreach ($handles as $phid => $handle) {
 
33
      $task = $objects[$phid];
 
34
      $id = $task->getID();
 
35
      $title = $task->getTitle();
 
36
 
 
37
      $handle->setName("T{$id}");
 
38
      $handle->setFullName("T{$id}: {$title}");
 
39
      $handle->setURI("/T{$id}");
 
40
 
 
41
      if ($task->isClosed()) {
 
42
        $handle->setStatus(PhabricatorObjectHandleStatus::STATUS_CLOSED);
 
43
      }
 
44
    }
 
45
  }
 
46
 
 
47
  public function canLoadNamedObject($name) {
 
48
    return preg_match('/^T\d*[1-9]\d*$/i', $name);
 
49
  }
 
50
 
 
51
  public function loadNamedObjects(
 
52
    PhabricatorObjectQuery $query,
 
53
    array $names) {
 
54
 
 
55
    $id_map = array();
 
56
    foreach ($names as $name) {
 
57
      $id = (int)substr($name, 1);
 
58
      $id_map[$id][] = $name;
 
59
    }
 
60
 
 
61
    $objects = id(new ManiphestTaskQuery())
 
62
      ->setViewer($query->getViewer())
 
63
      ->withIDs(array_keys($id_map))
 
64
      ->execute();
 
65
 
 
66
    $results = array();
 
67
    foreach ($objects as $id => $object) {
 
68
      foreach (idx($id_map, $id, array()) as $name) {
 
69
        $results[$name] = $object;
 
70
      }
 
71
    }
 
72
 
 
73
    return $results;
 
74
  }
 
75
 
 
76
}