Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/conduit/HeraldQueryRulesConduitAPIMethod.php
- This file was added.
<?php | |||||
final class HeraldQueryRulesConduitAPIMethod | |||||
extends HeraldConduitAPIMethod { | |||||
public function getAPIMethodName() { | |||||
return 'herald.queryrules'; | |||||
} | |||||
public function getMethodDescription() { | |||||
return pht('Execute searches for Herald rules.'); | |||||
} | |||||
private function getRuleTypes() { | |||||
return array( | |||||
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL, | |||||
HeraldRuleTypeConfig::RULE_TYPE_GLOBAL, | |||||
HeraldRuleTypeConfig::RULE_TYPE_OBJECT, | |||||
); | |||||
} | |||||
public function defineParamTypes() { | |||||
return array( | |||||
'ids' => 'optional list<id>', | |||||
'phids' => 'optional list<phid>', | |||||
'authorPHIDs' => 'optional list<phid>', | |||||
'contentTypes' => 'optional list<string>', | |||||
'ruleTypes' => 'optional list<string> (' | |||||
.implode(', ', $this->getRuleTypes()).')', | |||||
'needConditionsAndActions' => 'optional int<0|1> (default = 0)', | |||||
) + self::getPagerParamTypes(); | |||||
} | |||||
public function defineReturnType() { | |||||
return 'list<wild>'; | |||||
} | |||||
public function defineErrorTypes() { | |||||
return array(); | |||||
} | |||||
protected function execute(ConduitAPIRequest $request) { | |||||
$viewer = $request->getUser(); | |||||
$this->requireApplicationCapability( | |||||
HeraldManageGlobalRulesCapability::CAPABILITY, $viewer); | |||||
$query = id(new HeraldRuleQuery()) | |||||
->setViewer($viewer); | |||||
$ids = $request->getValue('ids'); | |||||
if ($ids !== null) { | |||||
$query->withIDs($ids); | |||||
} | |||||
$phids = $request->getValue('phids'); | |||||
if ($phids !== null) { | |||||
$query->withPHIDs($phids); | |||||
} | |||||
$author_phids = $request->getValue('authorPHIDs'); | |||||
if ($author_phids !== null) { | |||||
$query->withAuthorPHIDs($author_phids); | |||||
} | |||||
$content_types = $request->getValue('contentTypes'); | |||||
if ($content_types !== null) { | |||||
$query->withContentTypes($content_types); | |||||
} | |||||
$rule_types = $request->getValue('ruleTypes'); | |||||
if ($rule_types !== null) { | |||||
$query->withRuleTypes($rule_types); | |||||
} | |||||
$need_conditions_and_actions = | |||||
(bool) $request->getValue('needConditionsAndActions', false); | |||||
if (true === $need_conditions_and_actions) { | |||||
$query->needConditionsAndActions(true); | |||||
} | |||||
$pager = $this->newPager($request); | |||||
$results = $query->executeWithCursorPager($pager); | |||||
$rules = $this->buildRuleInfoDictionaries( | |||||
$results, $need_conditions_and_actions); | |||||
$result = array( | |||||
'data' => $rules, | |||||
); | |||||
return $this->addPagerResults($result, $pager); | |||||
} | |||||
} |