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

« back to all changes in this revision

Viewing changes to phabricator/src/applications/phurl/phid/PhabricatorPhurlURLPHIDType.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:
 
1
<?php
 
2
 
 
3
final class PhabricatorPhurlURLPHIDType extends PhabricatorPHIDType {
 
4
 
 
5
  const TYPECONST = 'PHRL';
 
6
 
 
7
  public function getTypeName() {
 
8
    return pht('URL');
 
9
  }
 
10
 
 
11
  public function getPHIDTypeApplicationClass() {
 
12
    return 'PhabricatorPhurlApplication';
 
13
  }
 
14
 
 
15
  public function newObject() {
 
16
    return new PhabricatorPhurlURL();
 
17
  }
 
18
 
 
19
  protected function buildQueryForObjects(
 
20
    PhabricatorObjectQuery $query,
 
21
    array $phids) {
 
22
 
 
23
    return id(new PhabricatorPhurlURLQuery())
 
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
      $url = $objects[$phid];
 
34
 
 
35
      $id = $url->getID();
 
36
      $name = $url->getName();
 
37
      $full_name = $url->getMonogram().' '.$name;
 
38
 
 
39
      $handle
 
40
        ->setName($name)
 
41
        ->setFullName($full_name)
 
42
        ->setURI($url->getURI());
 
43
    }
 
44
  }
 
45
 
 
46
  public function canLoadNamedObject($name) {
 
47
    return preg_match('/^U[1-9]\d*$/i', $name);
 
48
  }
 
49
 
 
50
  public function loadNamedObjects(
 
51
    PhabricatorObjectQuery $query,
 
52
    array $names) {
 
53
 
 
54
    $id_map = array();
 
55
    foreach ($names as $name) {
 
56
      $id = (int)substr($name, 1);
 
57
      $id_map[$id][] = $name;
 
58
    }
 
59
 
 
60
    $objects = id(new PhabricatorPhurlURLQuery())
 
61
      ->setViewer($query->getViewer())
 
62
      ->withIDs(array_keys($id_map))
 
63
      ->execute();
 
64
 
 
65
    $results = array();
 
66
    foreach ($objects as $id => $object) {
 
67
      foreach (idx($id_map, $id, array()) as $name) {
 
68
        $results[$name] = $object;
 
69
      }
 
70
    }
 
71
 
 
72
    return $results;
 
73
  }
 
74
}