[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/conpherence/conduit/ -> ConpherenceQueryTransactionConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class ConpherenceQueryTransactionConduitAPIMethod
   4    extends ConpherenceConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'conpherence.querytransaction';
   8    }
   9  
  10    public function getMethodDescription() {
  11      return pht(
  12        'Query for transactions for the logged in user within a specific '.
  13        'conpherence thread. You can specify the thread by id or phid. '.
  14        'Otherwise, specify limit and offset to query the most recent '.
  15        'transactions within the conpherence for the logged in user.');
  16    }
  17  
  18    public function defineParamTypes() {
  19      return array(
  20        'threadID' => 'optional int',
  21        'threadPHID' => 'optional phid',
  22        'limit' => 'optional int',
  23        'offset' => 'optional int',
  24      );
  25    }
  26  
  27    public function defineReturnType() {
  28      return 'nonempty dict';
  29    }
  30  
  31    public function defineErrorTypes() {
  32      return array(
  33        'ERR_USAGE_NO_THREAD_ID' => pht(
  34          'You must specify a thread id or thread phid to query transactions '.
  35          'from.'),
  36      );
  37    }
  38  
  39    protected function execute(ConduitAPIRequest $request) {
  40      $user = $request->getUser();
  41      $thread_id = $request->getValue('threadID');
  42      $thread_phid = $request->getValue('threadPHID');
  43      $limit = $request->getValue('limit');
  44      $offset = $request->getValue('offset');
  45  
  46      $query = id(new ConpherenceThreadQuery())
  47        ->setViewer($user);
  48  
  49      if ($thread_id) {
  50        $query->withIDs(array($thread_id));
  51      } else if ($thread_phid) {
  52        $query->withPHIDs(array($thread_phid));
  53      } else {
  54        throw new ConduitException('ERR_USAGE_NO_THREAD_ID');
  55      }
  56  
  57      $conpherence = $query->executeOne();
  58  
  59      $query = id(new ConpherenceTransactionQuery())
  60        ->setViewer($user)
  61        ->withObjectPHIDs(array($conpherence->getPHID()))
  62        ->setLimit($limit)
  63        ->setOffset($offset);
  64  
  65      $transactions = $query->execute();
  66  
  67      $data = array();
  68      foreach ($transactions as $transaction) {
  69        $comment = null;
  70        $comment_obj = $transaction->getComment();
  71        if ($comment_obj) {
  72          $comment = $comment_obj->getContent();
  73        }
  74        $title = null;
  75        $title_obj = $transaction->getTitle();
  76        if ($title_obj) {
  77          $title = $title_obj->getHTMLContent();
  78        }
  79        $id = $transaction->getID();
  80        $data[$id] = array(
  81          'transactionID' => $id,
  82          'transactionType' => $transaction->getTransactionType(),
  83          'transactionTitle' => $title,
  84          'transactionComment' => $comment,
  85          'transactionOldValue' => $transaction->getOldValue(),
  86          'transactionNewValue' => $transaction->getNewValue(),
  87          'transactionMetadata' => $transaction->getMetadata(),
  88          'authorPHID' => $transaction->getAuthorPHID(),
  89          'dateCreated' => $transaction->getDateCreated(),
  90          'conpherenceID' => $conpherence->getID(),
  91          'conpherencePHID' => $conpherence->getPHID(),
  92        );
  93      }
  94      return $data;
  95    }
  96  
  97  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1