[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/flag/conduit/ -> FlagEditConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class FlagEditConduitAPIMethod extends FlagConduitAPIMethod {
   4  
   5    public function getAPIMethodName() {
   6      return 'flag.edit';
   7    }
   8  
   9    public function getMethodDescription() {
  10      return 'Create or modify a flag.';
  11    }
  12  
  13    public function defineParamTypes() {
  14      return array(
  15        'objectPHID' => 'required phid',
  16        'color'      => 'optional int',
  17        'note'       => 'optional string',
  18      );
  19    }
  20  
  21    public function defineReturnType() {
  22      return 'dict';
  23    }
  24  
  25    public function defineErrorTypes() {
  26      return array(
  27      );
  28    }
  29  
  30    protected function execute(ConduitAPIRequest $request) {
  31      $user = $request->getUser()->getPHID();
  32      $phid = $request->getValue('objectPHID');
  33      $new = false;
  34  
  35      $flag = id(new PhabricatorFlag())->loadOneWhere(
  36        'objectPHID = %s AND ownerPHID = %s',
  37        $phid,
  38        $user);
  39      if ($flag) {
  40        $params = $request->getAllParameters();
  41        if (isset($params['color'])) {
  42          $flag->setColor($params['color']);
  43        }
  44        if (isset($params['note'])) {
  45          $flag->setNote($params['note']);
  46        }
  47      } else {
  48        $default_color = PhabricatorFlagColor::COLOR_BLUE;
  49        $flag = id(new PhabricatorFlag())
  50          ->setOwnerPHID($user)
  51          ->setType(phid_get_type($phid))
  52          ->setObjectPHID($phid)
  53          ->setReasonPHID($user)
  54          ->setColor($request->getValue('color', $default_color))
  55          ->setNote($request->getValue('note', ''));
  56        $new = true;
  57      }
  58      $this->attachHandleToFlag($flag, $request->getUser());
  59      $flag->save();
  60      $ret = $this->buildFlagInfoDictionary($flag);
  61      $ret['new'] = $new;
  62      return $ret;
  63    }
  64  
  65  }


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