1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 19:22:42 +01:00
phorge-phorge/src/applications/conpherence/conduit/ConpherenceQueryThreadConduitAPIMethod.php
epriestley 156b156e77 Give Conduit params/return/errors protected visibility
Summary:
Ref T7803. Ref T5873. I want to drive Conduit through more shared infrastructure, but can't currently add parameters automatically.

Put a `getX()` around the `defineX()` methods so the parent can provide default behaviors.

Also like 60% of methods don't define any special error types; don't require them to implement this method. I want to move away from this in general.

Test Plan:
  - Ran `arc unit --everything`.
  - Called `conduit.query`.
  - Browsed Conduit UI.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: hach-que, epriestley

Maniphest Tasks: T5873, T7803

Differential Revision: https://secure.phabricator.com/D12380
2015-04-13 11:58:35 -07:00

83 lines
2.5 KiB
PHP

<?php
final class ConpherenceQueryThreadConduitAPIMethod
extends ConpherenceConduitAPIMethod {
public function getAPIMethodName() {
return 'conpherence.querythread';
}
public function getMethodDescription() {
return pht(
'Query for conpherence threads for the logged in user. '.
'You can query by ids or phids for specific conpherence threads. '.
'Otherwise, specify limit and offset to query the most recently '.
'updated conpherences for the logged in user.');
}
protected function defineParamTypes() {
return array(
'ids' => 'optional array<int>',
'phids' => 'optional array<phids>',
'limit' => 'optional int',
'offset' => 'optional int',
);
}
protected function defineReturnType() {
return 'nonempty dict';
}
protected function execute(ConduitAPIRequest $request) {
$user = $request->getUser();
$ids = $request->getValue('ids', array());
$phids = $request->getValue('phids', array());
$limit = $request->getValue('limit');
$offset = $request->getValue('offset');
$query = id(new ConpherenceThreadQuery())
->setViewer($user)
->needParticipantCache(true)
->needFilePHIDs(true);
if ($ids) {
$conpherences = $query
->withIDs($ids)
->setLimit($limit)
->setOffset($offset)
->execute();
} else if ($phids) {
$conpherences = $query
->withPHIDs($phids)
->setLimit($limit)
->setOffset($offset)
->execute();
} else {
$participation = id(new ConpherenceParticipantQuery())
->withParticipantPHIDs(array($user->getPHID()))
->setLimit($limit)
->setOffset($offset)
->execute();
$conpherence_phids = array_keys($participation);
$query->withPHIDs($conpherence_phids);
$conpherences = $query->execute();
$conpherences = array_select_keys($conpherences, $conpherence_phids);
}
$data = array();
foreach ($conpherences as $conpherence) {
$id = $conpherence->getID();
$data[$id] = array(
'conpherenceID' => $id,
'conpherencePHID' => $conpherence->getPHID(),
'conpherenceTitle' => $conpherence->getTitle(),
'messageCount' => $conpherence->getMessageCount(),
'recentParticipantPHIDs' => $conpherence->getRecentParticipantPHIDs(),
'filePHIDs' => $conpherence->getFilePHIDs(),
'conpherenceURI' => $this->getConpherenceURI($conpherence),
);
}
return $data;
}
}