[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/macro/controller/ -> PhabricatorMacroAudioController.php (source)

   1  <?php
   2  
   3  final class PhabricatorMacroAudioController extends PhabricatorMacroController {
   4  
   5    private $id;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->id = idx($data, 'id');
   9    }
  10  
  11    public function processRequest() {
  12      $this->requireApplicationCapability(
  13        PhabricatorMacroManageCapability::CAPABILITY);
  14  
  15      $request = $this->getRequest();
  16      $viewer = $request->getUser();
  17  
  18      $macro = id(new PhabricatorMacroQuery())
  19        ->setViewer($viewer)
  20        ->requireCapabilities(
  21          array(
  22            PhabricatorPolicyCapability::CAN_VIEW,
  23          ))
  24        ->withIDs(array($this->id))
  25        ->executeOne();
  26  
  27      if (!$macro) {
  28        return new Aphront404Response();
  29      }
  30  
  31      $errors = array();
  32      $view_uri = $this->getApplicationURI('/view/'.$macro->getID().'/');
  33  
  34      $e_file = null;
  35      $file = null;
  36  
  37      if ($request->isFormPost()) {
  38        $xactions = array();
  39  
  40        if ($request->getBool('behaviorForm')) {
  41          $xactions[] = id(new PhabricatorMacroTransaction())
  42            ->setTransactionType(
  43              PhabricatorMacroTransactionType::TYPE_AUDIO_BEHAVIOR)
  44            ->setNewValue($request->getStr('audioBehavior'));
  45        } else {
  46          $file = null;
  47          if ($request->getFileExists('file')) {
  48            $file = PhabricatorFile::newFromPHPUpload(
  49              $_FILES['file'],
  50              array(
  51                'name' => $request->getStr('name'),
  52                'authorPHID' => $viewer->getPHID(),
  53                'isExplicitUpload' => true,
  54              ));
  55          }
  56  
  57          if ($file) {
  58            if (!$file->isAudio()) {
  59              $errors[] = pht('You must upload audio.');
  60              $e_file = pht('Invalid');
  61            } else {
  62              $xactions[] = id(new PhabricatorMacroTransaction())
  63                ->setTransactionType(PhabricatorMacroTransactionType::TYPE_AUDIO)
  64                ->setNewValue($file->getPHID());
  65            }
  66          } else {
  67            $errors[] = pht('You must upload an audio file.');
  68            $e_file = pht('Required');
  69          }
  70        }
  71  
  72        if (!$errors) {
  73          id(new PhabricatorMacroEditor())
  74            ->setActor($viewer)
  75            ->setContinueOnNoEffect(true)
  76            ->setContentSourceFromRequest($request)
  77            ->applyTransactions($macro, $xactions);
  78  
  79          return id(new AphrontRedirectResponse())->setURI($view_uri);
  80        }
  81      }
  82  
  83      $form = id(new AphrontFormView())
  84        ->addHiddenInput('behaviorForm', 1)
  85        ->setUser($viewer);
  86  
  87      $options = id(new AphrontFormRadioButtonControl())
  88        ->setLabel(pht('Audio Behavior'))
  89        ->setName('audioBehavior')
  90        ->setValue(
  91          nonempty(
  92            $macro->getAudioBehavior(),
  93            PhabricatorFileImageMacro::AUDIO_BEHAVIOR_NONE));
  94  
  95      $options->addButton(
  96        PhabricatorFileImageMacro::AUDIO_BEHAVIOR_NONE,
  97        pht('Do Not Play'),
  98        pht('Do not play audio.'));
  99  
 100      $options->addButton(
 101        PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE,
 102        pht('Play Once'),
 103        pht('Play audio once, when the viewer looks at the macro.'));
 104  
 105      $options->addButton(
 106        PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP,
 107        pht('Play Continuously'),
 108        pht(
 109          'Play audio continuously, treating the macro as an audio source. '.
 110          'Best for ambient sounds.'));
 111  
 112      $form->appendChild($options);
 113  
 114      $form
 115        ->appendChild(
 116          id(new AphrontFormSubmitControl())
 117            ->setValue(pht('Save Audio Behavior'))
 118            ->addCancelButton($view_uri));
 119  
 120      $crumbs = $this->buildApplicationCrumbs();
 121  
 122      $title = pht('Edit Audio Behavior');
 123      $crumb = pht('Edit Audio');
 124  
 125      $crumbs->addTextCrumb(pht('Macro "%s"', $macro->getName()), $view_uri);
 126      $crumbs->addTextCrumb($crumb, $request->getRequestURI());
 127  
 128      $upload_form = id(new AphrontFormView())
 129        ->setEncType('multipart/form-data')
 130        ->setUser($viewer)
 131        ->appendChild(
 132          id(new AphrontFormFileControl())
 133            ->setLabel(pht('Audio File'))
 134            ->setName('file'))
 135        ->appendChild(
 136          id(new AphrontFormSubmitControl())
 137            ->setValue(pht('Upload File')));
 138  
 139      $upload = id(new PHUIObjectBoxView())
 140        ->setHeaderText(pht('Upload New Audio'))
 141        ->setForm($upload_form);
 142  
 143      $form_box = id(new PHUIObjectBoxView())
 144        ->setHeaderText($title)
 145        ->setFormErrors($errors)
 146        ->setForm($form);
 147  
 148      return $this->buildApplicationPage(
 149        array(
 150          $crumbs,
 151          $form_box,
 152          $upload,
 153        ),
 154        array(
 155          'title' => $title,
 156        ));
 157    }
 158  
 159  }


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