[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diviner/controller/ -> DivinerFindController.php (source)

   1  <?php
   2  
   3  final class DivinerFindController extends DivinerController {
   4  
   5    public function shouldAllowPublic() {
   6      return true;
   7    }
   8  
   9    public function processRequest() {
  10      $request = $this->getRequest();
  11      $viewer = $request->getUser();
  12  
  13      $book_name = $request->getStr('book');
  14      $query_text = $request->getStr('name');
  15  
  16      $book = null;
  17      if ($book_name) {
  18        $book = id(new DivinerBookQuery())
  19          ->setViewer($viewer)
  20          ->withNames(array($book_name))
  21          ->executeOne();
  22        if (!$book) {
  23          return new Aphront404Response();
  24        }
  25      }
  26  
  27      $query = id(new DivinerAtomQuery())
  28        ->setViewer($viewer);
  29  
  30      if ($book) {
  31        $query->withBookPHIDs(array($book->getPHID()));
  32      }
  33  
  34      $context = $request->getStr('context');
  35      if (strlen($context)) {
  36        $query->withContexts(array($context));
  37      }
  38  
  39      $type = $request->getStr('type');
  40      if (strlen($type)) {
  41        $query->withTypes(array($type));
  42      }
  43  
  44      $name_query = clone $query;
  45  
  46      $name_query->withNames(
  47        array(
  48          $query_text,
  49          // TODO: This could probably be more smartly normalized in the DB,
  50          // but just fake it for now.
  51          phutil_utf8_strtolower($query_text),
  52        ));
  53  
  54      $atoms = $name_query->execute();
  55  
  56      if (!$atoms) {
  57        $title_query = clone $query;
  58        $title_query->withTitles(array($query_text));
  59        $atoms = $title_query->execute();
  60      }
  61  
  62      $not_found_uri = $this->getApplicationURI();
  63  
  64      if (!$atoms) {
  65        $dialog = id(new AphrontDialogView())
  66          ->setUser($viewer)
  67          ->setTitle(pht('Documentation Not Found'))
  68          ->appendChild(
  69            pht(
  70              'Unable to find the specified documentation. You may have '.
  71              'followed a bad or outdated link.'))
  72          ->addCancelButton($not_found_uri, pht('Read More Documentation'));
  73  
  74        return id(new AphrontDialogResponse())->setDialog($dialog);
  75      }
  76  
  77      if (count($atoms) == 1 && $request->getBool('jump')) {
  78        $atom_uri = head($atoms)->getURI();
  79        return id(new AphrontRedirectResponse())->setURI($atom_uri);
  80      }
  81  
  82      $list = $this->renderAtomList($atoms);
  83  
  84      return $this->buildApplicationPage(
  85        $list,
  86        array(
  87          'title' => array(pht('Find'), pht('"%s"', $query_text)),
  88        ));
  89    }
  90  
  91  }


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