protected function loadPage()
 {
     $table = new PhortuneAccount();
     $conn = $table->establishConnection('r');
     $rows = queryfx_all($conn, 'SELECT a.* FROM %T a %Q %Q %Q %Q', $table->getTableName(), $this->buildJoinClause($conn), $this->buildWhereClause($conn), $this->buildOrderClause($conn), $this->buildLimitClause($conn));
     return $table->loadAllFromArray($rows);
 }
 protected function addAccountCrumb($crumbs, PhortuneAccount $account, $link = true)
 {
     $name = pht('Account');
     $href = null;
     if ($link) {
         $href = $this->getApplicationURI($account->getID() . '/');
         $crumbs->addTextCrumb($name, $href);
     } else {
         $crumbs->addTextCrumb($name);
     }
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     if ($id) {
         $account = id(new PhortuneAccountQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$account) {
             return new Aphront404Response();
         }
         $is_new = false;
     } else {
         $account = PhortuneAccount::initializeNewAccount($viewer);
         $account->attachMemberPHIDs(array($viewer->getPHID()));
         $is_new = true;
     }
     $v_name = $account->getName();
     $e_name = true;
     $v_members = $account->getMemberPHIDs();
     $e_members = null;
     $validation_exception = null;
     if ($request->isFormPost()) {
         $v_name = $request->getStr('name');
         $v_members = $request->getArr('memberPHIDs');
         $type_name = PhortuneAccountTransaction::TYPE_NAME;
         $type_edge = PhabricatorTransactions::TYPE_EDGE;
         $xactions = array();
         $xactions[] = id(new PhortuneAccountTransaction())->setTransactionType($type_name)->setNewValue($v_name);
         $xactions[] = id(new PhortuneAccountTransaction())->setTransactionType($type_edge)->setMetadataValue('edge:type', PhortuneAccountHasMemberEdgeType::EDGECONST)->setNewValue(array('=' => array_fuse($v_members)));
         $editor = id(new PhortuneAccountEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true);
         try {
             $editor->applyTransactions($account, $xactions);
             $account_uri = $this->getApplicationURI($account->getID() . '/');
             return id(new AphrontRedirectResponse())->setURI($account_uri);
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
             $e_name = $ex->getShortMessage($type_name);
             $e_members = $ex->getShortMessage($type_edge);
         }
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->setBorder(true);
     if ($is_new) {
         $cancel_uri = $this->getApplicationURI('account/');
         $crumbs->addTextCrumb(pht('Accounts'), $cancel_uri);
         $crumbs->addTextCrumb(pht('Create Account'));
         $title = pht('Create Payment Account');
         $submit_button = pht('Create Account');
     } else {
         $cancel_uri = $this->getApplicationURI($account->getID() . '/');
         $crumbs->addTextCrumb($account->getName(), $cancel_uri);
         $crumbs->addTextCrumb(pht('Edit'));
         $title = pht('Edit %s', $account->getName());
         $submit_button = pht('Save Changes');
     }
     $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setName('name')->setLabel(pht('Name'))->setValue($v_name)->setError($e_name))->appendControl(id(new AphrontFormTokenizerControl())->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('Members'))->setName('memberPHIDs')->setValue($v_members)->setError($e_members))->appendChild(id(new AphrontFormSubmitControl())->setValue($submit_button)->addCancelButton($cancel_uri));
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Account'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setValidationException($validation_exception)->setForm($form);
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-pencil');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($box));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $accounts = id(new PhortuneAccountQuery())->setViewer($viewer)->withMemberPHIDs(array($viewer->getPHID()))->execute();
     if (!$accounts) {
         $account = PhortuneAccount::createNewAccount($viewer, PhabricatorContentSource::newFromRequest($request));
         $accounts = array($account);
     }
     if (count($accounts) == 1) {
         $account = head($accounts);
         $next_uri = $this->getApplicationURI($account->getID() . '/');
     } else {
         $next_uri = $this->getApplicationURI('account/');
     }
     return id(new AphrontRedirectResponse())->setURI($next_uri);
 }
 private function buildSubscriptionsSection(PhortuneAccount $account)
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $subscriptions = id(new PhortuneSubscriptionQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->setLimit(10)->execute();
     $subscriptions_uri = $this->getApplicationURI($account->getID() . '/subscription/');
     $handles = $this->loadViewerHandles(mpull($subscriptions, 'getPHID'));
     $table = id(new PhortuneSubscriptionTableView())->setUser($viewer)->setHandles($handles)->setSubscriptions($subscriptions);
     $header = id(new PHUIHeaderView())->setHeader(pht('Recent Subscriptions'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setIcon(id(new PHUIIconView())->setIconFont('fa-list'))->setHref($subscriptions_uri)->setText(pht('View All Subscriptions')));
     return id(new PHUIObjectBoxView())->setHeader($header)->setTable($table);
 }
 private function buildAccountHistorySection(PhortuneAccount $account)
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $header = id(new PHUIHeaderView())->setHeader(pht('Account History'));
     $xactions = id(new PhortuneAccountTransactionQuery())->setViewer($user)->withObjectPHIDs(array($account->getPHID()))->execute();
     $engine = id(new PhabricatorMarkupEngine())->setViewer($user);
     $xaction_view = id(new PhabricatorApplicationTransactionView())->setUser($user)->setObjectPHID($account->getPHID())->setTransactions($xactions)->setMarkupEngine($engine);
     $box = id(new PHUIObjectBoxView())->setHeader($header);
     return array($box, $xaction_view);
 }